From 6836380721363624b9a0b8ccb138423255e6d582 Mon Sep 17 00:00:00 2001 From: KeepSOBP Date: Tue, 31 Aug 2021 21:51:55 +0900 Subject: [PATCH 1/2] Support multiple architectures for docker * add github container registry * refactor! --- .github/workflows/docker.yml | 72 ++++++++++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index dd176b76..4e66e78d 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -11,28 +11,94 @@ on: - "master" jobs: - docker: + build: + runs-on: ubuntu-latest + strategy: + matrix: + architecture: [linux/amd64,linux/arm64,linux/arm/v7] + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + submodules: "recursive" + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + with: + platforms: ${{ matrix.architecture }} + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache/${{ matrix.architecture }} + key: ${{ runner.os }}-buildx-${{ matrix.architecture }}-${{ github.sha }} + - name: Build + uses: docker/build-push-action@v2 + with: + context: . + platforms: ${{ matrix.architecture }} + push: false + cache-from: type=local,src=/tmp/.buildx-cache/${{ matrix.architecture }} + cache-to: type=local,dest=/tmp/.buildx-cache-new/${{ matrix.architecture }},mode=max + - name: Move cache + run: | + rm -rf /tmp/.buildx-cache/${{ matrix.architecture }} + mv /tmp/.buildx-cache-new/${{ matrix.architecture }} /tmp/.buildx-cache/${{ matrix.architecture }} + + publish: + needs: [build] runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v2 with: submodules: "recursive" + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Cache arm64 Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache/linux/arm64 + key: ${{ runner.os }}-buildx-linux/arm64-${{ github.sha }} + - name: Cache amd64 Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache/linux/amd64 + key: ${{ runner.os }}-buildx-linux/amd64-${{ github.sha }} + - name: Cache armv7 Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache/linux/arm/v7 + key: ${{ runner.os }}-buildx-linux/arm/v7-${{ github.sha }} - name: Docker meta id: meta uses: docker/metadata-action@v3 with: - images: revoltchat/client + images: revoltchat/client, ghcr.io/revoltchat/client - name: Login to DockerHub if: github.event_name != 'pull_request' uses: docker/login-action@v1 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build and push + - name: Login to Github Container Registry + if: github.event_name != 'pull_request' + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Publish the Docker images uses: docker/build-push-action@v2 with: context: . push: ${{ github.event_name != 'pull_request' }} + platforms: linux/amd64,linux/arm64,linux/arm/v7 tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + cache-from: | + type=local,src=/tmp/.buildx-cache/linux/amd64 + type=local,src=/tmp/.buildx-cache/linux/arm64 + type=local,src=/tmp/.buildx-cache/linux/arm/v7 From d47827b9d09f77e016e82ffefaa388dff4f1d829 Mon Sep 17 00:00:00 2001 From: KeepSOBP Date: Thu, 2 Sep 2021 11:35:37 +0900 Subject: [PATCH 2/2] Refactor all --- .github/workflows/docker.yml | 45 +++++++++++++++++------------------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 4e66e78d..424f4a8c 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -6,16 +6,25 @@ on: - "master" tags: - "v*" + paths-ignore: + - ".github/**" + - "!.github/workflows/docker.yml" + - ".vscode/**" + - ".gitignore" + - ".gitlab-ci.yml" + - "LICENSE" + - "README" pull_request: branches: - "master" + workflow_dispatch: jobs: - build: + test: runs-on: ubuntu-latest strategy: matrix: - architecture: [linux/amd64,linux/arm64,linux/arm/v7] + architecture: [linux/amd64] steps: - name: Checkout uses: actions/checkout@v2 @@ -23,8 +32,6 @@ jobs: submodules: "recursive" - name: Set up QEMU uses: docker/setup-qemu-action@v1 - with: - platforms: ${{ matrix.architecture }} - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 - name: Cache Docker layers @@ -37,7 +44,6 @@ jobs: with: context: . platforms: ${{ matrix.architecture }} - push: false cache-from: type=local,src=/tmp/.buildx-cache/${{ matrix.architecture }} cache-to: type=local,dest=/tmp/.buildx-cache-new/${{ matrix.architecture }},mode=max - name: Move cache @@ -46,8 +52,9 @@ jobs: mv /tmp/.buildx-cache-new/${{ matrix.architecture }} /tmp/.buildx-cache/${{ matrix.architecture }} publish: - needs: [build] + needs: [test] runs-on: ubuntu-latest + if: github.event_name != 'pull_request' steps: - name: Checkout uses: actions/checkout@v2 @@ -57,48 +64,38 @@ jobs: uses: docker/setup-qemu-action@v1 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 - - name: Cache arm64 Docker layers - uses: actions/cache@v2 - with: - path: /tmp/.buildx-cache/linux/arm64 - key: ${{ runner.os }}-buildx-linux/arm64-${{ github.sha }} - name: Cache amd64 Docker layers uses: actions/cache@v2 with: path: /tmp/.buildx-cache/linux/amd64 key: ${{ runner.os }}-buildx-linux/amd64-${{ github.sha }} - - name: Cache armv7 Docker layers - uses: actions/cache@v2 - with: - path: /tmp/.buildx-cache/linux/arm/v7 - key: ${{ runner.os }}-buildx-linux/arm/v7-${{ github.sha }} - name: Docker meta id: meta uses: docker/metadata-action@v3 with: images: revoltchat/client, ghcr.io/revoltchat/client - name: Login to DockerHub - if: github.event_name != 'pull_request' uses: docker/login-action@v1 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Login to Github Container Registry - if: github.event_name != 'pull_request' uses: docker/login-action@v1 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Publish the Docker images + - name: Build and publish uses: docker/build-push-action@v2 with: context: . - push: ${{ github.event_name != 'pull_request' }} + push: true platforms: linux/amd64,linux/arm64,linux/arm/v7 tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - cache-from: | - type=local,src=/tmp/.buildx-cache/linux/amd64 - type=local,src=/tmp/.buildx-cache/linux/arm64 - type=local,src=/tmp/.buildx-cache/linux/arm/v7 + cache-from: type=local,src=/tmp/.buildx-cache/linux/amd64 + cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max + - name: Move cache + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache