|
| 1 | +name: K8s Manifests CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + paths: |
| 6 | + - 'k8s/**' |
| 7 | + pull_request: |
| 8 | + paths: |
| 9 | + - 'k8s/**' |
| 10 | + |
| 11 | +jobs: |
| 12 | + validate-manifests: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@v4 |
| 16 | + |
| 17 | + - name: Install kubeconform |
| 18 | + run: | |
| 19 | + curl -sSL https://github.com/yannh/kubeconform/releases/latest/download/kubeconform-linux-amd64.tar.gz | tar xz |
| 20 | + sudo mv kubeconform /usr/local/bin/ |
| 21 | +
|
| 22 | + - name: Validate K8s manifests (base) |
| 23 | + run: | |
| 24 | + kubeconform -summary -strict -kubernetes-version 1.28.0 -ignore-filename-pattern 'kustomization.yaml' k8s/base/*.yaml |
| 25 | +
|
| 26 | + - name: Install kubectl |
| 27 | + uses: azure/setup-kubectl@v3 |
| 28 | + |
| 29 | + - name: Kustomize build (template-app overlay) |
| 30 | + run: | |
| 31 | + kubectl kustomize k8s/overlays/template-app/ > /dev/null |
| 32 | + echo "Kustomize build succeeded for template-app" |
| 33 | +
|
| 34 | + - name: Validate kustomized output |
| 35 | + run: | |
| 36 | + kubectl kustomize k8s/overlays/template-app/ | kubeconform -summary -strict -kubernetes-version 1.28.0 |
| 37 | +
|
| 38 | + integration-test: |
| 39 | + runs-on: ubuntu-latest |
| 40 | + needs: validate-manifests |
| 41 | + strategy: |
| 42 | + fail-fast: false |
| 43 | + matrix: |
| 44 | + dockerfile: |
| 45 | + - Dockerfile_simple |
| 46 | + - Dockerfile |
| 47 | + steps: |
| 48 | + - uses: actions/checkout@v4 |
| 49 | + |
| 50 | + - name: Check if Dockerfile exists |
| 51 | + id: check |
| 52 | + run: | |
| 53 | + if [ -f "${{ matrix.dockerfile }}" ]; then |
| 54 | + echo "exists=true" >> "$GITHUB_OUTPUT" |
| 55 | + echo "Found ${{ matrix.dockerfile }}, will run integration test" |
| 56 | + else |
| 57 | + echo "exists=false" >> "$GITHUB_OUTPUT" |
| 58 | + echo "Skipping: ${{ matrix.dockerfile }} not found" |
| 59 | + fi |
| 60 | +
|
| 61 | + - name: Build Docker image from current code |
| 62 | + if: steps.check.outputs.exists == 'true' |
| 63 | + run: | |
| 64 | + docker build -t openms-streamlit:test -f ${{ matrix.dockerfile }} . |
| 65 | +
|
| 66 | + - name: Create kind cluster |
| 67 | + if: steps.check.outputs.exists == 'true' |
| 68 | + uses: helm/kind-action@v1 |
| 69 | + with: |
| 70 | + cluster_name: test-cluster |
| 71 | + |
| 72 | + - name: Load image into kind cluster |
| 73 | + if: steps.check.outputs.exists == 'true' |
| 74 | + run: | |
| 75 | + kind load docker-image openms-streamlit:test --name test-cluster |
| 76 | +
|
| 77 | + - name: Install nginx ingress controller |
| 78 | + if: steps.check.outputs.exists == 'true' |
| 79 | + run: | |
| 80 | + kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml |
| 81 | + kubectl wait --namespace ingress-nginx --for=condition=ready pod --selector=app.kubernetes.io/component=controller --timeout=90s |
| 82 | +
|
| 83 | + - name: Deploy with Kustomize |
| 84 | + if: steps.check.outputs.exists == 'true' |
| 85 | + run: | |
| 86 | + kubectl kustomize k8s/overlays/template-app/ | \ |
| 87 | + sed 's|imagePullPolicy: IfNotPresent|imagePullPolicy: Never|g' > /tmp/manifests.yaml |
| 88 | + for i in 1 2 3 4 5; do |
| 89 | + if kubectl apply -f /tmp/manifests.yaml; then |
| 90 | + echo "Deploy succeeded on attempt $i" |
| 91 | + break |
| 92 | + fi |
| 93 | + echo "Attempt $i failed, retrying in ${i}0s..." |
| 94 | + sleep "${i}0" |
| 95 | + done |
| 96 | +
|
| 97 | + - name: Wait for Redis to be ready |
| 98 | + if: steps.check.outputs.exists == 'true' |
| 99 | + run: | |
| 100 | + kubectl wait -n openms --for=condition=ready pod -l app=template-app,component=redis --timeout=60s |
| 101 | +
|
| 102 | + - name: Verify Redis Service is reachable |
| 103 | + if: steps.check.outputs.exists == 'true' |
| 104 | + run: | |
| 105 | + kubectl run redis-test -n openms --image=redis:7-alpine --rm -i --restart=Never -- redis-cli -h template-app-redis.openms.svc.cluster.local ping |
| 106 | +
|
| 107 | + - name: Verify all deployments are available |
| 108 | + if: steps.check.outputs.exists == 'true' |
| 109 | + run: | |
| 110 | + kubectl wait -n openms --for=condition=available deployment -l app=template-app --timeout=120s || true |
| 111 | + kubectl get pods -n openms -l app=template-app |
| 112 | + kubectl get services -n openms -l app=template-app |
0 commit comments