CD Frontend #8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CD Frontend | |
| on: | |
| workflow_run: | |
| workflows: | |
| - CI Frontend | |
| types: | |
| - completed | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: cd-frontend-master | |
| cancel-in-progress: false | |
| jobs: | |
| frontend-cd: | |
| if: > | |
| github.event.workflow_run.conclusion == 'success' && | |
| github.event.workflow_run.event == 'push' && | |
| github.event.workflow_run.head_branch == 'master' | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 30 | |
| env: | |
| KUBE_NAMESPACE: trafiq | |
| IMAGE_NAME: mohamedkhalil26/trafiq-frontend | |
| RELEASE_SHA: ${{ github.event.workflow_run.head_sha }} | |
| steps: | |
| - name: Checkout repository at the promoted commit | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.workflow_run.head_sha }} | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Authenticate to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: mohamedkhalil26 | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build and push frontend image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: frontend | |
| file: frontend/Dockerfile | |
| push: true | |
| tags: | | |
| docker.io/${{ env.IMAGE_NAME }}:${{ env.RELEASE_SHA }} | |
| docker.io/${{ env.IMAGE_NAME }}:latest | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Install kubectl | |
| uses: azure/setup-kubectl@v4 | |
| with: | |
| version: v1.29.4 | |
| - name: Write kubeconfig from GitHub secret | |
| env: | |
| KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA }} | |
| run: | | |
| echo "$KUBE_CONFIG_DATA" | base64 --decode > "$RUNNER_TEMP/kubeconfig" | |
| chmod 600 "$RUNNER_TEMP/kubeconfig" | |
| - name: Deploy frontend to Kubernetes | |
| env: | |
| KUBECONFIG: ${{ runner.temp }}/kubeconfig | |
| FRONTEND_IMAGE: docker.io/${{ env.IMAGE_NAME }}:${{ env.RELEASE_SHA }} | |
| DOCKERHUB_USERNAME: mohamedkhalil26 | |
| DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} | |
| DOCKERHUB_EMAIL: ${{ vars.DOCKERHUB_EMAIL || 'devops@example.com' }} | |
| WORKFLOW_RUN_ID: ${{ github.event.workflow_run.id }} | |
| run: | | |
| kubectl create namespace "$KUBE_NAMESPACE" --dry-run=client -o yaml | kubectl apply -f - | |
| kubectl apply -f k8s/configmap.yaml | |
| kubectl create secret docker-registry dockerhub-registry \ | |
| --namespace "$KUBE_NAMESPACE" \ | |
| --docker-server="https://index.docker.io/v1/" \ | |
| --docker-username="$DOCKERHUB_USERNAME" \ | |
| --docker-password="$DOCKERHUB_TOKEN" \ | |
| --docker-email="$DOCKERHUB_EMAIL" \ | |
| --dry-run=client -o yaml | kubectl apply -f - | |
| kubectl apply -f k8s/frontend-deployment.yaml | |
| kubectl apply -f k8s/ingress.yaml | |
| kubectl set image deployment/trafiq-frontend frontend="$FRONTEND_IMAGE" -n "$KUBE_NAMESPACE" | |
| kubectl annotate deployment/trafiq-frontend \ | |
| -n "$KUBE_NAMESPACE" \ | |
| ci.github.com/run-id="$WORKFLOW_RUN_ID" \ | |
| ci.github.com/sha="$RELEASE_SHA" \ | |
| --overwrite | |
| kubectl rollout status deployment/trafiq-frontend -n "$KUBE_NAMESPACE" --timeout=180s |