Skip to content

trigger front end

trigger front end #3

name: Deploy Next JS Front-End changes
on:
push:
branches:
- main
paths:
- 'frontend-web/**'
env:
IMAGE: charlyjazz/frontend-web
K8_DIR: frontend-web/k8s
jobs:
setup-build-publish-deploy:
name: Setup, Build, Publish, and Deploy
runs-on: ubuntu-latest
permissions:
contents: 'read'
id-token: 'write'
steps:
- name: Check out the repo
uses: actions/checkout@v4
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v2'
with:
credentials_json: '${{ secrets.GOOGLE_CREDENTIALS }}'
- name: 'Use gcloud CLI'
run: 'gcloud info'
- name: setup-gke-gcloud-auth-plugin
uses: simenandre/setup-gke-gcloud-auth-plugin@v1.1.2
- uses: google-github-actions/get-gke-credentials@v1
with:
cluster_name: ${{ secrets.GKE_CLUSTER }}
location: ${{ secrets.GKE_ZONE }}
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: frontend-web/
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Update Deployment Image
run: |
sed -i 's|${{ env.IMAGE }}:latest|${{ env.IMAGE }}:${{github.ref_name}}|' ${{env.K8_DIR}}/front-end-next-js-deployment.yaml
- name: Deploy to GKE
run: |
echo "Apply the deployment and capture the output"
DEPLOYMENT_OUTPUT=$(kubectl apply -f ${{env.K8_DIR}}/front-end-next-js-deployment.yaml)
echo "Check if the output contains 'unchanged'"
if echo "$DEPLOYMENT_OUTPUT" | grep -q 'unchanged'; then
echo "Deployment unchanged. Restarting to pick up possible new Docker image..."
kubectl rollout restart frontend-web-deployment
fi
kubectl apply -f ${{env.K8_DIR}}/front-end-next-js-service.yaml