Refactor CI pipeline with templates and add frontend tests
- Add frontend_tests job (npm run test with Vitest) - Add verification checks to deploy_stage (health, API, frontend) - Extract shared YAML anchors: deploy_template, helm_setup, verify_deployment - Reduce code duplication across deploy jobs
This commit is contained in:
131
.gitlab-ci.yml
131
.gitlab-ci.yml
@@ -15,7 +15,7 @@ hadolint:
|
|||||||
|
|
||||||
# secrets job is a blocking check - real credential leaks should fail the pipeline
|
# secrets job is a blocking check - real credential leaks should fail the pipeline
|
||||||
|
|
||||||
# Run Python tests
|
# Run Python backend tests
|
||||||
python_tests:
|
python_tests:
|
||||||
stage: test
|
stage: test
|
||||||
image: deps.global.bsf.tools/docker/python:3.12-slim
|
image: deps.global.bsf.tools/docker/python:3.12-slim
|
||||||
@@ -26,72 +26,34 @@ python_tests:
|
|||||||
- cd backend
|
- cd backend
|
||||||
- python -m pytest -v
|
- python -m pytest -v
|
||||||
|
|
||||||
# Deploy to stage (main branch)
|
# Run frontend tests
|
||||||
deploy_stage:
|
frontend_tests:
|
||||||
stage: deploy
|
stage: test
|
||||||
needs: [build_image]
|
image: deps.global.bsf.tools/docker/node:20-alpine
|
||||||
image: deps.global.bsf.tools/registry-1.docker.io/alpine/k8s:1.29.12
|
|
||||||
variables:
|
|
||||||
ENV: stage
|
|
||||||
NAMESPACE: orch-stage-namespace
|
|
||||||
VALUES_FILE: helm/orchard/values-stage.yaml
|
|
||||||
before_script:
|
before_script:
|
||||||
- kubectl config use-context esv/bsf/bsf-integration/orchard/orchard-mvp:orchard-stage
|
- cd frontend
|
||||||
- helm version
|
- npm ci
|
||||||
- helm repo add stable https://charts.helm.sh/stable
|
|
||||||
- helm repo add bitnami https://charts.bitnami.com/bitnami
|
|
||||||
- cd helm/orchard
|
|
||||||
- helm dependency update
|
|
||||||
- helm repo update
|
|
||||||
script:
|
script:
|
||||||
- echo "Deploying to stage environment"
|
- npm run test -- --run
|
||||||
- cd $CI_PROJECT_DIR
|
|
||||||
- helm upgrade --install orchard-stage ./helm/orchard --namespace $NAMESPACE -f $VALUES_FILE --set image.tag=git.linux-amd64-$CI_COMMIT_SHA
|
|
||||||
environment:
|
|
||||||
name: stage
|
|
||||||
url: https://orchard-stage.common.global.bsf.tools
|
|
||||||
kubernetes:
|
|
||||||
agent: esv/bsf/bsf-integration/orchard/orchard-mvp:orchard-stage
|
|
||||||
rules:
|
rules:
|
||||||
- if: '$CI_COMMIT_BRANCH == "main"'
|
- exists:
|
||||||
when: always
|
- frontend/package.json
|
||||||
|
|
||||||
# Deploy feature branch to dev namespace
|
# Shared deploy configuration
|
||||||
deploy_feature:
|
.deploy_template: &deploy_template
|
||||||
stage: deploy
|
stage: deploy
|
||||||
needs: [build_image]
|
needs: [build_image]
|
||||||
image: deps.global.bsf.tools/registry-1.docker.io/alpine/k8s:1.29.12
|
image: deps.global.bsf.tools/registry-1.docker.io/alpine/k8s:1.29.12
|
||||||
variables:
|
|
||||||
NAMESPACE: orch-dev-namespace
|
.helm_setup: &helm_setup
|
||||||
VALUES_FILE: helm/orchard/values-dev.yaml
|
|
||||||
before_script:
|
|
||||||
- kubectl config use-context esv/bsf/bsf-integration/orchard/orchard-mvp:orchard
|
|
||||||
- helm version
|
- helm version
|
||||||
- helm repo add stable https://charts.helm.sh/stable
|
- helm repo add stable https://charts.helm.sh/stable
|
||||||
- helm repo add bitnami https://charts.bitnami.com/bitnami
|
- helm repo add bitnami https://charts.bitnami.com/bitnami
|
||||||
- cd helm/orchard
|
- cd helm/orchard
|
||||||
- helm dependency update
|
- helm dependency update
|
||||||
- helm repo update
|
- helm repo update
|
||||||
script:
|
|
||||||
- echo "Deploying feature branch $CI_COMMIT_REF_SLUG"
|
|
||||||
- cd $CI_PROJECT_DIR
|
|
||||||
- |
|
|
||||||
helm upgrade --install orchard-$CI_COMMIT_REF_SLUG ./helm/orchard \
|
|
||||||
--namespace $NAMESPACE \
|
|
||||||
-f $VALUES_FILE \
|
|
||||||
--set image.tag=git.linux-amd64-$CI_COMMIT_SHA \
|
|
||||||
--set ingress.hosts[0].host=orchard-$CI_COMMIT_REF_SLUG.common.global.bsf.tools \
|
|
||||||
--set ingress.tls[0].hosts[0]=orchard-$CI_COMMIT_REF_SLUG.common.global.bsf.tools \
|
|
||||||
--set ingress.tls[0].secretName=orchard-$CI_COMMIT_REF_SLUG-tls \
|
|
||||||
--set minioIngress.host=minio-$CI_COMMIT_REF_SLUG.common.global.bsf.tools \
|
|
||||||
--set minioIngress.tls.secretName=minio-$CI_COMMIT_REF_SLUG-tls \
|
|
||||||
--wait \
|
|
||||||
--timeout 5m
|
|
||||||
- echo "Waiting for deployment to be ready..."
|
|
||||||
- kubectl rollout status deployment/orchard-$CI_COMMIT_REF_SLUG -n $NAMESPACE --timeout=5m
|
|
||||||
- |
|
|
||||||
BASE_URL="https://orchard-$CI_COMMIT_REF_SLUG.common.global.bsf.tools"
|
|
||||||
|
|
||||||
|
.verify_deployment: &verify_deployment |
|
||||||
echo "=== Waiting for health endpoint (certs may take a few minutes) ==="
|
echo "=== Waiting for health endpoint (certs may take a few minutes) ==="
|
||||||
for i in $(seq 1 30); do
|
for i in $(seq 1 30); do
|
||||||
if curl -sf --max-time 10 "$BASE_URL/health" > /dev/null 2>&1; then
|
if curl -sf --max-time 10 "$BASE_URL/health" > /dev/null 2>&1; then
|
||||||
@@ -132,6 +94,65 @@ deploy_feature:
|
|||||||
echo ""
|
echo ""
|
||||||
echo "=== All checks passed! ==="
|
echo "=== All checks passed! ==="
|
||||||
echo "Deployment URL: $BASE_URL"
|
echo "Deployment URL: $BASE_URL"
|
||||||
|
|
||||||
|
# Deploy to stage (main branch)
|
||||||
|
deploy_stage:
|
||||||
|
<<: *deploy_template
|
||||||
|
variables:
|
||||||
|
NAMESPACE: orch-stage-namespace
|
||||||
|
VALUES_FILE: helm/orchard/values-stage.yaml
|
||||||
|
BASE_URL: https://orchard-stage.common.global.bsf.tools
|
||||||
|
before_script:
|
||||||
|
- kubectl config use-context esv/bsf/bsf-integration/orchard/orchard-mvp:orchard-stage
|
||||||
|
- *helm_setup
|
||||||
|
script:
|
||||||
|
- echo "Deploying to stage environment"
|
||||||
|
- cd $CI_PROJECT_DIR
|
||||||
|
- |
|
||||||
|
helm upgrade --install orchard-stage ./helm/orchard \
|
||||||
|
--namespace $NAMESPACE \
|
||||||
|
-f $VALUES_FILE \
|
||||||
|
--set image.tag=git.linux-amd64-$CI_COMMIT_SHA \
|
||||||
|
--wait \
|
||||||
|
--timeout 5m
|
||||||
|
- kubectl rollout status deployment/orchard-stage -n $NAMESPACE --timeout=5m
|
||||||
|
- *verify_deployment
|
||||||
|
environment:
|
||||||
|
name: stage
|
||||||
|
url: https://orchard-stage.common.global.bsf.tools
|
||||||
|
kubernetes:
|
||||||
|
agent: esv/bsf/bsf-integration/orchard/orchard-mvp:orchard-stage
|
||||||
|
rules:
|
||||||
|
- if: '$CI_COMMIT_BRANCH == "main"'
|
||||||
|
when: always
|
||||||
|
|
||||||
|
# Deploy feature branch to dev namespace
|
||||||
|
deploy_feature:
|
||||||
|
<<: *deploy_template
|
||||||
|
variables:
|
||||||
|
NAMESPACE: orch-dev-namespace
|
||||||
|
VALUES_FILE: helm/orchard/values-dev.yaml
|
||||||
|
before_script:
|
||||||
|
- kubectl config use-context esv/bsf/bsf-integration/orchard/orchard-mvp:orchard
|
||||||
|
- *helm_setup
|
||||||
|
script:
|
||||||
|
- echo "Deploying feature branch $CI_COMMIT_REF_SLUG"
|
||||||
|
- cd $CI_PROJECT_DIR
|
||||||
|
- |
|
||||||
|
helm upgrade --install orchard-$CI_COMMIT_REF_SLUG ./helm/orchard \
|
||||||
|
--namespace $NAMESPACE \
|
||||||
|
-f $VALUES_FILE \
|
||||||
|
--set image.tag=git.linux-amd64-$CI_COMMIT_SHA \
|
||||||
|
--set ingress.hosts[0].host=orchard-$CI_COMMIT_REF_SLUG.common.global.bsf.tools \
|
||||||
|
--set ingress.tls[0].hosts[0]=orchard-$CI_COMMIT_REF_SLUG.common.global.bsf.tools \
|
||||||
|
--set ingress.tls[0].secretName=orchard-$CI_COMMIT_REF_SLUG-tls \
|
||||||
|
--set minioIngress.host=minio-$CI_COMMIT_REF_SLUG.common.global.bsf.tools \
|
||||||
|
--set minioIngress.tls.secretName=minio-$CI_COMMIT_REF_SLUG-tls \
|
||||||
|
--wait \
|
||||||
|
--timeout 5m
|
||||||
|
- kubectl rollout status deployment/orchard-$CI_COMMIT_REF_SLUG -n $NAMESPACE --timeout=5m
|
||||||
|
- export BASE_URL="https://orchard-$CI_COMMIT_REF_SLUG.common.global.bsf.tools"
|
||||||
|
- *verify_deployment
|
||||||
environment:
|
environment:
|
||||||
name: review/$CI_COMMIT_REF_SLUG
|
name: review/$CI_COMMIT_REF_SLUG
|
||||||
url: https://orchard-$CI_COMMIT_REF_SLUG.common.global.bsf.tools
|
url: https://orchard-$CI_COMMIT_REF_SLUG.common.global.bsf.tools
|
||||||
@@ -144,8 +165,8 @@ deploy_feature:
|
|||||||
|
|
||||||
# Cleanup feature branch deployment
|
# Cleanup feature branch deployment
|
||||||
cleanup_feature:
|
cleanup_feature:
|
||||||
stage: deploy
|
<<: *deploy_template
|
||||||
image: deps.global.bsf.tools/registry-1.docker.io/alpine/k8s:1.29.12
|
needs: []
|
||||||
variables:
|
variables:
|
||||||
NAMESPACE: orch-dev-namespace
|
NAMESPACE: orch-dev-namespace
|
||||||
before_script:
|
before_script:
|
||||||
|
|||||||
Reference in New Issue
Block a user