|
1 | | -name: Sync and Build Immich Images |
| 1 | +# .github/workflows/sync-and-build.yml |
| 2 | +name: Sync Immich Release & Build Images |
2 | 3 |
|
3 | 4 | on: |
4 | 5 | schedule: |
5 | | - - cron: '0 * * * *' # Runs every hour |
| 6 | + # every hour; adjust as you like |
| 7 | + - cron: '0 * * * *' |
6 | 8 | workflow_dispatch: |
7 | 9 |
|
8 | 10 | permissions: |
9 | | - contents: write |
10 | | - packages: write |
| 11 | + contents: write # to update branches |
| 12 | + packages: write # to push to GHCR |
| 13 | + actions: read |
11 | 14 |
|
12 | 15 | jobs: |
13 | | - sync-and-build: |
| 16 | + sync: |
14 | 17 | runs-on: ubuntu-latest |
15 | | - env: |
16 | | - GHCR_REPO: ghcr.io/${{ github.repository_owner }} |
| 18 | + # expose the fetched tag to downstream jobs |
| 19 | + outputs: |
| 20 | + release_tag: ${{ steps.get_release.outputs.tag }} |
17 | 21 | steps: |
18 | | - - name: Checkout target repo |
| 22 | + - name: Get latest Immich release tag |
| 23 | + id: get_release |
| 24 | + uses: actions/github-script@v6 |
| 25 | + with: |
| 26 | + script: | |
| 27 | + const latest = await github.rest.repos.getLatestRelease({ |
| 28 | + owner: 'immich-app', |
| 29 | + repo: 'immich', |
| 30 | + }); |
| 31 | + return latest.data.tag_name; |
| 32 | + result-encoding: string |
| 33 | + # now get_release.outputs.tag == e.g. "v1.134.0" |
| 34 | + |
| 35 | + - name: Check out this repo |
19 | 36 | uses: actions/checkout@v4 |
20 | 37 | with: |
21 | | - ref: dockerimageML |
| 38 | + fetch-depth: 0 # we need full history to push branches/tags |
22 | 39 |
|
23 | | - - name: Get latest release tag from source repo |
24 | | - id: get_release |
| 40 | + - name: Add Immich upstream remote |
25 | 41 | run: | |
26 | | - latest_tag=$(curl -s https://api.github.com/repos/immich-app/immich/releases/latest | jq -r .tag_name) |
27 | | - echo "::set-output name=latest_tag::$latest_tag" |
28 | | - shell: bash |
| 42 | + git remote add upstream https://github.com/immich-app/immich.git |
| 43 | + git fetch upstream --tags |
29 | 44 |
|
30 | | - - name: Check if latest release already exists in this branch |
31 | | - id: check_existing |
| 45 | + - name: Update `dockerimageML` branch |
32 | 46 | run: | |
33 | | - if git ls-remote --exit-code --heads origin dockerimageML | grep -q "${{ steps.get_release.outputs.latest_tag }}"; then |
34 | | - echo "exists=true" >> $GITHUB_ENV |
35 | | - else |
36 | | - echo "exists=false" >> $GITHUB_ENV |
| 47 | + git branch -f dockerimageML ${{ steps.get_release.outputs.tag }} |
| 48 | + git push origin dockerimageML --force |
37 | 49 |
|
38 | | - - name: Clone latest release from upstream if new |
39 | | - if: env.exists == 'false' |
40 | | - run: | |
41 | | - git clone --depth 1 --branch "${{ steps.get_release.outputs.latest_tag }}" https://github.com/immich-app/immich temp-clone |
42 | | - rsync -a --delete temp-clone/ ./ |
43 | | - rm -rf temp-clone |
44 | | - git config user.name "github-actions" |
45 | | - git config user.email "github-actions@github.com" |
46 | | - git add . |
47 | | - git commit -m "Sync immich release ${{ steps.get_release.outputs.latest_tag }}" |
48 | | - git push origin HEAD:dockerimageML |
| 50 | + build: |
| 51 | + needs: sync |
| 52 | + runs-on: ubuntu-latest |
| 53 | + env: |
| 54 | + IMAGE_TAG: ${{ needs.sync.outputs.release_tag }} |
| 55 | + GHCR_REPO: ghcr.io/${{ github.repository_owner }} |
| 56 | + steps: |
| 57 | + - name: Checkout `dockerimageML` |
| 58 | + uses: actions/checkout@v4 |
| 59 | + with: |
| 60 | + ref: dockerimageML |
| 61 | + |
| 62 | + - name: Set up Docker Buildx |
| 63 | + uses: docker/setup-buildx-action@v3 |
49 | 64 |
|
50 | 65 | - name: Log in to GHCR |
51 | | - if: env.exists == 'false' |
52 | 66 | uses: docker/login-action@v3 |
53 | 67 | with: |
54 | 68 | registry: ghcr.io |
55 | 69 | username: ${{ github.repository_owner }} |
56 | 70 | password: ${{ secrets.GHCR_PAT }} |
57 | 71 |
|
58 | | - - name: Set up Docker Buildx |
59 | | - if: env.exists == 'false' |
60 | | - uses: docker/setup-buildx-action@v3 |
61 | | - |
62 | | - - name: Build and push server image |
63 | | - if: env.exists == 'false' |
| 72 | + # === Server image === |
| 73 | + - name: Build & push server image |
64 | 74 | uses: docker/build-push-action@v6 |
65 | 75 | with: |
66 | 76 | context: . |
67 | 77 | file: server/Dockerfile |
68 | 78 | platforms: linux/amd64 |
69 | 79 | push: true |
70 | | - tags: ghcr.io/${{ github.repository_owner }}/immich-server:pr-${{ steps.get_release.outputs.latest_tag }} |
| 80 | + tags: | |
| 81 | + ${{ env.GHCR_REPO }}/immich-server:${{ env.IMAGE_TAG }} |
71 | 82 |
|
72 | | - - name: Build and push ML images |
73 | | - if: env.exists == 'false' |
| 83 | + # === ML images (CPU + CUDA) === |
| 84 | + - name: Build & push ML images |
| 85 | + uses: docker/build-push-action@v6 |
74 | 86 | strategy: |
75 | 87 | matrix: |
76 | | - include: |
77 | | - - device: cpu |
78 | | - suffix: "" |
79 | | - dockerfile: machine-learning/Dockerfile |
80 | | - - device: cuda |
81 | | - suffix: "-cuda" |
82 | | - dockerfile: machine-learning/Dockerfile |
83 | | - uses: docker/build-push-action@v6 |
| 88 | + device: [cpu, cuda] |
84 | 89 | with: |
85 | 90 | context: machine-learning |
86 | | - file: ${{ matrix.dockerfile }} |
| 91 | + file: machine-learning/Dockerfile |
87 | 92 | platforms: linux/amd64 |
88 | 93 | push: true |
89 | 94 | build-args: | |
90 | 95 | DEVICE=${{ matrix.device }} |
91 | | - tags: ghcr.io/${{ github.repository_owner }}/immich-machine-learning:pr-${{ steps.get_release.outputs.latest_tag }}${{ matrix.suffix }} |
| 96 | + tags: | |
| 97 | + ${{ env.GHCR_REPO }}/immich-machine-learning:${{ env.IMAGE_TAG }}${{ matrix.device == 'cuda' && '-cuda' || '' }} |
0 commit comments