From b8b85ce911af65699a5a90dca8748ff8a1b7c171 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Mon, 18 Jul 2022 19:14:42 +0300 Subject: [PATCH] workflows/Makefile: build Docker image for MacOS We build multiarch linux/amd64 and linux/arm64, because MacOS runner can't build docker images and even if it could that'd be linux/amd64 while we want linux/arm64 for Apple CPUs. Unfortunately, given the way GitHub workflows work we can't avoid using a Makefile helper, there is no easy way to set variables conditionally and/or use some logic to affect their contents. We reintroduce build_image_wsc as well here because Windows images can't be built with buildx using GitHub runners. --- .github/workflows/build.yml | 40 +++++++++++++++++++++++++++++++++---- Makefile | 11 +++++++++- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 016de7845..003d14989 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -66,10 +66,39 @@ jobs: build_image: needs: build_cli name: Build Docker image - runs-on: ${{matrix.os}} - strategy: - matrix: - os: [ubuntu-20.04, windows-2022] + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v2 + with: + ref: ${{ github.event.inputs.ref }} + fetch-depth: 0 + + - name: Set up QEMU + if: runner.os != 'Windows' + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Set vars + id: setvars + run: make gh-docker-vars + + - name: Build and push + uses: docker/build-push-action@v3 + with: + push: false + platforms: linux/amd64,linux/arm64 + build-args: | + REPO=${{ steps.setvars.outputs.repo }} + VERSION=${{ steps.setvars.outputs.version }} + tags: ${{ steps.setvars.outputs.repo }}:${{ steps.setvars.outputs.version }}${{ steps.setvars.outputs.suffix }} + + build_image_wsc: + needs: build_cli + name: Build Docker image (Windows Server Core) + runs-on: windows-2022 steps: - uses: actions/checkout@v2 @@ -100,6 +129,9 @@ jobs: ref: ${{ github.event.inputs.ref }} fetch-depth: 0 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + # For proper `deps` make target execution. - name: Set up Go uses: actions/setup-go@v2 diff --git a/Makefile b/Makefile index dd8bb62ff..3ad6298c0 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ IMAGE_REPO=nspccdev/neo-go # All of the targets are phony here because we don't really use make dependency # tracking for files .PHONY: build $(BINARY) deps image docker/$(BINARY) image-latest image-push image-push-latest clean-cluster \ - test vet lint fmt cover + test vet lint fmt cover version gh-docker-vars build: deps @echo "=> Building binary" @@ -92,6 +92,15 @@ deps: @CGO_ENABLED=0 \ go mod tidy -v +version: + @echo $(VERSION) + +gh-docker-vars: + @echo "::set-output name=file::$(D_FILE)" + @echo "::set-output name=version::$(VERSION)" + @echo "::set-output name=repo::$(REPO)" + @echo "::set-output name=suffix::$(IMAGE_SUFFIX)" + test: @go test ./... -cover