mirror of
https://github.com/armbian/configng.git
synced 2026-01-06 10:37:41 -08:00
Deploy database for Immich and Netbox in separate containers
- deleting doesn't delete Docker image - updating image upon (re)install - improving parameters handling
This commit is contained in:
@@ -17,9 +17,17 @@ function module_immich () {
|
||||
local title="immich"
|
||||
local condition=$(which "$title" 2>/dev/null)
|
||||
|
||||
# Database
|
||||
local DATABASE_USER="immich"
|
||||
local DATABASE_PASSWORD="immich"
|
||||
local DATABASE_NAME="immich"
|
||||
local DATABASE_HOST="postgres-immich"
|
||||
local DATABASE_IMAGE="tensorchord/pgvecto-rs:pg14-v0.2.0"
|
||||
local DATABASE_PORT="5432"
|
||||
|
||||
if pkg_installed docker-ce; then
|
||||
local container=$(docker container ls -a | mawk '/immich?( |$)/{print $1}')
|
||||
local image=$(docker image ls -a | mawk '/immich?( |$)/{print $3}')
|
||||
local container=$(docker ps -q -f "name=^immich$")
|
||||
local image=$(docker images -q ghcr.io/imagegenius/immich)
|
||||
fi
|
||||
|
||||
local commands
|
||||
@@ -31,6 +39,7 @@ function module_immich () {
|
||||
"${commands[0]}")
|
||||
shift
|
||||
|
||||
|
||||
if ! pkg_installed docker-ce; then
|
||||
module_docker install
|
||||
fi
|
||||
@@ -42,25 +51,31 @@ function module_immich () {
|
||||
"$IMMICH_BASE"/libraries
|
||||
touch "$IMMICH_BASE"/photos/{backups,thumbs,profile,upload,library,encoded-video}/.immich
|
||||
sudo chown -R 1000:1000 "$IMMICH_BASE"/
|
||||
|
||||
# Install armbian-config dependencies
|
||||
if ! docker container ls -a --format '{{.Names}}' | grep -q '^redis$'; then module_redis install; fi
|
||||
if ! docker container ls -a --format '{{.Names}}' | grep -q '^postgres$'; then module_postgres install; fi
|
||||
if ! docker container ls -a --format '{{.Names}}' | grep "^$DATABASE_HOST$"; then
|
||||
module_postgres install $DATABASE_USER $DATABASE_PASSWORD $DATABASE_NAME $DATABASE_IMAGE $DATABASE_HOST
|
||||
fi
|
||||
|
||||
until docker exec -i postgres psql -U armbian -c '\q' 2>/dev/null; do
|
||||
until docker exec -i $DATABASE_HOST psql -U $DATABASE_USER -c '\q' 2>/dev/null; do
|
||||
echo "⏳ Waiting for PostgreSQL to be ready..."
|
||||
sleep 2
|
||||
done
|
||||
echo "✅ PostgreSQL is ready. Creating Immich DB..."
|
||||
|
||||
if docker exec -i postgres psql -U armbian -tAc "SELECT 1 FROM pg_database WHERE datname='immich';" | grep -q 1; then
|
||||
echo "✅ Database 'immich' exists."
|
||||
if docker exec -i $DATABASE_HOST psql -U $DATABASE_USER -tAc "SELECT 1 FROM pg_database WHERE datname='$DATABASE_NAME';" | grep -q 1; then
|
||||
echo "✅ Database '$DATABASE_NAME' exists."
|
||||
else
|
||||
docker exec -i postgres psql -U armbian <<-EOT
|
||||
CREATE DATABASE immich;
|
||||
GRANT ALL PRIVILEGES ON DATABASE immich TO armbian;
|
||||
docker exec -i $DATABASE_HOST psql -U $DATABASE_USER <<-EOT
|
||||
CREATE DATABASE $DATABASE_NAME;
|
||||
GRANT ALL PRIVILEGES ON DATABASE $DATABASE_NAME TO $DATABASE_USER;
|
||||
EOT
|
||||
fi
|
||||
|
||||
# Download or update image
|
||||
docker pull ghcr.io/imagegenius/immich:latest
|
||||
|
||||
# Run Immich container
|
||||
if ! docker run -d \
|
||||
--name=immich \
|
||||
@@ -68,12 +83,12 @@ function module_immich () {
|
||||
-e PUID=1000 \
|
||||
-e PGID=1000 \
|
||||
-e TZ="$(cat /etc/timezone)" \
|
||||
-e DB_HOSTNAME=postgres \
|
||||
-e DB_USERNAME=armbian \
|
||||
-e DB_PASSWORD=armbian \
|
||||
-e DB_DATABASE_NAME=immich \
|
||||
-e DB_HOSTNAME=$DATABASE_HOST \
|
||||
-e DB_USERNAME=$DATABASE_USER \
|
||||
-e DB_PASSWORD=$DATABASE_PASSWORD \
|
||||
-e DB_DATABASE_NAME=$DATABASE_NAME \
|
||||
-e REDIS_HOSTNAME=redis \
|
||||
-e DB_PORT=5432 \
|
||||
-e DB_PORT=$DATABASE_PORT \
|
||||
-e REDIS_PORT=6379 \
|
||||
-e REDIS_PASSWORD= \
|
||||
-e SERVER_HOST=0.0.0.0 \
|
||||
@@ -115,13 +130,13 @@ function module_immich () {
|
||||
if [ -n "$container" ]; then
|
||||
docker container rm -f "$container" >/dev/null
|
||||
fi
|
||||
|
||||
if [ -n "$image" ]; then
|
||||
docker image rm "$image" >/dev/null
|
||||
fi
|
||||
;;
|
||||
"${commands[2]}")
|
||||
module_immich "${commands[1]}"
|
||||
if [ -n "$image" ]; then
|
||||
docker image rm -f "$image"
|
||||
fi
|
||||
module_postgres purge $DATABASE_USER $DATABASE_PASSWORD $DATABASE_NAME $DATABASE_IMAGE $DATABASE_HOST
|
||||
if [ -n "$IMMICH_BASE" ] && [ "$IMMICH_BASE" != "/" ]; then
|
||||
rm -rf "$IMMICH_BASE"
|
||||
fi
|
||||
|
||||
@@ -18,9 +18,21 @@ function module_netbox () {
|
||||
local title="netbox"
|
||||
local condition=$(which "$title" 2>/dev/null)
|
||||
|
||||
# Accept optional parameters
|
||||
local SUPERUSER_EMAIL="$2"
|
||||
local SUPERUSER_PASSWORD="$3"
|
||||
|
||||
# Database
|
||||
local DATABASE_USER="netbox"
|
||||
local DATABASE_PASSWORD="netbox"
|
||||
local DATABASE_NAME="netbox"
|
||||
local DATABASE_HOST="postgres-netbox"
|
||||
local DATABASE_IMAGE="postgres:17-alpine"
|
||||
local DATABASE_PORT="5432"
|
||||
|
||||
if pkg_installed docker-ce; then
|
||||
local container=$(docker container ls -a | mawk '/netbox?( |$)/{print $1}')
|
||||
local image=$(docker image ls -a | mawk '/netbox?( |$)/{print $3}')
|
||||
local container=$(docker ps -q -f "name=^netbox$")
|
||||
local image=$(docker images -q netboxcommunity/netbox)
|
||||
fi
|
||||
|
||||
local commands
|
||||
@@ -30,18 +42,12 @@ function module_netbox () {
|
||||
|
||||
case "$1" in
|
||||
"${commands[0]}")
|
||||
shift
|
||||
# Accept optional parameters
|
||||
local SUPERUSER_EMAIL="$1"
|
||||
local SUPERUSER_PASSWORD="$2"
|
||||
|
||||
# Prompt for email and password using dialog
|
||||
[[ -z "$SUPERUSER_EMAIL" ]] && \
|
||||
SUPERUSER_EMAIL=$($DIALOG --title "Enter superuser email" --inputbox "" 8 50 3>&1 1>&2 2>&3)
|
||||
SUPERUSER_EMAIL=$($DIALOG --title "Enter NetBox superuser email" --inputbox "" 8 50 3>&1 1>&2 2>&3)
|
||||
[[ -z "$SUPERUSER_EMAIL" ]] && SUPERUSER_EMAIL="info@armbian.com"
|
||||
|
||||
[[ -z "$SUPERUSER_PASSWORD" ]] && \
|
||||
SUPERUSER_PASSWORD=$($DIALOG --title "Enter admin password" --passwordbox "" 8 50 3>&1 1>&2 2>&3)
|
||||
SUPERUSER_PASSWORD=$($DIALOG --title "Enter NetBox admin password" --passwordbox "" 8 50 3>&1 1>&2 2>&3)
|
||||
[[ -z "$SUPERUSER_PASSWORD" ]] && SUPERUSER_PASSWORD="armbian"
|
||||
|
||||
clear # Clean up dialog artifacts
|
||||
@@ -51,7 +57,9 @@ function module_netbox () {
|
||||
|
||||
# Install armbian-config dependencies
|
||||
if ! docker container ls -a --format '{{.Names}}' | grep -q '^redis$'; then module_redis install; fi
|
||||
if ! docker container ls -a --format '{{.Names}}' | grep -q '^postgres$'; then module_postgres install; fi
|
||||
if ! docker container ls -a --format '{{.Names}}' | grep -q "^$DATABASE_HOST$"; then
|
||||
module_postgres install $DATABASE_USER $DATABASE_PASSWORD $DATABASE_NAME $DATABASE_IMAGE $DATABASE_HOST
|
||||
fi
|
||||
|
||||
# Generate a random secret key (50+ chars)
|
||||
NETBOX_SECRET_KEY=$(tr -dc 'A-Za-z0-9!@#$%^&*()-_=+' </dev/urandom | head -c 64)
|
||||
@@ -63,11 +71,11 @@ function module_netbox () {
|
||||
cat > "$NETBOX_BASE/config/configuration.py" <<- EOT
|
||||
ALLOWED_HOSTS = ['*']
|
||||
DATABASE = {
|
||||
'NAME': 'netbox',
|
||||
'USER': 'armbian',
|
||||
'PASSWORD': 'armbian',
|
||||
'HOST': 'postgres',
|
||||
'PORT': '5432',
|
||||
'NAME': '$DATABASE_NAME',
|
||||
'USER': '$DATABASE_USER',
|
||||
'PASSWORD': '$DATABASE_PASSWORD',
|
||||
'HOST': '$DATABASE_HOST',
|
||||
'PORT': '$DATABASE_PORT',
|
||||
}
|
||||
|
||||
REDIS = {
|
||||
@@ -90,6 +98,9 @@ function module_netbox () {
|
||||
EOT
|
||||
fi
|
||||
|
||||
# Download or update image
|
||||
docker pull netboxcommunity/netbox:latest
|
||||
|
||||
if ! docker run -d \
|
||||
--name=netbox \
|
||||
--net=lsio \
|
||||
@@ -140,13 +151,13 @@ function module_netbox () {
|
||||
if [[ -n "${container}" ]]; then
|
||||
docker container rm -f "$container" >/dev/null
|
||||
fi
|
||||
|
||||
if [[ -n "${image}" ]]; then
|
||||
docker image rm "$image" >/dev/null
|
||||
fi
|
||||
;;
|
||||
"${commands[2]}")
|
||||
${module_options["module_netbox,feature"]} ${commands[1]}
|
||||
if [[ -n "${image}" ]]; then
|
||||
docker image rm "$image" >/dev/null
|
||||
fi
|
||||
module_postgres purge $DATABASE_USER $DATABASE_PASSWORD $DATABASE_NAME $DATABASE_IMAGE $DATABASE_HOST
|
||||
if [[ -n "${NETBOX_BASE}" && "${NETBOX_BASE}" != "/" ]]; then
|
||||
rm -rf "${NETBOX_BASE}"
|
||||
fi
|
||||
|
||||
@@ -18,48 +18,54 @@ function module_postgres () {
|
||||
local title="postgres"
|
||||
local condition=$(which "$title" 2>/dev/null)
|
||||
|
||||
# Accept optional parameters
|
||||
local POSTGRES_USER="$2"
|
||||
local POSTGRES_PASSWORD="$3"
|
||||
local POSTGRES_DB="$4"
|
||||
local POSTGRES_IMAGE="$5"
|
||||
local POSTGRES_CONTAINER="$6"
|
||||
|
||||
# Defaults if nothing is set
|
||||
POSTGRES_USER="${POSTGRES_USER:-armbian}"
|
||||
POSTGRES_PASSWORD="${POSTGRES_PASSWORD:-armbian}"
|
||||
POSTGRES_DB="${POSTGRES_DB:-armbian}"
|
||||
POSTGRES_IMAGE="${POSTGRES_IMAGE:-tensorchord/pgvecto-rs:pg14-v0.2.0}"
|
||||
POSTGRES_CONTAINER="${POSTGRES_CONTAINER:-postgres}"
|
||||
|
||||
if pkg_installed docker-ce; then
|
||||
local container=$(docker container ls -a | mawk '/postgres?( |$)/{print $1}')
|
||||
local image=$(docker image ls -a | mawk '/pg14-v0.2.0?( |$)/{print $3}')
|
||||
local container=$(docker ps -q -f "name=^${POSTGRES_CONTAINER}$")
|
||||
local image=$(docker images -q $POSTGRES_IMAGE)
|
||||
fi
|
||||
|
||||
local commands
|
||||
IFS=' ' read -r -a commands <<< "${module_options["module_postgres,example"]}"
|
||||
|
||||
POSTGRES_BASE="${SOFTWARE_FOLDER}/postgres"
|
||||
POSTGRES_BASE="${SOFTWARE_FOLDER}/${POSTGRES_CONTAINER}"
|
||||
|
||||
case "$1" in
|
||||
"${commands[0]}")
|
||||
shift
|
||||
# Accept optional parameters
|
||||
local POSTGRES_USER="$1"
|
||||
local POSTGRES_PASSWORD="$2"
|
||||
local POSTGRES_DB="$3"
|
||||
pkg_installed docker-ce || module_docker install
|
||||
[[ -d "$POSTGRES_BASE" ]] || mkdir -p "$POSTGRES_BASE" || { echo "Couldn't create storage directory: $POSTGRES_BASE"; exit 1; }
|
||||
# Set defaults if empty
|
||||
POSTGRES_USER="${POSTGRES_USER:-armbian}"
|
||||
POSTGRES_PASSWORD="${POSTGRES_PASSWORD:-armbian}"
|
||||
POSTGRES_DB="${POSTGRES_DB:-armbian}"
|
||||
# Download or update image
|
||||
docker pull $POSTGRES_IMAGE
|
||||
docker run -d \
|
||||
--name=postgres \
|
||||
--name=${POSTGRES_CONTAINER} \
|
||||
--net=lsio \
|
||||
-e POSTGRES_USER=${POSTGRES_USER} \
|
||||
-e POSTGRES_PASSWORD=${POSTGRES_PASSWORD} \
|
||||
-e POSTGRES_DB=${POSTGRES_DB} \
|
||||
-e TZ="$(cat /etc/timezone)" \
|
||||
-p 5432:5432 \
|
||||
-v "${POSTGRES_BASE}/data:/var/lib/postgresql/data" \
|
||||
-v "${POSTGRES_BASE}/${POSTGRES_CONTAINER}/data:/var/lib/postgresql/data" \
|
||||
--restart unless-stopped \
|
||||
tensorchord/pgvecto-rs:pg14-v0.2.0
|
||||
${POSTGRES_IMAGE}
|
||||
for i in $(seq 1 20); do
|
||||
if docker inspect -f '{{ index .Config.Labels "org.opencontainers.image.version" }}' postgres >/dev/null 2>&1 ; then
|
||||
if docker inspect -f '{{ index .Config.Labels "org.opencontainers.image.version" }}' ${POSTGRES_CONTAINER} >/dev/null 2>&1 ; then
|
||||
break
|
||||
else
|
||||
sleep 3
|
||||
fi
|
||||
if [ $i -eq 20 ]; then
|
||||
echo -e "\nTimed out waiting for ${title} to start, consult your container logs for more info (\`docker logs postgres\`)"
|
||||
echo -e "\nTimed out waiting for ${title} to start, consult your container logs for more info (\`docker logs ${POSTGRES_CONTAINER}\`)"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
@@ -68,13 +74,12 @@ function module_postgres () {
|
||||
if [[ -n "${container}" ]]; then
|
||||
docker container rm -f "${container}" >/dev/null
|
||||
fi
|
||||
|
||||
if [[ -n "${image}" ]]; then
|
||||
docker image rm "${image}" >/dev/null
|
||||
fi
|
||||
;;
|
||||
"${commands[2]}")
|
||||
${module_options["module_postgres,feature"]} ${commands[1]}
|
||||
${module_options["module_postgres,feature"]} ${commands[1]} $POSTGRES_USER $POSTGRES_PASSWORD $POSTGRES_DB $POSTGRES_IMAGE $POSTGRES_CONTAINER
|
||||
if [[ -n "${POSTGRES_BASE}" && "${POSTGRES_BASE}" != "/" ]]; then
|
||||
rm -rf "${POSTGRES_BASE}"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user