From 6cd22c5fa8a94b6e1b8f5e0b7a646f8ccb7b7141 Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Fri, 16 Dec 2022 20:47:24 +0700 Subject: [PATCH] feat: initialize --- .editorconfig | 30 ++++++++++ .github/FUNDING.yml | 2 + .github/workflows/minio.yml | 50 ++++++++++++++++ .github/workflows/redpanda.yml | 50 ++++++++++++++++ .github/workflows/typesense.yml | 50 ++++++++++++++++ LICENSE | 21 +++++++ README.md | 101 ++++++++++++++++++++++++++++++++ minio/Dockerfile | 7 +++ redpanda/Dockerfile | 7 +++ typesense/Dockerfile | 16 +++++ 10 files changed, 334 insertions(+) create mode 100644 .editorconfig create mode 100644 .github/FUNDING.yml create mode 100644 .github/workflows/minio.yml create mode 100644 .github/workflows/redpanda.yml create mode 100644 .github/workflows/typesense.yml create mode 100644 LICENSE create mode 100644 README.md create mode 100644 minio/Dockerfile create mode 100644 redpanda/Dockerfile create mode 100644 typesense/Dockerfile diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..01b9841 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,30 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_style = space +indent_size = 4 +insert_final_newline = true +trim_trailing_whitespace = true + +[*.{json,json5}] +indent_size = 2 + +[*.{yml,yaml}] +indent_size = 2 + +[*.md] +trim_trailing_whitespace = false + +[*.{htm,html,js,ts,tsx,css,sass,scss,less,svg,vue}] +indent_size = 2 + +[*.{xml,config}] +indent_size = 2 + +[*.{cmd,bat}] +end_of_line = crlf + +[*.sh] +end_of_line = lf \ No newline at end of file diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..dfe42b8 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,2 @@ +ko_fi: aldy505 +github: aldy505 diff --git a/.github/workflows/minio.yml b/.github/workflows/minio.yml new file mode 100644 index 0000000..f2254f6 --- /dev/null +++ b/.github/workflows/minio.yml @@ -0,0 +1,50 @@ +name: Minio + +on: + push: + branches: + - master + +env: + REGISTRY: ghcr.io + IMAGE_NAME: minio-ci + +jobs: + build: + name: Build + runs-on: ubuntu-latest + timeout-minutes: 300 + permissions: + contents: read + packages: write + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Log in to the Container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + flavor: | + latest=true + tags: | + type=sha + + - name: Build and push Docker image + uses: docker/build-push-action@v3 + with: + context: "{{defaultContext}}:minio" + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/redpanda.yml b/.github/workflows/redpanda.yml new file mode 100644 index 0000000..8c0bb3d --- /dev/null +++ b/.github/workflows/redpanda.yml @@ -0,0 +1,50 @@ +name: Redpanda + +on: + push: + branches: + - master + +env: + REGISTRY: ghcr.io + IMAGE_NAME: redpanda-ci + +jobs: + build: + name: Build + runs-on: ubuntu-latest + timeout-minutes: 300 + permissions: + contents: read + packages: write + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Log in to the Container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + flavor: | + latest=true + tags: | + type=sha + + - name: Build and push Docker image + uses: docker/build-push-action@v3 + with: + context: "{{defaultContext}}:redpanda" + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/typesense.yml b/.github/workflows/typesense.yml new file mode 100644 index 0000000..9c540b8 --- /dev/null +++ b/.github/workflows/typesense.yml @@ -0,0 +1,50 @@ +name: Typesense + +on: + push: + branches: + - master + +env: + REGISTRY: ghcr.io + IMAGE_NAME: typesense-ci + +jobs: + build: + name: Build + runs-on: ubuntu-latest + timeout-minutes: 300 + permissions: + contents: read + packages: write + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Log in to the Container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + flavor: | + latest=true + tags: | + type=sha + + - name: Build and push Docker image + uses: docker/build-push-action@v3 + with: + context: "{{defaultContext}}:typesense" + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f40888d --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Reinaldy Rafli + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..9592851 --- /dev/null +++ b/README.md @@ -0,0 +1,101 @@ +# Continuous Integration Images + +The story begins as I moved to another company that stores their repository on Github. +Thus, the CI/CD platform will be Github Actions. Well, technically you can use other +CI/CD platforms such as Travis or Circle CI, but Github Actions has been the default +and the go-to of CI/CD runner in 2022, so why not. It's a good platform anyway. + +You can easily run integration tests on your application to execute things directly +to anything (database, message broker, even Hashicorp stuff) if they provide their +Docker image version of the app. The configuration will be as simple as: + +```yaml + logger: + name: Some Go Application + runs-on: ubuntu-latest + container: golang:1.18 + services: + db: + image: influxdb:2.3.0 + env: + DOCKER_INFLUXDB_INIT_MODE: setup + DOCKER_INFLUXDB_INIT_USERNAME: root + DOCKER_INFLUXDB_INIT_PASSWORD: password + DOCKER_INFLUXDB_INIT_ORG: organization + DOCKER_INFLUXDB_INIT_BUCKET: public + DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: random_admin_token_that_is_secret + options: >- + --health-cmd "influx ping" + --health-interval 30s + --health-timeout 10s + --health-retries 5 + --health-start-period 30s + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + - name: Build test + run: go build . + - name: Run test + run: go test -v -race -coverprofile=coverage.out -covermode=atomic + env: + ACCESS_TOKEN: testing + INFLUX_URL: http://db:8086/ + INFLUX_ORG: organization + INFLUX_TOKEN: random_admin_token_that_is_secret +``` + +The problem with that configuration is that, when you have something like MinIO +that requires some command to be executed. So your `docker run` became: +`docker run minio server /data`. The problem with this one is that you can't +give additional command to run on Github Actions container configuration. + +The simple alternative that won't mess with your head is to just create a new image +that is by default sets those additional commands. + +This also comes with a cost: maintaining it. + +This repository aims to fix just that. I can maintain the version and everyone will +be happy because everything is here, alongside with the version. I also don't need +to authenticate to Docker Hub, because Github Packages already did that for me. + +## How to use the packages? + +See the **Packages** section on the right of the repository, click it. + +Then just use it, without any settings. If there are authentication, +there should be a note on the `README.md` of each directory. + +## I want to add another package, yet I'm also lazy on maintaining it. + +Sure, submit a PR that supply a `Dockerfile` and a Github Action workflow file +(inside the `.github/workflows` directory). I'll take a look and merge it. + +## License + +``` +MIT License + +Copyright (c) 2022 Reinaldy Rafli + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +``` + +See [LICENSE](./LICENSE). diff --git a/minio/Dockerfile b/minio/Dockerfile new file mode 100644 index 0000000..e156ba9 --- /dev/null +++ b/minio/Dockerfile @@ -0,0 +1,7 @@ +FROM minio/minio:RELEASE.2022-12-12T19-27-27Z + +RUN mkdir -p /data + +HEALTHCHECK --interval=30s --timeout=20s --start-period=30s --retries=3 CMD [ "curl -f http://localhost:9000/minio/health/live" ] + +CMD [ "minio", "server", "/data" ] diff --git a/redpanda/Dockerfile b/redpanda/Dockerfile new file mode 100644 index 0000000..e6fa255 --- /dev/null +++ b/redpanda/Dockerfile @@ -0,0 +1,7 @@ +FROM docker.redpanda.com/vectorized/redpanda:v22.2.2 + +WORKDIR / + +RUN mkdir -p /var/lib/redpanda/data/ + +CMD ["redpanda", "start", "--smp 1", "--memory 1G", "--reserve-memory 0M", "--overprovisioned", "--node-id 0", "--check=false", "--pandaproxy-addr PLAINTEXT://0.0.0.0:28082,OUTSIDE://0.0.0.0:8082", "--advertise-pandaproxy-addr PLAINTEXT://kafka:28082,OUTSIDE://localhost:8082", "--kafka-addr PLAINTEXT://0.0.0.0:29092,OUTSIDE://0.0.0.0:9092", "--rpc-addr 0.0.0.0:33145", "--advertise-kafka-addr PLAINTEXT://kafka:29092,OUTSIDE://localhost:9092", "--advertise-rpc-addr kafka:33145"] diff --git a/typesense/Dockerfile b/typesense/Dockerfile new file mode 100644 index 0000000..4b47c5a --- /dev/null +++ b/typesense/Dockerfile @@ -0,0 +1,16 @@ +FROM typesense/typesense:0.24.0.rcn43 + +RUN apt-get update && \ + apt-get upgrade -y && \ + apt-get install -y \ + apt-transport-https \ + ca-certificates \ + curl \ + gnupg-agent \ + software-properties-common + +HEALTHCHECK --interval=30s --timeout=15s --start-period=30s --retries=5 CMD [ "curl -f 'http://localhost:8108/health' || exit 1" ] + +EXPOSE 8108 + +ENTRYPOINT ["/opt/typesense-server"]