From 8d451b6b06137ec76e021971137c9bb63fd4e4ce Mon Sep 17 00:00:00 2001 From: Rick <1450685+LinuxSuRen@users.noreply.github.com> Date: Thu, 27 May 2021 11:19:32 +0800 Subject: [PATCH] Add GitHub action to build multi-arch image (#153) Signed-off-by: rick Co-authored-by: rick --- .github/workflows/build.yaml | 86 ++++++++++++++++++++++++++++++++++++ Makefile | 3 ++ deploy/Dockerfile.multiarch | 12 +++++ 3 files changed, 101 insertions(+) create mode 100644 .github/workflows/build.yaml create mode 100644 deploy/Dockerfile.multiarch diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 00000000..ac16cc68 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,86 @@ +name: Image Build + +on: + push: + branches: + - master + - test-* # make it be easier for contributors to test + tags: + - 'v*.*.*' + pull_request: + branches: + - 'master' + +jobs: + Build: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + - name: Docker meta for KubeSphere + id: meta + if: github.repository_owner == 'kubesphere' + uses: docker/metadata-action@v3 + with: + images: | + kubespheredev/s2ioperator + ghcr.io/${{ github.repository_owner }}/s2ioperator + tags: | + type=schedule + type=ref,event=branch + type=ref,event=pr + type=semver,pattern=v{{version}} + type=semver,pattern=v{{major}}.{{minor}} + type=semver,pattern=v{{major}} + type=sha + - name: Docker meta for Contributors + id: metaContributors + if: github.repository_owner != 'kubesphere' + uses: docker/metadata-action@v3 + with: + images: | + ghcr.io/${{ github.repository_owner }}/s2ioperator + tags: | + type=schedule + type=ref,event=branch + type=ref,event=pr + type=semver,pattern=v{{version}} + type=semver,pattern=v{{major}}.{{minor}} + type=semver,pattern=v{{major}} + type=sha + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - name: Set up 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_HUB_USER }} + password: ${{ secrets.DOCKER_HUB_SECRETS }} + - name: Login to GHCR + if: github.event_name != 'pull_request' + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GHCR_TOKEN }} + - name: Build and push Docker images + uses: docker/build-push-action@v2.4.0 + if: github.repository_owner == 'kubesphere' + with: + context: . + file: deploy/Dockerfile.multiarch + tags: ${{ steps.meta.outputs.tags }} + push: ${{ github.event_name != 'pull_request' }} + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64,linux/arm64 + - name: Build and push Docker images for Contributors + uses: docker/build-push-action@v2.4.0 + if: github.repository_owner != 'kubesphere' + with: + context: . + file: deploy/Dockerfile.multiarch + tags: ${{ steps.metaContributors.outputs.tags }} + push: ${{ github.event_name != 'pull_request' }} + labels: ${{ steps.metaContributors.outputs.labels }} + platforms: linux/amd64,linux/arm64 diff --git a/Makefile b/Makefile index 724e50d6..51e720b5 100644 --- a/Makefile +++ b/Makefile @@ -54,6 +54,9 @@ docker-build: docker build -f deploy/Dockerfile -t $(IMG) bin/ docker push $(IMG) +image-multiarch: + docker build . -t $(IMG) -f deploy/Dockerfile.multiarch + debug: manager ./hack/build-image.sh diff --git a/deploy/Dockerfile.multiarch b/deploy/Dockerfile.multiarch new file mode 100644 index 00000000..20aa6fd0 --- /dev/null +++ b/deploy/Dockerfile.multiarch @@ -0,0 +1,12 @@ +FROM golang:1.12 AS builder + +WORKDIR /work +COPY . . +RUN CGO_ENABLED=0 go build -ldflags "-w" -o bin/manager \ + github.com/kubesphere/s2ioperator/cmd/manager + +FROM alpine:3.10 + +WORKDIR / +COPY --from=builder /work/bin/manager manager +ENTRYPOINT ["/manager"]