1- name : nmrium CI/CD
1+ name : Build and Deploy
22
33on :
44 push :
5- branches : [development]
5+ branches : [development,main ]
66
77env :
88 PROJECT_ID : ${{ secrets.GKE_PROJECT }}
9- GKE_CLUSTER : nmrxiv-dev
9+ GKE_CLUSTER_DEV : nmrxiv-dev
10+ GKE_CLUSTER_PROD : nmrxiv-prod
1011 GKE_ZONE : europe-west3-a
1112 DEPLOYMENT_NAME : nmrxiv-nmrium
12- REPOSITORY_NAME : nmrxiv-dev
13+ REPOSITORY_NAME_DEV : nmrxiv-dev
14+ REPOSITORY_NAME_PROD : nmrxiv-prod
1315 IMAGE : nmrium
1416
1517jobs :
2931 - name : Check types
3032 run : npm run check-types
3133
32- setup-build-publish-deploy :
33- name : Setup, Build, Publish, and Deploy
34+ setup-build-publish-deploy-dev :
35+ name : deploy to dev
3436 if : github.ref == 'refs/heads/development'
3537 runs-on : ubuntu-latest
3638 needs : lint
@@ -50,18 +52,59 @@ jobs:
5052 # Get the GKE credentials so we can deploy to the cluster
5153 - uses : google-github-actions/get-gke-credentials@v0.3.0
5254 with :
53- cluster_name : ${{ env.GKE_CLUSTER }}
55+ cluster_name : ${{ env.GKE_CLUSTER_DEV }}
5456 location : ${{ env.GKE_ZONE }}
5557 credentials : ${{ secrets.GKE_SA_KEY }}
5658
5759 # Build the Docker image
5860 - name : Build Image
5961 run : |-
60- docker build -f Dockerfile.prod --tag europe-west3-docker.pkg.dev/$PROJECT_ID/$REPOSITORY_NAME /$IMAGE:latest .
62+ docker build -f Dockerfile.prod --tag europe-west3-docker.pkg.dev/$PROJECT_ID/$REPOSITORY_NAME_DEV /$IMAGE:latest .
6163 # Push the Docker image to Google Artifact Registry
6264 - name : Publish Image to Google Artifact Registry
6365 run : |-
64- docker push "europe-west3-docker.pkg.dev/$PROJECT_ID/$REPOSITORY_NAME/$IMAGE:latest"
66+ docker push "europe-west3-docker.pkg.dev/$PROJECT_ID/$REPOSITORY_NAME_DEV/$IMAGE:latest"
67+
68+ # Deploy the latest Docker image to the GKE cluster
69+ - name : Deploy
70+ run : |-
71+ kubectl rollout restart deployment/$DEPLOYMENT_NAME
72+ kubectl rollout status deployment/$DEPLOYMENT_NAME --timeout=300s
73+ kubectl get services -o wide
74+
75+ setup-build-publish-deploy-prod :
76+ name : deploy to prod
77+ if : github.ref == 'refs/heads/main'
78+ runs-on : ubuntu-latest
79+ needs : lint
80+ steps :
81+ - name : Checkout
82+ uses : actions/checkout@v2
83+
84+ # Setup gcloud CLI
85+ - uses : google-github-actions/setup-gcloud@94337306dda8180d967a56932ceb4ddcf01edae7
86+ with :
87+ service_account_key : ${{ secrets.GKE_SA_KEY }}
88+ project_id : ${{ secrets.GKE_PROJECT }}
89+
90+ # Configure docker to use the gcloud command-line tool as a credential helper
91+ - run : |-
92+ gcloud auth configure-docker europe-west3-docker.pkg.dev
93+ # Get the GKE credentials so we can deploy to the cluster
94+ - uses : google-github-actions/get-gke-credentials@v0.3.0
95+ with :
96+ cluster_name : ${{ env.GKE_CLUSTER_PROD }}
97+ location : ${{ env.GKE_ZONE }}
98+ credentials : ${{ secrets.GKE_SA_KEY }}
99+
100+ # Build the Docker image
101+ - name : Build Image
102+ run : |-
103+ docker build -f Dockerfile.prod --tag europe-west3-docker.pkg.dev/$PROJECT_ID/$REPOSITORY_NAME_PROD/$IMAGE:latest .
104+ # Push the Docker image to Google Artifact Registry
105+ - name : Publish Image to Google Artifact Registry
106+ run : |-
107+ docker push "europe-west3-docker.pkg.dev/$PROJECT_ID/$REPOSITORY_NAME_PROD/$IMAGE:latest"
65108
66109 # Deploy the latest Docker image to the GKE cluster
67110 - name : Deploy
0 commit comments