diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml index 374423a..7410fc1 100644 --- a/.github/actions/build/action.yml +++ b/.github/actions/build/action.yml @@ -46,16 +46,6 @@ runs: version: latest buildkitd-flags: --debug - # Login to a registry to push the image - - name: Login to Container Registry - # Only login if we are pushing the image - if: ${{ inputs.push == 'true' }} - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ inputs.username }} - password: ${{ inputs.password }} - - name: Docker Image id: image shell: bash @@ -100,6 +90,12 @@ runs: cat $GITHUB_OUTPUT + - name: Tar file + id: tar + shell: bash + run: | + echo "path=/tmp/${{ steps.meta.outputs.version }}" >> $GITHUB_OUTPUT + - name: Build Image id: build uses: docker/bake-action@v4 @@ -107,8 +103,37 @@ runs: DOCKER_TAG: ${{ steps.tag.outputs.tag }} with: targets: app - push: ${{ inputs.push }} - load: ${{ inputs.push == 'false' }} set: | - *.cache-from=type=registry,ref=${{ steps.tag.outputs.tag_cache }} - *.cache-to=type=registry,ref=${{ steps.tag.outputs.tag_cache }},mode=max,compression-level=9,force-compression=true,ignore-error=true + *.output=type=docker,dest=${{ steps.tar.outputs.path }} + + - name: Get image digest + id: digest + shell: bash + run: | + echo '${{ steps.build.outputs.metadata }}' > metadata.json + echo "digest=$(cat metadata.json | jq -r '.app."containerimage.digest"')" >> $GITHUB_OUTPUT + cat $GITHUB_OUTPUT + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: ${{ steps.meta.outputs.version }} + path: ${{ steps.tar.outputs.path }} + retention-days: 1 + compression-level: 9 + overwrite: true + + - name: Login to Container Registry + if: inputs.push == 'true' + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ inputs.username }} + password: ${{ inputs.password }} + + - name: Push Image + if: inputs.push == 'true' + shell: bash + run: | + docker load < ${{ steps.tar.outputs.path }} + docker image push --all-tags ${{ steps.image.outputs.image }} diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 596db8f..c93a0e4 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -13,6 +13,9 @@ jobs: build: runs-on: ubuntu-latest + outputs: + version: ${{ steps.build.outputs.version }} + steps: - uses: actions/checkout@v4 @@ -20,11 +23,31 @@ jobs: uses: ./.github/actions/context - uses: ./.github/actions/build + id: build with: - push: true + push: ${{ steps.context.outputs.is_fork == 'false' }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} node_env: production latest: ${{ steps.context.outputs.is_release_master }} + download: + runs-on: ubuntu-latest + needs: [build] + + steps: + - uses: actions/checkout@v4 + + - uses: actions/download-artifact@v4 + with: + name: ${{ needs.build.outputs.version }} + path: /tmp/ + + - name: Load image + shell: bash + run: | + docker load < /tmp/${{ needs.build.outputs.version }} + docker image ls + +