Browse Source

Merge pull request #9537 from sinanmohd/feat-upstall-sqlite

feat: add sqlite support in the upstall script
pull/9575/head
Pranav C 2 months ago committed by GitHub
parent
commit
ebb3abeb02
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 150
      docker-compose/1_Auto_Upstall/noco.sh

150
docker-compose/1_Auto_Upstall/noco.sh

@ -34,6 +34,7 @@ CONFIG_REDIS_PASSWORD=""
CONFIG_MINIO_ACCESS_KEY="" CONFIG_MINIO_ACCESS_KEY=""
CONFIG_MINIO_ACCESS_SECRET="" CONFIG_MINIO_ACCESS_SECRET=""
CONFIG_DOCKER_COMMAND="" CONFIG_DOCKER_COMMAND=""
CONFIG_POSTGRES_SQLITE=""
declare -a message_arr declare -a message_arr
@ -82,7 +83,7 @@ urlencode() {
c=${string:$pos:1} c=${string:$pos:1}
case "$c" in case "$c" in
[-_.~a-zA-Z0-9]) o="$c" ;; [-_.~a-zA-Z0-9]) o="$c" ;;
* ) printf -v o '%%%02X' "'$c" *) printf -v o '%%%02X' "'$c" ;;
esac esac
encoded+="$o" encoded+="$o"
done done
@ -153,7 +154,6 @@ get_nproc() {
fi fi
} }
prompt() { prompt() {
local prompt_text="$1" local prompt_text="$1"
local default_value="$2" local default_value="$2"
@ -172,6 +172,41 @@ prompt() {
fi fi
} }
prompt_oneof() {
local response
local resp_upper
local oneof_text
local prompt_text="$1"
local default_response="$2"
shift 1
prompt_text+=" (default: $default_response) "
oneof_text+="["
for one in "$@"; do
oneof_text+="$one,"
done
oneof_text="${oneof_text%%,}]"
prompt_text+="${oneof_text}: "
while true; do
read -r -p "$prompt_text" response
if [ -z "$response" ]; then
echo "$default_response"
return
fi
for one in "$@"; do
resp_upper="$(echo "$response" | tr '[:lower:]' '[:upper:]')"
one_upper="$(echo "$one" | tr '[:lower:]' '[:upper:]')"
if [ "$resp_upper" = "$one_upper" ]; then
echo "$one"
return
fi
done
print_error "This field should be one of ${oneof_text}."
done
}
prompt_required() { prompt_required() {
local prompt_text="$1" local prompt_text="$1"
local response local response
@ -205,25 +240,21 @@ prompt_number() {
confirm() { confirm() {
local prompt_text="$1" local prompt_text="$1"
local default_response="${2:-N}" local default_response="${2:-N}"
local secondary_response
local response local response
case "$default_response" in
"Y") secondary_response="N" ;;
"N") secondary_response="Y" ;;
esac
if [ "$default_response" = "Y" ] || [ "$default_response" = "y" ]; then response="$(prompt_oneof "$prompt_text" "$default_response" "$secondary_response")"
prompt_text+=" [Y/n]: " if [ "$response" = "Y" ]; then
else
prompt_text+=" [y/N]: "
fi
read -r -p "$prompt_text" response
response="${response:-$default_response}"
if [ "$response" = "Y" ] || [ "$response" = "y" ]; then
return 0 return 0
else elif [ "$response" = "N" ]; then
return 1 return 1
fi fi
} }
generate_contact_email() { generate_contact_email() {
local domain="$1" local domain="$1"
local email local email
@ -266,7 +297,6 @@ add_to_hosts() {
local HOSTS_FILE="/etc/hosts" local HOSTS_FILE="/etc/hosts"
local TEMP_HOSTS_FILE="/tmp/hosts.tmp" local TEMP_HOSTS_FILE="/tmp/hosts.tmp"
if is_valid_domain $CONFIG_MINIO_DOMAIN_NAME; then if is_valid_domain $CONFIG_MINIO_DOMAIN_NAME; then
return 0 return 0
elif sudo grep -q "${CONFIG_MINIO_DOMAIN_NAME}" "$HOSTS_FILE"; then elif sudo grep -q "${CONFIG_MINIO_DOMAIN_NAME}" "$HOSTS_FILE"; then
@ -350,6 +380,25 @@ check_if_docker_is_running() {
fi fi
} }
persistent_store_isdeleted() {
_persistent_store="$1"
if [ ! -d "$_persistent_store" ]; then
print_warning "Persistent store was deleted without stopping the containers"
for container in $($CONFIG_DOCKER_COMMAND ps | grep -Eo 'nocodb-[a-z]+-[0-9]+$'); do
if ! $CONFIG_DOCKER_COMMAND stop "$container" > /dev/null 2>&1; then
print_error "Failed to stop ${container}"
exit 1
fi
done
return 0
fi
return 1
}
# Main functions # Main functions
check_existing_installation() { check_existing_installation() {
NOCO_FOUND=false NOCO_FOUND=false
@ -358,18 +407,17 @@ check_existing_installation() {
if [ -d "$NOCO_HOME" ]; then if [ -d "$NOCO_HOME" ]; then
NOCO_FOUND=true NOCO_FOUND=true
elif $CONFIG_DOCKER_COMMAND ps --format '{{.Names}}' | grep -q "nocodb"; then elif $CONFIG_DOCKER_COMMAND ps --format '{{.Names}}' | grep -q "nocodb"; then
NOCO_ID=$($CONFIG_DOCKER_COMMAND ps | grep "nocodb/nocodb" | cut -d ' ' -f 1) NOCO_ID="$($CONFIG_DOCKER_COMMAND ps | grep "nocodb/nocodb" | cut -d ' ' -f 1)"
CUSTOM_HOME=$($CONFIG_DOCKER_COMMAND inspect --format='{{index .Mounts 0}}' "$NOCO_ID" | cut -d ' ' -f 3) CUSTOM_HOME="$($CONFIG_DOCKER_COMMAND inspect --format='{{index .Mounts 0}}' "$NOCO_ID" | cut -d ' ' -f 3)"
PARENT_DIR=$(dirname "$CUSTOM_HOME") PARENT_DIR="$(dirname "$CUSTOM_HOME")"
if ! persistent_store_isdeleted "$PARENT_DIR"; then
ln -s "$PARENT_DIR" "$NOCO_HOME" ln -s "$PARENT_DIR" "$NOCO_HOME"
basename "$PARENT_DIR" >"$NOCO_HOME/.COMPOSE_PROJECT_NAME" basename "$PARENT_DIR" >"$NOCO_HOME/.COMPOSE_PROJECT_NAME"
NOCO_FOUND=true NOCO_FOUND=true
else
mkdir -p "$NOCO_HOME"
fi fi
fi
mkdir -p "$NOCO_HOME"
cd "$NOCO_HOME" || exit 1 cd "$NOCO_HOME" || exit 1
# Check if nocodb is already installed # Check if nocodb is already installed
@ -388,7 +436,7 @@ check_existing_installation() {
exit 0 exit 0
else else
echo "Reinstalling NocoDB..." echo "Reinstalling NocoDB..."
$CONFIG_DOCKER_COMMAND compose down $CONFIG_DOCKER_COMMAND compose down -v
unset COMPOSE_PROJECT_NAME unset COMPOSE_PROJECT_NAME
cd /tmp || exit 1 cd /tmp || exit 1
@ -430,11 +478,7 @@ get_user_inputs() {
CONFIG_DOMAIN_NAME=$(prompt "Enter the IP address or domain name for the NocoDB instance" "$(get_public_ip)") CONFIG_DOMAIN_NAME=$(prompt "Enter the IP address or domain name for the NocoDB instance" "$(get_public_ip)")
if is_valid_domain "$CONFIG_DOMAIN_NAME"; then if is_valid_domain "$CONFIG_DOMAIN_NAME"; then
if confirm "Do you want to configure SSL for $CONFIG_DOMAIN_NAME?"; then CONFIG_SSL_ENABLED="$(prompt_oneof "Do you want to configure SSL for $CONFIG_DOMAIN_NAME" "Y" "N")"
CONFIG_SSL_ENABLED="Y"
else
CONFIG_SSL_ENABLED="N"
fi
else else
CONFIG_SSL_ENABLED="N" CONFIG_SSL_ENABLED="N"
fi fi
@ -447,31 +491,29 @@ get_user_inputs() {
} }
get_advanced_options() { get_advanced_options() {
CONFIG_EDITION=$(prompt "Choose Community or Enterprise Edition [CE/EE]" "CE") CONFIG_EDITION=$(prompt_oneof "Choose Community or Enterprise Edition" "CE" "EE")
if [ "$CONFIG_EDITION" = "EE" ] || [ "$CONFIG_EDITION" = "ee" ]; then if [ "$CONFIG_EDITION" = "EE" ]; then
CONFIG_LICENSE_KEY=$(prompt_required "Enter the NocoDB license key") CONFIG_LICENSE_KEY=$(prompt_required "Enter the NocoDB license key")
else
CONFIG_POSTGRES_SQLITE=$(prompt_oneof "Select PostgreSQL or SQLite as your database" "P" "S")
fi fi
CONFIG_REDIS_ENABLED=$(confirm "Do you want to enable Redis for caching?" "Y" && echo "Y" || echo "N" "Y") CONFIG_REDIS_ENABLED=$(prompt_oneof "Do you want to enable Redis for caching?" "Y" "N")
CONFIG_MINIO_ENABLED=$(confirm "Do you want to enable Minio for file storage?" "Y" && echo "Y" || echo "N" "Y") CONFIG_MINIO_ENABLED=$(prompt_oneof "Do you want to enable Minio for file storage?" "Y" "N")
if [ "$CONFIG_MINIO_ENABLED" = "Y" ] || [ "$CONFIG_MINIO_ENABLED" = "y" ]; then if [ "$CONFIG_MINIO_ENABLED" = "Y" ]; then
CONFIG_MINIO_DOMAIN_NAME=$(prompt "Enter the MinIO domain name" "$(get_public_ip)") CONFIG_MINIO_DOMAIN_NAME=$(prompt "Enter the MinIO domain name" "$(get_public_ip)")
if is_valid_domain "$CONFIG_MINIO_DOMAIN_NAME"; then if is_valid_domain "$CONFIG_MINIO_DOMAIN_NAME"; then
if confirm "Do you want to configure SSL for $CONFIG_MINIO_DOMAIN_NAME?"; then CONFIG_MINIO_SSL_ENABLED="$(prompt_oneof "Do you want to configure SSL for $CONFIG_MINIO_DOMAIN_NAME" "Y" "N")"
CONFIG_MINIO_SSL_ENABLED="Y"
else
CONFIG_MINIO_SSL_ENABLED="N"
fi
else else
CONFIG_MINIO_SSL_ENABLED="N" CONFIG_MINIO_SSL_ENABLED="N"
fi fi
fi fi
CONFIG_WATCHTOWER_ENABLED=$(confirm "Do you want to enable Watchtower for automatic updates?" "Y" && echo "Y" || echo "N") CONFIG_WATCHTOWER_ENABLED=$(prompt_oneof "Do you want to enable Watchtower for automatic updates?" "Y" "N")
NUM_CORES=$(get_nproc) NUM_CORES=$(get_nproc)
CONFIG_NUM_INSTANCES=$(read_number_range "How many instances of NocoDB do you want to run?" 1 "$NUM_CORES" 1) CONFIG_NUM_INSTANCES=$(read_number_range "How many instances of NocoDB do you want to run?" 1 "$NUM_CORES" 1)
@ -479,6 +521,7 @@ get_advanced_options() {
set_default_options() { set_default_options() {
CONFIG_EDITION="CE" CONFIG_EDITION="CE"
CONFIG_POSTGRES_SQLITE="P"
CONFIG_REDIS_ENABLED="Y" CONFIG_REDIS_ENABLED="Y"
CONFIG_MINIO_ENABLED="Y" CONFIG_MINIO_ENABLED="Y"
CONFIG_MINIO_DOMAIN_NAME=$(get_public_ip) CONFIG_MINIO_DOMAIN_NAME=$(get_public_ip)
@ -496,13 +539,12 @@ generate_credentials() {
create_docker_compose_file() { create_docker_compose_file() {
if [ "${CONFIG_EDITION}" = "EE" ] || [ "${CONFIG_EDITION}" = "ee" ]; then if [ "${CONFIG_EDITION}" = "EE" ]; then
image="nocodb/nocodb-ee:latest" image="nocodb/nocodb-ee:latest"
else else
image="nocodb/nocodb:latest" image="nocodb/nocodb:latest"
fi fi
# for easier string interpolation # for easier string interpolation
if [ "${CONFIG_REDIS_ENABLED}" = "Y" ]; then if [ "${CONFIG_REDIS_ENABLED}" = "Y" ]; then
gen_redis=1 gen_redis=1
@ -510,6 +552,9 @@ create_docker_compose_file() {
if [ "${CONFIG_MINIO_ENABLED}" = "Y" ]; then if [ "${CONFIG_MINIO_ENABLED}" = "Y" ]; then
gen_minio=1 gen_minio=1
fi fi
if [ "${CONFIG_POSTGRES_SQLITE}" = "P" ]; then
gen_postgres=1
fi
local compose_file="docker-compose.yml" local compose_file="docker-compose.yml"
@ -521,10 +566,18 @@ services:
deploy: deploy:
mode: replicated mode: replicated
replicas: ${CONFIG_NUM_INSTANCES} replicas: ${CONFIG_NUM_INSTANCES}
EOF
if [ -n "$gen_postgres" ] || [ -n "$gen_redis" ] || [ "$gen_redis" ]; then
cat >>"$compose_file" <<EOF
depends_on: depends_on:
- db ${gen_postgres:+- db}
${gen_redis:+- redis} ${gen_redis:+- redis}
${gen_minio:+- minio} ${gen_minio:+- minio}
EOF
fi
cat >>"$compose_file" <<EOF
restart: unless-stopped restart: unless-stopped
volumes: volumes:
- ./nocodb:/usr/app/data - ./nocodb:/usr/app/data
@ -551,7 +604,10 @@ EOF
cat >>"$compose_file" <<EOF cat >>"$compose_file" <<EOF
networks: networks:
- nocodb-network - nocodb-network
EOF
if [ "$CONFIG_POSTGRES_SQLITE" = "P" ]; then
cat >>"$compose_file" <<EOF
db: db:
image: postgres:16.1 image: postgres:16.1
env_file: docker.env env_file: docker.env
@ -565,7 +621,10 @@ EOF
retries: 5 retries: 5
networks: networks:
- nocodb-network - nocodb-network
EOF
fi
cat >>"$compose_file" <<EOF
traefik: traefik:
image: traefik:v3.1 image: traefik:v3.1
command: command:
@ -708,10 +767,10 @@ POSTGRES_USER=postgres
POSTGRES_PASSWORD=${CONFIG_POSTGRES_PASSWORD} POSTGRES_PASSWORD=${CONFIG_POSTGRES_PASSWORD}
EOF EOF
if [ "${CONFIG_EDITION}" = "EE" ] || [ "${CONFIG_EDITION}" = "ee" ]; then if [ "${CONFIG_EDITION}" = "EE" ]; then
echo "DATABASE_URL=postgres://postgres:${encoded_password}@db:5432/nocodb" >>"$env_file" echo "DATABASE_URL=postgres://postgres:${encoded_password}@db:5432/nocodb" >>"$env_file"
echo "NC_LICENSE_KEY=${CONFIG_LICENSE_KEY}" >>"$env_file" echo "NC_LICENSE_KEY=${CONFIG_LICENSE_KEY}" >>"$env_file"
else elif [ "${CONFIG_POSTGRES_SQLITE}" = "P" ]; then
echo "NC_DB=pg://db:5432?d=nocodb&user=postgres&password=${encoded_password}" >>"$env_file" echo "NC_DB=pg://db:5432?d=nocodb&user=postgres&password=${encoded_password}" >>"$env_file"
fi fi
@ -937,7 +996,6 @@ monitoring_service() {
$CONFIG_DOCKER_COMMAND stats $CONFIG_DOCKER_COMMAND stats
} }
main() { main() {
CONFIG_DOCKER_COMMAND=$([ "$(check_for_docker_sudo)" = "y" ] && echo "sudo docker" || echo "docker") CONFIG_DOCKER_COMMAND=$([ "$(check_for_docker_sudo)" = "y" ] && echo "sudo docker" || echo "docker")
@ -952,7 +1010,7 @@ main() {
start_services start_services
display_completion_message display_completion_message
if confirm "Do you want to start the management menu?"; then if confirm "Do you want to start the management menu?" "Y"; then
management_menu management_menu
fi fi
} }

Loading…
Cancel
Save