moonstream/backend/deploy/deploy.bash

45 wiersze
1.3 KiB
Bash
Czysty Zwykły widok Historia

2021-07-19 10:31:18 +00:00
#!/usr/bin/env bash
# Deployment script - intended to run on Moonstream servers
# Main
2021-07-28 09:40:21 +00:00
APP_DIR="${APP_DIR:-/home/ubuntu/moonstream}"
2021-07-29 13:52:32 +00:00
APP_BACKEND_DIR="${APP_DIR}/backend"
2021-07-19 10:31:18 +00:00
AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION:-us-east-1}"
2021-07-28 09:40:21 +00:00
PYTHON_ENV_DIR="${PYTHON_ENV_DIR:-/home/ubuntu/moonstream-env}"
2021-07-19 10:31:18 +00:00
PYTHON="${PYTHON_ENV_DIR}/bin/python"
PIP="${PYTHON_ENV_DIR}/bin/pip"
SCRIPT_DIR="$(realpath $(dirname $0))"
PARAMETERS_SCRIPT="${SCRIPT_DIR}/parameters.py"
2021-07-28 09:40:21 +00:00
SECRETS_DIR="${SECRETS_DIR:-/home/ubuntu/moonstream-secrets}"
2021-07-19 10:31:18 +00:00
PARAMETERS_ENV_PATH="${SECRETS_DIR}/app.env"
AWS_SSM_PARAMETER_PATH="${AWS_SSM_PARAMETER_PATH:-/moonstream/prod}"
SERVICE_FILE="${SCRIPT_DIR}/moonstream.service"
set -eu
2021-07-28 09:40:21 +00:00
echo
echo
echo "Updating pip and setuptools"
"${PIP}" install -U pip setuptools
2021-07-19 10:31:18 +00:00
echo
echo
echo "Updating Python dependencies"
2021-07-29 13:52:32 +00:00
"${PIP}" install -r "${APP_BACKEND_DIR}/requirements.txt"
2021-07-19 10:31:18 +00:00
echo
echo
echo "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 "Replacing existing Moonstream service definition with ${SERVICE_FILE}"
chmod 644 "${SERVICE_FILE}"
cp "${SERVICE_FILE}" /etc/systemd/system/moonstream.service
systemctl daemon-reload
systemctl restart moonstream.service
systemctl status moonstream.service