refactor: simplify dev setup [skip ci]
This commit is contained in:
parent
a2fb8895ee
commit
00eba02767
3 changed files with 101 additions and 19 deletions
|
@ -7,7 +7,7 @@
|
|||
"commit": "git-cz",
|
||||
"act:test-install": "act --container-architecture linux/amd64 -j test-install",
|
||||
"act:docker": "act --container-architecture linux/amd64 --secret-file github.secrets -j build-images",
|
||||
"start:dev": "sudo ./scripts/start-dev.sh",
|
||||
"start:dev": "./scripts/start-dev.sh",
|
||||
"start:rc": "docker-compose -f docker-compose.rc.yml --env-file .env up --build",
|
||||
"start:prod": "docker-compose --env-file .env up --build",
|
||||
"start:pg": "docker run --name test-db -p 5433:5432 -d --rm -e POSTGRES_PASSWORD=postgres postgres",
|
||||
|
|
|
@ -1,11 +1,97 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e # Exit immediately if a command exits with a non-zero status.
|
||||
|
||||
source "${BASH_SOURCE%/*}/common.sh"
|
||||
|
||||
### --------------------------------
|
||||
### General variables
|
||||
### --------------------------------
|
||||
ROOT_FOLDER="${PWD}"
|
||||
STATE_FOLDER="${ROOT_FOLDER}/state"
|
||||
SED_ROOT_FOLDER="$(echo "$ROOT_FOLDER" | sed 's/\//\\\//g')"
|
||||
NGINX_PORT=80
|
||||
NGINX_PORT_SSL=443
|
||||
DOMAIN=tipi.localhost
|
||||
DNS_IP=9.9.9.9 # Default to Quad9 DNS
|
||||
ARCHITECTURE="$(uname -m)"
|
||||
TZ="UTC"
|
||||
JWT_SECRET=secret
|
||||
POSTGRES_PASSWORD=postgres
|
||||
TIPI_VERSION=$(get_json_field "${ROOT_FOLDER}/package.json" version)
|
||||
INTERNAL_IP=localhost
|
||||
storage_path="${ROOT_FOLDER}"
|
||||
STORAGE_PATH_ESCAPED="$(echo "${storage_path}" | sed 's/\//\\\//g')"
|
||||
|
||||
### --------------------------------
|
||||
### Apps repository configuration
|
||||
### --------------------------------
|
||||
apps_repository="https://github.com/meienberger/runtipi-appstore"
|
||||
APPS_REPOSITORY_ESCAPED="$(echo ${apps_repository} | sed 's/\//\\\//g')"
|
||||
REPO_ID="$("${ROOT_FOLDER}"/scripts/git.sh get_hash ${apps_repository})"
|
||||
|
||||
# Override configs with settings.json
|
||||
if [[ -f "${STATE_FOLDER}/settings.json" ]]; then
|
||||
if [[ "$(get_json_field "${STATE_FOLDER}/settings.json" appsRepoUrl)" != "null" ]]; then
|
||||
apps_repository=$(get_json_field "${STATE_FOLDER}/settings.json" appsRepoUrl)
|
||||
APPS_REPOSITORY_ESCAPED="$(echo "${apps_repository}" | sed 's/\//\\\//g')"
|
||||
REPO_ID="$("${ROOT_FOLDER}"/scripts/git.sh get_hash "${apps_repository}")"
|
||||
fi
|
||||
fi
|
||||
|
||||
### --------------------------------
|
||||
### Watcher and system-info
|
||||
### --------------------------------
|
||||
if [[ ! -f "${ROOT_FOLDER}/state/events" ]]; then
|
||||
touch "${ROOT_FOLDER}/state/events"
|
||||
fi
|
||||
|
||||
if [[ ! -f "${ROOT_FOLDER}/state/system-info.json" ]]; then
|
||||
echo "{}" >"${ROOT_FOLDER}/state/system-info.json"
|
||||
fi
|
||||
|
||||
kill_watcher
|
||||
chmod -R a+rwx "${ROOT_FOLDER}/state/events"
|
||||
chmod -R a+rwx "${ROOT_FOLDER}/state/system-info.json"
|
||||
kill_watcher
|
||||
"${ROOT_FOLDER}/scripts/watcher.sh" &
|
||||
|
||||
### --------------------------------
|
||||
### env file generation
|
||||
### --------------------------------
|
||||
ENV_FILE=$(mktemp)
|
||||
[[ -f "${ROOT_FOLDER}/.env" ]] && rm -f "${ROOT_FOLDER}/.env"
|
||||
[[ -f "$ROOT_FOLDER/templates/env-sample" ]] && cp "$ROOT_FOLDER/templates/env-sample" "$ENV_FILE"
|
||||
|
||||
OS=$(uname)
|
||||
sed_args=(-i)
|
||||
# If os is macos, use gnu sed
|
||||
if [[ "$OS" == "Darwin" ]]; then
|
||||
echo "Using gnu sed"
|
||||
sed_args=(-i '')
|
||||
fi
|
||||
|
||||
for template in ${ENV_FILE}; do
|
||||
sed "${sed_args[@]}" "s/<dns_ip>/${DNS_IP}/g" "${template}"
|
||||
sed "${sed_args[@]}" "s/<internal_ip>/${INTERNAL_IP}/g" "${template}"
|
||||
sed "${sed_args[@]}" "s/<tz>/${TZ}/g" "${template}"
|
||||
sed "${sed_args[@]}" "s/<jwt_secret>/${JWT_SECRET}/g" "${template}"
|
||||
sed "${sed_args[@]}" "s/<root_folder>/${SED_ROOT_FOLDER}/g" "${template}"
|
||||
sed "${sed_args[@]}" "s/<tipi_version>/${TIPI_VERSION}/g" "${template}"
|
||||
sed "${sed_args[@]}" "s/<architecture>/${ARCHITECTURE}/g" "${template}"
|
||||
sed "${sed_args[@]}" "s/<nginx_port>/${NGINX_PORT}/g" "${template}"
|
||||
sed "${sed_args[@]}" "s/<nginx_port_ssl>/${NGINX_PORT_SSL}/g" "${template}"
|
||||
sed "${sed_args[@]}" "s/<postgres_password>/${POSTGRES_PASSWORD}/g" "${template}"
|
||||
sed "${sed_args[@]}" "s/<apps_repo_id>/${REPO_ID}/g" "${template}"
|
||||
sed "${sed_args[@]}" "s/<apps_repo_url>/${APPS_REPOSITORY_ESCAPED}/g" "${template}"
|
||||
sed "${sed_args[@]}" "s/<domain>/${DOMAIN}/g" "${template}"
|
||||
sed "${sed_args[@]}" "s/<storage_path>/${STORAGE_PATH_ESCAPED}/g" "${template}"
|
||||
done
|
||||
|
||||
mv -f "$ENV_FILE" "$ROOT_FOLDER/.env.dev"
|
||||
cp "$ROOT_FOLDER/.env.dev" "$ROOT_FOLDER/.env"
|
||||
chmod a+rwx "$ROOT_FOLDER/.env"
|
||||
chmod a+rwx "${ROOT_FOLDER}/.env.dev"
|
||||
|
||||
### --------------------------------
|
||||
### Start the project
|
||||
### --------------------------------
|
||||
docker compose -f docker-compose.dev.yml --env-file "${ROOT_FOLDER}/.env.dev" up --build
|
||||
|
|
|
@ -63,7 +63,9 @@ if [[ "$ARCHITECTURE" == "aarch64" ]]; then
|
|||
ARCHITECTURE="arm64"
|
||||
fi
|
||||
|
||||
# Parse arguments
|
||||
### --------------------------------
|
||||
### CLI arguments
|
||||
### --------------------------------
|
||||
while [ -n "$1" ]; do
|
||||
case "$1" in
|
||||
--rc) rc="true" ;;
|
||||
|
@ -143,15 +145,6 @@ export DOCKER_CLIENT_TIMEOUT=240
|
|||
export COMPOSE_HTTP_TIMEOUT=240
|
||||
|
||||
echo "Generating config files..."
|
||||
# Remove current .env file
|
||||
[[ -f "${ROOT_FOLDER}/.env" ]] && rm -f "${ROOT_FOLDER}/.env"
|
||||
|
||||
# Store paths to intermediary config files
|
||||
ENV_FILE=$(mktemp)
|
||||
|
||||
# Copy template configs to intermediary configs
|
||||
[[ -f "$ROOT_FOLDER/templates/env-sample" ]] && cp "$ROOT_FOLDER/templates/env-sample" "$ENV_FILE"
|
||||
|
||||
# Override vars with values from settings.json
|
||||
if [[ -f "${STATE_FOLDER}/settings.json" ]]; then
|
||||
|
||||
|
@ -167,12 +160,9 @@ if [[ -f "${STATE_FOLDER}/settings.json" ]]; then
|
|||
|
||||
# If appsRepoUrl is set in settings.json, use it
|
||||
if [[ "$(get_json_field "${STATE_FOLDER}/settings.json" appsRepoUrl)" != "null" ]]; then
|
||||
APPS_REPOSITORY_ESCAPED="$(echo ${apps_repository} | sed 's/\//\\\//g')"
|
||||
fi
|
||||
|
||||
# If appsRepoId is set in settings.json, use it
|
||||
if [[ "$(get_json_field "${STATE_FOLDER}/settings.json" appsRepoId)" != "null" ]]; then
|
||||
REPO_ID=$(get_json_field "${STATE_FOLDER}/settings.json" appsRepoId)
|
||||
apps_repository=$(get_json_field "${STATE_FOLDER}/settings.json" appsRepoUrl)
|
||||
APPS_REPOSITORY_ESCAPED="$(echo "${apps_repository}" | sed 's/\//\\\//g')"
|
||||
REPO_ID="$("${ROOT_FOLDER}"/scripts/git.sh get_hash "${apps_repository}")"
|
||||
fi
|
||||
|
||||
# If port is set in settings.json, use it
|
||||
|
@ -197,10 +187,16 @@ if [[ -f "${STATE_FOLDER}/settings.json" ]]; then
|
|||
fi
|
||||
fi
|
||||
|
||||
# Set array with all new values
|
||||
new_values="DOMAIN=${DOMAIN}\nDNS_IP=${DNS_IP}\nAPPS_REPOSITORY=${APPS_REPOSITORY_ESCAPED}\nREPO_ID=${REPO_ID}\nNGINX_PORT=${NGINX_PORT}\nNGINX_PORT_SSL=${NGINX_PORT_SSL}\nINTERNAL_IP=${INTERNAL_IP}\nSTORAGE_PATH=${STORAGE_PATH_ESCAPED}\nTZ=${TZ}\nJWT_SECRET=${JWT_SECRET}\nROOT_FOLDER=${SED_ROOT_FOLDER}\nTIPI_VERSION=${TIPI_VERSION}\nARCHITECTURE=${ARCHITECTURE}"
|
||||
write_log "Final values: \n${new_values}"
|
||||
|
||||
### --------------------------------
|
||||
### env file generation
|
||||
### --------------------------------
|
||||
ENV_FILE=$(mktemp)
|
||||
[[ -f "${ROOT_FOLDER}/.env" ]] && rm -f "${ROOT_FOLDER}/.env"
|
||||
[[ -f "$ROOT_FOLDER/templates/env-sample" ]] && cp "$ROOT_FOLDER/templates/env-sample" "$ENV_FILE"
|
||||
|
||||
for template in ${ENV_FILE}; do
|
||||
sed -i "s/<dns_ip>/${DNS_IP}/g" "${template}"
|
||||
sed -i "s/<internal_ip>/${INTERNAL_IP}/g" "${template}"
|
||||
|
|
Loading…
Reference in a new issue