Commit f78089d4 authored by Aryan Noshirvnai's avatar Aryan Noshirvnai

Add deploy_dev CI job + run test on dev pushes too, not just main

test was only: main, which was backwards for "test runs on every dev
push" - the real gap was the frontend test job never running on dev at
all. deploy_dev mirrors deploy_prod (same deploy.sh, no PROD_DOMAIN -
dev stays plain HTTP on the bare IP, same tradeoff prod itself had
before a domain was set up) but SSHes in as the unprivileged ubuntu
user with sudo wrapping the actual deploy.sh invocation, not a direct
root login.

Needs DEV_SERVER_IP and DEV_SSH_PRIVATE_KEY as CI/CD variables.
Co-Authored-By: 's avatarClaude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019i3NAUkLkHNbsPg5vKfzF9
parent 48490dae
Pipeline #1314 failed with stages
......@@ -29,6 +29,7 @@ test:
- dist/
expire_in: 1 hour
only:
- dev
- main
# Only ever runs on main, and fires automatically once the test job above passes - being in a
......@@ -85,3 +86,41 @@ deploy_prod:
bash /root/stax_webapp_deploy_bootstrap.sh"
only:
- main
# Runs on every push to dev, after test passes. Same deploy.sh, same logic as deploy_prod -
# only the target box and how we get root on it differ: deploy_prod SSHes straight in as root
# (unchanged, its own long-standing setup); deploy_dev SSHes in as the unprivileged `ubuntu`
# user instead and wraps the actual deploy.sh invocation in `sudo` - no root login is ever
# exposed on the dev box, root access only exists transiently for this one command via sudo
# access that's already configured there. rsync's destination is under /tmp (ubuntu-writable)
# rather than /root directly, since the plain ubuntu user can't write into /root over SSH -
# deploy.sh's own mv into place then runs as root via the sudo-wrapped ssh command below, which
# can read a /tmp path owned by ubuntu without issue. No PROD_DOMAIN here on purpose - dev stays
# plain HTTP on the bare IP, same tradeoff prod itself had before a domain was set up.
deploy_dev:
stage: deploy
image: python:3.10-slim
variables:
STAX_WEBAPP_DEPLOY_DIR: "/var/www/stax_webapp"
before_script:
- apt-get update -qq && apt-get install -y -qq --no-install-recommends openssh-client rsync
- echo "$DEV_SSH_PRIVATE_KEY" > /tmp/dev_deploy_key
- chmod 600 /tmp/dev_deploy_key
- ssh-keyscan -p "${DEV_SSH_PORT:-22}" "$DEV_SERVER_IP" > /tmp/known_hosts 2>/dev/null || true
script:
- echo "Deploying $CI_COMMIT_SHORT_SHA to dev..."
- >
scp -o StrictHostKeyChecking=accept-new -o UserKnownHostsFile=/tmp/known_hosts -i /tmp/dev_deploy_key -P "${DEV_SSH_PORT:-22}"
deploy/scripts/deploy.sh ubuntu@"$DEV_SERVER_IP":/tmp/stax_webapp_dev_deploy_bootstrap.sh
- >
rsync -az -e "ssh -o StrictHostKeyChecking=accept-new -o UserKnownHostsFile=/tmp/known_hosts -i /tmp/dev_deploy_key -p ${DEV_SSH_PORT:-22}"
dist/ ubuntu@"$DEV_SERVER_IP":/tmp/stax_webapp_release_${CI_COMMIT_SHORT_SHA}/
- >
ssh -o StrictHostKeyChecking=accept-new -o UserKnownHostsFile=/tmp/known_hosts -i /tmp/dev_deploy_key -p "${DEV_SSH_PORT:-22}"
ubuntu@"$DEV_SERVER_IP"
"sudo env STAX_WEBAPP_DEPLOY_DIR='${STAX_WEBAPP_DEPLOY_DIR}'
STAX_RELEASE_SHA='${CI_COMMIT_SHORT_SHA}'
STAX_RELEASE_SRC='/tmp/stax_webapp_release_${CI_COMMIT_SHORT_SHA}'
bash /tmp/stax_webapp_dev_deploy_bootstrap.sh"
only:
- dev
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment