feat: push container images for fork PR

This commit is contained in:
bo0tzz 2025-02-18 20:23:37 +01:00
parent 8cdf78f8af
commit cd120182a9
No known key found for this signature in database
2 changed files with 72 additions and 0 deletions

66
.github/workflows/docker-pr-push.yml vendored Normal file
View File

@ -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

View File

@ -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]