016256cd2f
Dev keeps auto-deploying on every push to main, same as before, but now also publishes each build to git.jerodrigged.com's container registry tagged by short commit SHA (best-effort - never blocks the dev deploy if REGISTRY_TOKEN isn't set yet). Prod deploys only on an intentional `git push origin main:prod`, and only ever pulls a pre-built SHA-tagged image - it never rebuilds from source. This guarantees prod runs the exact artifact dev already validated, and makes promoting an untested commit fail loudly (pull of a nonexistent tag) instead of silently rebuilding something new. Needs new secrets before the prod path works: PROD_SSH_KEY, PROD_HOST, PROD_USER, REGISTRY_USER, REGISTRY_TOKEN. PROD_SSH_KEY/PROD_HOST/ REGISTRY_USER are already set; PROD_USER and REGISTRY_TOKEN still need Jerod's input.
74 lines
2.7 KiB
YAML
74 lines
2.7 KiB
YAML
name: Deploy to Dev
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
|
|
jobs:
|
|
deploy:
|
|
name: Deploy & Smoke Test
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Install SSH client
|
|
run: which ssh || (apt-get update -qq && apt-get install -y -qq openssh-client)
|
|
|
|
- name: Setup SSH key
|
|
run: |
|
|
mkdir -p ~/.ssh
|
|
echo "${{ secrets.DEV_SSH_KEY }}" > ~/.ssh/deploy_key
|
|
chmod 600 ~/.ssh/deploy_key
|
|
ssh-keyscan -H ${{ secrets.DEV_HOST }} >> ~/.ssh/known_hosts 2>/dev/null || true
|
|
|
|
- name: Deploy
|
|
run: |
|
|
ssh -i ~/.ssh/deploy_key \
|
|
-o StrictHostKeyChecking=no \
|
|
-o ConnectTimeout=10 \
|
|
${{ secrets.DEV_USER }}@${{ secrets.DEV_HOST }} \
|
|
'set -e
|
|
cd /opt/lisilou-portfolio
|
|
git fetch origin
|
|
git reset --hard origin/main
|
|
docker compose build
|
|
SHA=$(git rev-parse --short HEAD)
|
|
if [ -n "${{ secrets.REGISTRY_TOKEN }}" ]; then
|
|
set +e
|
|
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login git.jerodrigged.com -u "${{ secrets.REGISTRY_USER }}" --password-stdin \
|
|
&& docker tag lisilou-portfolio-web:local git.jerodrigged.com/jhodgkin/lisilou-portfolio-web:$SHA \
|
|
&& docker tag lisilou-portfolio-api:local git.jerodrigged.com/jhodgkin/lisilou-portfolio-api:$SHA \
|
|
&& docker push git.jerodrigged.com/jhodgkin/lisilou-portfolio-web:$SHA \
|
|
&& docker push git.jerodrigged.com/jhodgkin/lisilou-portfolio-api:$SHA \
|
|
&& echo "Published $SHA to registry" \
|
|
|| echo "WARNING: registry publish failed, continuing deploy anyway"
|
|
set -e
|
|
else
|
|
echo "REGISTRY_TOKEN not set - skipping registry publish (prod promotion unavailable until configured)"
|
|
fi
|
|
docker compose up -d
|
|
echo "Deploy complete"'
|
|
|
|
- name: Wait for health check
|
|
run: |
|
|
echo "Waiting for services..."
|
|
for i in $(seq 1 24); do
|
|
if curl -sf --max-time 4 "http://${{ secrets.DEV_HOST }}:8080/health" > /dev/null 2>&1; then
|
|
echo "Services are up (attempt $i)"
|
|
exit 0
|
|
fi
|
|
echo " Attempt $i/24 — sleeping 5s"
|
|
sleep 5
|
|
done
|
|
echo "Health check timed out after 2 minutes"
|
|
exit 1
|
|
|
|
- name: Smoke tests
|
|
run: bash scripts/smoke-test.sh "http://${{ secrets.DEV_HOST }}:8080"
|
|
|
|
- name: Cleanup SSH key
|
|
if: always()
|
|
run: rm -f ~/.ssh/deploy_key
|