Skip to content

Commit

Permalink
Support build docker image (#209)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
xiaoyao9184 authored Nov 30, 2023
1 parent 845eee7 commit 5812acc
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
14 changes: 14 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,25 @@ 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:
fetch-depth: 0

- 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:
Expand All @@ -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 }}
38 changes: 37 additions & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
COPY pgroll /usr/bin/pgroll
ENTRYPOINT [ "/usr/bin/pgroll" ]

0 comments on commit 5812acc

Please sign in to comment.