-
Notifications
You must be signed in to change notification settings - Fork 54
83 lines (66 loc) · 2.79 KB
/
Copy pathdeploy-staging.yml
File metadata and controls
83 lines (66 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
name: Deploy Staging
on:
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-deploy:
runs-on: ubuntu-latest
environment: staging
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 2 # needed to get previous tag for rollback
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha,format=long
# In a real scenario, this would authenticate to a registry
# For Phase 0, we just build the image locally and tag it with the SHA
- name: Build Docker image
uses: docker/build-push-action@v5
with:
context: .
load: true # load into local docker daemon
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# We simulate the staging deployment locally on the GitHub Runner
# since there's no remote target specified yet.
- name: Deploy to Staging (Runner)
env:
DATABASE_URL: ${{ secrets.STAGING_DATABASE_URL || 'postgresql://learnault:staging_password@localhost:5432/learnault_staging?schema=public' }}
JWT_SECRET: ${{ secrets.STAGING_JWT_SECRET || 'fallback-staging-secret' }}
run: |
echo "Actor: ${{ github.actor }}"
echo "Digest/Tag: ${{ steps.meta.outputs.version }}"
# We need to run the postgres db as a mock for staging
docker compose -f docker-compose.staging.yml up -d db
sleep 10 # Wait for db to initialize
# Run deployment
./scripts/deploy-staging.sh ${{ steps.meta.outputs.version }}
- name: Run Smoke Tests
run: ./scripts/smoke-test.sh
- name: Handle Failure & Rollback
if: failure()
run: |
echo "Deployment or Smoke Tests failed. Initiating Rollback..."
# Get the previous commit SHA to rollback to
PREV_SHA=$(git rev-parse HEAD^)
PREV_TAG="sha-$PREV_SHA"
echo "Rolling back to tag: $PREV_TAG"
# Since this is a CI mock, we just run the rollback script
# In reality, this tag would be pulled from the registry
# We'll just build it to simulate
docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$PREV_TAG .
./scripts/rollback-staging.sh ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$PREV_TAG