NMUI SaaS Deployment #32
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: NMUI SaaS Deployment | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'Version to deploy' | |
required: true | |
type: choice | |
options: | |
- 'v0.24.1' | |
- 'v0.24.2' | |
- 'v0.24.3' | |
- 'v0.25.0' | |
- 'v0.26.0' | |
environment: | |
description: 'Environment to deploy to' | |
required: true | |
type: choice | |
options: | |
- 'dev' | |
- 'staging' | |
- 'prod' | |
jobs: | |
build-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: 'Checkout to release-${{ github.event.inputs.version }}' | |
uses: actions/checkout@v4 | |
with: | |
ref: release-${{ github.event.inputs.version }} | |
- name: Set release tag | |
run: | | |
TAG="$(git rev-parse --short HEAD)" | |
echo "TAG=${TAG}" >> $GITHUB_ENV | |
- name: Setup Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and push | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
file: ./Dockerfile.saas | |
platforms: linux/amd64 | |
push: true | |
tags: ${{ github.repository_owner }}/netmaker-ui-saas:${{ env.TAG }} | |
- name: Set environment variables | |
run: | | |
if [ "${{ github.event.inputs.environment }}" == "dev" ]; then | |
echo "CLUSTER_NAME=saas-dev-cluster-europe-1" >> $GITHUB_ENV | |
elif [ "${{ github.event.inputs.environment }}" == "staging" ]; then | |
echo "CLUSTER_NAME=saas-staging-cluster-us-west" >> $GITHUB_ENV | |
elif [ "${{ github.event.inputs.environment }}" == "prod" ]; then | |
echo "CLUSTER_NAME=saas-prod-cluster-us-west" >> $GITHUB_ENV | |
fi | |
VERSION_WITH_DASHES=$(echo "${{ github.event.inputs.version }}" | tr '.' '-') | |
echo "VERSION_WITH_DASHES=netmaker-ui-${VERSION_WITH_DASHES}" >> $GITHUB_ENV | |
- name: Set up kubectl | |
uses: matootie/[email protected] | |
with: | |
personalAccessToken: ${{ secrets.DIGITALOCEAN_TOKEN }} | |
clusterName: ${{ env.CLUSTER_NAME }} | |
- name: Set k8s deployment image | |
run: kubectl set image deployment ${{ env.VERSION_WITH_DASHES }} netmaker-ui=${{ github.repository_owner }}/netmaker-ui-saas:${{ env.TAG }} -n accounts | |
- name: Set Intercom vars | |
run: | | |
if [ "${{ github.event.inputs.environment }}" == "dev" ]; then | |
kubectl set env deployment ${{ env.VERSION_WITH_DASHES }} PUBLIC_POSTHOG_KEY=${{ secrets.REACT_APP_PUBLIC_POSTHOG_DEV_KEY }} -n accounts | |
elif [ "${{ github.event.inputs.environment }}" == "staging" ]; then | |
kubectl set env deployment ${{ env.VERSION_WITH_DASHES }} PUBLIC_POSTHOG_KEY=${{ secrets.REACT_APP_PUBLIC_POSTHOG_DEV_KEY }} -n accounts | |
elif [ "${{ github.event.inputs.environment }}" == "prod" ]; then | |
kubectl set env deployment ${{ env.VERSION_WITH_DASHES }} PUBLIC_POSTHOG_KEY=${{ secrets.REACT_APP_PUBLIC_POSTHOG_KEY }} -n accounts | |
fi | |
kubectl set env deployment ${{ env.VERSION_WITH_DASHES }} INTERCOM_APP_ID=al371us8 -n accounts | |
kubectl set env deployment ${{ env.VERSION_WITH_DASHES }} PUBLIC_POSTHOG_HOST=${{ secrets.REACT_APP_PUBLIC_POSTHOG_HOST }} -n accounts | |
- name: Deploy to k8s cluster | |
run: kubectl rollout restart deploy ${{ env.VERSION_WITH_DASHES }} -n accounts | |
- name: Verify deployment | |
run: kubectl rollout status deployment/${{ env.VERSION_WITH_DASHES }} -n accounts |