120 lines
4.2 KiB
YAML
120 lines
4.2 KiB
YAML
name: Promote ready UAT questions to PRD
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
mode:
|
|
description: "dry-run or apply"
|
|
required: true
|
|
default: dry-run
|
|
confirmation:
|
|
description: "Enter PROMOTE_TO_PRD when mode is apply"
|
|
required: false
|
|
default: ""
|
|
|
|
concurrency:
|
|
group: step3-question-promotion
|
|
cancel-in-progress: false
|
|
|
|
jobs:
|
|
promote:
|
|
runs-on: self-hosted
|
|
steps:
|
|
- name: Checkout production configuration
|
|
uses: actions/checkout@v4
|
|
with:
|
|
ref: production
|
|
|
|
- name: Configure kubeconfig
|
|
env:
|
|
KUBECONFIG_CONTENT: ${{ secrets.KUBECONFIG }}
|
|
run: |
|
|
if [ -n "$KUBECONFIG_CONTENT" ]; then
|
|
mkdir -p /tmp/kube
|
|
printf '%s\n' "$KUBECONFIG_CONTENT" > /tmp/kube/config
|
|
echo "KUBECONFIG=/tmp/kube/config" >> "$GITHUB_ENV"
|
|
fi
|
|
|
|
- name: Validate promotion request
|
|
env:
|
|
MODE: ${{ inputs.mode }}
|
|
CONFIRMATION: ${{ inputs.confirmation }}
|
|
run: |
|
|
test "$MODE" = "dry-run" || test "$MODE" = "apply"
|
|
if [ "$MODE" = "apply" ]; then
|
|
test "$CONFIRMATION" = "PROMOTE_TO_PRD"
|
|
fi
|
|
|
|
- name: Configure question promotion credentials
|
|
env:
|
|
SOURCE_CONNECTION: ${{ secrets.UAT_MONGODB_CONNECTION_STRING }}
|
|
TARGET_CONNECTION: ${{ secrets.PRD_MONGODB_CONNECTION_STRING }}
|
|
run: |
|
|
test -n "$SOURCE_CONNECTION"
|
|
test -n "$TARGET_CONNECTION"
|
|
kubectl create secret generic step3-question-promotion \
|
|
--from-literal=source-connection="$SOURCE_CONNECTION" \
|
|
--from-literal=target-connection="$TARGET_CONNECTION" \
|
|
--dry-run=client -o yaml | kubectl apply -n step3-prd -f -
|
|
|
|
- name: Run ready-question promotion
|
|
env:
|
|
MODE: ${{ inputs.mode }}
|
|
CONFIRMATION: ${{ inputs.confirmation }}
|
|
run: |
|
|
IMAGE="$(kubectl get deployment step3-api -n step3-prd -o jsonpath='{.spec.template.spec.containers[0].image}')"
|
|
REVISION="${IMAGE##*:}"
|
|
POD="question-promotion-${GITHUB_RUN_NUMBER}"
|
|
APPLY_ARGS=""
|
|
if [ "$MODE" = "apply" ]; then
|
|
APPLY_ARGS="--apply --confirm $CONFIRMATION"
|
|
fi
|
|
cat <<EOF | kubectl apply -f -
|
|
apiVersion: v1
|
|
kind: Pod
|
|
metadata:
|
|
name: ${POD}
|
|
namespace: step3-prd
|
|
labels:
|
|
app: step3-question-promotion
|
|
spec:
|
|
restartPolicy: Never
|
|
containers:
|
|
- name: promotion
|
|
image: ${IMAGE}
|
|
imagePullPolicy: IfNotPresent
|
|
command: ["/bin/sh", "-c"]
|
|
args:
|
|
- >-
|
|
dotnet QuestionsApi.dll promote-questions
|
|
--source-database ranaze_step3_uat
|
|
--target-database ranaze_step3_prd
|
|
--operator "${GITHUB_ACTOR:-gitea-operator}"
|
|
--build-revision "${REVISION}"
|
|
${APPLY_ARGS}
|
|
env:
|
|
- name: SOURCE_MONGODB_CONNECTION_STRING
|
|
valueFrom:
|
|
secretKeyRef:
|
|
name: step3-question-promotion
|
|
key: source-connection
|
|
- name: TARGET_MONGODB_CONNECTION_STRING
|
|
valueFrom:
|
|
secretKeyRef:
|
|
name: step3-question-promotion
|
|
key: target-connection
|
|
EOF
|
|
for attempt in $(seq 1 120); do
|
|
PHASE="$(kubectl get pod "$POD" -n step3-prd -o jsonpath='{.status.phase}')"
|
|
if [ "$PHASE" = "Succeeded" ] || [ "$PHASE" = "Failed" ]; then break; fi
|
|
sleep 2
|
|
done
|
|
kubectl logs "$POD" -n step3-prd
|
|
test "$(kubectl get pod "$POD" -n step3-prd -o jsonpath='{.status.phase}')" = "Succeeded"
|
|
|
|
- name: Remove promotion credentials and pod
|
|
if: always()
|
|
run: |
|
|
kubectl delete pod "question-promotion-${GITHUB_RUN_NUMBER}" -n step3-prd --ignore-not-found
|
|
kubectl delete secret step3-question-promotion -n step3-prd --ignore-not-found
|