feat(ci): add Kubernetes deployment toggle and update conditions for deployment steps
All checks were successful
All checks were successful
This commit is contained in:
@@ -140,6 +140,7 @@ jobs:
|
|||||||
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
|
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
|
||||||
STAGING_KUBE_CONFIG: ${{ secrets.STAGING_KUBE_CONFIG }}
|
STAGING_KUBE_CONFIG: ${{ secrets.STAGING_KUBE_CONFIG }}
|
||||||
PROD_KUBE_CONFIG: ${{ secrets.PROD_KUBE_CONFIG }}
|
PROD_KUBE_CONFIG: ${{ secrets.PROD_KUBE_CONFIG }}
|
||||||
|
K8S_DEPLOY_ENABLED: ${{ secrets.K8S_DEPLOY_ENABLED }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@@ -159,6 +160,16 @@ jobs:
|
|||||||
echo "REGISTRY_HOST=${registry_host}" >> "$GITHUB_ENV"
|
echo "REGISTRY_HOST=${registry_host}" >> "$GITHUB_ENV"
|
||||||
echo "REGISTRY_REPOSITORY=${registry_repository}" >> "$GITHUB_ENV"
|
echo "REGISTRY_REPOSITORY=${registry_repository}" >> "$GITHUB_ENV"
|
||||||
|
|
||||||
|
- name: Report Kubernetes deployment toggle
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
enabled="${K8S_DEPLOY_ENABLED:-}"
|
||||||
|
if [ "${enabled}" = "true" ]; then
|
||||||
|
echo "Kubernetes deployment is enabled for this run."
|
||||||
|
else
|
||||||
|
echo "::notice::Kubernetes deployment steps are disabled (set secrets.K8S_DEPLOY_ENABLED to 'true' to enable)."
|
||||||
|
fi
|
||||||
|
|
||||||
- name: Capture commit metadata
|
- name: Capture commit metadata
|
||||||
id: commit_meta
|
id: commit_meta
|
||||||
run: |
|
run: |
|
||||||
@@ -167,21 +178,21 @@ jobs:
|
|||||||
echo "message=$message" >> "$GITHUB_OUTPUT"
|
echo "message=$message" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
- name: Set up kubectl for staging
|
- name: Set up kubectl for staging
|
||||||
if: contains(steps.commit_meta.outputs.message, '[deploy staging]')
|
if: env.K8S_DEPLOY_ENABLED == 'true' && contains(steps.commit_meta.outputs.message, '[deploy staging]')
|
||||||
uses: azure/k8s-set-context@v3
|
uses: azure/k8s-set-context@v3
|
||||||
with:
|
with:
|
||||||
method: kubeconfig
|
method: kubeconfig
|
||||||
kubeconfig: ${{ env.STAGING_KUBE_CONFIG }}
|
kubeconfig: ${{ env.STAGING_KUBE_CONFIG }}
|
||||||
|
|
||||||
- name: Set up kubectl for production
|
- name: Set up kubectl for production
|
||||||
if: contains(steps.commit_meta.outputs.message, '[deploy production]')
|
if: env.K8S_DEPLOY_ENABLED == 'true' && contains(steps.commit_meta.outputs.message, '[deploy production]')
|
||||||
uses: azure/k8s-set-context@v3
|
uses: azure/k8s-set-context@v3
|
||||||
with:
|
with:
|
||||||
method: kubeconfig
|
method: kubeconfig
|
||||||
kubeconfig: ${{ env.PROD_KUBE_CONFIG }}
|
kubeconfig: ${{ env.PROD_KUBE_CONFIG }}
|
||||||
|
|
||||||
- name: Deploy to staging
|
- name: Deploy to staging
|
||||||
if: contains(steps.commit_meta.outputs.message, '[deploy staging]')
|
if: env.K8S_DEPLOY_ENABLED == 'true' && contains(steps.commit_meta.outputs.message, '[deploy staging]')
|
||||||
run: |
|
run: |
|
||||||
kubectl set image deployment/calminer-app calminer=${REGISTRY_REPOSITORY}:latest
|
kubectl set image deployment/calminer-app calminer=${REGISTRY_REPOSITORY}:latest
|
||||||
kubectl apply -f k8s/configmap.yaml
|
kubectl apply -f k8s/configmap.yaml
|
||||||
@@ -189,7 +200,7 @@ jobs:
|
|||||||
kubectl rollout status deployment/calminer-app
|
kubectl rollout status deployment/calminer-app
|
||||||
|
|
||||||
- name: Collect staging deployment logs
|
- name: Collect staging deployment logs
|
||||||
if: contains(steps.commit_meta.outputs.message, '[deploy staging]')
|
if: env.K8S_DEPLOY_ENABLED == 'true' && contains(steps.commit_meta.outputs.message, '[deploy staging]')
|
||||||
run: |
|
run: |
|
||||||
mkdir -p logs/deployment/staging
|
mkdir -p logs/deployment/staging
|
||||||
kubectl get pods -o wide > logs/deployment/staging/pods.txt
|
kubectl get pods -o wide > logs/deployment/staging/pods.txt
|
||||||
@@ -197,7 +208,7 @@ jobs:
|
|||||||
kubectl logs deployment/calminer-app --all-containers=true --tail=500 > logs/deployment/staging/calminer-app.log
|
kubectl logs deployment/calminer-app --all-containers=true --tail=500 > logs/deployment/staging/calminer-app.log
|
||||||
|
|
||||||
- name: Deploy to production
|
- name: Deploy to production
|
||||||
if: contains(steps.commit_meta.outputs.message, '[deploy production]')
|
if: env.K8S_DEPLOY_ENABLED == 'true' && contains(steps.commit_meta.outputs.message, '[deploy production]')
|
||||||
run: |
|
run: |
|
||||||
kubectl set image deployment/calminer-app calminer=${REGISTRY_REPOSITORY}:latest
|
kubectl set image deployment/calminer-app calminer=${REGISTRY_REPOSITORY}:latest
|
||||||
kubectl apply -f k8s/configmap.yaml
|
kubectl apply -f k8s/configmap.yaml
|
||||||
@@ -205,7 +216,7 @@ jobs:
|
|||||||
kubectl rollout status deployment/calminer-app
|
kubectl rollout status deployment/calminer-app
|
||||||
|
|
||||||
- name: Collect production deployment logs
|
- name: Collect production deployment logs
|
||||||
if: contains(steps.commit_meta.outputs.message, '[deploy production]')
|
if: env.K8S_DEPLOY_ENABLED == 'true' && contains(steps.commit_meta.outputs.message, '[deploy production]')
|
||||||
run: |
|
run: |
|
||||||
mkdir -p logs/deployment/production
|
mkdir -p logs/deployment/production
|
||||||
kubectl get pods -o wide > logs/deployment/production/pods.txt
|
kubectl get pods -o wide > logs/deployment/production/pods.txt
|
||||||
|
|||||||
Reference in New Issue
Block a user