Skip to content

Commit f4d5fec

Browse files
committed
perf: use env vars to identify alembic migrations
1 parent 231f97a commit f4d5fec

File tree

4 files changed

+42
-7
lines changed

4 files changed

+42
-7
lines changed

.github/workflows/k8s_test.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
call-k8-db-upgrade:
2727
uses: code-kern-ai/cicd-deployment-scripts/.github/workflows/k8s_db_upgrade.yml@dev
2828
needs: [call-az-acr-push-test, call-gh-db-migration-wait]
29-
if: ${{ github.event.repository.name == 'refinery-gateway' || github.event.repository.name == 'gates-gateway' || github.event.repository.name == 'cognition-gateway' || github.event.repository.name == 'hosted-inference-api' }}
29+
if: ${{ vars.ENABLE_ALEMBIC_MIGRATIONS == 'true' }}
3030
secrets: inherit
3131
with:
3232
alembic_upgrade_rev: 'head'
@@ -45,6 +45,7 @@ jobs:
4545
KUBERNETES_MANIFEST_PATH: "${{ vars.KUBERNETES_MANIFEST_PATH }}"
4646
AZURE_RESOURCE_GROUP: "${{ vars.AZURE_RESOURCE_GROUP }}"
4747
AZURE_CONTAINER_REGISTRY: "${{ vars.AZURE_CONTAINER_REGISTRY }}"
48+
ENABLE_ALEMBIC_MIGRATIONS: "${{ vars.ENABLE_ALEMBIC_MIGRATIONS }}"
4849
steps:
4950
# Checkout the repository to the GitHub Actions runner
5051
- name: Checkout
@@ -85,12 +86,13 @@ jobs:
8586
-d ${{ github.event.repository.name }} \
8687
-t ${{ needs.call-az-acr-push-test.outputs.GH_REF_NAME }} \
8788
-r ${{ env.AZURE_CONTAINER_REGISTRY }} \
88-
-c "${{ inputs.test_cmd }}"
89+
-c "${{ inputs.test_cmd }}" \
90+
-a "${{ env.ENABLE_ALEMBIC_MIGRATIONS }}"
8991
9092
call-k8-db-downgrade:
9193
uses: code-kern-ai/cicd-deployment-scripts/.github/workflows/k8s_db_downgrade.yml@dev
9294
needs: [call-az-acr-push-test, call-k8-db-upgrade, k8-test]
93-
if: ${{ always() && !cancelled() && (needs.call-k8-db-upgrade.outputs.ALEMBIC_CURRENT_REV != needs.call-k8-db-upgrade.outputs.ALEMBIC_UPGRADED_REV) && (github.event.repository.name == 'refinery-gateway' || github.event.repository.name == 'gates-gateway' || github.event.repository.name == 'cognition-gateway' || github.event.repository.name == 'hosted-inference-api') }}
95+
if: ${{ always() && !cancelled() && (needs.call-k8-db-upgrade.outputs.ALEMBIC_CURRENT_REV != needs.call-k8-db-upgrade.outputs.ALEMBIC_UPGRADED_REV) && vars.ENABLE_ALEMBIC_MIGRATIONS == 'true' }}
9496
secrets: inherit
9597
with:
9698
alembic_downgrade_rev: ${{ needs.call-k8-db-upgrade.outputs.ALEMBIC_CURRENT_REV }}

k8s/db_downgrade.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ do
2323
esac
2424
done
2525

26-
if [ $KUBERNETES_DEPLOYMENT_NAME = "cognition-gateway" ]; then
26+
if [ $KUBERNETES_DEPLOYMENT_NAME != "refinery-gateway" ] && [ $KUBERNETES_DEPLOYMENT_NAME != "gates-gateway" ] && [ $KUBERNETES_DEPLOYMENT_NAME != "hosted-inference-api" ]; then
2727
KUBERNETES_DEPLOYMENT_NAME="refinery-gateway"
2828
set +e
2929
IMAGE_TAG_EXISTS=$(az acr repository show --name ${AZURE_CONTAINER_REGISTRY} --image ${KUBERNETES_DEPLOYMENT_NAME}:${IMAGE_TAG} 2> /dev/null)

k8s/db_upgrade.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ do
2323
esac
2424
done
2525

26-
if [ $KUBERNETES_DEPLOYMENT_NAME = "cognition-gateway" ]; then
26+
if [ $KUBERNETES_DEPLOYMENT_NAME != "refinery-gateway" ] && [ $KUBERNETES_DEPLOYMENT_NAME != "gates-gateway" ] && [ $KUBERNETES_DEPLOYMENT_NAME != "hosted-inference-api" ]; then
2727
KUBERNETES_DEPLOYMENT_NAME="refinery-gateway"
2828
set +e
2929
IMAGE_TAG_EXISTS=$(az acr repository show --name ${AZURE_CONTAINER_REGISTRY} --image ${KUBERNETES_DEPLOYMENT_NAME}:${IMAGE_TAG} 2> /dev/null)

k8s/test.sh

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ KUBERNETES_DEPLOYMENT_NAME=""
66
TEST_IMAGE_TAG=""
77
AZURE_CONTAINER_REGISTRY=""
88
TEST_CMD=""
9+
ENABLE_ALEMBIC_MIGRATIONS="false"
910

