Allow custom port

This commit is contained in:
Nicolas Meienberger 2022-05-18 20:13:58 +02:00
parent ccfa2931c0
commit 287999caca
8 changed files with 81 additions and 58 deletions

View file

@ -6,8 +6,8 @@ services:
image: traefik:v2.6
restart: always
ports:
- 80:80
- 8080:8080
- ${NGINX_PORT}:80
- ${PROXY_PORT}:8080
command: --api.insecure=true --providers.docker
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro

View file

@ -6,8 +6,8 @@ services:
image: traefik:v2.6
restart: always
ports:
- 80:80
- 8080:8080
- ${NGINX_PORT}:80
- ${PROXY_PORT}:8080
command: --api.insecure=true --providers.docker
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
@ -15,7 +15,6 @@ services:
networks:
- tipi_main_network
api:
image: meienberger/tipi-api:${TIPI_VERSION}
container_name: api

View file

@ -12,7 +12,7 @@ ROOT_FOLDER="$($rdlk -f $(dirname "${BASH_SOURCE[0]}")/..)"
STATE_FOLDER="${ROOT_FOLDER}/state"
show_help() {
cat << EOF
cat <<EOF
app 0.0.1
CLI for managing Tipi apps
@ -31,10 +31,10 @@ EOF
# Get field from json file
function get_json_field() {
local json_file="$1"
local field="$2"
local json_file="$1"
local field="$2"
echo $(jq -r ".${field}" "${json_file}")
echo $(jq -r ".${field}" "${json_file}")
}
list_installed_apps() {
@ -98,7 +98,7 @@ compose() {
# Pick arm architecture if running on arm and if the app has a docker-compose.arm.yml file
if [[ "$architecture" == "arm"* ]] && [[ -f "${app_dir}/docker-compose.arm.yml" ]]; then
app_compose_file="${app_dir}/docker-compose.arm.yml"
fi
fi
local common_compose_file="${ROOT_FOLDER}/apps/docker-compose.common.yml"
local app_dir="${ROOT_FOLDER}/apps/${app}"
@ -183,4 +183,4 @@ fi
# If we get here it means no valid command was supplied
# Show help and exit
show_help
exit 1
exit 1

View file

@ -1,5 +1,5 @@
#!/usr/bin/env bash
set -e # Exit immediately if a command exits with a non-zero status.
set -e # Exit immediately if a command exits with a non-zero status.
ROOT_FOLDER="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/..)"
USERNAME="$(id -nu 1000)"
@ -37,25 +37,25 @@ fi
# Add deb repo for docker (Debian)
if [[ "${LSB}" == "Debian" ]]; then
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list >/dev/null
fi
# Add deb repo for docker (Ubuntu)
if [[ "${LSB}" == "Ubuntu" ]]; then
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list >/dev/null
fi
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
# Install docker compose if not here
if ! command -v docker-compose > /dev/null; then
if ! command -v docker-compose >/dev/null; then
sudo curl -L "https://github.com/docker/compose/releases/download/v2.3.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
fi
# create docker group
if ! getent group docker > /dev/null; then
if ! getent group docker >/dev/null; then
sudo groupadd docker
fi
sudo usermod -aG docker "${USERNAME}"
@ -65,4 +65,4 @@ sudo usermod -aG docker "${USERNAME}"
# find "$ROOT_FOLDER" -path "$ROOT_FOLDER/app-data" -prune -o -exec chown 1000:1000 {} + || true
# Create configured status
touch "${ROOT_FOLDER}/state/configured"
touch "${ROOT_FOLDER}/state/configured"

View file

@ -1,5 +1,5 @@
#!/usr/bin/env bash
set -e # Exit immediately if a command exits with a non-zero status.
set -e # Exit immediately if a command exits with a non-zero status.
# use greadlink instead of readlink on osx
if [[ "$(uname)" == "Darwin" ]]; then
@ -8,18 +8,42 @@ else
readlink=readlink
fi
while [ -n "$1" ]; do # while loop starts
NGINX_PORT=80
PROXY_PORT=8080
case "$1" in
--rc) rc="true" ;;
--ci) ci="true" ;;
--)
shift # The double dash makes them parameters
break
;;
*) echo "Option $1 not recognized" && exit 1 ;;
esac
shift
while [ -n "$1" ]; do # while loop starts
case "$1" in
--rc) rc="true" ;;
--ci) ci="true" ;;
--port)
port="$2"
if [[ "${port}" =~ ^[0-9]+$ ]]; then
NGINX_PORT="${port}"
else
echo "--port must be a number"
exit 1
fi
shift
;;
--proxy-port)
proxy_port="$2"
if [[ "${proxy_port}" =~ ^[0-9]+$ ]]; then
PROXY_PORT="${proxy_port}"
else
echo "--proxy-port must be a number"
exit 1
fi
shift
;;
--)
shift # The double dash makes them parameters
break
;;
*) echo "Option $1 not recognized" && exit 1 ;;
esac
shift
done
# Check we are on linux
@ -40,10 +64,10 @@ if [[ "$ARCHITECTURE" == "aarch64" ]]; then
fi
if [[ $UID != 0 ]]; then
echo "Tipi must be started as root"
echo "Please re-run this script as"
echo " sudo ./scripts/start"
exit 1
echo "Tipi must be started as root"
echo "Please re-run this script as"
echo " sudo ./scripts/start"
exit 1
fi
# Configure Tipi if it isn't already configured
@ -53,20 +77,20 @@ fi
# Get field from json file
function get_json_field() {
local json_file="$1"
local field="$2"
local json_file="$1"
local field="$2"
echo $(jq -r ".${field}" "${json_file}")
echo $(jq -r ".${field}" "${json_file}")
}
# Deterministically derives 128 bits of cryptographically secure entropy
function derive_entropy() {
SEED_FILE="${STATE_FOLDER}/seed"
identifier="${1}"
tipi_seed=$(cat "${SEED_FILE}") || true
tipi_seed=$(cat "${SEED_FILE}") || true
if [[ -z "$tipi_seed" ]] || [[ -z "$identifier" ]]; then
>&2 echo "Missing derivation parameter, this is unsafe, exiting."
echo >&2 "Missing derivation parameter, this is unsafe, exiting."
exit 1
fi
@ -107,7 +131,7 @@ fi
# Create seed file with cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1
if [[ ! -f "${STATE_FOLDER}/seed" ]]; then
echo "Generating seed..."
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1 > "${STATE_FOLDER}/seed"
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1 >"${STATE_FOLDER}/seed"
fi
export DOCKER_CLIENT_TIMEOUT=240
@ -136,7 +160,8 @@ for template in "${ENV_FILE}"; do
sed -i "s/<root_folder>/${SED_ROOT_FOLDER}/g" "${template}"
sed -i "s/<tipi_version>/$(cat "${ROOT_FOLDER}/VERSION")/g" "${template}"
sed -i "s/<architecture>/${ARCHITECTURE}/g" "${template}"
sed -i "/<nginx_port>/${NGINX_PORT}" "${template}"
sed -i "/<proxy_port>/${PROXY_PORT}" "${template}"
done
mv -f "$ENV_FILE" "$ROOT_FOLDER/.env"
@ -170,7 +195,7 @@ fi
echo "Tipi is now running"
echo ""
cat << "EOF"
cat <<"EOF"
_,.
,` -.)
'( _/'-\\-.
@ -195,5 +220,3 @@ EOF
echo ""
echo "Visit http://${INTERNAL_IP}/ to view the dashboard"
echo ""

View file

@ -8,12 +8,11 @@ else
readlink=readlink
fi
if [[ $UID != 0 ]]; then
echo "Tipi must be stopped as root"
echo "Please re-run this script as"
echo " sudo ./scripts/stop"
exit 1
echo "Tipi must be stopped as root"
echo "Please re-run this script as"
echo " sudo ./scripts/stop"
exit 1
fi
ROOT_FOLDER="$($readlink -f $(dirname "${BASH_SOURCE[0]}")/..)"
@ -27,10 +26,10 @@ export DOCKER_CLIENT_TIMEOUT=240
export COMPOSE_HTTP_TIMEOUT=240
function get_json_field() {
local json_file="$1"
local field="$2"
local json_file="$1"
local field="$2"
echo $(jq -r ".${field}" "${json_file}")
echo $(jq -r ".${field}" "${json_file}")
}
str=$(get_json_field ${STATE_FOLDER}/apps.json installed)
@ -38,11 +37,11 @@ apps_to_start=($str)
# If apps_to_start is not empty, then we're stopping all apps
if [[ ${#apps_to_start[@]} -gt 0 ]]; then
for app in "${apps_to_start[@]}"; do
"${ROOT_FOLDER}/scripts/app.sh" stop $app
done
for app in "${apps_to_start[@]}"; do
"${ROOT_FOLDER}/scripts/app.sh" stop $app
done
fi
echo "Stopping Docker services..."
echo
docker-compose down --remove-orphans --rmi local
docker-compose down --remove-orphans --rmi local

View file

@ -1,5 +1,5 @@
#!/usr/bin/env bash
set -e # Exit immediately if a command exits with a non-zero status.
set -e # Exit immediately if a command exits with a non-zero status.
ROOT_FOLDER="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/..)"
STATE_FOLDER="${ROOT_FOLDER}/state"
@ -19,7 +19,7 @@ MEM_USED_BYTES=$(($MEM_TOTAL_BYTES - $MEM_AVAILABLE_BYTES))
# Create temporary json file
TEMP_JSON_FILE=$(mktemp)
echo '{ "cpu": { "load": '"${CPU_LOAD_PERCENTAGE}"' }, "memory": { "total": '"${MEM_TOTAL_BYTES}"' , "used": '"${MEM_USED_BYTES}"', "available": '"${MEM_AVAILABLE_BYTES}"' }, "disk": { "total": '"${TOTAL_DISK_SPACE_BYTES}"' , "used": '"${USED_DISK_SPACE_BYTES}"', "available": '"${AVAILABLE_DISK_SPACE_BYTES}"' } }' > "${TEMP_JSON_FILE}"
echo '{ "cpu": { "load": '"${CPU_LOAD_PERCENTAGE}"' }, "memory": { "total": '"${MEM_TOTAL_BYTES}"' , "used": '"${MEM_USED_BYTES}"', "available": '"${MEM_AVAILABLE_BYTES}"' }, "disk": { "total": '"${TOTAL_DISK_SPACE_BYTES}"' , "used": '"${USED_DISK_SPACE_BYTES}"', "available": '"${AVAILABLE_DISK_SPACE_BYTES}"' } }' >"${TEMP_JSON_FILE}"
# Write to state file
echo "$(cat "${TEMP_JSON_FILE}")" > "${STATE_FOLDER}/system-info.json"
echo "$(cat "${TEMP_JSON_FILE}")" >"${STATE_FOLDER}/system-info.json"

View file

@ -10,3 +10,5 @@ ARCHITECTURE=<architecture>
TIPI_VERSION=<tipi_version>
JWT_SECRET=<jwt_secret>
ROOT_FOLDER_HOST=<root_folder>
NGINX_PORT=<nginx_port>
PROXY_PORT=<proxy_port>