kopia lustrzana https://github.com/bugout-dev/moonstream
72 wiersze
2.2 KiB
Bash
Executable File
72 wiersze
2.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# Deployment script - intended to run on Moonstream API server
|
|
|
|
# Colors
|
|
C_RESET='\033[0m'
|
|
C_RED='\033[1;31m'
|
|
C_GREEN='\033[1;32m'
|
|
C_YELLOW='\033[1;33m'
|
|
|
|
# Logs
|
|
PREFIX_INFO="${C_GREEN}[INFO]${C_RESET} [$(date +%d-%m\ %T)]"
|
|
PREFIX_WARN="${C_YELLOW}[WARN]${C_RESET} [$(date +%d-%m\ %T)]"
|
|
PREFIX_CRIT="${C_RED}[CRIT]${C_RESET} [$(date +%d-%m\ %T)]"
|
|
|
|
# Main
|
|
APP_DIR="${APP_DIR:-/home/ubuntu/moonstream}"
|
|
APP_BACKEND_DIR="${APP_DIR}/backend"
|
|
AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION:-us-east-1}"
|
|
PYTHON_ENV_DIR="${PYTHON_ENV_DIR:-/home/ubuntu/moonstream-env}"
|
|
PYTHON="${PYTHON_ENV_DIR}/bin/python"
|
|
PIP="${PYTHON_ENV_DIR}/bin/pip"
|
|
SCRIPT_DIR="$(realpath $(dirname $0))"
|
|
SECRETS_DIR="${SECRETS_DIR:-/home/ubuntu/moonstream-secrets}"
|
|
PARAMETERS_ENV_PATH="${SECRETS_DIR}/app.env"
|
|
AWS_SSM_PARAMETER_PATH="${AWS_SSM_PARAMETER_PATH:-/moonstream/prod}"
|
|
|
|
# Parameters scripts
|
|
PARAMETERS_SCRIPT="${SCRIPT_DIR}/parameters.py"
|
|
CHECKENV_PARAMETERS_SCRIPT="${SCRIPT_DIR}/parameters.bash"
|
|
CHECKENV_NODES_CONNECTIONS_SCRIPT="${SCRIPT_DIR}/nodes-connections.bash"
|
|
|
|
# API server service file
|
|
SERVICE_FILE="${SCRIPT_DIR}/moonstreamapi.service"
|
|
|
|
set -eu
|
|
|
|
echo
|
|
echo
|
|
echo -e "${PREFIX_INFO} Upgrading Python pip and setuptools"
|
|
"${PIP}" install --upgrade pip setuptools
|
|
|
|
echo
|
|
echo
|
|
echo -e "${PREFIX_INFO} Installing Python dependencies"
|
|
"${PIP}" install -e "${APP_BACKEND_DIR}/"
|
|
|
|
echo
|
|
echo
|
|
echo -e "${PREFIX_INFO} Retrieving deployment parameters"
|
|
mkdir -p "${SECRETS_DIR}"
|
|
AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION}" "${PYTHON}" "${PARAMETERS_SCRIPT}" "${AWS_SSM_PARAMETER_PATH}" -o "${PARAMETERS_ENV_PATH}"
|
|
|
|
echo
|
|
echo
|
|
echo -e "${PREFIX_INFO} Retrieving addition deployment parameters"
|
|
bash "${CHECKENV_PARAMETERS_SCRIPT}" -v -p "moonstream" -o "${PARAMETERS_ENV_PATH}"
|
|
|
|
echo
|
|
echo
|
|
echo -e "${PREFIX_INFO} Updating nodes connection parameters"
|
|
bash "${CHECKENV_NODES_CONNECTIONS_SCRIPT}" -v -f "${PARAMETERS_ENV_PATH}"
|
|
|
|
echo
|
|
echo
|
|
echo -e "${PREFIX_INFO} Replacing existing Moonstream API service definition with ${SERVICE_FILE}"
|
|
chmod 644 "${SERVICE_FILE}"
|
|
cp "${SERVICE_FILE}" /etc/systemd/system/moonstreamapi.service
|
|
systemctl daemon-reload
|
|
systemctl restart moonstreamapi.service
|
|
systemctl status moonstreamapi.service
|