fix: build #610
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 uv | |
uses: astral-sh/setup-uv@v5 | |
- name: Install python dependencies | |
run: | | |
uv venv | |
uv pip install -r pyproject.toml | |
- name: Create Dockerfile from template | |
run: uv run python3 -m render_templates.main --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 |