From 6fe03698e2aa79882e8d28649da8868b05e60c4a Mon Sep 17 00:00:00 2001 From: Christian Kuhtz Date: Sat, 13 Jul 2024 07:17:03 +0000 Subject: [PATCH] adopt same approach as for api --- .github/workflows/cli.yml | 87 ++++++++++++--------------------------- 1 file changed, 27 insertions(+), 60 deletions(-) diff --git a/.github/workflows/cli.yml b/.github/workflows/cli.yml index 2bf80bc..9cf891f 100644 --- a/.github/workflows/cli.yml +++ b/.github/workflows/cli.yml @@ -18,81 +18,48 @@ on: - 'cli/**/requirements.txt' - '**/cli.yml' +env: + COMPONENT: cli + jobs: - containers: + build-and-push: + name: Build and push images runs-on: ubuntu-latest - - strategy: - matrix: - component: [ cli ] - platform: [ linux/amd64, linux/arm64 ] - + # Cancel in-progress jobs if matching component and platform when new PR arrives. concurrency: - group: containers-${{ matrix.component }}-${{ matrix.platform }} + group: cli cancel-in-progress: true steps: - - name: Create a variable with platform '${{ matrix.platform }}' value - run: echo "PLATFORM=${{ matrix.platform }}" >> $GITHUB_ENV - - - name: Swap / for - in '${{ matrix.platform }}' and create local_platform variable - id: local_platform - run: | - LOCAL_PLATFORM="${PLATFORM//\//-}" - echo "LOCAL_PLATFORM=${LOCAL_PLATFORM}" >> $GITHUB_ENV - echo "local_platform=${LOCAL_PLATFORM}" >> $GITHUB_STATE - - - name: checkout repo + - name: Checkout repo uses: actions/checkout@v4 - - name: setup docker buildx + - name: Set up QEMU + # if: matrix.architecture != 'amd64' + uses: docker/setup-qemu-action@v3 + + - name: Setup Docker buildx uses: docker/setup-buildx-action@v3 # with: # buildkitd-flags: --debug - - name: Login to GitHub Container Registry + - name: Login to Docker Hub Container Registry uses: docker/login-action@v3 with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GHCR_TOKEN }} - - - name: Cache Docker layers - id: cache-docker-layers - uses: actions/cache@v4 - with: - path: /tmp/.buildx-cache--${{ steps.local_platform.outputs.local_platform }}-${{ matrix.component }} - key: ${{ runner.os }}-buildx - restore-keys: | - ${{ runner.os }}-buildx - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - # - name: Build and push (ghcr.io/${{ github.repository_owner }}/hamframe-${{ matrix.component }}:test) - # uses: docker/build-push-action@v6 - # with: - # context: ./${{ matrix.component }} - # load: true - # tags: ghcr.io/${{ github.repository_owner }}/hamframe-${{ matrix.component }}:test - # platforms: ${{ matrix.platform }} - # cache-from: type=local,src=/tmp/.buildx-cache--${{ steps.local_platform.outputs.local_platform }}-${{ matrix.component }} - # cache-to: type=local,mode=max,dest=/tmp/.buildx-cache--${{ steps.local_platform.outputs.local_platform }}-${{ matrix.component }} - - # # FIXME: this needs to be more than a do we exit with code 0 test.. - # # https://github.com/ckuhtz/hamframe/issues/2 - # - name: Run tests in container (ghcr.io/${{ github.repository_owner }}/hamframe-${{ matrix.component }}:test) - # run: docker run --rm --platform ${{ matrix.platform }} ghcr.io/${{ github.repository_owner }}/hamframe-${{ matrix.component }}:test - - - name: Build and push (ghcr.io/${{ github.repository_owner }}/hamframe-${{ matrix.component }}:latest) - # if: success() + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + # logout: false + + - name: Build and push Docker image uses: docker/build-push-action@v6 with: - context: ./${{ matrix.component }} + context: . + file: ./${{ env.COMPONENT }}/Dockerfile push: true - tags: ghcr.io/${{ github.repository_owner }}/hamframe-${{ matrix.component }}:latest - platforms: ${{ matrix.platform }} - cache-from: type=local,src=/tmp/.buildx-cache--${{ steps.local_platform.outputs.local_platform }}-${{ matrix.component }} - cache-to: type=local,mode=max,dest=/tmp/.buildx-cache--${{ steps.local_platform.outputs.local_platform }}-${{ matrix.component }} - + # cache-from: type=gha,scope=${{ matrix.architecture }} + # cache-to: type=gha,mode=max,scope=${{ matrix.architecture }} + cache-from: type=gha + cache-to: type=gha,mode=max + platforms: linux/amd64, linux/arm64 + tags: ${{ secrets.DOCKERHUB_USERNAME }}/hamframe-${{ env.COMPONENT}}:latest