10-
while getopts n:d:h:r:t:c: flag
11+
while getopts n:d:h:r:t:c:a: flag
1112
do
1213
case "${flag}" in
1314
n) KUBERNETES_NAMESPACE=${OPTARG};;
1415
d) KUBERNETES_DEPLOYMENT_NAME=${OPTARG};;
1516
t) TEST_IMAGE_TAG=${OPTARG};;
1617
r) AZURE_CONTAINER_REGISTRY=${OPTARG};;
1718
c) TEST_CMD=${OPTARG};;
19+
a) ENABLE_ALEMBIC_MIGRATIONS=${OPTARG};;
1820
esac
1921
done
2022

@@ -24,11 +26,30 @@ echo "Context set to namespace: \"$KUBERNETES_NAMESPACE\""
2426
echo "::endgroup::"
2527

2628

27-
echo "::group::Upgrade deployment image"
2829
KUBERNETES_POD_EXISTING_IMAGE=$(kubectl get pod --output json \
2930
--selector app=${KUBERNETES_DEPLOYMENT_NAME} \
3031
| jq -r '.items[0] | .spec.containers[0].image')
3132

33+
REFINERY_DEPLOYMENT_NAME="refinery-gateway"
34+
REFINERY_POD_EXISTING_IMAGE=$(kubectl get pod --output json \
35+
--selector app=${REFINERY_DEPLOYMENT_NAME} \
36+
| jq -r '.items[0] | .spec.containers[0].image')
37+
38+
39+
if [ "$ENABLE_ALEMBIC_MIGRATIONS" = "true" ]; then
40+
echo "::group::Preparing alembic migrations for test"
41+
if [ $KUBERNETES_DEPLOYMENT_NAME != "refinery-gateway" ] && [ $KUBERNETES_DEPLOYMENT_NAME != "gates-gateway" ] && [ $KUBERNETES_DEPLOYMENT_NAME != "hosted-inference-api" ]; then
42+
kubectl set image deployment/${REFINERY_DEPLOYMENT_NAME} \
43+
${REFINERY_DEPLOYMENT_NAME}-migrate=${AZURE_CONTAINER_REGISTRY}/${REFINERY_DEPLOYMENT_NAME}:${TEST_IMAGE_TAG} \
44+
${REFINERY_DEPLOYMENT_NAME}=${AZURE_CONTAINER_REGISTRY}/${REFINERY_DEPLOYMENT_NAME}:${TEST_IMAGE_TAG}
45+
kubectl rollout status deployment ${REFINERY_DEPLOYMENT_NAME}
46+
else
47+
kubectl set image deployment/${KUBERNETES_DEPLOYMENT_NAME} ${KUBERNETES_DEPLOYMENT_NAME}-migrate=${AZURE_CONTAINER_REGISTRY}/${KUBERNETES_DEPLOYMENT_NAME}:${TEST_IMAGE_TAG}
48+
fi
49+
echo "::endgroup::"
50+
fi
51+
52+
echo "::group::Upgrade deployment image"
3253
kubectl set image deployment/${KUBERNETES_DEPLOYMENT_NAME} ${KUBERNETES_DEPLOYMENT_NAME}=${AZURE_CONTAINER_REGISTRY}/${KUBERNETES_DEPLOYMENT_NAME}:${TEST_IMAGE_TAG}
3354
kubectl rollout status deployment ${KUBERNETES_DEPLOYMENT_NAME}
3455
echo "::endgroup::"
@@ -46,6 +67,18 @@ set -e
4667
kubectl set image deployment/${KUBERNETES_DEPLOYMENT_NAME} ${KUBERNETES_DEPLOYMENT_NAME}=${KUBERNETES_POD_EXISTING_IMAGE}
4768
echo "::endgroup::"
4869

70+
if [ "$ENABLE_ALEMBIC_MIGRATIONS" = "true" ]; then
71+
echo "::group::Reverting alembic migrations for test"
72+
if [ $KUBERNETES_DEPLOYMENT_NAME != "refinery-gateway" ] && [ $KUBERNETES_DEPLOYMENT_NAME != "gates-gateway" ] && [ $KUBERNETES_DEPLOYMENT_NAME != "hosted-inference-api" ]; then
73+
kubectl set image deployment/${REFINERY_DEPLOYMENT_NAME} \
74+
${REFINERY_DEPLOYMENT_NAME}-migrate=${REFINERY_POD_EXISTING_IMAGE} \
75+
${REFINERY_DEPLOYMENT_NAME}=${REFINERY_POD_EXISTING_IMAGE}
76+
kubectl rollout status deployment ${REFINERY_DEPLOYMENT_NAME}
77+
else
78+
kubectl set image deployment/${KUBERNETES_DEPLOYMENT_NAME} ${KUBERNETES_DEPLOYMENT_NAME}-migrate=${REFINERY_POD_EXISTING_IMAGE}
79+
fi
80+
echo "::endgroup::"
81+
fi
4982

5083
echo "::notice::using ${KUBERNETES_POD_EXISTING_IMAGE}"
5184

0 commit comments

Comments
 (0)