Post

Immich

Immich est une solution de sauvegarde de photos et de vidéos auto-hébergée très performante, directement à partir de votre téléphone portable. Vous pouvez exécuter Immich sur votre homelab et il vous permet de télécharger des photos et des vidéos à partir de votre navigateur ou de votre téléphone portable via l’application Android Immich dédiée ou l’application iOS Immich. L’interface utilisateur d’Immich ressemble à celle de Google Photos, surtout si vous utilisez les applications mobiles.

Prérequis

Source: Immich

La machine virtuelle utilisée pour cette stack dispose de 8 vCPUs et de 8 Go de RAM. Pensez à ajuster les ressources en conséquence en fonction des ressources de votre machine.

Il faut avoir lu mes articles sur Traefik (lui est les autres) :)

Fichiers requis

Pensez à renseigner les vraies valeurs des variables comportant des ‘…’.

../_vm/common.yml

[Fichier]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
version: "3.0"

#
# updated: 2023-09-07
# stack:   x-common
#

services:

  x-common:

    extends:
      file: ./host.yml
      service: x-host

    init: true

    sysctls:
      net.core.somaxconn: 1024
      net.ipv4.tcp_syncookies: 0

../_vm/host.yml

[Fichier]

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
version: "3.0"

#
# updated: 2023-09-29
# stack:   host
#

services:

  x-host:

    logging:
      driver: loki
      options:
        loki-url: "http://...:.../loki/api/v1/push"
        loki-retries: "8"
        loki-max-backoff: 800ms
        loki-timeout: 1s
        loki-batch-wait: 60s
        loki-batch-size: "400"
        no-file: "false"
        keep-file: "true"
        max-size: "32m"
        max-file: "8"

    restart: unless-stopped
    stop_grace_period: 5s
    stdin_open: true
    tty: true

    user: 1000:1000

    privileged: false

    security_opt:
      - no-new-privileges=true

    cap_drop:
      - ALL

    cap_add:
      - KILL

    ipc: "private"

    dns:
      - 1.1.1.1
      - 8.8.8.8
      - 1.0.0.1
      - 8.8.4.4

    healthcheck:
      interval: 60s
      timeout: 10s
      retries: 5
      start_period: 60s

    environment:
      TZ: "Europe/Paris"
      PUID: 1000
      PGID: 1000
      DOCKER_HOST: "tcp://...:..."

    labels:
      com.centurylinklabs.watchtower.enable: true
      logging: "promtail"
      com.vm.versionning: "..."
      com.stack.owner: "Olivier Le Bris"
      com.stack.owner.email: "tech@zogg.fr"
      com.stack.owner.url: "https://zogg.fr"
      com.stack.name: "common"
      com.stack.service.name: "common"
      traefik.docker.network: traefik

    ulimits:
      nproc: 65535
      nofile:
        soft: 20000
        hard: 40000

    deploy:
      resources:
        limits:
          cpus: "0.50"
          memory: 64M
          pids: 64

    tmpfs:
      - /tmp:rw,noexec,nosuid,size=64M

    volumes:
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
      - /opt/docker/ssl:/ssl:ro
      - /proc/cgroups:/cgroup:rw

docker-compose.yml

Pour cet article, j’ai utilisé l’accélération GPU NVidia.

[Fichier]

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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
version: "3.0"

#
# updated: 2023-10-09
# stack:   immich
#

#
# Test NVIDIA usage
#   sudo docker exec -it immich-microservices nvidia-smi
#

networks:
  immich:
    name: immich
    driver: bridge
    enable_ipv6: true

x-hwaccel: &x-hwaccel
  devices:
    - /dev/dri:/dev/dri
  environment:
    NVIDIA_VISIBLE_DEVICES: 'all'
    NVIDIA_DRIVER_CAPABILITIES: 'all'
  deploy:
    resources:
      reservations:
        devices:
          - driver: nvidia
            count: 1
            capabilities: [gpu,video]
  runtime: nvidia

volumes:
  immich-typesense:
    driver_opts:
      type: "cifs"
      o: username=...,password=...,uid=1000,gid=1000,vers=3.0,rw
      device: "//.../immich/typesense"
  immich-upload:
    driver_opts:
      type: "cifs"
      o: username=...,password=...,uid=1000,gid=1000,vers=3.0,rw
      device: "//.../immich/upload"
  immich-cache:
    driver_opts:
      type: "cifs"
      o: username=...,password=...,uid=1000,gid=1000,vers=3.0,rw
      device: "//.../immich/cache"
  immich-micro:
    driver_opts:
      type: "cifs"
      o: username=...,password=...,uid=1000,gid=1000,vers=3.0,rw
      device: "//.../immich/micro"

