Skip to content

Commit

Permalink
feat: push container images for fork PR
Browse files Browse the repository at this point in the history
  • Loading branch information
bo0tzz committed Feb 18, 2025
1 parent 8cdf78f commit cd12018
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/docker-pr-push.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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
6 changes: 6 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
with:
image: merged-manifest

success-check-server:
name: Docker Build & Push Server Success
needs: [merge_server, retag_server]
Expand Down

0 comments on commit cd12018

Please sign in to comment.