- Timestamp:
- 06/23/26 13:23:01 (2 weeks ago)
- Branches:
- master
- Children:
- 52fee06
- Parents:
- c0086c0
- File:
-
- 1 edited
-
.github/workflows/ci-cd.yml (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
.github/workflows/ci-cd.yml
rc0086c0 ra8fe58e 1 name: CI /CD1 name: CI 2 2 3 3 on: 4 4 push: 5 branches: [master ]5 branches: [master, dev] 6 6 pull_request: 7 7 branches: [master] … … 12 12 13 13 jobs: 14 # ── CI: build both images on every push / PR ──────────────────────────────15 14 build: 16 15 name: Build … … 22 21 uses: docker/setup-buildx-action@v3 23 22 24 - name: Build backend image (no push)23 - name: Build backend image 25 24 uses: docker/build-push-action@v5 26 25 with: … … 30 29 cache-to: type=gha,scope=backend,mode=max 31 30 32 - name: Build frontend image (no push)31 - name: Build frontend image 33 32 uses: docker/build-push-action@v5 34 33 with: … … 38 37 cache-to: type=gha,scope=frontend,mode=max 39 38 40 # ── CD part 1: push images to DockerHub (master only) ─────────────────────41 39 push: 42 40 name: Push to DockerHub … … 44 42 needs: build 45 43 if: github.ref == 'refs/heads/master' && github.event_name == 'push' 46 outputs:47 image_tag: ${{ github.sha }}48 44 steps: 49 45 - uses: actions/checkout@v4 … … 79 75 cache-from: type=gha,scope=frontend 80 76 cache-to: type=gha,scope=frontend,mode=max 81 82 # ── CD part 2: deploy to k3s cluster ──────────────────────────────────────83 deploy:84 name: Deploy to Kubernetes85 runs-on: ubuntu-latest86 needs: push87 steps:88 - uses: actions/checkout@v489 90 - name: Set up kubectl91 uses: azure/setup-kubectl@v392 with:93 version: latest94 95 - name: Configure kubeconfig96 run: |97 echo "${{ secrets.KUBECONFIG_B64 }}" | base64 -d > $HOME/kubeconfig.yaml98 chmod 600 $HOME/kubeconfig.yaml99 echo "KUBECONFIG=$HOME/kubeconfig.yaml" >> $GITHUB_ENV100 101 - name: Apply namespace102 run: kubectl apply -f k8s/namespace.yaml103 104 - name: Create / update app secrets105 run: |106 kubectl create secret generic trekr-secrets \107 --namespace=trekr \108 --from-literal=db-password=${{ secrets.DB_PASSWORD }} \109 --from-literal=jwt-secret=${{ secrets.JWT_SECRET }} \110 --save-config \111 --dry-run=client -o yaml | kubectl apply -f -112 113 - name: Create DB init ConfigMap from DDL114 run: |115 kubectl create configmap trekr-db-init \116 --namespace=trekr \117 --from-file=01-ddl.sql=db-scripts/ddl.sql \118 --save-config \119 --dry-run=client -o yaml | kubectl apply -f -120 121 - name: Apply Postgres manifests122 run: kubectl apply -f k8s/postgres.yaml123 124 - name: Wait for Postgres to be ready125 run: kubectl rollout status statefulset/postgres -n trekr --timeout=120s126 127 - name: Apply backend manifests128 run: kubectl apply -f k8s/backend.yaml129 130 - name: Apply frontend manifests131 run: kubectl apply -f k8s/frontend.yaml132 133 - name: Roll out new images134 run: |135 kubectl set image deployment/backend \136 backend=${{ env.BACKEND_IMAGE }}:${{ github.sha }} \137 -n trekr138 kubectl set image deployment/frontend \139 frontend=${{ env.FRONTEND_IMAGE }}:${{ github.sha }} \140 -n trekr141 142 - name: Wait for rollout to complete143 run: |144 kubectl rollout status deployment/backend -n trekr --timeout=180s145 kubectl rollout status deployment/frontend -n trekr --timeout=60s146 147 - name: Print app URL148 run: |149 NODE_IP=$(kubectl get nodes -o jsonpath='{.items[0].status.addresses[?(@.type=="ExternalIP")].address}' 2>/dev/null || \150 kubectl get nodes -o jsonpath='{.items[0].status.addresses[0].address}')151 echo "App available at: http://${NODE_IP}:30080"
Note:
See TracChangeset
for help on using the changeset viewer.
