Publish multi-arch image with Docker buildx

This commit is contained in:
stefanprodan
2020-05-20 14:44:23 +03:00
parent 713d1094a2
commit f75f6e9fbc
2 changed files with 28 additions and 10 deletions

20
.github/workflows/build.yml vendored Normal file
View File

@@ -0,0 +1,20 @@
name: build
on:
push:
branches: '*'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: crazy-max/ghaction-docker-buildx@v1
- name: build
run: |
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login --username "${{ secrets.DOCKER_USERNAME }}" --password-stdin
docker buildx build --platform "linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64" \
--output "type=image,push=true" \
--build-arg "REVISION=${GITHUB_SHA::8}" \
--tag "docker.io/stefanprodan/podinfo:multiarch" \
--file Dockerfile .

View File

@@ -1,4 +1,6 @@
FROM golang:1.14 as builder
FROM --platform=${TARGETPLATFORM:-linux/amd64} golang:1.14-alpine as builder
ARG REVISION
RUN mkdir -p /podinfo/
@@ -8,19 +10,15 @@ COPY . .
RUN go mod download
RUN go test -v -race ./...
RUN GIT_COMMIT=$(git rev-list -1 HEAD) && \
CGO_ENABLED=0 GOOS=linux go build -ldflags "-s -w \
-X github.com/stefanprodan/podinfo/pkg/version.REVISION=${GIT_COMMIT}" \
RUN CGO_ENABLED=0 go build -ldflags "-s -w \
-X github.com/stefanprodan/podinfo/pkg/version.REVISION=${REVISION}" \
-a -o bin/podinfo cmd/podinfo/*
RUN GIT_COMMIT=$(git rev-list -1 HEAD) && \
CGO_ENABLED=0 GOOS=linux go build -ldflags "-s -w \
-X github.com/stefanprodan/podinfo/pkg/version.REVISION=${GIT_COMMIT}" \
RUN CGO_ENABLED=0 go build -ldflags "-s -w \
-X github.com/stefanprodan/podinfo/pkg/version.REVISION=${REVISION}" \
-a -o bin/podcli cmd/podcli/*
FROM alpine:3.11
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.11
RUN addgroup -S app \
&& adduser -S -g app app \