services:

  immich-typesense:
    extends:
      file: ../_vm/common.yml
      service: x-common
    user: 0:0
    cap_add:
      - CHOWN
      - DAC_OVERRIDE
      - FOWNER
      - FSETID
      - SETGID
      - SETUID
      - NET_BIND_SERVICE
      - MKNOD
    container_name: immich-typesense
    hostname: typesense
    image: typesense/typesense:0.25.0
    restart: "unless-stopped"
    ports:
      - "8108:8108"
    expose:
      - "8108"
    networks:
      - immich
    healthcheck:
      test: uname -rms || exit 1
    env_file:
     - ./conf/immich/env/immich.env
    labels:
      com.stack.name: "immich"
      com.stack.service.name: "typesense"
    tmpfs:
      - /tmp:rw,noexec,nosuid,size=512M
    deploy:
      resources:
        limits:
          cpus: "4.0"
          memory: 512M
          pids: 4096
    volumes:
      - immich-typesense:/data:rw

  immich-machine-learning:
    extends:
      file: ../_vm/host.yml
      service: x-host
    user: 0:0
    cap_add:
      - CHOWN
      - DAC_OVERRIDE
      - FOWNER
      - FSETID
      - SETGID
      - SETUID
      - MKNOD
    container_name: immich-machine-learning
    hostname: immich-machine-learning
    image: ghcr.io/immich-app/immich-machine-learning:${IMMICH_VERSION:-release}
    restart: "unless-stopped"
    ports:
      - "3005:3003"
    expose:
      - "3003"
    networks:
      - immich
    healthcheck:
      test: python --version || exit 1
    env_file:
     - ./conf/immich/env/immich.env
    labels:
      com.stack.name: "immich"
      com.stack.service.name: "machine-learning"
    tmpfs:
      - /tmp:rw,noexec,nosuid,size=512M
    deploy:
      resources:
        limits:
          cpus: "4.0"
          memory: 4G
          pids: 4096
    volumes:
      - immich-cache:/cache:rw
      - immich-upload:/usr/src/app/upload:rw

  immich-server:
    extends:
      file: ../_vm/host.yml
      service: x-host
    container_name: immich-server
    hostname: immich-server
    image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release}
    restart: "unless-stopped"
    ports:
      - "3002:3001"
    expose:
      - "3001"
    networks:
      - immich
    depends_on:
      immich-typesense:
        condition: service_healthy
    healthcheck:
      test: node -v || exit 1
    command: ["start.sh", "immich"]
    env_file:
     - ./conf/immich/env/immich.env
    labels:
      com.stack.name: "immich"
      com.stack.service.name: "server"
    tmpfs:
      - /tmp:rw,noexec,nosuid,size=512M
    deploy:
      resources:
        limits:
          cpus: "4.0"
          memory: 512M
    volumes:
      - immich-upload:/usr/src/app/upload:rw

  immich-microservices:
    extends:
      file: ../_vm/host.yml
      service: x-host
    user: 0:0
    cap_add:
      - CHOWN
      - DAC_OVERRIDE
      - FOWNER
      - FSETID
      - SETGID
      - SETUID
      - MKNOD
    <<: *x-hwaccel
    container_name: immich-microservices
    hostname: immich-microservices
    image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release}
    restart: "unless-stopped"
    ports:
      - "3006:3002"
    expose:
      - "3002"
    networks:
      - immich
    depends_on:
      immich-typesense:
        condition: service_healthy
    healthcheck:
      test: node -v || exit 1
    command: ["start-microservices.sh"]
    env_file:
     - ./conf/immich/env/immich.env
    labels:
      com.stack.name: "immich"
      com.stack.service.name: "microservices"
    tmpfs:
      - /tmp:rw,noexec,nosuid,size=512M
    deploy:
      resources:
        limits:
          cpus: "8.0"
          memory: 4G
          pids: 8192
    volumes:
      - immich-micro:/usr/src/app/.reverse-geocoding-dump:rw
      - immich-upload:/usr/src/app/upload:rw

  immich-web:
    extends:
      file: ../_vm/host.yml
      service: x-host
    container_name: immich-web
    hostname: immich-web
    image: ghcr.io/immich-app/immich-web:${IMMICH_VERSION:-release}
    restart: "unless-stopped"
    ports:
      - "3004:3000"
    expose:
      - "3000"
    networks:
      - immich
    depends_on:
      immich-server:
        condition: service_healthy
    healthcheck:
      test: wget --no-verbose --tries=1 --spider http://0.0.0.0:3000/ || exit 1
    env_file:
     - ./conf/immich/env/immich.env
    labels:
      com.stack.name: "immich"
      com.stack.service.name: "web"
    tmpfs:
      - /tmp:rw,noexec,nosuid,size=512M
    deploy:
      resources:
        limits:
          cpus: "4.0"
          memory: 512M

  immich-proxy:
    extends:
      file: ../_vm/common.yml
      service: x-common
    user: 0:0
    cap_add:
      - CHOWN
      - DAC_OVERRIDE
      - FOWNER
      - FSETID
      - SETGID
      - SETUID
      - NET_BIND_SERVICE
      - MKNOD
    container_name: immich-proxy
    hostname: immich-proxy
    image: ghcr.io/immich-app/immich-proxy:${IMMICH_VERSION:-release}
    restart: "unless-stopped"
    ports:
      - "8212:8080"
    expose:
      - "8080"
    networks:
      - immich
    depends_on:
      immich-server:
        condition: service_healthy
    healthcheck:
      test: wget --no-verbose --tries=1 --spider http://0.0.0.0:8080/ || exit 1
    env_file:
     - ./conf/immich/env/immich.env
    labels:
      com.stack.name: "immich"
      com.stack.service.name: "proxy"
    tmpfs:
      - /tmp:rw,noexec,nosuid,size=512M
    deploy:
      resources:
        limits:
          cpus: "4.0"
          memory: 512M

