From d114bd40d824cb61de12ed3dfee68bdb651a88b0 Mon Sep 17 00:00:00 2001 From: "Bo-Yi.Wu" Date: Sat, 7 Jan 2023 08:48:06 +0800 Subject: [PATCH] chore(CI): update build docker image Signed-off-by: Bo-Yi.Wu --- .github/workflows/build.yaml | 106 ++++++++++------------------------- 1 file changed, 31 insertions(+), 75 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 6916003..50a1629 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -1,4 +1,4 @@ -name: Release Binary +name: Docker Image on: push: @@ -9,7 +9,19 @@ on: jobs: build: - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} + strategy: + max-parallel: 3 + matrix: + os: [ubuntu-latest] + system: [linux] + arch: [amd64, arm, arm64] + # support windows build and push? + # see the issue: https://github.com/docker/build-push-action/issues/18 + # include: + # - os: windows-2022 + # system: windows + # arch: amd64 steps: - name: Setup go uses: actions/setup-go@v3 @@ -22,17 +34,17 @@ jobs: - name: Build binary run : | - make build_linux_amd64 - make build_linux_arm64 - make build_linux_arm + make build_${{ matrix.system }}_${{ matrix.arch }} - name: Check binary + if: matrix.system == 'linux' && matrix.arch == 'amd64' run : | - ./release/linux/amd64/gorush --help + ./release/${{ matrix.system }}/${{ matrix.arch }}/${GITHUB_REPOSITORY#*/} --help - name: Set up QEMU uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 @@ -53,86 +65,30 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - - name: Docker meta for linux amd64 - id: meta-linux-amd64 + name: Docker meta for ${{ matrix.system }} ${{ matrix.arch }} + id: docker-meta uses: docker/metadata-action@v4 with: flavor: | latest=false - suffix=linux-amd64 + suffix=${{ matrix.system }}-${{ matrix.arch }} images: | - appleboy/gorush - ghcr.io/appleboy/gorush + ${{ github.repository }} + ghcr.io/${{ github.repository }} tags: | type=raw,value=,enable={{is_default_branch}} type=raw,value=latest,suffix=,enable={{is_default_branch}} - type=semver,event=tag,pattern={{version}},suffix=-linux-amd64 - type=semver,event=tag,pattern={{major}}.{{minor}},suffix=-linux-amd64 - type=semver,event=tag,pattern={{major}},suffix=-linux-amd64 + type=semver,event=tag,pattern={{version}},suffix=-${{ matrix.system }}-${{ matrix.arch }} + type=semver,event=tag,pattern={{major}}.{{minor}},suffix=-${{ matrix.system }}-${{ matrix.arch }} + type=semver,event=tag,pattern={{major}},suffix=-${{ matrix.system }}-${{ matrix.arch }} - - name: Build and push linux amd64 + name: Build and push ${{ matrix.system }} ${{ matrix.arch }} uses: docker/build-push-action@v3 with: context: . - file: docker/Dockerfile.linux.amd64 - platforms: linux/amd64 + file: docker/Dockerfile.${{ matrix.system }}.${{ matrix.arch }} + platforms: ${{ matrix.system }}/${{ matrix.arch }} push: true - tags: ${{ steps.meta-linux-amd64.outputs.tags }} - labels: ${{ steps.meta-linux-amd64.outputs.labels }} - - - - name: Docker meta for linux arm64 - id: meta-linux-arm64 - uses: docker/metadata-action@v4 - with: - flavor: | - latest=false - suffix=linux-arm64 - images: | - appleboy/gorush - ghcr.io/appleboy/gorush - tags: | - type=raw,value=,enable={{is_default_branch}} - type=semver,event=tag,pattern={{version}},suffix=-linux-arm64 - type=semver,event=tag,pattern={{major}}.{{minor}},suffix=-linux-arm64 - type=semver,event=tag,pattern={{major}},suffix=-linux-arm64 - - - - name: Build and push linux arm64 - uses: docker/build-push-action@v3 - with: - context: . - file: docker/Dockerfile.linux.arm64 - platforms: linux/arm64 - push: true - tags: ${{ steps.meta-linux-arm64.outputs.tags }} - labels: ${{ steps.meta-linux-arm64.outputs.labels }} - - - - name: Docker meta for linux arm - id: meta-linux-arm - uses: docker/metadata-action@v4 - with: - flavor: | - latest=false - suffix=linux-arm - images: | - appleboy/gorush - ghcr.io/appleboy/gorush - tags: | - type=raw,value=,enable={{is_default_branch}} - type=semver,event=tag,pattern={{version}},suffix=-linux-arm - type=semver,event=tag,pattern={{major}}.{{minor}},suffix=-linux-arm - type=semver,event=tag,pattern={{major}},suffix=-linux-arm - - - - name: Build and push linux arm - uses: docker/build-push-action@v3 - with: - context: . - file: docker/Dockerfile.linux.arm - platforms: linux/arm - push: true - tags: ${{ steps.meta-linux-arm.outputs.tags }} - labels: ${{ steps.meta-linux-arm.outputs.labels }} + tags: ${{ steps.docker-meta.outputs.tags }} + labels: ${{ steps.docker-meta.outputs.labels }}