Skip to content

Commit e2248ae

Browse files
committed
fix: function definition ordering
1 parent 18d8115 commit e2248ae

File tree

1 file changed

+51
-50
lines changed

1 file changed

+51
-50
lines changed

k8s/test.sh

+51-50
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,45 @@ do
2525
esac
2626
done
2727

28+
29+
REFINERY_ALEMBIC_VERSION=""
30+
KUBERNETES_DEPLOYMENT_ALEMBIC_VERSION=""
31+
32+
REFINERY_IMAGE_TAG_EXISTS=$(az acr repository show --name ${AZURE_CONTAINER_REGISTRY} --image ${REFINERY_DEPLOYMENT_NAME}:${TEST_IMAGE_TAG} 2> /dev/null || true)
33+
34+
downgrade_alembic_migrations() {
35+
echo "::group::Downgrade alembic migrations"
36+
if [ $KUBERNETES_DEPLOYMENT_NAME != "refinery-gateway" ] && [ $KUBERNETES_DEPLOYMENT_NAME != "gates-gateway" ] && [ $KUBERNETES_DEPLOYMENT_NAME != "hosted-inference-api" ]; then
37+
if [ -n "$REFINERY_IMAGE_TAG_EXISTS" ]; then
38+
set +e
39+
kubectl exec -i deployment/test-${REFINERY_DEPLOYMENT_NAME} -c test-${REFINERY_DEPLOYMENT_NAME} -- alembic downgrade $REFINERY_ALEMBIC_VERSION
40+
if [ "$?" != "0" ]; then
41+
echo "::error::Alembic downgrade failed. Please update your code to support downgrading the current alembic version"
42+
kubectl delete --kustomize apps/${REFINERY_DEPLOYMENT_NAME}/test
43+
kubectl delete --kustomize infrastructure/test
44+
exit 1
45+
else
46+
echo "::notice::downgraded test-$REFINERY_DEPLOYMENT_NAME alembic version to $REFINERY_ALEMBIC_VERSION"
47+
fi
48+
set -e
49+
fi
50+
kubectl delete --kustomize apps/${REFINERY_DEPLOYMENT_NAME}/test
51+
else
52+
set +e
53+
kubectl exec -i deployment/test-${KUBERNETES_DEPLOYMENT_NAME} -c test-${KUBERNETES_DEPLOYMENT_NAME} -- alembic downgrade $KUBERNETES_DEPLOYMENT_ALEMBIC_VERSION
54+
if [ "$?" != "0" ]; then
55+
echo "::error::Alembic downgrade failed. Please update your code to support downgrading the current alembic version"
56+
kubectl delete --kustomize apps/${REFINERY_DEPLOYMENT_NAME}/test
57+
kubectl delete --kustomize infrastructure/test
58+
exit 1
59+
else
60+
echo "::notice::downgraded test-$KUBERNETES_DEPLOYMENT_NAME alembic version to $REFINERY_ALEMBIC_VERSION"
61+
fi
62+
set -e
63+
fi
64+
echo "::endgroup::"
65+
}
66+
2867
__safe_migration_rollout() {
2968
deploy=$1
3069

@@ -48,24 +87,6 @@ __safe_migration_rollout() {
4887
fi
4988
}
5089

51-
echo "::group::Kubernetes Context & Test Infrastructure"
52-
kubectl config set-context --current --namespace=$KUBERNETES_NAMESPACE
53-
echo "Context set to namespace: \"$KUBERNETES_NAMESPACE\""
54-
kubectl apply --kustomize infrastructure/test
55-
__safe_migration_rollout test-postgres
56-
until kubectl exec -i deployment/test-postgres -- sh -c pg_isready; do
57-
echo "Waiting for postgres to be ready..."
58-
sleep 3
59-
done
60-
kubectl exec -i deployment/test-postgres -- sh -c "psql -U postgres -c '$(cat infrastructure/test/deployment/assets/init.sql)'"
61-
echo "::endgroup::"
62-
63-
64-
REFINERY_ALEMBIC_VERSION=""
65-
KUBERNETES_DEPLOYMENT_ALEMBIC_VERSION=""
66-
67-
REFINERY_IMAGE_TAG_EXISTS=$(az acr repository show --name ${AZURE_CONTAINER_REGISTRY} --image ${REFINERY_DEPLOYMENT_NAME}:${TEST_IMAGE_TAG} 2> /dev/null || true)
68-
6990
upgrade_alembic_migrations() {
7091
echo "::group::Upgrade alembic migrations for test"
7192
if [ $KUBERNETES_DEPLOYMENT_NAME != "refinery-gateway" ] && [ $KUBERNETES_DEPLOYMENT_NAME != "gates-gateway" ] && [ $KUBERNETES_DEPLOYMENT_NAME != "hosted-inference-api" ]; then
@@ -108,38 +129,18 @@ upgrade_alembic_migrations() {
108129
echo "::endgroup::"
109130
}
110131

111-
downgrade_alembic_migrations() {
112-
echo "::group::Downgrade alembic migrations"
113-
if [ $KUBERNETES_DEPLOYMENT_NAME != "refinery-gateway" ] && [ $KUBERNETES_DEPLOYMENT_NAME != "gates-gateway" ] && [ $KUBERNETES_DEPLOYMENT_NAME != "hosted-inference-api" ]; then
114-
if [ -n "$REFINERY_IMAGE_TAG_EXISTS" ]; then
115-
set +e
116-
kubectl exec -i deployment/test-${REFINERY_DEPLOYMENT_NAME} -c test-${REFINERY_DEPLOYMENT_NAME} -- alembic downgrade $REFINERY_ALEMBIC_VERSION
117-
if [ "$?" != "0" ]; then
118-
echo "::error::Alembic downgrade failed. Please update your code to support downgrading the current alembic version"
119-
kubectl delete --kustomize apps/${REFINERY_DEPLOYMENT_NAME}/test
120-
kubectl delete --kustomize infrastructure/test
121-
exit 1
122-
else
123-
echo "::notice::downgraded test-$REFINERY_DEPLOYMENT_NAME alembic version to $REFINERY_ALEMBIC_VERSION"
124-
fi
125-
set -e
126-
fi
127-
kubectl delete --kustomize apps/${REFINERY_DEPLOYMENT_NAME}/test
128-
else
129-
set +e
130-
kubectl exec -i deployment/test-${KUBERNETES_DEPLOYMENT_NAME} -c test-${KUBERNETES_DEPLOYMENT_NAME} -- alembic downgrade $KUBERNETES_DEPLOYMENT_ALEMBIC_VERSION
131-
if [ "$?" != "0" ]; then
132-
echo "::error::Alembic downgrade failed. Please update your code to support downgrading the current alembic version"
133-
kubectl delete --kustomize apps/${REFINERY_DEPLOYMENT_NAME}/test
134-
kubectl delete --kustomize infrastructure/test
135-
exit 1
136-
else
137-
echo "::notice::downgraded test-$KUBERNETES_DEPLOYMENT_NAME alembic version to $REFINERY_ALEMBIC_VERSION"
138-
fi
139-
set -e
140-
fi
141-
echo "::endgroup::"
142-
}
132+
echo "::group::Kubernetes Context & Test Infrastructure"
133+
kubectl config set-context --current --namespace=$KUBERNETES_NAMESPACE
134+
echo "Context set to namespace: \"$KUBERNETES_NAMESPACE\""
135+
kubectl apply --kustomize infrastructure/test
136+
__safe_migration_rollout test-postgres
137+
until kubectl exec -i deployment/test-postgres -- sh -c pg_isready; do
138+
echo "Waiting for postgres to be ready..."
139+
sleep 3
140+
done
141+
kubectl exec -i deployment/test-postgres -- sh -c "psql -U postgres -c '$(cat infrastructure/test/deployment/assets/init.sql)'"
142+
echo "::endgroup::"
143+
143144

144145
if [ "$ENABLE_ALEMBIC_MIGRATIONS" = "true" ]; then
145146
upgrade_alembic_migrations

0 commit comments

Comments
 (0)