test ingress

This commit is contained in:
alexbelgium
2023-01-13 12:10:36 +01:00
parent 1826005537
commit 9e0604b6aa
15 changed files with 642 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
#!/bin/bash
echo "Starting..."
####################
# Starting scripts #
####################
for SCRIPTS in /etc/cont-init.d/*; do
[ -e "$SCRIPTS" ] || continue
echo "$SCRIPTS: executing"
chown "$(id -u)":"$(id -g)" "$SCRIPTS"
chmod a+x "$SCRIPTS"
# Change shebang if no s6 supervision
sed -i 's|/usr/bin/with-contenv bashio|/usr/bin/env bashio|g' "$SCRIPTS"
/."$SCRIPTS" || echo "$SCRIPTS: exiting $?"
done

View File

@@ -0,0 +1,24 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
#################
# DATA_LOCATION #
#################
PUID="$(bashio::config 'PUID')"
PGID="$(bashio::config 'PGID')"
bashio::log.info "Setting data location"
DATA_LOCATION="$(bashio::config 'data_location')"
echo "... check $DATA_LOCATION folder exists"
mkdir -p "$DATA_LOCATION"
echo "... setting permissions"
chown -R "$PUID":"$PGID" "$DATA_LOCATION"
echo "... correcting official script"
for file in $(grep -sril '/photos' /etc); do sed -i "s|/photos|$DATA_LOCATION|g" "$file"; done
rm -r /photos
ln -sf "$DATA_LOCATION" /photos
chown -R "$PUID":"$PGID" /photos

View File

@@ -0,0 +1,15 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
#################
# NGINX SETTING #
#################
declare ingress_interface
declare ingress_port
ingress_port=$(bashio::addon.ingress_port)
ingress_interface=$(bashio::addon.ip_address)
ingress_entry=$(bashio::addon.ingress_entry)
sed -i "s/%%port%%/${ingress_port}/g" /etc/nginx/servers/ingress.conf
sed -i "s/%%interface%%/${ingress_interface}/g" /etc/nginx/servers/ingress.conf
sed -i "s|%%ingress_entry%%|${ingress_entry}|g" /etc/nginx/servers/ingress.conf

View File

@@ -0,0 +1,111 @@
#!/usr/bin/env bashio
# shellcheck shell=bash
# shellcheck disable=SC2155,SC2016
###################################
# Export all addon options as env #
###################################
bashio::log.info "Setting variables"
# For all keys in options.json
JSONSOURCE="/data/options.json"
# Export keys as env variables
# echo "All addon options were exported as variables"
mapfile -t arr < <(jq -r 'keys[]' "${JSONSOURCE}")
for KEYS in "${arr[@]}"; do
# export key
VALUE=$(jq ."$KEYS" "${JSONSOURCE}")
line="${KEYS}='${VALUE//[\"\']/}'"
# text
if bashio::config.false "verbose" || [[ "${KEYS}" == *"PASS"* ]]; then
bashio::log.blue "${KEYS}=******"
else
bashio::log.blue "$line"
fi
# Use locally
export "${KEYS}=${VALUE//[\"\']/}"
done
###################
# Define database #
###################
bashio::log.info "Defining database"
bashio::log.info "-----------------"
case $(bashio::config 'database') in
"external_postgresql")
bashio::log.info "Using external postgresql"
bashio::log.info ""
# Check if values exist
if ! bashio::config.has_value 'DB_USERNAME' && \
! bashio::config.has_value 'DB_HOSTNAME' && \
! bashio::config.has_value 'DB_PASSWORD' && \
! bashio::config.has_value 'DB_DATABASE_NAME' && \
! bashio::config.has_value 'JWT_SECRET' && \
! bashio::config.has_value 'DB_PORT'
then
! bashio::exit.nok "Please make sure that the following options are set : DB_USERNAME, DB_HOSTNAME, DB_PASSWORD, DB_DATABASE_NAME, DB_PORT"
fi
# Settings parameters
export DB_USERNAME=$(bashio::config 'DB_USERNAME')
export DB_HOSTNAME=$(bashio::config 'DB_HOSTNAME')
export DB_PASSWORD=$(bashio::config 'DB_PASSWORD')
export DB_DATABASE_NAME=$(bashio::config 'DB_DATABASE_NAME')
export DB_PORT=$(bashio::config 'DB_PORT')
export JWT_SECRET=$(bashio::config 'JWT_SECRET')
;;
**)
bashio::log.info "Using internal postgresql"
bashio::log.info ""
# Settings files & permissions
ln -s /usr/lib/postgresql/14/bin/postgres /usr/bin || true
ln -s /usr/lib/postgresql/14/bin/psql /usr/psql || true
mkdir -p /data/postgresql
cp -rnf /var/lib/postgresql/14/main/* /data/postgresql/
chown -R postgres /data/postgresql
chmod -R 700 /data/postgresql
# Start postgresql
/etc/init.d/postgresql start
# Create database
echo "CREATE ROLE root WITH LOGIN SUPERUSER CREATEDB CREATEROLE PASSWORD 'securepassword';
CREATE DATABASE immich; CREATE USER immich WITH ENCRYPTED PASSWORD 'immich';
GRANT ALL PRIVILEGES ON DATABASE immich to immich;
\q"> setup_postgres.sql
chown postgres setup_postgres.sql
sudo -iu postgres psql < setup_postgres.sql
rm setup_postgres.sql
# Settings parameters
export DB_USERNAME=immich
export DB_HOSTNAME=localhost
export DB_PASSWORD=immich
export DB_DATABASE_NAME=immich
export DB_PORT=5432
export JWT_SECRET=$(bashio::config 'JWT_SECRET')
;;
esac
##################
# Starting redis #
##################
exec redis-server & bashio::log.info "Starting redis"
################
# Starting app #
################
bashio::log.info "Starting app"
/./usr/bin/supervisord

View File

@@ -0,0 +1,42 @@
server {
listen %%interface%%:%%port%% default_server;
include /etc/nginx/includes/server_params.conf;
include /etc/nginx/includes/proxy_params.conf;
client_max_body_size 0;
server_name immich.*;
location / {
include /config/nginx/proxy.conf;
include /config/nginx/resolver.conf;
proxy_pass http://127.0.0.1:3000;
proxy_buffering off;
proxy_buffer_size 16k;
proxy_busy_buffers_size 24k;
proxy_buffers 64 4k;
proxy_force_ranges on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
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_set_header Connection $connection_upgrade;
}
location /api {
include /config/nginx/proxy.conf;
include /config/nginx/resolver.conf;
proxy_pass http://127.0.0.1:3001;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
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_set_header Connection $connection_upgrade;
rewrite /api/(.*) /$1 break;
}
}