Skip to content

Deploy to Dev/Staging #9

Deploy to Dev/Staging

Deploy to Dev/Staging #9

Workflow file for this run

name: Deploy to Dev/Staging
on:
workflow_dispatch:
inputs:
choice:
type: choice
description: Select an Environment
options:
- homer-content-v2
tag:
description: The tag of Squidex to pull
jobs:
build_and_deploy:
name: Deploy
runs-on: ubuntu-latest # Using a linux runner
# Setting environment variables
env:
IMAGE_TAG: ${{ github.event.inputs.tag }}
HELM_PATH: ${{ github.workspace }}/k8s
NAMESPACE: ${{ github.event.inputs.choice }}
steps:
- name: set-env-vars
uses: FranzDiebold/github-env-vars-action@v2
# Checks out the current repository
- name: Check out code
uses: actions/checkout@v2
# Helm is required to generate the manifests
- name: Install Helm
run: |
wget https://get.helm.sh/helm-v3.9.1-linux-amd64.tar.gz
tar xvf helm-v3.9.1-linux-amd64.tar.gz
sudo mv linux-amd64/helm /usr/local/bin
echo "Installed helm"
# Install yq - yaml processor
- name: Install yq
run: |
sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
sudo chmod a+x /usr/local/bin/yq
yq --version
echo "Installed yq"
# Set kubeconfig context for Staging cluster
- name: Staging :- Set Kubeconfig
if: ${{ github.event.inputs.choice != 'devopsTest' }}
uses: azure/k8s-set-context@v2
with:
method: kubeconfig
kubeconfig: ${{ secrets.STAGING_KUBECONFIG }}
# This generates the deployment manifests for specified environment
- name: Generate manifest for '${{ env.APP_ENVIRONMENT }}'
run: |
export DEPLOY_NAME=$(yq e '.name' $HELM_PATH/staging/values.yaml)
export REPLICAS=$(kubectl get deployment $DEPLOY_NAME -n $NAMESPACE -o=jsonpath={.spec.replicas})
[ -z $REPLICAS ] && export REPLICAS=$(yq e '.replicas' $HELM_PATH/values.yaml)
echo "Number of replicas: $REPLICAS"
echo "Namespace: $NAMESPACE"
echo "NAMESPACE=$NAMESPACE" >> $GITHUB_ENV
helm template $HELM_PATH/squidex -f $HELM_PATH/staging/$NAMESPACE.yaml --set imageTag=$IMAGE_TAG --set replicas=$REPLICAS --set version=$NAMESPACE > manifest.yaml
echo "Generated manifest"
# This deploys to staging/test cluster, for the specified env
- name: Deploy to '${{ env.APP_ENVIRONMENT }}'
uses: Azure/k8s-deploy@v4.4
with:
namespace: ${{ env.NAMESPACE }}
manifests: |
./manifest.yaml
./Dockerfile
slack-notify-success:
if: ${{ success() }}
needs: [build_and_deploy]
uses: LearnWithHomer/infrastructure-public/.github/workflows/slack-notify-success.yml@main
with:
app_env: ${{ github.event.inputs.choice }}
slack_channel: homer-staging-status
runner: ubuntu-latest
secrets:
slack_bot_token: ${{ secrets.CODESPARK_SLACK_BOT_TOKEN }}
slack-notify-failure:
if: ${{ failure() }}
needs: [build_and_deploy]
uses: LearnWithHomer/infrastructure-public/.github/workflows/slack-notify-failure.yml@main
with:
app_env: ${{ github.event.inputs.choice }}
slack_channel: homer-staging-status
runner: ubuntu-latest
secrets:
slack_bot_token: ${{ secrets.CODESPARK_SLACK_BOT_TOKEN }}