-
Notifications
You must be signed in to change notification settings - Fork 1
72 lines (64 loc) · 1.97 KB
/
deploy_app.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
name: Deploy App
on:
# Run this workflow from other workflows
workflow_call:
inputs:
app_name:
description: 'Name of app to get current k8s deployment'
required: true
type: string
commit_id:
description: 'HEAD commit hash'
required: true
type: string
environment:
description: 'environment to affect'
required: true
type: string
deploy_check:
description: 'Check current deployment?'
required: false
default: true
type: boolean
repo_name:
description: 'Name of app repo for Docker image'
required: false
default: ''
type: string
secrets:
creds:
required: true
jobs:
deploy_app:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: azure/login@v2
with:
creds: ${{ secrets.creds }}
- uses: azure/aks-set-context@v4
with:
resource-group: kubernetes
cluster-name: microservices
- name: Get current deploy
if: ${{ inputs.deploy_check }}
run: |
echo "DEPLOYED_IMAGE_TAG=$(kubectl get deployment ${{ inputs.app_name }}-${{ inputs.environment }}-app -o=jsonpath='{$.spec.template.spec.containers[:1].image}' | cut -d':' -f 2)" >> $GITHUB_ENV
- name: Check if deploy is necessary
if: ${{ inputs.deploy_check }}
run: |
if [ $DEPLOYED_IMAGE_TAG == ${{ inputs.commit_id }} ]; then
echo "::warning::Deployed image matches latest commit, no new code to deploy. "
exit 1
fi
- name: Modify & apply template
run: |
sed "s/__IMAGE_TAG__/${{ inputs.commit_id }}/g" ./kubernetes/deployment-${{ inputs.environment }}.tmpl \
| kubectl apply -f -