build buildx
parent
0360668cc1
commit
607a2ce7ec
@ -0,0 +1,55 @@
|
||||
name: build-image
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "image-buildx"
|
||||
|
||||
jobs:
|
||||
buildx:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
- uses: docker/setup-qemu-action@v1
|
||||
- uses: docker/setup-buildx-action@v1
|
||||
with:
|
||||
driver-opts: network=host
|
||||
|
||||
- id: prepare
|
||||
name: Build binaries && Prepare
|
||||
env:
|
||||
GITHUB_REF: ${{ github.sha }}
|
||||
GITHUB_SHA: ${{ github.ref }}
|
||||
TARGET_PLATFORMS: linux/amd64,linux/arm64
|
||||
run: |-
|
||||
export TAG=${GITHUB_SHA::7}
|
||||
|
||||
if [[ ${{ github.ref }} == "refs/tags/v"* ]]; then
|
||||
TAG=$(echo ${{ github.ref }} | sed -e "s/refs\/tags\///")
|
||||
fi
|
||||
|
||||
echo ::set-output name=target_platforms::${TARGET_PLATFORMS}
|
||||
echo ::set-output name=tag::${TAG}
|
||||
|
||||
- uses: docker/login-action@v1
|
||||
name: Login docker.io
|
||||
with:
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
registry: docker.io
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
|
||||
- uses: docker/build-push-action@v2
|
||||
name: Build image && May Push
|
||||
with:
|
||||
file: Dockerfile.docker-buildx
|
||||
context: .
|
||||
labels: |-
|
||||
org.opencontainers.image.source=https://github.com/${{ github.repository }}
|
||||
org.opencontainers.image.revision=${{ github.sha }}
|
||||
platforms: ${{ steps.prepare.outputs.target_platforms }}
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: |
|
||||
docker.io/${{ github.repository }}:${{ steps.prepare.outputs.tag }}
|
@ -0,0 +1,22 @@
|
||||
# syntax = docker/dockerfile:experimental
|
||||
|
||||
FROM --platform=${BUILDPLATFORM} golang:1.15.5 AS builder
|
||||
|
||||
WORKDIR /go/src
|
||||
|
||||
COPY ./ ./
|
||||
|
||||
ARG GOPROXY
|
||||
RUN --mount=type=cache,id=gomod,target=/go/pkg/mod go mod download
|
||||
|
||||
ARG TARGETARCH
|
||||
RUN --mount=type=cache,id=gomod,target=/go/pkg/mod CGO_ENABLED=0 GOARCH=${TARGETARCH} go build -o /go/bin/docker-buildx-${TARGETARCH} ./cmd/buildx;
|
||||
|
||||
FROM docker
|
||||
|
||||
RUN apk add --no-cache make
|
||||
|
||||
ARG TARGETARCH
|
||||
COPY --from=builder /go/bin/docker-buildx-${TARGETARCH} /root/.docker/cli-plugins/docker-buildx
|
||||
|
||||
ENV DOCKER_CLI_EXPERIMENTAL=enabled
|
Loading…
Reference in New Issue