Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build docker images with GoReleaser #112

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 0 additions & 35 deletions .github/workflows/cicd-to-dockerhub.yml

This file was deleted.

14 changes: 14 additions & 0 deletions .github/workflows/release_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,25 @@ jobs:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}

- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

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

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@master
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GO_RELEASER_GITHUB_TOKEN }}
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
31 changes: 30 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ builds:
- amd64
- 386
- arm64
env:
- CGO_ENABLED=0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to add this because binaries are now being built on host OS with Go cross-complier and then copy to the Docker image. Therefore, the applications that have been built on e.g. Ubuntu don't run inside Alpine image.
CGO_ENABLED=0 enables static linking for binaries and makes them more portable.

ignore:
- goos: darwin
goarch: 386
Expand All @@ -23,7 +25,34 @@ archives:
format_overrides:
- goos: windows
format: zip

dockers:
- image_templates:
- "{{ .Env.DOCKER_HUB_USERNAME }}/gau:{{ .Tag }}-amd64"
- "{{ .Env.DOCKER_HUB_USERNAME }}/gau:latest-amd64"
use: buildx
goos: linux
goarch: amd64
build_flag_templates:
- "--pull"
- "--platform=linux/amd64"
- image_templates:
- "{{ .Env.DOCKER_HUB_USERNAME }}/gau:{{ .Tag }}-arm64"
- "{{ .Env.DOCKER_HUB_USERNAME }}/gau:latest-arm64"
use: buildx
goos: linux
goarch: arm64
build_flag_templates:
- "--pull"
- "--platform=linux/arm64"
docker_manifests:
- name_template: '{{ .Env.DOCKER_HUB_USERNAME }}/gau:{{ .Tag }}'
image_templates:
- "{{ .Env.DOCKER_HUB_USERNAME }}/gau:{{ .Tag }}-amd64"
- "{{ .Env.DOCKER_HUB_USERNAME }}/gau:{{ .Tag }}-arm64"
- name_template: '{{ .Env.DOCKER_HUB_USERNAME }}/gau:latest'
image_templates:
- "{{ .Env.DOCKER_HUB_USERNAME }}/gau:latest-amd64"
- "{{ .Env.DOCKER_HUB_USERNAME }}/gau:latest-arm64"
signs:
- artifacts: checksum
args: [ "--batch", "-u", "{{ .Env.GPG_FINGERPRINT }}", "--output", "${signature}", "--detach-sign", "${artifact}" ]
12 changes: 1 addition & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
# Build image: golang:1.21.0-alpine3.17
FROM golang:1.21.0-alpine3.17 as build

WORKDIR /app

COPY . .
RUN go mod download && go build -o ./build/gau ./cmd/gau

ENTRYPOINT ["/app/gau/build/gau"]

# Release image: alpine:3.17
FROM alpine:3.17

RUN apk -U upgrade --no-cache
COPY --from=build /app/build/gau /usr/local/bin/gau
COPY gau /usr/local/bin/gau

RUN adduser \
--gecos "" \
Expand Down