Skip to content

Commit

Permalink
Merge pull request #8 from narqo/docker-multiplatform
Browse files Browse the repository at this point in the history
ci: build multi-platform docker image
  • Loading branch information
narqo authored Sep 22, 2020
2 parents 6501b08 + db06b48 commit 3a7b4b5
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 28 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/dist
53 changes: 39 additions & 14 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,60 @@ name: Github Weather Release
on:
push:
tags:
- '*'
- 'v*'

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Setup vars
id: vars
run: echo ::set-output name=tag::${GITHUB_REF#refs/tags/v}

- name: Checkout
uses: actions/checkout@v2

- name: Unshallow
run: git fetch --prune --unshallow
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v1
uses: actions/setup-go@v2
with:
go-version: 1.14.x
go-version: 1.15.x

- name: Docker Login Hub
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: >-
echo "${{ secrets.DOCKER_PASSWORD }}"
| docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
- name: Set up QEMU
uses: docker/setup-qemu-action@v1

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

- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v1
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: --debug
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Build and Push to DockerHub
id: docker_build
uses: docker/build-push-action@v2
with:
builder: ${{ steps.docker_buildx.outputs.name }}
context: .
file: ./Dockerfile
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x
push: ${{ github.event_name != 'pull_request' }}
tags: |
docker.io/varankinv/github-weather:latest
docker.io/varankinv/github-weather:${{ steps.vars.outputs.tag }}
- name: Show Docker Image Digest
run: echo ${{ steps.docker_build.outputs.digest }}
18 changes: 9 additions & 9 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ builds:
- amd64
- arm
- arm64
checksum:
name_template: '{{ .ProjectName }}_checksums.txt'
dockers:
- image_templates:
- 'docker.io/varankinv/github-weather:{{ .Tag }}'
- 'docker.io/varankinv/github-weather:latest'
dockerfile: Dockerfile
binaries:
- github-weather
archives:
- name_template: '{{ .ProjectName }}_{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
replacements:
amd64: x86_64
checksum:
name_template: '{{ .ProjectName }}_checksums.txt'
# dockers:
# - image_templates:
# - 'docker.io/varankinv/github-weather:{{ .Tag }}'
# - 'docker.io/varankinv/github-weather:latest'
# dockerfile: Dockerfile
# binaries:
# - github-weather
12 changes: 7 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
FROM alpine as build

RUN apk add --update --no-cache ca-certificates
FROM golang:1.15-alpine as builder
RUN apk add --update --no-cache build-base ca-certificates
WORKDIR /go/src/github-weather
COPY . /go/src/github-weather
RUN CGO_ENABLED=0 go build -a -ldflags '-extldflags "-static"' -o bin/github-weather .

FROM scratch
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY github-weather /bin/github-weather
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=builder /go/src/github-weather/bin/github-weather /bin/github-weather
ENTRYPOINT ["/bin/github-weather"]

0 comments on commit 3a7b4b5

Please sign in to comment.