Add create-service script
This commit is contained in:
parent
b286596765
commit
76ec8b4ed9
2 changed files with 83 additions and 2 deletions
81
_utils/create-service.sh
Executable file
81
_utils/create-service.sh
Executable file
|
@ -0,0 +1,81 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
# Get variables for docker-compose
|
||||
read -rp "Enter the service name: " NAME
|
||||
read -rp "Enter the service image: " IMAGE
|
||||
read -rp "Enable watchtower? (y/N): " WATCHTOWER
|
||||
|
||||
# Get variables for env files
|
||||
read -rp "Create .env file? (y/N): " CREATE_ENV
|
||||
read -rp "Create .secret.env file? (y/N): " CREATE_SECRET_ENV
|
||||
|
||||
# Get variables for caddy
|
||||
read -rp "Enter the service domain: " DOMAIN
|
||||
read -rp "Enter the service port: " PORT
|
||||
read -rp "Enter the target host: " HOST
|
||||
|
||||
mkdir -p "${NAME}"
|
||||
|
||||
|
||||
parse_yn_bool() {
|
||||
bool_lower=$(echo "${1}" | tr '[:upper:]' '[:lower:]')
|
||||
# Map y/yes to true, otherwise false
|
||||
if [ "${bool_lower}" == "y" ] || [ "${bool_lower}" == "yes" ]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
parse_yn_str() {
|
||||
if parse_yn_bool "${1}"; then
|
||||
echo "true"
|
||||
else
|
||||
echo "false"
|
||||
fi
|
||||
}
|
||||
|
||||
# Create the env files
|
||||
YAML_ENV=""
|
||||
if parse_yn_bool "${CREATE_ENV_YN}" || parse_yn_bool "${CREATE_SECRET_ENV_YN}"; then
|
||||
YAML_ENV="env_file:"
|
||||
fi
|
||||
if parse_yn_bool "${CREATE_ENV_YN}"; then
|
||||
YAML_ENV="${YAML_ENV}
|
||||
- .env"
|
||||
touch "${NAME}/.env"
|
||||
fi
|
||||
if parse_yn_bool "${CREATE_SECRET_ENV_YN}"; then
|
||||
YAML_ENV="${YAML_ENV}
|
||||
- .secret.env"
|
||||
touch "${NAME}/.secret.env"
|
||||
fi
|
||||
|
||||
|
||||
# Create the docker-compose file
|
||||
cat <<EOF > "${NAME}/docker-compose.yml"
|
||||
version: '3'
|
||||
services:
|
||||
app:
|
||||
image: ${IMAGE}
|
||||
restart: always
|
||||
labels:
|
||||
com.centurylinklabs.watchtower.enable: $(parse_yn_str "${WATCHTOWER}")
|
||||
${YAML_ENV}
|
||||
networks:
|
||||
apps:
|
||||
aliases:
|
||||
- ${SERVICE_NAME}
|
||||
networks:
|
||||
apps:
|
||||
external: true
|
||||
EOF
|
||||
|
||||
# Create the caddy config
|
||||
cat <<EOF > "caddy/config/conf.${HOST}.d/${DOMAIN}.config"
|
||||
${DOMAIN} {
|
||||
import default
|
||||
reverse_proxy ${SERVICE_NAME}:${PORT}
|
||||
}
|
||||
EOF
|
|
@ -31,11 +31,11 @@ check_url "git.serguzim.me"
|
|||
check_url "graph.serguzim.me"
|
||||
check_url "hook.serguzim.me"
|
||||
check_url "mail.serguzim.me"
|
||||
check_url "msrg.cc"
|
||||
#check_url "msrg.cc" # disabled because it keeps creating false alerts
|
||||
check_url "prometheus.serguzim.me/-/healthy"
|
||||
check_url "registry.serguzim.me/account/sign-in"
|
||||
check_url "rss.serguzim.me"
|
||||
check_url "serguzim.me"
|
||||
#check_url "serguzim.me" # disabled because it keeps creating false alerts
|
||||
check_url "tick.serguzim.me"
|
||||
check_url "wiki.serguzim.me"
|
||||
check_url "www.reitanlage-oranienburg.de"
|
||||
|
|
Reference in a new issue