-
Notifications
You must be signed in to change notification settings - Fork 3
155 lines (127 loc) · 4.81 KB
/
deploy-aks.yml
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
name: Deploy Service
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
env:
MANIFESTS: |
./.deploy/deployment.yml
./.deploy/service.yml
IMAGE: sierrasoftworks/honeypot
STAGING_CLUSTER: k8s-common
STAGING_RESOURCEGROUP: app-common
STAGING_NAMESPACE: "honeypot-staging"
STAGING_HEALTHCHECK: "https://staging.honeypot.sierrasoftworks.com/api/v1/stats"
LIVE_CLUSTER: k8s-common
LIVE_RESOURCEGROUP: app-common
LIVE_NAMESPACE: "honeypot-prod"
LIVE_HEALTHCHECK: "https://honeypot.sierrasoftworks.com/api/v1/stats"
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build Dockerfile
run: docker build . --file Dockerfile
push:
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v4
- name: Build image
run: docker build . --file Dockerfile --tag image
- name: Log into registries
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
echo "${{ secrets.DOCKER_HUB }}" | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin
- name: Calculate version number
id: version
run: |
VERSION=$(git describe --tags 2>/dev/null || git rev-parse --short HEAD)
echo "::set-output name=version::$VERSION"
- name: Push image to GitHub
run: |
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/${{ github.event.repository.name }}
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
docker tag image $IMAGE_ID:latest
docker push $IMAGE_ID:latest
docker tag image $IMAGE_ID:${{ steps.version.outputs.version }}
docker push $IMAGE_ID:${{ steps.version.outputs.version }}
- name: Push image to Docker Hub
run: |
IMAGE_ID=${{ env.IMAGE }}
echo IMAGE_ID=$IMAGE_ID
docker tag image $IMAGE_ID:latest
docker push $IMAGE_ID:latest
docker tag image $IMAGE_ID:${{ steps.version.outputs.version }}
docker push $IMAGE_ID:${{ steps.version.outputs.version }}
deploy-staging:
needs: push
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: actions/checkout@v4
- name: Calculate version number
id: version
run: |
VERSION=$(git describe --tags 2>/dev/null || git rev-parse --short HEAD)
echo "::set-output name=version::$VERSION"
- uses: azure/aks-set-context@v4
with:
creds: "${{ secrets.AZURE_CREDENTIALS }}"
resource-group: "${{ env.STAGING_RESOURCEGROUP }}"
cluster-name: "${{ env.STAGING_CLUSTER }}"
- uses: azure/k8s-deploy@v5
with:
namespace: "${{ env.STAGING_NAMESPACE }}"
manifests: "${{ env.MANIFESTS }}"
images: |
docker.pkg.github.com/${{ github.repository }}/${{ github.event.repository.name }}:${{ steps.version.outputs.version }}
${{ env.IMAGE }}:${{ steps.version.outputs.version }}
healthcheck-staging:
needs: deploy-staging
runs-on: ubuntu-latest
steps:
- name: Probe
uses: Jtalk/url-health-check-action@v4
with:
url: ${{ env.STAGING_HEALTHCHECK }}
max-attempts: 5
retry-delay: 10s
follow-redirect: true
deploy-live:
needs: healthcheck-staging
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: actions/checkout@v4
- name: Calculate version number
id: version
run: |
VERSION=$(git describe --tags 2>/dev/null || git rev-parse --short HEAD)
echo "::set-output name=version::$VERSION"
- uses: azure/aks-set-context@v4
with:
creds: "${{ secrets.AZURE_CREDENTIALS }}"
resource-group: "${{ env.LIVE_RESOURCEGROUP }}"
cluster-name: "${{ env.LIVE_CLUSTER }}"
- uses: azure/k8s-deploy@v5
with:
namespace: "${{ env.LIVE_NAMESPACE }}"
manifests: "${{ env.MANIFESTS }}"
images: |
docker.pkg.github.com/${{ github.repository }}/${{ github.event.repository.name }}:${{ steps.version.outputs.version }}
${{ env.IMAGE }}:${{ steps.version.outputs.version }}
healthcheck-live:
needs: deploy-live
runs-on: ubuntu-latest
steps:
- name: Probe
uses: Jtalk/url-health-check-action@v4
with:
url: ${{ env.LIVE_HEALTHCHECK }}
max-attempts: 5
retry-delay: 10s
follow-redirect: true