|
| 1 | +name: Build & Deploy Dev |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches-ignore: [release] |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +env: |
| 9 | + REGISTRY: ghcr.io |
| 10 | + |
| 11 | +jobs: |
| 12 | + build-and-push: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + permissions: |
| 15 | + contents: read |
| 16 | + packages: write |
| 17 | + |
| 18 | + strategy: |
| 19 | + matrix: |
| 20 | + include: |
| 21 | + - service: user-service |
| 22 | + context: ./services/user-service |
| 23 | + - service: admin-service |
| 24 | + context: ./services/admin-service |
| 25 | + - service: checklist-service |
| 26 | + context: ./services/checklist-service |
| 27 | + - service: calendar-service |
| 28 | + context: ./services/calendar-service |
| 29 | + - service: note-service |
| 30 | + context: ./services/note-service |
| 31 | + - service: genai-service |
| 32 | + context: ./services/genai-service |
| 33 | + - service: client |
| 34 | + context: ./web-client |
| 35 | + build_args: | |
| 36 | + VITE_API_URL=/dev/api |
| 37 | + VITE_BASE_PATH=/dev |
| 38 | +
|
| 39 | + steps: |
| 40 | + - name: Checkout |
| 41 | + uses: actions/checkout@v4 |
| 42 | + |
| 43 | + - name: Log in to Container Registry |
| 44 | + uses: docker/login-action@v3 |
| 45 | + with: |
| 46 | + registry: ${{ env.REGISTRY }} |
| 47 | + username: ${{ github.actor }} |
| 48 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 49 | + |
| 50 | + - name: Set up Docker Buildx |
| 51 | + uses: docker/setup-buildx-action@v3 |
| 52 | + |
| 53 | + - name: Build & push ${{ matrix.service }} |
| 54 | + uses: docker/build-push-action@v6 |
| 55 | + with: |
| 56 | + context: ${{ matrix.context }} |
| 57 | + push: true |
| 58 | + tags: | |
| 59 | + ${{ env.REGISTRY }}/aet-devops26/team-devopss26/${{ matrix.service }}:latest |
| 60 | + ${{ env.REGISTRY }}/aet-devops26/team-devopss26/${{ matrix.service }}:${{ github.sha }} |
| 61 | + build-args: ${{ matrix.build_args }} |
| 62 | + |
| 63 | + deploy-to-k8s: |
| 64 | + needs: build-and-push |
| 65 | + runs-on: ubuntu-latest |
| 66 | + steps: |
| 67 | + - name: Checkout |
| 68 | + uses: actions/checkout@v4 |
| 69 | + |
| 70 | + - name: Set up kubectl |
| 71 | + uses: azure/setup-kubectl@v3 |
| 72 | + |
| 73 | + - name: Set up Helm |
| 74 | + uses: azure/setup-helm@v4 |
| 75 | + |
| 76 | + - name: Configure kubectl |
| 77 | + run: | |
| 78 | + mkdir -p $HOME/.kube |
| 79 | + echo "${{ secrets.KUBECONFIG }}" | base64 -d > $HOME/.kube/config |
| 80 | + kubectl auth can-i get namespaces 2>&1 || true |
| 81 | +
|
| 82 | + - name: Deploy with Helm |
| 83 | + run: | |
| 84 | + helm upgrade --install devopss26-dev ./infra/iac/aet \ |
| 85 | + --namespace team-devopss26-dev \ |
| 86 | + --set global.imageTag=${{ github.sha }} \ |
| 87 | + --set genaiService.geminiApiKey=${{ secrets.GEMINI_API_KEY }} \ |
| 88 | + -f infra/iac/aet/values-dev.yaml \ |
| 89 | + --timeout 5m |
| 90 | +
|
| 91 | + - name: Wait for rollout |
| 92 | + run: | |
| 93 | + for deploy in admin-service calendar-service checklist-service note-service user-service genai-service client; do |
| 94 | + echo "Waiting for $deploy..." |
| 95 | + kubectl rollout status deployment/$deploy -n team-devopss26-dev --timeout=5m |
| 96 | + done |
| 97 | + echo "Waiting for postgres..." |
| 98 | + kubectl rollout status statefulset/postgres -n team-devopss26-dev --timeout=5m |
| 99 | + echo "All deployments rolled out!" |
| 100 | +
|
| 101 | + - name: Verify deployment |
| 102 | + run: | |
| 103 | + TAG="${{ github.sha }}" |
| 104 | + echo "Checking pods are running image tag: $TAG" |
| 105 | + kubectl get pods -n team-devopss26-dev -o wide |
| 106 | + echo "" |
| 107 | + MISMATCH=0 |
| 108 | + for pod in $(kubectl get pods -n team-devopss26-dev --no-headers -o name); do |
| 109 | + IMAGES=$(kubectl get -n team-devopss26-dev "$pod" -o jsonpath='{range .spec.containers[*]}{.image}{"\n"}{end}') |
| 110 | + while IFS= read -r img; do |
| 111 | + case "$img" in |
| 112 | + *postgres*) ;; |
| 113 | + *:$TAG) ;; |
| 114 | + *) |
| 115 | + echo "::warning::$pod has wrong image: $img (expected tag: $TAG)" |
| 116 | + MISMATCH=$((MISMATCH + 1)) |
| 117 | + ;; |
| 118 | + esac |
| 119 | + done <<< "$IMAGES" |
| 120 | + done |
| 121 | + if [ "$MISMATCH" -gt 0 ]; then |
| 122 | + echo "::error::$MISMATCH pods have wrong image tag" |
| 123 | + exit 1 |
| 124 | + fi |
| 125 | + echo "All pods running expected images!" |
0 commit comments