Skip to content

Commit

Permalink
chore: use buildx
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Sep 10, 2022
1 parent 8e932de commit efd71d6
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 35 deletions.
25 changes: 12 additions & 13 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,17 @@ jobs:
with:
fetch-depth: 0

# Install Docker image multi-arch builder
- name: Install seihon ${{ env.SEIHON_VERSION }}
run: |
curl -sSfL https://raw.githubusercontent.com/ldez/seihon/master/godownloader.sh | sh -s -- -b $(go env GOPATH)/bin ${SEIHON_VERSION}
seihon --version
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Docker Login
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: |
echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Deploy Docker Images (seihon)
run: make publish-images
# https://goreleaser.com/ci/actions/
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN_REPO }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
vendor/
/whoamiudp
dist/
86 changes: 86 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
project_name: whoamiudp

builds:
- binary: whoamiudp
goos:
- windows
- darwin
- linux
goarch:
- amd64
- arm
- arm64
goarm:
- '7'

changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^doc:'
- '^chore:'
- '^chore(deps):'
- '^test:'
- '^tests:'

archives:
- id: whoamiudp
name_template: '{{ .ProjectName }}_v{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm}}v{{ .Arm }}{{ end }}'
format: tar.gz
format_overrides:
- goos: windows
format: zip
files:
- LICENSE

docker_manifests:
- name_template: 'traefik/whoamiudp:{{ .Tag }}'
image_templates:
- 'traefik/whoamiudp:{{ .Tag }}-amd64'
- 'traefik/whoamiudp:{{ .Tag }}-arm64'
- name_template: 'traefik/whoamiudp:latest'
image_templates:
- 'traefik/whoamiudp:{{ .Tag }}-amd64'
- 'traefik/whoamiudp:{{ .Tag }}-arm64'
- name_template: 'traefik/whoamiudp:v{{ .Major }}.{{ .Minor }}'
image_templates:
- 'traefik/whoamiudp:v{{ .Major }}.{{ .Minor }}-amd64'
- 'traefik/whoamiudp:v{{ .Major }}.{{ .Minor }}-arm64'

dockers:
- use: buildx
goos: linux
goarch: amd64
dockerfile: buildx.Dockerfile
image_templates:
- 'traefik/whoamiudp:latest-amd64'
- 'traefik/whoamiudp:{{ .Tag }}-amd64'
- 'traefik/whoamiudp:v{{ .Major }}.{{ .Minor }}-amd64'
build_flag_templates:
- '--pull'
- '--label=org.opencontainers.image.description=Tiny Go UDP server that prints OS information and request to output'
- '--label=org.opencontainers.image.created={{.Date}}'
- '--label=org.opencontainers.image.title={{.ProjectName}}'
- '--label=org.opencontainers.image.revision={{.FullCommit}}'
- '--label=org.opencontainers.image.version={{.Version}}'
- '--label=org.opencontainers.image.source={{.GitURL}}'
- '--platform=linux/amd64'

- use: buildx
goos: linux
goarch: arm64
dockerfile: buildx.Dockerfile
image_templates:
- 'traefik/whoamiudp:latest-arm64'
- 'traefik/whoamiudp:{{ .Tag }}-arm64'
- 'traefik/whoamiudp:v{{ .Major }}.{{ .Minor }}-arm64'
build_flag_templates:
- '--pull'
- '--label=org.opencontainers.image.description=Tiny Go UDP server that prints OS information and request to output'
- '--label=org.opencontainers.image.created={{.Date}}'
- '--label=org.opencontainers.image.title={{.ProjectName}}'
- '--label=org.opencontainers.image.revision={{.FullCommit}}'
- '--label=org.opencontainers.image.version={{.Version}}'
- '--label=org.opencontainers.image.source={{.GitURL}}'
- '--platform=linux/arm64'
12 changes: 2 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
.PHONY: default check test build image publish-images

TAG_NAME := $(shell git tag -l --contains HEAD)
.PHONY: default check test build image

IMAGE_NAME := traefik/whoamiudp

default: check test build

clean:
rm -rf cover.out

build: clean
build:
CGO_ENABLED=0 go build -v --trimpath .

test:
Expand All @@ -20,6 +15,3 @@ check:

image:
docker build -t $(IMAGE_NAME) .

publish-images:
seihon publish -v "$(TAG_NAME)" -v "latest" --image-name $(IMAGE_NAME) --dry-run=false
17 changes: 5 additions & 12 deletions tmpl.Dockerfile → buildx.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
# syntax=docker/dockerfile:1.2
FROM golang:1-alpine as builder

RUN apk --no-cache --no-progress add git ca-certificates tzdata make \
&& update-ca-certificates \
&& rm -rf /var/cache/apk/*

WORKDIR /go/whoamiudp

# Download go modules
COPY go.mod .
#COPY go.sum .
RUN GO111MODULE=on GOPROXY=https://proxy.golang.org go mod download

COPY . .
RUN GOARCH={{ .GoARCH }} GOARM={{ .GoARM }} make build

# syntax=docker/dockerfile:1.2
# Create a minimal container to run a Golang static binary
FROM scratch

COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /go/whoamiudp/whoamiudp .
COPY whoamiudp /

ENTRYPOINT ["/whoamiudp"]
EXPOSE 8080
EXPOSE 80

0 comments on commit efd71d6

Please sign in to comment.