Automatically groups similar photos into stacks within the Immich photo management system.
50K+
Automatically groups similar photos into stacks within the Immich photo management system.
# Create a .env file
cat > .env << EOL
API_KEY=your_immich_api_key
API_URL=http://immich-server:2283/api
RUN_MODE=cron
CRON_INTERVAL=60
EOL
# Run with Docker (using Docker Hub)
docker run -d --name immich-stack --env-file .env -v ./logs:/app/logs majorfi/immich-stack:latest
# Or using GitHub Container Registry
docker run -d --name immich-stack --env-file .env -v ./logs:/app/logs ghcr.io/majorfi/immich-stack:latest
| Variable | Description | Default |
|---|---|---|
API_KEY | Your Immich API key | (required) |
API_URL | Immich API URL | http://immich-server:2283/api |
RUN_MODE | Run mode (once or cron) | once |
CRON_INTERVAL | Interval in seconds for cron mode | 86400 |
DRY_RUN | Don't apply changes | false |
RESET_STACKS | Delete all existing stacks | false |
REPLACE_STACKS | Replace stacks for new groups | false |
PARENT_FILENAME_PROMOTE | Parent filename promote | edit |
PARENT_EXT_PROMOTE | Parent extension promote | .jpg,.dng |
WITH_ARCHIVED | Include archived assets | false |
WITH_DELETED | Include deleted assets | false |
version: "3.8"
services:
immich-stack:
container_name: immich_stack
# Use Docker Hub image (recommended for Portainer)
image: majorfi/immich-stack:latest
# Or use GitHub Container Registry
# image: ghcr.io/majorfi/immich-stack:latest
environment:
- API_KEY=${API_KEY}
- API_URL=${API_URL:-http://immich-server:2283/api}
- DRY_RUN=${DRY_RUN:-false}
- RESET_STACKS=${RESET_STACKS:-false}
- REPLACE_STACKS=${REPLACE_STACKS:-false}
- PARENT_FILENAME_PROMOTE=${PARENT_FILENAME_PROMOTE:-edit}
- PARENT_EXT_PROMOTE=${PARENT_EXT_PROMOTE:-.jpg,.dng}
- WITH_ARCHIVED=${WITH_ARCHIVED:-false}
- WITH_DELETED=${WITH_DELETED:-false}
- RUN_MODE=${RUN_MODE:-once}
- CRON_INTERVAL=${CRON_INTERVAL:-86400}
volumes:
- ./logs:/app/logs
restart: on-failure
# Build locally
docker build -t immich-stack .
# Run locally
docker run -d \
--name immich-stack \
--env-file .env \
-v ./logs:/app/logs \
immich-stack
Immich Stack is a Go CLI tool and library for automatically grouping ("stacking") similar photos in the Immich photo management system. It provides configurable, robust, and extensible logic for grouping, sorting, and managing photo stacks via the Immich API. This project is heavily inspired by immich-auto-stack.
Clone the repository:
git clone https://github.com/majorfi/immich-stack.git
cd immich-stack
Build the binary:
go build -o immich-stack ./cmd/main.go
Move the binary to your PATH (optional):
sudo mv immich-stack /usr/local/bin/
Clone the repository:
git clone https://github.com/majorfi/immich-stack.git
cd immich-stack
Create a .env file from the example:
cp .env.example .env
Edit the .env file with your Immich credentials and preferences:
# Required
API_KEY=your_immich_api_key
API_URL=http://your_immich_server:3001/api
# Optional - Default values shown
DRY_RUN=false
RESET_STACKS=false
REPLACE_STACKS=false
PARENT_FILENAME_PROMOTE=edit
PARENT_EXT_PROMOTE=.jpg,.dng
WITH_ARCHIVED=false
WITH_DELETED=false
# Run mode settings
RUN_MODE=once # Options: once, cron
CRON_INTERVAL=86400 # in seconds, only used if RUN_MODE=cron
Start the service:
docker compose up -d
To run in cron mode, set RUN_MODE=cron in your .env file and restart:
docker compose down
docker compose up -d
To view logs:
docker compose logs -f
To stop the service:
docker compose down
To integrate with an existing Immich installation:
Copy the immich-stack service from our docker-compose.yml into your Immich's docker-compose.yml
Add these environment variables to your Immich's .env file (you can also add the optional ones):
# Immich Stack settings
API_KEY=your_immich_api_key
API_URL=http://immich-server:2283/api # Use internal Docker network
RUN_MODE=once # Options: once, cron
CRON_INTERVAL=86400 # in seconds, only used if RUN_MODE=cron
Add the service dependency in Immich's docker-compose.yml:
immich-stack:
container_name: immich_stack
image: ghcr.io/majorfi/immich-stack:latest
environment:
- API_KEY=${API_KEY}
- API_URL=${API_URL:-http://immich-server:2283/api}
- DRY_RUN=${DRY_RUN:-false}
- RESET_STACKS=${RESET_STACKS:-false}
- REPLACE_STACKS=${REPLACE_STACKS:-false}
- PARENT_FILENAME_PROMOTE=${PARENT_FILENAME_PROMOTE:-edit}
- PARENT_EXT_PROMOTE=${PARENT_EXT_PROMOTE:-.jpg,.dng}
- WITH_ARCHIVED=${WITH_ARCHIVED:-false}
- WITH_DELETED=${WITH_DELETED:-false}
- RUN_MODE=${RUN_MODE:-once}
- CRON_INTERVAL=${CRON_INTERVAL:-86400}
volumes:
- ./logs:/app/logs
restart: on-failure
depends_on:
immich-server:
condition: service_healthy
Restart your Immich stack:
docker compose down
docker compose up -d
Create a .env file in your working directory with your Immich credentials:
API_KEY=your_immich_api_key
API_URL=http://your_immich_server:3001/api
Run the stacker:
# Using the binary
./immich-stack
# Or if installed in PATH
immich-stack
Optional: Configure additional options via environment variables or flags:
# Example with flags
./immich-stack --dry-run --parent-filename-promote=edit --parent-ext-promote=.jpg,.dng --with-archived --with-deleted
# Or using environment variables
export DRY_RUN=true
export PARENT_FILENAME_PROMOTE=edit
export PARENT_EXT_PROMOTE=.jpg,.dng
export WITH_ARCHIVED=true
export WITH_DELETED=true
./immich-stack
immich-auto-stack/
├── cmd/ # CLI entrypoint (main.go)
├── pkg/
│ ├── stacker/ # Stacking logic, types, and tests
│ ├── immich/ # Immich API client and integration
│ └── utils/ # Utility helpers and logging
The main entrypoint is cmd/main.go, which provides a Cobra-based CLI:
go run ./cmd/main.go --api-key <API_KEY> --api-url <API_URL> [flags]
| Flag | Env Var | Description |
|---|---|---|
--api-key | API_KEY | Immich API key |
--api-url | API_URL | Immich API base URL |
--reset-stacks | RESET_STACKS | Delete all existing stacks before processing |
--replace-stacks | REPLACE_STACKS | Replace stacks for new groups |
--dry-run | DRY_RUN | Simulate actions without making changes |
--criteria | CRITERIA | Custom grouping criteria |
--parent-filename-promote | PARENT_FILENAME_PROMOTE | Substrings to promote as parent filenames |
--parent-ext-promote | PARENT_EXT_PROMOTE | Extensions to promote as parent files |
--with-archived | WITH_ARCHIVED | Include archived assets in processing |
--with-deleted | WITH_DELETED | Include deleted assets in processing |
--run-mode | RUN_MODE | Run mode: "once" (default) or "cron" |
--cron-interval | CRON_INTERVAL | Interval in seconds for cron mode |
--reset-stacks is set, user confirmation is required.--criteria flag or CRITERIA environment variable.--parent-filename-promote or PARENT_FILENAME_PROMOTE (comma-separated substrings) to promote files as stack parents.--parent-ext-promote or PARENT_EXT_PROMOTE (comma-separated extensions) to further prioritize..jpeg > .jpg > .png > others.For files: L1010229.JPG, L1010229.edit.jpg, L1010229.DNG
With PARENT_FILENAME_PROMOTE=edit and PARENT_EXT_PROMOTE=.jpg,.dng in your .env file, or with --parent-filename-promote=edit and --parent-ext-promote=.jpg,.dng, the order will be:
L1010229.edit.jpg
L1010229.JPG
L1010229.DNG
Asset, Stack, Criteria, etc.pkg/stacker/stacker_test.go and pkg/immich/client_test.go.go test ./pkg/...
--parent-filename-promote and/or --parent-ext-promote for your workflow.pkg/immich/client.go for new Immich endpoints.MIT
Content type
Image
Digest
sha256:52f39f24d…
Size
9.2 MB
Last updated
22 days ago
docker pull majorfi/immich-stack