From 3402bd9102c10ce7ac8835b7a0453e6068b5a0d1 Mon Sep 17 00:00:00 2001 From: Mason Tran Date: Tue, 18 Jun 2024 18:04:14 -0400 Subject: [PATCH] [actions] upload docker image tar to artifacts --- .github/workflows/docker.yml | 78 ++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 25 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 4bd9e463..34c9f5a1 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -32,6 +32,8 @@ env: TEST_TAG: siliconlabsinc/ot-efr32-dev:test SHA_TAG: siliconlabsinc/ot-efr32-dev:${{ github.sha }} LATEST_TAG: siliconlabsinc/ot-efr32-dev:latest + DOCKER_IMAGE_ARTIFACT_NAME: ot-efr32-dev-image-${{ github.sha }}-${{ github.event_name}} + DOCKER_IMAGE_TAR: ot-efr32-dev-image-${{ github.sha }}.tar on: push: @@ -77,8 +79,10 @@ jobs: linux/amd64 tags: | ${{ env.TEST_TAG }} + ${{ env.SHA_TAG }} cache-from: type=gha cache-to: type=gha,mode=max + outputs: type=oci,dest=${{ env.DOCKER_IMAGE_TAR}} - name: Container image sanity checks run: | @@ -106,30 +110,54 @@ jobs: run: | docker run -v ${{ github.workspace }}:/ot-efr32/ --user $(id -u) --rm ${{ env.TEST_TAG }} script/build --skip-silabs-apps brd4151a - - name: Login to DockerHub - uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3.2.0 - if: | - success() && - github.repository == 'SiliconLabs/ot-efr32' && - github.event_name != 'pull_request' && - github.ref == 'refs/heads/main' + - name: Upload docker image + uses: actions/upload-artifact@4 with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} + name: ${{ env.DOCKER_IMAGE_ARTIFACT_NAME }} + path: ${{ env.DOCKER_IMAGE_TAR }} - - name: Build and push - uses: docker/build-push-action@v5 - if: | - success() && - github.repository == 'SiliconLabs/ot-efr32' && - github.event_name != 'pull_request' && - github.ref == 'refs/heads/main' - with: - context: . - file: docker/Dockerfile - push: true - tags: | - ${{ env.LATEST_TAG }} - ${{ env.SHA_TAG }} - platforms: - linux/amd64 + publish: + name: Publish to DockerHub + runs-on: ubuntu-22.04 + needs: [build] + if: | + github.repository == 'SiliconLabs/ot-efr32' && + github.event_name != 'pull_request' + steps: + - name: Login to DockerHub + uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3.2.0 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Download Docker image + uses: actions/download-artifact@v4 + with: + name: ${{ env.DOCKER_IMAGE_ARTIFACT_NAME }} + + - name: Load Docker image + run: docker load -i ${{ env.DOCKER_IMAGE_TAR }} + + - name: Build and push + uses: docker/build-push-action@v5 + if: github.ref == 'refs/heads/main' + with: + context: . + file: docker/Dockerfile + push: true + tags: | + ${{ env.SHA_TAG }} + platforms: + linux/amd64 + + - name: Tag `latest` and push + uses: docker/build-push-action@v5 + if: github.ref == 'refs/heads/main' + with: + context: . + file: docker/Dockerfile + push: true + tags: | + ${{ env.LATEST_TAG }} + platforms: + linux/amd64