From e8330622317109ff5d4359cfb576348fb2df92d5 Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Thu, 20 Mar 2025 23:20:03 +0000 Subject: [PATCH] Update .gitlab-ci.yml --- .gitlab-ci.yml | 134 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 115 insertions(+), 19 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 64a201e..8e20abe 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,30 +1,127 @@ stages: - deploy + - deploy-streamlit variables: - # Change these to match your desired domain/app name - STREAMLIT_APP_NAME: "art.ai.unturf.com" + BACKEND_APP_NAME: "slop.unturf.com" + BACKEND_APP_DIR: "/opt/${BACKEND_APP_NAME}" + BACKEND_VENV_DIR: "${BACKEND_APP_DIR}/venv" + STREAMLIT_APP_NAME: "streamlit.slop.unturf.com" STREAMLIT_APP_DIR: "/opt/${STREAMLIT_APP_NAME}" STREAMLIT_VENV_DIR: "${STREAMLIT_APP_DIR}/venv" - - # Adjust if your main Streamlit script has a different filename - STREAMLIT_SCRIPT_FILENAME: "streamlit_art_app.py" - - # Caddy-related directories CADDYFILE_DIR: "/etc/caddy" CADDY_SNIPPETS_DIR: "/etc/caddy/caddy_snippets" deploy: stage: deploy tags: - - master.unturf.com # Change to match your runner’s tags + - master.unturf.com only: - main # Deploy only from the 'main' branch script: - # Step 1: Define variables for systemd service + # Step 1: Define variables with substitutions + - | + SERVICE_NAME="uwsgi-${BACKEND_APP_NAME//./-}.service" # Replace dots with dashes + UWSGI_SOCKET="${BACKEND_APP_DIR}/uwsgi.sock" # Place socket in app directory + + # Step 2: Synchronize the code to the backend application directory + - | + if [ ! -d "${BACKEND_APP_DIR}" ]; then + mkdir -p "${BACKEND_APP_DIR}" + fi + rsync -a --exclude=data/ --exclude=venv/ --delete "${CI_PROJECT_DIR}/" "${BACKEND_APP_DIR}/" + + # Step 3: Set up Python virtual environment and install dependencies + - | + if [ ! -d "${BACKEND_VENV_DIR}" ]; then + python3 -m venv "${BACKEND_VENV_DIR}" + fi + source "${BACKEND_VENV_DIR}/bin/activate" + pip install --upgrade pip + pip install -r "${BACKEND_APP_DIR}/requirements.txt" + + # Step 4: Install uWSGI in virtual environment + - | + source "${BACKEND_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}/${BACKEND_APP_NAME}.caddy" < ~/.config/systemd/user/${SERVICE_NAME} < "${CADDYFILE_DIR}/Caddyfile" cat "${CADDY_SNIPPETS_DIR}"/*.caddy >> "${CADDYFILE_DIR}/Caddyfile" - # Validate the final Caddyfile + # Validate the Caddyfile caddy validate --config "${CADDYFILE_DIR}/Caddyfile" + # Step 7: Reload Caddy service - sudo /bin/systemctl restart caddy.service - - echo "Streamlit deployment for ${STREAMLIT_APP_NAME} completed successfully." + # Deployment completed + - echo "Streamlit deployment completed successfully." \ No newline at end of file