Skip to content

Commit

Permalink
feat: Build multi-arch image via goreleaser
Browse files Browse the repository at this point in the history
* push to ghcr
  • Loading branch information
project0 committed Oct 20, 2022
1 parent cc496af commit 8e22372
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 23 deletions.
37 changes: 31 additions & 6 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,47 @@ jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
- name: unshallow
run: git fetch --prune --unshallow
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: set lower case names
run: |
echo "GITHUB_ACTOR_LC=${ACTOR,,}" >>${GITHUB_ENV}
echo "GITHUB_REPO_NAME_LC=${REPO,,}" >>${GITHUB_ENV}
env:
ACTOR: ${{ github.actor }}
REPO: ${{ github.repository }}

- name: setup-go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: 1.18
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

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

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ env.GITHUB_ACTOR_LC }}
password: ${{ secrets.GITHUB_TOKEN }}


- name: capture current date
id: date
run: echo "::set-output name=date::$(date -u '+%Y-%m-%d-%H:%M:%S-%Z')"
- name: goreleaser
uses: goreleaser/goreleaser-action@v2
uses: goreleaser/goreleaser-action@v3
with:
version: latest
args: release --rm-dist
env:
DOCKER_REPO: ghcr.io/${{ env.GITHUB_REPO_NAME_LC }}
DATE: ${{ steps.date.outputs.date }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62 changes: 45 additions & 17 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,57 @@ before:
hooks:
- go mod download
env:
- CGO_ENABLED=0
- GOPROXY=https://proxy.golang.org
- CGO_ENABLED=0
- GOPROXY=https://proxy.golang.org
project_name: athens

builds:
- id: builds
goos:
- linux
- darwin
goarch:
- amd64
- x86_64
main: cmd/proxy/main.go
binary: athens
ldflags:
- -X "github.com/gomods/athens/pkg/build.version={{ .Tag }}"
- -X "github.com/gomods/athens/pkg/build.buildDate={{ .Env.DATE }}"
- id: builds
goos:
- linux
- darwin
goarch:
- amd64
- arm64

main: cmd/proxy/main.go
binary: athens
ldflags:
- -X "github.com/gomods/athens/pkg/build.version={{ .Tag }}"
- -X "github.com/gomods/athens/pkg/build.buildDate={{ .Env.DATE }}"

dockers:
- image_templates:
- "{{ .Env.DOCKER_REPO }}:{{ .Version }}-amd64"
use: buildx
dockerfile: goreleaser.dockerfile
build_flag_templates:
- "--platform=linux/amd64"
extra_files:
- config.dev.toml
- image_templates:
- "{{ .Env.DOCKER_REPO }}:{{ .Version }}-arm64"
use: buildx
goarch: arm64
dockerfile: goreleaser.dockerfile
build_flag_templates:
- "--platform=linux/arm64"
extra_files:
- config.dev.toml

docker_manifests:
- name_template: "{{ .Env.DOCKER_REPO }}:{{ .Version }}"
image_templates:
- "{{ .Env.DOCKER_REPO }}:{{ .Version }}-amd64"
- "{{ .Env.DOCKER_REPO }}:{{ .Version }}-arm64"

checksum:
name_template: 'checksums.txt'
name_template: "checksums.txt"
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
- "^docs:"
- "^test:"
24 changes: 24 additions & 0 deletions goreleaser.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Use by goreleaser
ARG GOLANG_VERSION=1.18
ARG ALPINE_VERSION=3.15

FROM golang:${GOLANG_VERSION}-alpine AS builder

FROM alpine:${ALPINE_VERSION}

ENV GO111MODULE=on
COPY --from=builder /usr/local/go/bin/go /bin/go

COPY athens /bin/athens-proxy
COPY config.dev.toml /config/config.toml

RUN apk add --no-cache --update git git-lfs mercurial openssh-client subversion procps fossil tini && \
mkdir -p /usr/local/go && \
chmod 644 /config/config.toml

# Add tini, see https://github.com/gomods/athens/issues/1155 for details.
EXPOSE 3000

ENTRYPOINT [ "/sbin/tini", "--" ]

CMD ["athens-proxy", "-config_file=/config/config.toml"]

0 comments on commit 8e22372

Please sign in to comment.