From 5812acc886d5c9e1ea411bda4d8305a88e5c3e12 Mon Sep 17 00:00:00 2001 From: xiaoyao9184 <6614349+xiaoyao9184@users.noreply.github.com> Date: Thu, 30 Nov 2023 22:13:07 +0800 Subject: [PATCH] Support build docker image (#209) Build the docker image during release and push to ghcr.io Package results: https://github.com/users/xiaoyao9184/packages/container/package/pgroll There are two modifications for `.goreleaser.yaml`: - Add `DOCKER_USERNAME` environment variable for push customize docker registry. - Add `GITHUB_USERNAME` environment variable for fix unable to update Homebrew Tap. see https://github.com/xiaoyao9184/pgroll/actions/runs/6994513095/job/19028379596#step:8:81 --- .github/workflows/build.yml | 14 ++++++++++++++ .goreleaser.yaml | 38 ++++++++++++++++++++++++++++++++++++- Dockerfile | 3 +++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 Dockerfile diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 975afa1e..2d43e040 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -105,6 +105,8 @@ jobs: runs-on: ubuntu-latest needs: [test, lint, examples, license-check] if: startsWith(github.ref, 'refs/tags/') + env: + DOCKER_CLI_EXPERIMENTAL: "enabled" steps: - uses: actions/checkout@v3 with: @@ -112,6 +114,16 @@ jobs: - run: git fetch --force --tags + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GIT_TOKEN }} + - name: Set up Go uses: actions/setup-go@v4 with: @@ -125,3 +137,5 @@ jobs: args: release --clean env: GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }} + GITHUB_USERNAME: ${{ github.repository_owner }} + DOCKER_USERNAME: ghcr.io/${{ github.repository_owner }} diff --git a/.goreleaser.yaml b/.goreleaser.yaml index f2b3924a..d4625213 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -31,7 +31,7 @@ brews: description: "Postgres zero-downtime migrations made easy" license: "Apache-2.0" repository: - owner: xataio + owner: "{{ .Env.GITHUB_USERNAME }}" name: homebrew-pgroll archives: @@ -47,3 +47,39 @@ changelog: exclude: - "^docs:" - "^test:" + +dockers: + - image_templates: + - "{{ .Env.DOCKER_USERNAME }}/{{ .ProjectName }}:{{ .Tag }}-amd64" + dockerfile: Dockerfile + use: buildx + build_flag_templates: + - --platform=linux/amd64 + - --label=org.opencontainers.image.title={{ .ProjectName }} + - --label=org.opencontainers.image.description={{ .ProjectName }} + - --label=org.opencontainers.image.url=https://github.com/{{ .Env.GITHUB_USERNAME }}/{{ .ProjectName }} + - --label=org.opencontainers.image.source=https://github.com/{{ .Env.GITHUB_USERNAME }}/{{ .ProjectName }} + - --label=org.opencontainers.image.version={{ .Version }} + - --label=org.opencontainers.image.created={{ .Date }} + - --label=org.opencontainers.image.revision={{ .FullCommit }} + - --label=org.opencontainers.image.licenses=AL2.0 + - image_templates: + - "{{ .Env.DOCKER_USERNAME }}/{{ .ProjectName }}:{{ .Tag }}-arm64v8" + goarch: arm64 + dockerfile: Dockerfile + use: buildx + build_flag_templates: + - --platform=linux/arm64/v8 + - --label=org.opencontainers.image.title={{ .ProjectName }} + - --label=org.opencontainers.image.description={{ .ProjectName }} + - --label=org.opencontainers.image.url=https://github.com/{{ .Env.GITHUB_USERNAME }}/{{ .ProjectName }} + - --label=org.opencontainers.image.source=https://github.com/{{ .Env.GITHUB_USERNAME }}/{{ .ProjectName }} + - --label=org.opencontainers.image.version={{ .Version }} + - --label=org.opencontainers.image.created={{ .Date }} + - --label=org.opencontainers.image.revision={{ .FullCommit }} + - --label=org.opencontainers.image.licenses=AL2.0 +docker_manifests: + - name_template: "{{ .Env.DOCKER_USERNAME }}/{{ .ProjectName }}:{{ .Tag }}" + image_templates: + - "{{ .Env.DOCKER_USERNAME }}/{{ .ProjectName }}:{{ .Tag }}-amd64" + - "{{ .Env.DOCKER_USERNAME }}/{{ .ProjectName }}:{{ .Tag }}-arm64v8" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..5591935f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,3 @@ +FROM scratch +COPY pgroll /usr/bin/pgroll +ENTRYPOINT [ "/usr/bin/pgroll" ] \ No newline at end of file