L’utilisateur utilisé pour les partages Samba a le couple uid/gid 1000:1000. Pensez à l’ajuster selon vos besoins.

conf/immich/env/immich.env

[Fichier]

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
NODE_ENV: "production"

DB_HOSTNAME: "..."
DB_PORT: "..."
DB_USERNAME: "..."
DB_PASSWORD: "..."
DB_DATABASE_NAME: "immich"

REDIS_HOSTNAME: "..."
REDIS_PORT: "..."

JWT_SECRET: "..."

PUBLIC_LOGIN_PAGE_MESSAGE: ""

IMMICH_SERVER_URL: "http://...:3002"
IMMICH_WEB_URL: "http://...:3004"
IMMICH_MACHINE_LEARNING_URL: "http://...:3005"

TYPESENSE_API_KEY: "..."
TYPESENSE_DATA_DIR: "/data"

LOG_LEVEL: "simple"
GLOG_minloglevel: 1

DISABLE_REVERSE_GEOCODING: "false"
REVERSE_GEOCODING_PRECISION: "3"

NVIDIA_VISIBLE_DEVICES: 'all'
NVIDIA_DRIVER_CAPABILITIES: 'all'

Précisions

Dans cet article, j’utlise des volumes de stockages Samba déportés permettant de découpler la partie logicielle de la partie stockage des données.

La partie base de données, tout comme Redis sont sur mon homelab mutualisées, donc indépendantes de la stack.

Rien ne vous empêche de les ajouter afin de former un ensemble complet et indépendant.

Variables d’environnement

Je vous invites à parcourir la documentation officielle afin d’ajuster au besoin certaines variables d’environnements en fonction de vos besoin.

Désactiver l’accélération GPU

Si vous ne souhaitez pas utiliser l’accélération GPU NVidia, il vous suffit de commenter la partie :

1
  <<: *x-hwaccel

Dans le fichier docker-compose pour le service immich-microservices.

Dans le cas ou vous souhaitez conserver l’accélération GPU NVidia, je vous renvoie à la documentation de Jellyfin.

Informations

L’utilisation de ce genre d’outil requiert une bonne bande passante (à la fois montante et descendante).

Le machine learning requiert aussi une puissante conséquente, il se peut que vous deviez vous en passer.

Utilisation

Afin de profiter du logiciel, il vous suffit de vous rendre sur :

1
http://[ip]:8212

A premier lancement, vous aurez à créer le premier compte utilisateur qui sera administrateur par défaut.

Traefik

Pour l’accès à Immich depuis internet en passant par Traefik, il suffit de lui donner les bonnes informations :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 2023-10-08

http:

  routers:

    immich:
      entryPoints:
        - https
      rule: Host(`immich.domain.com`)
      middlewares:
        - default@file
      tls: {}
      service: immich

  services:

    immich:
      loadBalancer:
        servers:
          - url: "http://[ip]]:8212/"

