-
Notifications
You must be signed in to change notification settings - Fork 0
122 lines (108 loc) · 4.5 KB
/
deploy.yml
File metadata and controls
122 lines (108 loc) · 4.5 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
name: Deploy
on:
push:
tags: ['v*']
workflow_dispatch:
inputs:
environment:
description: 'Target environment'
required: true
type: choice
options:
- staging
- production
image_tag:
description: 'Docker image tag to deploy'
required: true
type: string
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
prepare:
name: Prepare Deployment
runs-on: ubuntu-latest
outputs:
image_tag: ${{ steps.resolve-tag.outputs.tag }}
version: ${{ steps.resolve-tag.outputs.version }}
steps:
- name: Resolve image tag
id: resolve-tag
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "tag=${{ inputs.image_tag }}" >> $GITHUB_OUTPUT
echo "version=${{ inputs.image_tag }}" >> $GITHUB_OUTPUT
else
TAG="${GITHUB_REF#refs/tags/}"
echo "tag=${TAG}" >> $GITHUB_OUTPUT
echo "version=${TAG}" >> $GITHUB_OUTPUT
fi
- name: Verify image exists
run: |
echo "Verifying image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.resolve-tag.outputs.tag }}"
deploy-staging:
name: Deploy to Staging
needs: prepare
runs-on: ubuntu-latest
environment:
name: staging
url: https://ordermonitor-api.staging.printerpix.com/health
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set image tag in manifests
run: |
cd k8s/overlays/staging
kustomize edit set image ghcr.io/printerpix/printerpix-backoffice-ordermonitor-api=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.prepare.outputs.image_tag }}
- name: Deploy to staging
run: |
echo "Deploying ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.prepare.outputs.image_tag }} to staging"
echo "kubectl apply -k k8s/overlays/staging"
# Uncomment when cluster credentials are configured:
# kubectl apply -k k8s/overlays/staging
# kubectl -n ordermonitor-staging rollout status deployment/staging-ordermonitor-api --timeout=300s
- name: Run smoke tests
run: |
echo "Running smoke tests against staging..."
# Uncomment when staging is accessible:
# chmod +x scripts/smoke-test.sh
# ./scripts/smoke-test.sh https://ordermonitor-api.staging.printerpix.com
- name: Staging deployment summary
run: |
echo "## Staging Deployment" >> $GITHUB_STEP_SUMMARY
echo "- **Image:** ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.prepare.outputs.image_tag }}" >> $GITHUB_STEP_SUMMARY
echo "- **Version:** ${{ needs.prepare.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "- **Environment:** staging" >> $GITHUB_STEP_SUMMARY
deploy-production:
name: Deploy to Production
needs: [prepare, deploy-staging]
runs-on: ubuntu-latest
environment:
name: production
url: https://ordermonitor-api.printerpix.com/health
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set image tag in manifests
run: |
cd k8s/overlays/production
kustomize edit set image ghcr.io/printerpix/printerpix-backoffice-ordermonitor-api=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.prepare.outputs.image_tag }}
- name: Deploy to production
run: |
echo "Deploying ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.prepare.outputs.image_tag }} to production"
echo "kubectl apply -k k8s/overlays/production"
# Uncomment when cluster credentials are configured:
# kubectl apply -k k8s/overlays/production
# kubectl -n ordermonitor rollout status deployment/ordermonitor-api --timeout=300s
- name: Run smoke tests
run: |
echo "Running smoke tests against production..."
# Uncomment when production is accessible:
# chmod +x scripts/smoke-test.sh
# ./scripts/smoke-test.sh https://ordermonitor-api.printerpix.com
- name: Production deployment summary
run: |
echo "## Production Deployment" >> $GITHUB_STEP_SUMMARY
echo "- **Image:** ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.prepare.outputs.image_tag }}" >> $GITHUB_STEP_SUMMARY
echo "- **Version:** ${{ needs.prepare.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "- **Environment:** production" >> $GITHUB_STEP_SUMMARY