-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7be9712
commit 5e7f768
Showing
2 changed files
with
245 additions
and
70 deletions.
There are no files selected for viewing
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
name: Deploy to kubernetes | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
name: | ||
description: 'Name of application. Do not include namespace.' | ||
required: true | ||
type: string | ||
namespace: | ||
description: 'Namespace or system of the application.' | ||
required: true | ||
type: string | ||
environment: | ||
description: 'Environment to deploy to. Must be from dev, test or prod' | ||
required: true | ||
type: string | ||
AZURE_CLIENT_ID: | ||
description: 'ClientId of a service principal that can deploy to AKS.' | ||
required: false | ||
default: '' | ||
type: string | ||
AZURE_TENANT_ID: | ||
description: 'TenantId of a service principal that can deploy to AKS.' | ||
required: false | ||
default: '' | ||
type: string | ||
AKS_SUBSCRIPTION_ID: | ||
description: 'Subscription ID of AKS to deploy to.' | ||
required: false | ||
default: '' | ||
type: string | ||
AKS_CLUSTER_NAME: | ||
description: 'Subscription ID of AKS to deploy to.' | ||
required: false | ||
default: '' | ||
type: string | ||
AKS_RESOURCE_GROUP: | ||
description: 'Subscription ID of AKS to deploy to.' | ||
required: false | ||
default: '' | ||
type: string | ||
|
||
env: | ||
image_tag: ${{ github.sha }}-${{ github.run_number }} | ||
|
||
jobs: | ||
deploy_kubernetes: | ||
name: Deploy to ${{ inputs.environment}} | ||
runs-on: ubuntu-latest | ||
environment: ${{ inputs.environment}} | ||
steps: | ||
- name: Parse input | ||
run: | | ||
if [ -z "${{ inputs.AZURE_CLIENT_ID}}" ] | ||
then | ||
echo "AZURE_CLIENT_ID=${{ vars.AZURE_CLIENT_ID}}" >> "$GITHUB_ENV" | ||
else | ||
echo "AZURE_CLIENT_ID=${{ inputs.AZURE_CLIENT_ID}}" >> "$GITHUB_ENV" | ||
fi | ||
if [ -z "${{ inputs.AZURE_TENANT_ID}}" ] | ||
then | ||
echo "AZURE_TENANT_ID=${{ vars.AZURE_TENANT_ID}}" >> "$GITHUB_ENV" | ||
else | ||
echo "AZURE_TENANT_ID=${{ inputs.AZURE_TENANT_ID}}" >> "$GITHUB_ENV" | ||
fi | ||
if [ -z "${{ inputs.AKS_SUBSCRIPTION_ID}}" ] | ||
then | ||
echo "AKS_SUBSCRIPTION_ID=${{ vars.AKS_SUBSCRIPTION_ID}}" >> "$GITHUB_ENV" | ||
else | ||
echo "AKS_SUBSCRIPTION_ID=${{ inputs.AKS_SUBSCRIPTION_ID}}" >> "$GITHUB_ENV" | ||
fi | ||
if [ -z "${{ inputs.AKS_CLUSTER_NAME}}" ] | ||
then | ||
echo "AKS_CLUSTER_NAME=${{ vars.AKS_CLUSTER_NAME}}" >> "$GITHUB_ENV" | ||
else | ||
echo "AKS_CLUSTER_NAME=${{ inputs.AKS_CLUSTER_NAME}}" >> "$GITHUB_ENV" | ||
fi | ||
if [ -z "${{ inputs.AKS_RESOURCE_GROUP}}" ] | ||
then | ||
echo "AKS_RESOURCE_GROUP=${{ vars.AKS_RESOURCE_GROUP}}" >> "$GITHUB_ENV" | ||
else | ||
echo "AKS_RESOURCE_GROUP=${{ inputs.AKS_RESOURCE_GROUP}}" >> "$GITHUB_ENV" | ||
fi | ||
- name: checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: authenticate with Azure | ||
uses: azure/login@v1 | ||
with: | ||
client-id: ${{ env.AZURE_CLIENT_ID}} | ||
tenant-id: ${{ env.AZURE_TENANT_ID}} | ||
subscription-id: ${{ env.AKS_SUBSCRIPTION_ID}} | ||
|
||
- name: setup kubelogin | ||
uses: azure/use-kubelogin@v1 | ||
with: | ||
kubelogin-version: 'v0.0.24' | ||
|
||
- name: set AKS context | ||
uses: azure/aks-set-context@v3 | ||
with: | ||
cluster-name: ${{ env.AKS_CLUSTER_NAME }} | ||
resource-group: ${{ env.AKS_RESOURCE_GROUP }} | ||
admin: 'false' | ||
use-kubelogin: 'true' | ||
subscription: ${{ env.AKS_SUBSCRIPTION_ID }} | ||
|
||
- name: helm deploy | ||
run: | | ||
helm repo add elvia-charts https://raw.githubusercontent.com/3lvia/kubernetes-charts/master | ||
helm repo update | ||
helm upgrade --debug --install -n ${{ inputs.namespace}} -f CI/values.yaml ${{ inputs.name}} elvia-charts/elvia-deployment \ | ||
--set environment=dev --set image.tag=${{ env.image_tag }} --set labels.repositoryName=${{ github.repository }} --set labels.commitHash=${{ github.sha }} | ||
- name: rollout status | ||
run: | | ||
kubectl -n ${{ inputs.namespace}} rollout status deploy ${{ inputs.name}} | ||
- name: get events | ||
continue-on-error: true | ||
run: | | ||
kubectl -n ${{ inputs.namespace}} get events --sort-by='.lastTimestamp' |grep ${{ inputs.name}} || true | ||
if: always() | ||
|
||
- name: set grafana annotations | ||
uses: 3lvia/core-github-actions-templates/post-grafana-annotations.yaml | ||
with: | ||
title: 'Event - Deploy ${{job.status}}' | ||
description: 'description' | ||
app: '${{input.name}}' | ||
system: '${{input.namespace}}' | ||
env: 'dev' | ||
event: 'deploy' |