generated from hjess/PythonTemplateProject
Lets make the frontpage in markdown too
Some checks failed
Some checks failed
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
name: Build, Push, and Deploy to Nomad
|
||||
name: Build, Push, and Deploy with Blue/Green or Canary
|
||||
|
||||
on:
|
||||
push:
|
||||
@@ -6,7 +6,7 @@ on:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
docker-nomad:
|
||||
build-push:
|
||||
runs-on: self-hosted
|
||||
steps:
|
||||
- name: Check out code
|
||||
@@ -18,46 +18,54 @@ jobs:
|
||||
- name: Build Docker Image
|
||||
run: |
|
||||
COMMIT_HASH=$(git rev-parse --short HEAD)
|
||||
docker build -t registry.i80.dk/gitea/lifefaq:latest -t registry.i80.dk/gitea/lifefaq:${COMMIT_HASH} .
|
||||
|
||||
docker build -t registry.i80.dk/gitea/lifefaq:green -t registry.i80.dk/gitea/lifefaq:${COMMIT_HASH} .
|
||||
|
||||
- name: Push Docker Image
|
||||
run: |
|
||||
COMMIT_HASH=$(git rev-parse --short HEAD)
|
||||
echo "registry.i80.dk/gitea/lifefaq:latest"
|
||||
echo "registry.i80.dk/gitea/lifefaq:${COMMIT_HASH}"
|
||||
docker push registry.i80.dk/gitea/lifefaq:${COMMIT_HASH}
|
||||
docker push registry.i80.dk/gitea/lifefaq:latest
|
||||
docker push registry.i80.dk/gitea/lifefaq:green
|
||||
|
||||
|
||||
- name: Validate Nomad Job
|
||||
blue-green-deploy:
|
||||
runs-on: self-hosted
|
||||
needs: build-push
|
||||
steps:
|
||||
- name: Deploy Green Version
|
||||
env:
|
||||
NOMAD_ADDR: https://nomad.i80.dk
|
||||
run: nomad job validate .gitea/workflows/nomad-job.hcl
|
||||
run: nomad job run -var="image=registry.i80.dk/gitea/lifefaq:green" .gitea/workflows/nomad-job-green.hcl
|
||||
|
||||
- name: Stop old deployment
|
||||
- name: Switch Traffic to Green
|
||||
run: ssh runner@nomad sudo /opt/nginx_updater/venv/bin/python3 /opt/nginx_updater/nginx_updater.py lifefaq --target green
|
||||
|
||||
- name: Validate Deployment
|
||||
run: curl -f https://lifefaq.i80.dk/health || exit 1
|
||||
|
||||
- name: Purge Old Blue Version
|
||||
if: success()
|
||||
env:
|
||||
NOMAD_ADDR: https://nomad.i80.dk
|
||||
run: nomad job stop -purge -no-shutdown-delay lifefaq
|
||||
continue-on-error: true
|
||||
run: nomad job stop -purge lifefaq-blue
|
||||
|
||||
|
||||
- name: Apply Nomad Job
|
||||
canary-deploy:
|
||||
runs-on: self-hosted
|
||||
needs: build-push
|
||||
steps:
|
||||
- name: Deploy Canary Version
|
||||
env:
|
||||
NOMAD_ADDR: https://nomad.i80.dk
|
||||
run: nomad job run .gitea/workflows/nomad-job.hcl
|
||||
run: nomad job run -var="image=registry.i80.dk/gitea/lifefaq:${COMMIT_HASH}" .gitea/workflows/nomad-job-canary.hcl
|
||||
|
||||
- name: Update Nginx Configuration
|
||||
run: ssh runner@nomad sudo /opt/nginx_updater/venv/bin/python3 /opt/nginx_updater/nginx_updater.py lifefaq
|
||||
- name: Update Forwarder for Canary (10% traffic)
|
||||
run: ssh runner@nomad sudo /opt/nginx_updater/venv/bin/python3 /opt/nginx_updater/update_forwarder.py --subdomain lifefaq --weight 10
|
||||
|
||||
- name: Update Forwarder Configuration
|
||||
run: ssh runner@nomad sudo /opt/nginx_updater/venv/bin/python3 /opt/nginx_updater/update_forwarder.py --subdomain lifefaq
|
||||
- name: Monitor and Scale Canary
|
||||
run: |
|
||||
# Monitor performance for 10 minutes
|
||||
sleep 600
|
||||
curl -f https://lifefaq.i80.dk/health || exit 1
|
||||
ssh runner@nomad sudo /opt/nginx_updater/venv/bin/python3 /opt/nginx_updater/update_forwarder.py --subdomain lifefaq --weight 50
|
||||
|
||||
|
||||
# - name: Restart Nomad Job
|
||||
# env:
|
||||
# NOMAD_ADDR: https://nomad.i80.dk
|
||||
# run: |
|
||||
# nomad job stop lifefaq
|
||||
# sleep 5 # Optional: Wait to ensure the old allocation is stopped
|
||||
# nomad job run .gitea/workflows/nomad-job.hcl
|
||||
- name: Complete Canary Rollout
|
||||
if: success()
|
||||
run: ssh runner@nomad sudo /opt/nginx_updater/venv/bin/python3 /opt/nginx_updater/update_forwarder.py --subdomain lifefaq --weight 100
|
||||
|
||||
Reference in New Issue
Block a user