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
|
||||
|
||||
# Run Python tests
|
||||
# Run Python backend tests
|
||||
python_tests:
|
||||
stage: test
|
||||
image: deps.global.bsf.tools/docker/python:3.12-slim
|
||||
@@ -26,72 +26,34 @@ python_tests:
|
||||
- cd backend
|
||||
- python -m pytest -v
|
||||
|
||||
# Deploy to stage (main branch)
|
||||
deploy_stage:
|
||||
stage: deploy
|
||||
needs: [build_image]
|
||||
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
|
||||
# Run frontend tests
|
||||
frontend_tests:
|
||||
stage: test
|
||||
image: deps.global.bsf.tools/docker/node:20-alpine
|
||||
before_script:
|
||||
- kubectl config use-context esv/bsf/bsf-integration/orchard/orchard-mvp:orchard-stage
|
||||
- helm version
|
||||
- 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
|
||||
- cd frontend
|
||||
- npm ci
|
||||
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
|
||||
environment:
|
||||
name: stage
|
||||
url: https://orchard-stage.common.global.bsf.tools
|
||||
kubernetes:
|
||||
agent: esv/bsf/bsf-integration/orchard/orchard-mvp:orchard-stage
|
||||
- npm run test -- --run
|
||||
rules:
|
||||
- if: '$CI_COMMIT_BRANCH == "main"'
|
||||
when: always
|
||||
- exists:
|
||||
- frontend/package.json
|
||||
|
||||
# Deploy feature branch to dev namespace
|
||||
deploy_feature:
|
||||
# Shared deploy configuration
|
||||
.deploy_template: &deploy_template
|
||||
stage: deploy
|
||||
needs: [build_image]
|
||||
image: deps.global.bsf.tools/registry-1.docker.io/alpine/k8s:1.29.12
|
||||
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: &helm_setup
|
||||
- helm version
|
||||
- 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:
|
||||
- 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) ==="
|
||||
for i in $(seq 1 30); do
|
||||
if curl -sf --max-time 10 "$BASE_URL/health" > /dev/null 2>&1; then
|
||||
@@ -132,6 +94,65 @@ deploy_feature:
|
||||
echo ""
|
||||
echo "=== All checks passed! ==="
|
||||
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:
|
||||
name: review/$CI_COMMIT_REF_SLUG
|
||||
url: https://orchard-$CI_COMMIT_REF_SLUG.common.global.bsf.tools
|
||||
@@ -144,8 +165,8 @@ deploy_feature:
|
||||
|
||||
# Cleanup feature branch deployment
|
||||
cleanup_feature:
|
||||
stage: deploy
|
||||
image: deps.global.bsf.tools/registry-1.docker.io/alpine/k8s:1.29.12
|
||||
<<: *deploy_template
|
||||
needs: []
|
||||
variables:
|
||||
NAMESPACE: orch-dev-namespace
|
||||
before_script:
|
||||
|
||||
Reference in New Issue
Block a user