Skip to content

Commit

Permalink
Build docker images (#39)
Browse files Browse the repository at this point in the history
Co-authored-by: Norman Gehrsitz <[email protected]>
  • Loading branch information
ngehrsitz and Norman Gehrsitz authored Oct 17, 2023
1 parent 6f9a1fd commit 8313150
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: setup go
uses: actions/setup-go@v4
Expand All @@ -15,11 +18,24 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: v1.21.2
args: release --clean
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
GITHUB_TOKEN: ${{ secrets.github_token }}
53 changes: 53 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,56 @@ archives:
- README.md
- LICENSE

dockers:
- image_templates:
- '{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Tag }}-amd64'
- '{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:latest-amd64'
dockerfile: goreleaser.Dockerfile
use: buildx
goarch: amd64
build_flag_templates:
- "--platform=linux/amd64"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.name={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.source={{.GitURL}}"
- image_templates:
- '{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Tag }}-arm'
- '{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:latest-arm'
dockerfile: goreleaser.Dockerfile
use: buildx
goarch: arm
goarm: 7
build_flag_templates:
- "--platform=linux/arm/v7"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.name={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.source={{.GitURL}}"
- image_templates:
- '{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Tag }}-arm64'
- '{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:latest-arm64'
dockerfile: goreleaser.Dockerfile
use: buildx
goarch: arm64
build_flag_templates:
- "--platform=linux/arm64/v8"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.name={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.source={{.GitURL}}"

docker_manifests:
- name_template: '{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Tag }}'
image_templates:
- '{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Tag }}-amd64'
- '{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Tag }}-arm'
- '{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Tag }}-arm64'
- name_template: '{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:latest'
image_templates:
- '{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:latest-amd64'
- '{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:latest-arm'
- '{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:latest-arm64'
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM golang:1.21 AS binary

WORKDIR /src

COPY . .

RUN CGO_ENABLED=0 go build -o /bin/cob -ldflags "-s -w -extldflags '-static'" .

FROM scratch

COPY --from=binary /bin/cob /bin/cob

ENTRYPOINT ["/bin/cob"]
5 changes: 5 additions & 0 deletions goreleaser.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM scratch

COPY cob /bin/cob

ENTRYPOINT ["/bin/cob"]

0 comments on commit 8313150

Please sign in to comment.