Update prod-build.yml #33
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
# This worklflow will perform following actions when a release is published: | |
# - Fetch Latest release. | |
# - Build the latest docker image in production. | |
# - Build release and commit to repo. | |
# - Push the docker image to Github Artifact Registry-Prod. | |
# - Rollout latest docker image to GKE. | |
# | |
# Maintainers: | |
# - name: Nisha Sharma | |
# - email: [email protected] | |
name : Build and Deploy to Prod | |
on: | |
push: | |
branches: [prod-helm-deploy] | |
env: | |
PROJECT_ID: ${{ secrets.GKE_PROJECT }} | |
GKE_CLUSTER_PROD: nmrxiv-prod | |
GKE_ZONE: europe-west3-a | |
DEPLOYMENT_NAME: nmrxiv-nmrium | |
DOCKER_HUB_USERNAME : ${{ secrets.DOCKER_HUB_USERNAME }} | |
DOCKER_HUB_PASSWORD : ${{ secrets.DOCKER_HUB_PASSWORD }} | |
REPOSITORY_NAME: nmrium-react-wrapper | |
REPOSITORY_NAMESPACE: nfdi4chem | |
jobs: | |
setup-build-publish-deploy-prod: | |
name: Deploy to prod | |
if: github.ref == 'refs/heads/prod-helm-deploy' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/[email protected] | |
# Setup gcloud CLI | |
- name: Setup CLI | |
uses: google-github-actions/setup-gcloud@94337306dda8180d967a56932ceb4ddcf01edae7 | |
with: | |
service_account_key: ${{ secrets.GKE_SA_KEY }} | |
project_id: ${{ secrets.GKE_PROJECT }} | |
# Login to Docker Hub | |
- name: Log in to Docker Hub | |
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a | |
with: | |
username: ${{ env.DOCKER_HUB_USERNAME }} | |
password: ${{ env.DOCKER_HUB_PASSWORD }} | |
# Get the GKE credentials so we can deploy to the cluster | |
- name: Get GKE credentials | |
uses: google-github-actions/[email protected] | |
with: | |
cluster_name: ${{ env.GKE_CLUSTER_PROD }} | |
location: ${{ env.GKE_ZONE }} | |
credentials: ${{ secrets.GKE_SA_KEY }} | |
#Fetch latest release | |
- name: Fetch latest release | |
id: fetch-latest-release | |
uses: InsonusK/[email protected] | |
with: | |
myToken: ${{ github.token }} | |
exclude_types: "draft|prerelease" | |
view_top: 10 | |
- name: "Print release name" | |
run: | | |
echo "tag_name: ${{ steps.fetch-latest-release.outputs.tag_name }}" | |
#Build and push Docker image to Docker Hub | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
file: ./Dockerfile.prod | |
push: true | |
build-args: | | |
RELEASE_VERSION=${{ steps.fetch-latest-release.outputs.tag_name }} | |
tags: ${{ env.REPOSITORY_NAMESPACE }}/${{ env.REPOSITORY_NAME }}:${{ steps.fetch-latest-release.outputs.tag_name }}, ${{ env.REPOSITORY_NAMESPACE }}/${{ env.REPOSITORY_NAME }}:latest | |
username: ${{ env.DOCKER_HUB_USERNAME }} | |
password: ${{ env.DOCKER_HUB_PASSWORD }} | |
# Build npm for release | |
- name: Build npm | |
run: |- | |
npm install | |
npm run build -- --outDir=build | |
npm run build -- --outDir=releases/${{ steps.fetch-latest-release.outputs.tag_name }} | |
# Commit | |
- name: Commit to repo | |
uses: EndBug/[email protected] | |
with: | |
default_author: github_actions | |
# Deploy the latest Docker image to the GKE cluster | |
- name: Deploy | |
if: ${{ steps.fetch-latest-release.outputs.tag_name }} | |
run: |- | |
kubectl rollout restart deployment/$DEPLOYMENT_NAME | |
kubectl rollout status deployment/$DEPLOYMENT_NAME --timeout=300s | |
kubectl get services -o wide |