-
Notifications
You must be signed in to change notification settings - Fork 0
59 lines (53 loc) · 2.08 KB
/
Copy pathcd.yml
File metadata and controls
59 lines (53 loc) · 2.08 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
name: CD
on:
workflow_run:
workflows: ["CI"]
types: [completed]
branches: [master, main]
jobs:
deploy-production:
name: Deploy to Production
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
environment: production
env:
PRODUCTION_KUBECONFIG: ${{ secrets.PRODUCTION_KUBECONFIG }}
PRODUCTION_KUBECONFIG_CONTEXT: ${{ secrets.PRODUCTION_KUBECONFIG_CONTEXT }}
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
ref: ${{ github.event.workflow_run.head_sha }}
- name: Set up kubectl
uses: azure/setup-kubectl@v4
- name: Configure kubeconfig
run: |
if [ -z "$PRODUCTION_KUBECONFIG" ]; then
echo "Skipping production deploy because PRODUCTION_KUBECONFIG is not configured."
exit 0
fi
printf '%s' "$PRODUCTION_KUBECONFIG" > "$RUNNER_TEMP/kubeconfig"
chmod 600 "$RUNNER_TEMP/kubeconfig"
echo "KUBECONFIG=$RUNNER_TEMP/kubeconfig" >> "$GITHUB_ENV"
if [ -n "$PRODUCTION_KUBECONFIG_CONTEXT" ]; then
kubectl config use-context "$PRODUCTION_KUBECONFIG_CONTEXT"
fi
- name: Render production manifests
run: |
if [ -z "$PRODUCTION_KUBECONFIG" ]; then
exit 0
fi
chmod +x ./scripts/render-k8s-manifests.sh
./scripts/render-k8s-manifests.sh \
deployments/k8s/overlays/production \
"${{ secrets.DOCKERHUB_USERNAME }}/agentmsg-api-gateway:${{ github.event.workflow_run.head_sha }}" \
"${{ secrets.DOCKERHUB_USERNAME }}/agentmsg-message-engine:${{ github.event.workflow_run.head_sha }}" \
> "$RUNNER_TEMP/agentmsg-production.yaml"
- name: Deploy to Kubernetes
run: |
if [ -z "$PRODUCTION_KUBECONFIG" ]; then
exit 0
fi
kubectl apply -f "$RUNNER_TEMP/agentmsg-production.yaml"
kubectl rollout status deployment/api-gateway -n agentmsg
kubectl rollout status deployment/message-engine -n agentmsg