commit b3b745a7d242704dddf1257176ec91867460bd17 Author: Russell Ballestrini Date: Wed Mar 19 23:36:28 2025 +0000 Update file .gitlab-ci-yml diff --git a/.gitlab-ci-yml b/.gitlab-ci-yml new file mode 100644 index 0000000..2fe6e81 --- /dev/null +++ b/.gitlab-ci-yml @@ -0,0 +1,120 @@ +stages: + - deploy + +variables: + APP_NAME: "slop.unturf.com" + APP_DIR: "/opt/${APP_NAME}" + VENV_DIR: "${APP_DIR}/venv" + CADDYFILE_DIR: "/etc/caddy" + CADDY_SNIPPETS_DIR: "/etc/caddy/caddy_snippets" + +deploy: + stage: deploy + tags: + - master.unturf.com + only: + - main # Deploy only from the 'main' branch + script: + # Step 1: Define variables with substitutions + - | + SERVICE_NAME="uwsgi-${APP_NAME//./-}.service" # Replace dots with dashes + UWSGI_SOCKET="${APP_DIR}/uwsgi.sock" # Place socket in app directory + + # Step 2: Synchronize the code to the application directory + - | + if [ ! -d "${APP_DIR}" ]; then + mkdir -p "${APP_DIR}" + fi + rsync -a --exclude=data/ --exclude=venv/ --delete "${CI_PROJECT_DIR}/" "${APP_DIR}/" + + # Step 3: Set up Python virtual environment and install dependencies + - | + if [ ! -d "${VENV_DIR}" ]; then + python3 -m venv "${VENV_DIR}" + fi + source "${VENV_DIR}/bin/activate" + pip install --upgrade pip + pip install -r "${APP_DIR}/requirements.txt" + + # Step 4: Install uWSGI in virtual environment + - | + source "${VENV_DIR}/bin/activate" + pip install uwsgi + + # Step 5: Create or update the systemd user service file for uWSGI + - | + mkdir -p ~/.config/systemd/user/ + + # Set the MODULE for slop_with_models.py + MODULE="slop_with_models:app" + + cat > ~/.config/systemd/user/${SERVICE_NAME} < "${CADDY_SNIPPETS_DIR}/${APP_NAME}.caddy" < "${CADDYFILE_DIR}/Caddyfile" + cat "${CADDY_SNIPPETS_DIR}"/*.caddy >> "${CADDYFILE_DIR}/Caddyfile" + + # Validate the Caddyfile + caddy validate --config "${CADDYFILE_DIR}/Caddyfile" + + # Step 8: Reload Caddy service + - sudo /bin/systemctl restart caddy.service + + # Deployment completed + - echo "Deployment completed successfully." \ No newline at end of file