Sachant que sur mon homelab, voici la définition des middlewares :

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
  middlewares:

    httpsredirect:
      redirectScheme:
        scheme: https

    wss:
      headers:
        customRequestHeaders:
          Connection: keep-alive, Upgrade
          Upgrade: WebSocket

    defaults:
      headers:
        frameDeny: false
        browserXssFilter: false
        forceSTSHeader: true
        stsIncludeSubdomains: true
        stsPreload: true
        stsSeconds: 15552000
        contentsecuritypolicy: "\
            script-src    'self' 'unsafe-hashes' 'unsafe-inline' 'unsafe-eval' blob: data: https: wss: http: ws:;\
            img-src       'self' 'unsafe-hashes' 'unsafe-inline' 'unsafe-eval' blob: data: https: wss: http: ws:;\
            font-src      'self' 'unsafe-hashes' 'unsafe-inline' 'unsafe-eval' blob: data: https: wss: http: ws:;\
            connect-src   'self' 'unsafe-hashes' 'unsafe-inline' 'unsafe-eval' blob: data: https: wss: http: ws:;\
            frame-src     'self' 'unsafe-hashes' 'unsafe-inline' 'unsafe-eval' blob: data: https: wss: http: ws:;\
            media-src     'self' 'unsafe-hashes' 'unsafe-inline' 'unsafe-eval' blob: data: https: wss: http: ws:;\
            style-src     'self' 'unsafe-hashes' 'unsafe-inline' 'unsafe-eval' blob: data: https: wss: http: ws:;\
            child-src     'self' 'unsafe-hashes' 'unsafe-inline' 'unsafe-eval' blob: data: https: wss: http: ws:;\
            default-src   'self' 'unsafe-hashes' 'unsafe-inline' 'unsafe-eval' blob: data: https: wss: http: ws:;\
            object-src    'none';\
          "

    security:
      headers:
        customRequestheaders:
          X-Content-Type-Options: ""
        customResponseHeaders:
          Permissions-Policy: "fullscreen=(*), display-capture=(self), accelerometer=(), battery=(), camera=(), autoplay=(self), vibrate=(self), geolocation=(self), midi=(self), notifications=(*), push=(*), microphone=(self), magnetometer=(self), gyroscope=(self), payment=(self)"
          X-Forwarded-Proto: https
          X-Permitted-Cross-Domain-Policies: all
          X-Content-Type-Options: ""
        sslProxyHeaders:
          X-Forwarded-Proto: https
        referrerPolicy: strict-origin-when-cross-origin

    corsall:
      headers:
        customRequestHeaders:
          Access-Control-Allow-Origin: origin-list-or-null
          Sec-Fetch-Site: cross-site
          X-Forwarded-Proto: https
          Access-Control-Allow-Headers: "*, Authorization"
        customResponseHeaders:
          Access-Control-Allow-Origin: "*"
          Sec-Fetch-Site: cross-site
          X-Forwarded-Proto: https
          Access-Control-Allow-Headers: "*, Authorization"
        accessControlAllowMethods:
          - OPTIONS
          - POST
          - GET
          - PUT
          - DELETE
          - PATCH
        accessControlAllowHeaders:
          - "*, Authorization"
        accessControlExposeHeaders:
          - "*, Authorization"
        accessControlMaxAge: 100
        addVaryHeader: true
        accessControlAllowCredentials: true
        accessControlAllowOriginList:
          - "*"

    waf:
      plugin:
        modsecurity:
          modSecurityUrl: http://...:...
          maxBodySize: 10485760

    crowdsec:
      forwardauth:
        address: http://...:.../api/v1/forwardAuth
        trustForwardHeader: true

    compress:
      compress: {}

    inflightreq:
      inFlightReq:
        amount: 128

    ratelimit:
      rateLimit:
        average: 64
        burst: 64

    retry:
      retry:
        attempts: 16
        initialInterval: 100ms

    autodetect:
      contentType: {}

    nowaf:
      chain:
        middlewares:
          - httpsredirect
          - inflightreq
          - ratelimit
          - retry
          - autodetect
          - defaults
          - security
          - crowdsec
          - compress

    default:
      chain:
        middlewares:
          - nowaf
          - waf

Conclusion

Avec cette solution vous disposer d’une alternative aux logiciels comme Google Photos.

N’oubliez-pas que ce logiciel est activement en développement et je vous invite à effectuer régulièrement des sauvegardes de vos photos et vidéos.

Remerciements

Cet article est sous licence CC BY 4.0 par l'auteur.

© 2022- Olivier. Certains droits réservés.

Propulsé par τζ avec le thème Χ