countithigher
Cadet
- Joined
- Nov 2, 2023
- Messages
- 4
I wanted to get Immich working on my TrueNAS system but saw there was no official support for it on FreeBSD and found no guides from others trying to do it. I think there's an interest, so I'll describe here the steps I took to get it to work and hopefully that'll help others do the same. For those a lot smarter than me, please feel free to suggest improvements or just comment where I did something wrong.
Immich is a self-hosted backup solution for photos and videos with mobile device support. The recommended way to install it is with docker and that would run in several containers. Why not get them to work in a jail on TrueNAS CORE instead. They break it out into 8 containers, only two of them I couldn't get to work since (as far as I know) they are not supported on FreeBSD. Immich can still work without the machine learning and typesense, just some features won't work.
Hope this helps! (and hope I didn't miss anything)
Immich is a self-hosted backup solution for photos and videos with mobile device support. The recommended way to install it is with docker and that would run in several containers. Why not get them to work in a jail on TrueNAS CORE instead. They break it out into 8 containers, only two of them I couldn't get to work since (as far as I know) they are not supported on FreeBSD. Immich can still work without the machine learning and typesense, just some features won't work.
name | uses | got working with |
immich_server | node | node 18 |
immich_microservices | node | node 18 |
immich_machine_learning | pytorch2.0 | not supported on FreeBSD |
immich_web | node | node 18 |
immich_typesense | typesense | not supported on FreeBSD |
immich_redis | redis | redis 7 |
immich_postgres | postgres | postgresql 14 |
immich_proxy | nginx | nginx 1.24 |
First Steps:
- Create Jail, I'm using release 13.2 with DHCP auto-configured
- I'm mounting a dataset to the jail in the location: /mnt/data
- install packages: node18, npm-node18, nginx, graphics/vips, multimedia/ffmpeg, git, postgresql14-server, postgresql14-contrib, redis
- create immich user in the wheel group: adduser
- chown immich:wheel /mnt/data
- enable services in /etc/rc.conf
- nginx_enable="YES"
- redis_enable="YES"
- postgresql_enable="YES"
- configure postgresql, run these commands
- /usr/local/etc/rc.d/postgresql initdb
- service postgresql start
- passwd postgres
- need this pw later
- using "postgres" for this example
- su - postgres
- createuser postgres
- createdb immich -O postgres
- (any other configurations you want)
- serice postgresql restart
- start redis: service redis start
Install Immich
- clone immich, git clone https://github.com/immich-app/immich
- checkout desired release version, using 1.84.0 here
build server/microservices
- navigate to server dir in the immich git repo
- npm ci
- npm run build
- npm prune --omit=dev --omit=optional
- mkdir /usr/local/www/immich/server
- cp -R ./ /usr/local/www/immich/server
- chown -R immich:wheel /usr/local/www/immich
- mkdir /usr/local/etc/immich
- strip these files (strip command)
- /usr/local/www/immich/server/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node
- /usr/local/www/immich/server/node_modules/bcrypt/build-tmp-napi-v3/Release/obj.target/bcrypt_lib.node
- /usr/local/www/immich/server/node_modules/bcrypt/build-tmp-napi-v3/Release/bcrypt_lib.node
- /usr/local/www/immich/server/node_modules/sharp/build/Release/obj.target/sharp-freebsd-x64.node
- /usr/local/www/immich/server/node_modules/sharp/build/Release/sharp-freebsd-x64.node
- change these files with sed
- sed -i '' -e "1s|/bin/bash|/usr/local/bin/bash|" /usr/local/www/immich/server/node_modules/fluent-ffmpeg/tools/test-travis.sh
- sed -i '' -e "1s|/usr/bin/perl|/usr/local/bin/perl|" /usr/local/www/immich/server/node_modules/exiftool-vendored.pl/bin/validate
- sed -i '' -e "1s|/usr/bin/perl|/usr/local/bin/perl|" /usr/local/www/immich/server/node_modules/exiftool-vendored.pl/bin/build_tag_lookup
- sed -i '' -e "1s|/usr/bin/perl|/usr/local/bin/perl|" /usr/local/www/immich/server/node_modules/exiftool-vendored.pl/bin/exiftool
- create immich_microservices service script in /usr/local/etc/rc.d (make sure it's executable)
Code:#!/bin/sh # # $FreeBSD$ # # PROVIDE: immich_microservices # REQUIRE: NETWORKING DAEMON postgres # KEYWORD: shutdown # # Add the following lines to /etc/rc.conf: # #immich_microservices_enable="YES" . /etc/rc.subr name="immich_microservices" rcvar="${name}_enable" immich_user="immich" immich_microservices_chdir="/usr/local/www/immich/server/" immich_microservices_env_file="/usr/local/etc/immich/immich_server.env" immich_microservices_env="NODE_ENV=production" pidfile="/var/run/${name}.pid" procname="/usr/local/bin/node" node="/usr/local/bin/node" node_arg="dist/main microservices" command="/usr/sbin/daemon" command_args=" -S -l daemon -s debug -T ${name} -p ${pidfile} -u ${immich_user} ${node} ${node_arg}" load_rc_config ${name} run_rc_command "$1"
- create immich_server service script in /usr/local/etc/rc.d (make sure it's executable)
Code:#!/bin/sh # # $FreeBSD$ # # PROVIDE: immich_server # REQUIRE: NETWORKING DAEMON postgres redis # KEYWORD: shutdown # # Add the following lines to /etc/rc.conf: # #immich_server_enable="YES" . /etc/rc.subr name="immich_server" rcvar="${name}_enable" immich_user="immich" immich_server_chdir="/usr/local/www/immich/server/" immich_server_env_file="/usr/local/etc/immich/immich_server.env" immich_server_env="NODE_ENV=production" pidfile="/var/run/$name.pid" procname="/usr/local/bin/node" node="/usr/local/bin/node" node_arg="dist/main immich" command="/usr/sbin/daemon" command_args=" -S -l daemon -s debug -T ${name} -p ${pidfile} -u ${immich_user} ${node} ${node_arg}" load_rc_config ${name} run_rc_command "$1"
- create immich_server.env in /usr/local/etc/immich
Code:# You can find documentation for all the supported env variables at https://immich.app/docs/install/environment-variables # The location where your uploaded files are stored UPLOAD_LOCATION=./library # The Immich version to use. You can pin this to a specific version like "v1.71.0" IMMICH_VERSION=release # Connection secrets for postgres and typesense. You should change these to random passwords TYPESENSE_ENABLED=false DB_HOSTNAME=localhost DB_USERNAME=postgres DB_DATABASE_NAME=immich DB_PASSWORD=postgres REDIS_HOSTNAME=localhost # Path where Immich will store its assets IMMICH_MEDIA_LOCATION="/mnt/data"
build web
- navigate to web dir in the immich git repo
- npm ci
- npm run build
- npm prune --omit=dev
- mkdir /usr/local/www/immich/web
- cp -R ./ /usr/local/www/immich/web
- chown -R immich:wheel /usr/local/www/immich
- create immich_web service script in /usr/local/etc/rc.d (make sure it's executable)
Code:#!/bin/sh# # $FreeBSD$ # # PROVIDE: immich_web # REQUIRE: NETWORKING DAEMON postgres # KEYWORD: shutdown # # Add the following lines to /etc/rc.conf: # #immich_web_enable="YES" . /etc/rc.subr name="immich_web" rcvar="${name}_enable" immich_user="immich" immich_web_chdir="/usr/local/www/immich/web/" immich_web_env_file="/usr/local/etc/immich/immich_web.env" immich_web_env="NODE_ENV=production" pidfile="/var/run/${name}.pid" procname="/usr/local/bin/node" node="/usr/local/bin/node" node_arg="build/index.js" command="/usr/sbin/daemon" command_args=" -S -l daemon -s debug -T ${name} -p ${pidfile} -u ${immich_user} ${node} ${node_arg}" load_rc_config ${name} run_rc_command "$1"
- create immich_web.env in /usr/local/etc/immich
Code:# You can find documentation for all the supported env variables at https://imm> # Port where the web application will listen. Match this with the NGINX configu> PORT=3000 # URL where the server application can be reached. IMMICH_SERVER_URL=http://localhost:3001 PUBLIC_IMMICH_SERVER_URL=http://localhost:3001
- create a immich.conf in /usr/local/www/nginx
Code:server { server_name localhost; listen 80; access_log off; client_max_body_size 50000M; # Compression gzip off; gzip_comp_level 2; gzip_min_length 1000; gzip_proxied any; gzip_vary on; gunzip on; # text/html is included by default gzip_types application/javascript application/json font/ttf image/svg+xml text/css; location /api { proxy_buffering off; proxy_buffer_size 16k; proxy_busy_buffers_size 24k; proxy_buffers 64 4k; proxy_force_ranges on; proxy_http_version 1.1; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-Host $http_host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Upgrade $http_upgrade; rewrite /api/(.*) /$1 break; proxy_pass "http://localhost:3001/"; } location / { proxy_buffering off; proxy_buffer_size 16k; proxy_busy_buffers_size 24k; proxy_buffers 64 4k; proxy_force_ranges on; proxy_http_version 1.1; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-Host $http_host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Upgrade $http_upgrade; proxy_pass "http://localhost:3000/"; } }
- include that conf under the http tag in the nginx conf (probably want to remove the template servers in that file too)
- check the nginx config with, nginx -t
- service nginx start
- service immich_microservices start
- service immich_server start
- service immich_web start
Hope this helps! (and hope I didn't miss anything)