-
Notifications
You must be signed in to change notification settings - Fork 0
199 lines (174 loc) · 7.7 KB
/
docker.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
name: Docker build
on:
workflow_dispatch:
inputs:
version:
description: "version"
required: false
type: string
base_image_tag:
description: "base image tag"
required: false
type: string
push:
branches: ["main"]
paths:
- "templates/**"
- "root/**"
- ".github/**"
pull_request:
branches: ["main"]
paths:
- "templates/**"
- "root/**"
- ".github/**"
schedule:
- cron: "0 12 * * 3"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
packages: write
jobs:
build_docker:
name: build docker images
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- image: armnn
platforms: linux/arm64
suffix: -armnn
- image: cuda
platforms: linux/amd64
suffix: -cuda
- image: cpu
platforms: linux/amd64,linux/arm64
- image: noml
platforms: linux/amd64,linux/arm64
suffix: -noml
- image: openvino
platforms: linux/amd64
suffix: -openvino
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set tags
id: tags
run: |
echo "Generate tags"
if [ "${{ inputs.version }}" != '' ]; then
immich_version="${{ inputs.version }}"
else
immich_version=$(curl -sL https://api.github.com/repos/immich-app/immich/releases/latest | jq -r '.tag_name')
counter=0
# Loop until immich_version is not "null" or counter reaches 10
while [ $counter -lt 10 ]; do
immich_version=$(curl -sL https://api.github.com/repos/immich-app/immich/releases/latest | jq -r '.tag_name')
# Check if immich_version is not "null"
if [ "$immich_version" != "null" ]; then
echo "immich_version is not null: $immich_version"
break
else
echo "immich_version is still null, retrying in 10 seconds..."
sleep 10
((counter++))
fi
done
if [ "$immich_version" = "null" ]; then
echo "immich_version is still null after 10 attempts, exiting..."
exit 1
fi
fi
if [ "${{ inputs.base_image_tag }}" != '' ]; then
base_image_tag="${{ inputs.base_image_tag }}"
else
mkdir /tmp/immich
curl -o \
/tmp/immich.tar.gz -L \
"https://github.com/immich-app/immich/archive/${immich_version}.tar.gz" && \
tar xf \
/tmp/immich.tar.gz -C \
/tmp/immich --strip-components=1 && \
dockerfile_content=$(cat /tmp/immich/server/Dockerfile)
date=$(echo "$dockerfile_content" | grep -oP 'base-server-prod:\K\d{8}')
if [ -z "$date" ]; then
base_image_tag="latest";
else
base_image_tag="$date";
fi
fi
short_version="${immich_version#v}"
echo "immich_version=${immich_version}" >> $GITHUB_OUTPUT
echo "build_date=$(date +'%Y-%m-%dT%H:%M:%S%:z')" >> $GITHUB_OUTPUT
echo "short_date=$(date '+%Y%m%d')" >> $GITHUB_OUTPUT
echo "commit=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "short_version=${short_version}" >> $GITHUB_OUTPUT
echo "base_image_tag=${base_image_tag}" >> $GITHUB_OUTPUT
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install poetry
run: pipx install poetry
- name: Setup poetry
uses: actions/setup-python@v5
with:
python-version: 3.12
cache: "poetry"
- name: Install python dependencies
run: poetry install --without dev,test
- name: Create Dockerfile from template
run: poetry run python3 render_templates/main.py --flavor ${{ matrix.image }} --print-dockerfile --enable-patches --immich-version ${{ steps.tags.outputs.immich_version }}
- name: Generate docker image tags
id: metadata
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository_owner }}/immich
tags: |
type=ref,event=pr,value=${{ steps.tags.outputs.immich_version }},enable=${{ github.event_name == 'pull_request' }},suffix=${{ matrix.suffix }}
type=ref,event=pr,value=${{ steps.tags.outputs.immich_version }},enable=${{ github.event_name == 'pull_request' }},suffix=${{ matrix.suffix }}-${{ steps.tags.outputs.immich_version }}
type=ref,event=pr,value=${{ steps.tags.outputs.immich_version }},enable=${{ github.event_name == 'pull_request' }},suffix=${{ matrix.suffix }}-${{ steps.tags.outputs.immich_version }}-${{ steps.tags.outputs.commit }}
type=raw,value=latest,enable=${{ github.event_name != 'pull_request' }},suffix=${{ matrix.suffix }}
type=raw,value=${{ matrix.image }},enable=${{ matrix.image != 'cpu' && github.event_name != 'pull_request' }}
type=raw,value=${{ steps.tags.outputs.short_version }},enable=${{ github.event_name != 'pull_request' }},suffix=${{ matrix.suffix }}
type=raw,value=${{ steps.tags.outputs.immich_version }},enable=${{ github.event_name != 'pull_request' }},suffix=${{ matrix.suffix }}
type=raw,value=${{ steps.tags.outputs.immich_version }},enable=${{ github.event_name != 'pull_request' }},suffix=${{ matrix.suffix }}-${{ steps.tags.outputs.short_date }}-${{ steps.tags.outputs.commit }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push docker images
uses: docker/build-push-action@v6
with:
context: build-${{ matrix.image }}
provenance: false # prevent unknown architecture
platforms: ${{ matrix.platforms }}
push: ${{ !github.event.pull_request.head.repo.fork }}
labels: ${{ steps.metadata.outputs.labels }}
tags: ${{ steps.metadata.outputs.tags }}
build-args: |
BUILD_VERSION=${{ steps.tags.outputs.build_date }}
BUILD_ID=${{ github.run_id }}
BUILD_IMAGE=${{ matrix.image == 'cpu' && 'latest' || matrix.image }}
BUILD_IMAGE_URL=https://github.com/${{ github.repository }}/pkgs/container/immich
BUILD_REPOSITORY=${{ github.repository }}
BUILD_REPOSITORY_URL=https://github.com/${{ github.repository }}
BUILD_SOURCE_COMMIT=${{ github.sha }}
BUILD_SOURCE_REF=${{ github.ref_name }}
BUILD_SOURCE_URL=https://github.com/${{ github.repository }}/commit/${{ github.sha }}
BUILD_URL=https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
BASE_IMAGE_TAG=${{ steps.tags.outputs.base_image_tag }}
IMMICH_VERSION=${{ steps.tags.outputs.immich_version }}
THIRD_PARTY_BUG_FEATURE_URL=https://github.com/${{ github.repository }}/issues
THIRD_PARTY_DOCUMENTATION_URL=https://github.com/${{ github.repository }}/blob/main/README.md
THIRD_PARTY_SOURCE_URL=https://github.com/${{ github.repository }}
THIRD_PARTY_SUPPORT_URL=https://github.com/${{ github.repository }}/discussions