|
| 1 | +# .github/workflows/cd-deploy.yml |
| 2 | +name: CD – Build, Push & Deploy |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: [ listOfMed ] |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + packages: write |
| 11 | + |
| 12 | +env: |
| 13 | + IMAGE_REG: ghcr.io/${{ github.repository_owner }} |
| 14 | + |
| 15 | +jobs: |
| 16 | + build: |
| 17 | + name: Build & Push Production Images |
| 18 | + runs-on: ubuntu-latest |
| 19 | + outputs: |
| 20 | + tag: ${{ steps.set-vars.outputs.TAG }} |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v3 |
| 23 | + |
| 24 | + - name: Set version tag |
| 25 | + id: set-vars |
| 26 | + run: | |
| 27 | + # e.g. v1.2.3 or commit SHA fallback |
| 28 | + if [[ "${GITHUB_REF##*/}" =~ ^v[0-9] ]]; then |
| 29 | + echo "TAG=${GITHUB_REF##*/}" >> $GITHUB_OUTPUT |
| 30 | + else |
| 31 | + echo "TAG=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT |
| 32 | + fi |
| 33 | +
|
| 34 | + - name: Login to registry |
| 35 | + uses: docker/login-action@v2 |
| 36 | + with: |
| 37 | + registry: ghcr.io |
| 38 | + username: ${{ github.repository_owner }} |
| 39 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 40 | + |
| 41 | + - name: Build & push backend |
| 42 | + uses: docker/build-push-action@v3 |
| 43 | + with: |
| 44 | + context: server |
| 45 | + file: server/Dockerfile.prod |
| 46 | + push: true |
| 47 | + tags: | |
| 48 | + ${{ env.IMAGE_REG }}/balancer-backend:${{ needs.build.outputs.tag }} |
| 49 | + ${{ env.IMAGE_REG }}/balancer-backend:latest |
| 50 | +
|
| 51 | + - name: Build & push frontend |
| 52 | + uses: docker/build-push-action@v3 |
| 53 | + with: |
| 54 | + context: frontend |
| 55 | + file: frontend/Dockerfile |
| 56 | + push: true |
| 57 | + tags: | |
| 58 | + ${{ env.IMAGE_REG }}/balancer-frontend:${{ needs.build.outputs.tag }} |
| 59 | + ${{ env.IMAGE_REG }}/balancer-frontend:latest |
| 60 | +
|
| 61 | + # deploy: |
| 62 | + # name: Deploy to Kubernetes |
| 63 | + # needs: build |
| 64 | + # runs-on: ubuntu-latest |
| 65 | + # steps: |
| 66 | + # - uses: actions/checkout@v3 |
| 67 | + |
| 68 | + # - name: Set up kubectl |
| 69 | + # # or use azure/setup-kubectl, google-github-actions/setup-gcloud, etc. |
| 70 | + # uses: azure/setup-kubectl@v3 |
| 71 | + # with: |
| 72 | + # version: 'latest' |
| 73 | + # # supply your kubeconfig via a secret |
| 74 | + # kubeconfig: ${{ secrets.KUBE_CONFIG_DATA }} |
| 75 | + |
| 76 | + # - name: Update Helm chart values |
| 77 | + # run: | |
| 78 | + # helm upgrade --install balancer ./charts/balancer \ |
| 79 | + # --namespace production \ |
| 80 | + # --create-namespace \ |
| 81 | + # --set backend.image.tag=${{ needs.build.outputs.tag }} \ |
| 82 | + # --set frontend.image.tag=${{ needs.build.outputs.tag }} |
0 commit comments