diff --git a/.github/workflows/docker-pr-push.yml b/.github/workflows/docker-pr-push.yml new file mode 100644 index 0000000000..5a722b1153 --- /dev/null +++ b/.github/workflows/docker-pr-push.yml @@ -0,0 +1,66 @@ +name: Docker fork PR push +on: + workflow_run: + workflows: ["Docker"] + types: + - completed + +permissions: + packages: write + +jobs: + push: + # TODO: Push ML as well + name: Push fork server image + if: ${{ github.event.workflow_run.head_repository.fork }} + env: + GHCR_REPO: ghcr.io/${{ github.repository_owner }}/immich-server + steps: + - name: Login to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Download image from artifact + uses: ishworkh/container-image-artifact-download@v2.0.0 + with: + image: merged-manifest + workflow_run_id: ${{ github.event.workflow_run.id }} + + - name: Determine parameters + id: parameters + uses: actions/github-script@v7 + with: + script: | + let pull_number = context.payload.workflow_run.pull_requests[0]?.number; + + // Adapted from docs-deploy.yml. I'm not sure whether we need this fallback? + if(!pull_number) { + console.info("Using fallback to get pull request") + const response = await github.rest.search.issuesAndPullRequests({q: 'repo:${{ github.repository }} is:pr sha:${{ github.event.workflow_run.head_sha }}',per_page: 1,}) + const items = response.data.items + if (items.length < 1) { + throw new Error("No pull request found for the commit") + } + pull_number = items[0].number + } + + parameters = { + pr_number: pull_number, + head_sha: context.payload.workflow_run.head_sha + }; + + console.log(parameters); + return parameters; + + - name: Push + run: | + docker buildx imagetools create \ + -t ${{ env.GHCR_REPO }}:commit-${{ steps.parameters.outputs.head_sha }} \ + -t ${{ env.GHCR_REPO }}:pr-${{ steps.parameters.outputs.pr_number }} \ + merged-manifest diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 4fd5a0976b..ef2864f41c 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -428,6 +428,12 @@ jobs: if: ${{ !github.event.pull_request.head.repo.fork }} run: docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") merged-manifest + - name: Save artifact + if: ${{ github.event.pull_request.head.repo.fork }} + uses: ishworkh/container-image-artifact-upload@v2.0.0 + with: + image: merged-manifest + success-check-server: name: Docker Build & Push Server Success needs: [merge_server, retag_server]