Skip to content

CD

CD #15

Workflow file for this run

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