-
Notifications
You must be signed in to change notification settings - Fork 0
135 lines (131 loc) · 4.39 KB
/
deploy.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
name: Slender keeper CI
on:
push:
workflow_dispatch:
env:
IMAGE_NAME: ${{ github.repository }}
REGISTRY: ${{ vars.REGISTRY }}
LIMIT_CPU: "500m"
LIMIT_MEMORY: "512Mi"
jobs:
build-image-app:
runs-on: ubuntu-latest
outputs:
output_tag: ${{ steps.tag_env.outputs.tag }}
steps:
- uses: actions/checkout@v4
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ vars.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,enable=true,priority=600,prefix=,suffix=-{{date 'YYYYMMDD'}}-{{sha}},event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'deploy') }}
- id: tag_env
run: echo "tag=${{ env.DOCKER_METADATA_OUTPUT_VERSION }}" >> $GITHUB_OUTPUT
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
deploy-app-slender-stage:
needs: build-image-app
env:
SERVICE_NAME: ${{ vars.APP_NAME }}
NAMESPACE: ${{ vars.NAMESPACE}}-stage
runs-on: 'ubuntu-latest'
steps:
- uses: azure/setup-kubectl@v3
with:
version: 'v1.27.1'
id: install
- uses: azure/setup-helm@v3
with:
version: 'v3.12.0'
- name: 'Clone Helm repository'
uses: actions/checkout@v3
with:
repository: ${{ vars.HELM_REPOSITORY }}
ref: 'main'
token: ${{ secrets.PAT }}
- name: 'Prep extraEnv'
run: |
cat <<EOF > extraEnv.yml
${{ vars.EXTRA_ENV_FILE }}
EOF
- name: Set Kubernetes Context
uses: azure/k8s-set-context@v3
with:
method: kubeconfig
kubeconfig: ${{ secrets.KUBECONFIG }}
context: ${{ env.CLUSTER }}
- name: Deploy
run: |
helm upgrade \
-i ${{ env.SERVICE_NAME }} \
-n ${{ env.NAMESPACE }} \
--set nameOverride=${{ env.SERVICE_NAME }} \
--set imagePullSecrets[0].name=${{ vars.GH_SECR }}\
--set image.repository=${{ env.REGISTRY }} \
--set image.name=${{ env.IMAGE_NAME }} \
--set image.tag=${{ needs.build-image-app.outputs.output_tag }} \
--set resources.limits.cpu=${{ env.LIMIT_CPU }} \
--set resources.limits.memory=${{ env.LIMIT_MEMORY }} \
-f extraEnv.yml \
./
deploy-app-slender-prod:
needs: build-image-app
runs-on: 'ubuntu-latest'
env:
SERVICE_NAME: ${{ vars.APP_NAME }}
NAMESPACE: ${{ vars.NAMESPACE}}-prod
steps:
- uses: azure/setup-kubectl@v3
with:
version: 'v1.27.1'
id: install
- uses: azure/setup-helm@v3
with:
version: 'v3.12.0'
- name: 'Clone Helm repository'
uses: actions/checkout@v3
with:
repository: ${{ vars.HELM_REPOSITORY }}
ref: 'main'
token: ${{ secrets.PAT }}
- name: 'Prep extraEnv'
run: |
cat <<EOF > extraEnv.yml
${{ vars.EXTRA_ENV_FILE_PROD }}
EOF
- name: Set Kubernetes Context
uses: azure/k8s-set-context@v3
with:
method: kubeconfig
kubeconfig: ${{ secrets.KUBECONFIG }}
context: ${{ env.CLUSTER }}
- name: Deploy
run: |
helm upgrade \
-i ${{ env.SERVICE_NAME }} \
-n ${{ env.NAMESPACE }} \
--set nameOverride=${{ env.SERVICE_NAME }} \
--set imagePullSecrets[0].name=${{ vars.GH_SECR }}\
--set image.repository=${{ env.REGISTRY }} \
--set image.name=${{ env.IMAGE_NAME }} \
--set image.tag=${{ needs.build-image-app.outputs.output_tag }} \
--set resources.limits.cpu=${{ env.LIMIT_CPU }} \
--set resources.limits.memory=${{ env.LIMIT_MEMORY }} \
-f extraEnv.yml \
./