From 37937d8cf519a9da528150128915a81ea4a53aa4 Mon Sep 17 00:00:00 2001 From: Lin Yang Date: Wed, 2 Oct 2024 00:05:07 +0800 Subject: [PATCH] feat: build image on runner of target platform (#368) * feat: build image in runner of target platform Signed-off-by: Lin Yang * fix: runs on Signed-off-by: Lin Yang * fix: runs on Signed-off-by: Lin Yang * fix: runs on Signed-off-by: Lin Yang * fix: runs on Signed-off-by: Lin Yang * fix: runs on Signed-off-by: Lin Yang * fix: runs on Signed-off-by: Lin Yang * fix: runs on Signed-off-by: Lin Yang --------- Signed-off-by: Lin Yang --- .github/workflows/build-pipy-euler.yml | 69 +++++++++++++-------- .github/workflows/build-pipy-nonroot.yml | 78 +++++++++++++----------- 2 files changed, 86 insertions(+), 61 deletions(-) diff --git a/.github/workflows/build-pipy-euler.yml b/.github/workflows/build-pipy-euler.yml index 992a0163..ca5e5266 100644 --- a/.github/workflows/build-pipy-euler.yml +++ b/.github/workflows/build-pipy-euler.yml @@ -9,16 +9,24 @@ on: type: string jobs: - debian: - name: Build pipy euler image - runs-on: ubuntu-22.04 - steps: - - name: Set up QEMU - uses: docker/setup-qemu-action@v3.2.0 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3.6.1 + euler: + name: Build pipy euler images + strategy: + fail-fast: false + matrix: + platform: + - linux/amd64 + - linux/arm64 + include: + - platform: linux/amd64 + runner: ubuntu-latest + suffix: amd64 + - platform: linux/arm64 + runner: [self-hosted, ARM64] + suffix: arm64 + runs-on: ${{ matrix.runner }} + steps: - name: Login to DockerHub uses: docker/login-action@v3.3.0 with: @@ -30,22 +38,31 @@ jobs: with: fetch-depth: 0 - - name: Docker meta - id: docker_meta - uses: crazy-max/ghaction-docker-meta@v5.5.1 - with: - images: flomesh/pipy - tags: | - type=raw,${{ inputs.tag }}-euler - - name: Build and Push - uses: docker/build-push-action@v6.9.0 + run: | + docker build --platform=${{ matrix.platform }} \ + -t flomesh/pipy:${{ inputs.tag }}-euler-${{ matrix.suffix }} \ + -f ./dockerfiles/Dockerfile.euler \ + --build-arg PIPY_VERSION=${{ inputs.tag }} \ + --push . + + manifest: + name: Create Docker manifest + runs-on: ubuntu-22.04 + needs: [ euler ] + steps: + - name: Set up QEMU + uses: docker/setup-qemu-action@v3.2.0 + + - name: Login to DockerHub + uses: docker/login-action@v3.3.0 with: - context: . - file: ./dockerfiles/Dockerfile.euler - platforms: linux/amd64,linux/arm64 - push: true - tags: ${{ steps.docker_meta.outputs.tags }} - labels: ${{ steps.docker_meta.outputs.labels }} - build-args: | - PIPY_VERSION=${{ inputs.tag }} \ No newline at end of file + username: ${{ secrets.RELEASE_DOCKER_USER }} + password: ${{ secrets.RELEASE_DOCKER_PASS }} + + - name: Create Docker manifest + run: | + docker manifest create flomesh/pipy:${{ inputs.tag }}-euler \ + --amend flomesh/pipy:${{ inputs.tag }}-euler-amd64 \ + --amend flomesh/pipy:${{ inputs.tag }}-euler-arm64 + docker manifest push flomesh/pipy:${{ inputs.tag }}-euler \ No newline at end of file diff --git a/.github/workflows/build-pipy-nonroot.yml b/.github/workflows/build-pipy-nonroot.yml index 9259f6b0..0dee6b12 100644 --- a/.github/workflows/build-pipy-nonroot.yml +++ b/.github/workflows/build-pipy-nonroot.yml @@ -10,24 +10,23 @@ on: jobs: debian: - name: Build pipy debian image - runs-on: ubuntu-22.04 - steps: - - name: Increase swapfile - run: | - sudo swapoff -a - sudo fallocate -l 8G /swapfile - sudo chmod 600 /swapfile - sudo mkswap /swapfile - sudo swapon /swapfile - sudo swapon --show - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3.2.0 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3.6.1 + name: Build pipy debian images + strategy: + fail-fast: false + matrix: + platform: + - linux/amd64 + - linux/arm64 + include: + - platform: linux/amd64 + runner: ubuntu-latest + suffix: amd64 + - platform: linux/arm64 + runner: [ self-hosted, ARM64 ] + suffix: arm64 + runs-on: ${{ matrix.runner }} + steps: - name: Login to DockerHub uses: docker/login-action@v3.3.0 with: @@ -39,30 +38,39 @@ jobs: with: fetch-depth: 0 - - name: Docker meta - id: docker_meta - uses: crazy-max/ghaction-docker-meta@v5.5.1 - with: - images: flomesh/pipy - tags: | - type=raw,${{ inputs.tag }}-debian - - name: Build and Push - uses: docker/build-push-action@v6.9.0 + run: | + docker build --platform=${{ matrix.platform }} \ + -t flomesh/pipy:${{ inputs.tag }}-debian-${{ matrix.suffix }} \ + -f ./dockerfiles/Dockerfile.pipy-debian \ + --build-arg PIPY_VERSION=${{ inputs.tag }} \ + --push . + + manifest: + name: Create Docker manifest + runs-on: ubuntu-22.04 + needs: [debian] + steps: + - name: Set up QEMU + uses: docker/setup-qemu-action@v3.2.0 + + - name: Login to DockerHub + uses: docker/login-action@v3.3.0 with: - context: . - file: ./dockerfiles/Dockerfile.pipy-debian - platforms: linux/amd64,linux/arm64 - push: true - tags: ${{ steps.docker_meta.outputs.tags }} - labels: ${{ steps.docker_meta.outputs.labels }} - build-args: | - PIPY_VERSION=${{ inputs.tag }} + username: ${{ secrets.RELEASE_DOCKER_USER }} + password: ${{ secrets.RELEASE_DOCKER_PASS }} + + - name: Create Docker manifest + run: | + docker manifest create flomesh/pipy:${{ inputs.tag }}-debian \ + --amend flomesh/pipy:${{ inputs.tag }}-debian-amd64 \ + --amend flomesh/pipy:${{ inputs.tag }}-debian-arm64 + docker manifest push flomesh/pipy:${{ inputs.tag }}-debian pipy-nonroot: name: Build pipy nonroot image runs-on: ubuntu-22.04 - needs: debian + needs: manifest strategy: matrix: id: [ "nonroot", "debug-nonroot" ]