CICD workflow working, cleanup index.jade #13
This file contains 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: cicd | |
on: | |
push: | |
branches: [ main ] | |
workflow_dispatch: | |
env: | |
GCP_CLUSTER_NAME: website-cluster | |
GCP_PROJECT_ID: personal-website-421100 | |
GCP_REGION: us-east1-d | |
DOCKER_TAG: ${{ github.sha }} | |
IMAGE_NAME: personal-site | |
jobs: | |
check-changed-files: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
- name: Get changed files for the site | |
id: changed-site-files | |
uses: tj-actions/changed-files@v41 | |
with: | |
files: | | |
app.js | |
routes/** | |
views/** | |
public/** | |
Dockerfile | |
- name: Get changed infrastructure files | |
id: changed-infra-files | |
uses: tj-actions/changed-files@v41 | |
with: | |
files: | | |
src/main/helm/** | |
outputs: | |
site-changed: ${{ steps.changed-site-files.outputs.any_changed }} | |
infra-changed: ${{ steps.changed-site-files.outputs.any_changed }} | |
build-push-image: | |
runs-on: ubuntu-latest | |
needs: check-changed-files | |
if: | | |
needs.check-changed-files.outputs.site-changed == 'true' | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Build docker image | |
run: | | |
docker build -t gcr.io/${{ env.GCP_PROJECT_ID }}/${{ env.IMAGE_NAME }}:${{ env.DOCKER_TAG }} -f Dockerfile . | |
- name: Authenticate to Google Cloud | |
uses: google-github-actions/auth@v2 | |
with: | |
credentials_json: ${{ secrets.GCP_SA_KEY }} | |
- name: Setup GCloud CLI | |
uses: google-github-actions/setup-gcloud@v2 | |
with: | |
version: '>= 363.0.0' | |
project_id: ${{ env.GCP_PROJECT_ID }} | |
- name: Configure Docker with GCloud CLI | |
run: | | |
gcloud auth configure-docker --quiet | |
- name: Push docker image to GCR | |
run: | | |
docker push gcr.io/${{ env.GCP_PROJECT_ID }}/${{ env.IMAGE_NAME }}:${{ env.DOCKER_TAG }} | |
deploy-service-to-gcp: | |
runs-on: ubuntu-latest | |
needs: | |
- check-changed-files | |
- build-push-image | |
if: | | |
always() && | |
(needs.build-push-image.result == 'success' && needs.check-changed-files.outputs.site-changed == 'true') || | |
(needs.build-push-image.result == 'skipped' && needs.check-changed-files.outputs.infra-changed == 'true') | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Update deployment | |
if: needs.check-changed-files.outputs.site-changed == 'true' | |
run: | | |
sed -i 's|image:.*|image: gcr.io/${{ env.GCP_PROJECT_ID }}/${{ env.IMAGE_NAME }}:${{ env.DOCKER_TAG }}|' src/main/helm/templates/deployment.yaml | |
- name: Authenticate to Google Cloud | |
uses: google-github-actions/auth@v2 | |
with: | |
credentials_json: ${{ secrets.GCP_SA_KEY }} | |
- name: Get GKE Credentials | |
uses: google-github-actions/get-gke-credentials@v2 | |
with: | |
cluster_name: ${{ env.GCP_CLUSTER_NAME }} | |
location: ${{ env.GCP_REGION }} | |
- name: Deploy the new site to the cluster with helm | |
if: | | |
needs.check-changed-files.outputs.site-changed == 'true' || | |
(needs.build-push-image.result == 'skipped' && needs.check-changed-files.outputs.infra-changed == 'true') | |
run: | | |
helm upgrade --install website src/main/helm --set image.tag=${{ env.DOCKER_TAG }} | |