diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml new file mode 100644 index 0000000..85f4b5b --- /dev/null +++ b/.github/workflows/push.yml @@ -0,0 +1,21 @@ +name: multi-arch-build + +on: + push: + tags: '*' + +jobs: + build-push: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: crazy-max/ghaction-docker-buildx@v1 + - name: buildx + 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}" \ + --tag "docker.io/stefanprodan/podinfo:${GITHUB_REF#refs/tags/}" \ + --tag "docker.io/stefanprodan/podinfo:latest" \ + --file Dockerfile . diff --git a/Dockerfile b/Dockerfile index f0fd5ca..becd468 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,6 @@ -FROM golang:1.14 as builder +FROM golang:1.14-alpine as builder + +ARG REVISION RUN mkdir -p /podinfo/ @@ -8,16 +10,12 @@ 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 diff --git a/README.md b/README.md index 581b7cb..2cd0008 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ Specifications: * Helm and Kustomize installers * End-to-End testing with Kubernetes Kind and Helm * Kustomize testing with GitHub Actions and Open Policy Agent +* Multi-arch container image with Docker buildx and Github Actions Web API: diff --git a/e2e/build.sh b/e2e/build.sh index 9b6523c..ed856e8 100755 --- a/e2e/build.sh +++ b/e2e/build.sh @@ -2,5 +2,7 @@ set -o errexit -docker build -t test/podinfo:latest . +GIT_COMMIT=$(git rev-list -1 HEAD) + +docker build -t test/podinfo:latest --build-arg "REVISION=${GIT_COMMIT}" .