From 9c6ae5b7ab6a2fadf01cb6f9f2685e46601d191f Mon Sep 17 00:00:00 2001 From: Senis John Date: Wed, 21 Dec 2022 20:38:59 +0800 Subject: [PATCH] update: speedup docker build --- .github/workflows/docker.yml | 119 +++++++++++++++++++++++++++++++++-- 1 file changed, 113 insertions(+), 6 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 14724ba..2da8096 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -15,8 +15,8 @@ on: branches: - 'master' jobs: - push_to_registry: - name: Push Docker image to Docker Hub + build-armv7-image: + name: Build armv7 Image runs-on: ubuntu-latest steps: - name: Check out the repo @@ -38,9 +38,116 @@ jobs: uses: docker/build-push-action@v3 with: context: . - platforms: linux/arm/v7,linux/arm64,linux/amd64,linux/s390x + platforms: linux/arm/v7 push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.meta.outputs.tags }} + tags: ${{ steps.meta.outputs.tags }}-armv7 labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max + build-arm64-image: + name: Build arm64 Image + runs-on: ubuntu-latest + steps: + - name: Check out the repo + uses: actions/checkout@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Log in to the Container registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: ghcr.io/${{ github.repository }} + - name: Build and push + uses: docker/build-push-action@v3 + with: + context: . + platforms: linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }}-arm64 + labels: ${{ steps.meta.outputs.labels }} + build-amd64-image: + name: Build amd64 Image + runs-on: ubuntu-latest + steps: + - name: Check out the repo + uses: actions/checkout@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Log in to the Container registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: ghcr.io/${{ github.repository }} + - name: Build and push + uses: docker/build-push-action@v3 + with: + context: . + platforms: linux/amd64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }}-amd64 + labels: ${{ steps.meta.outputs.labels }} + build-s390x-image: + name: Build s390x Image + runs-on: ubuntu-latest + steps: + - name: Check out the repo + uses: actions/checkout@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Log in to the Container registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: ghcr.io/${{ github.repository }} + - name: Build and push + uses: docker/build-push-action@v3 + with: + context: . + platforms: linux/s390x + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }}-s390x + labels: ${{ steps.meta.outputs.labels }} + combine-images: + name: Combine Images + runs-on: ubuntu-latest + needs: + - build-armv7-image + - build-arm64-image + - build-amd64-image + - build-s390x-image + steps: + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: ghcr.io/${{ github.repository }} + - name: Combine images + run: | + docker manifest create ${{ steps.meta.outputs.tags }} \ + --amend ${{ steps.meta.outputs.tags }}-armv7 \ + --amend ${{ steps.meta.outputs.tags }}-arm64 \ + --amend ${{ steps.meta.outputs.tags }}-amd64 \ + --amend ${{ steps.meta.outputs.tags }}-s390x + docker manifest push ${{ steps.meta.outputs.tags }}