-
Notifications
You must be signed in to change notification settings - Fork 2
176 lines (170 loc) · 6.15 KB
/
tia-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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
name: "tia-deploy"
on:
workflow_dispatch:
inputs:
portainer_image:
description: 'Portainer image:'
required: true
default: 'portainerci/portainer:develop'
portainer_agent_image:
description: 'Portainer Agent image:'
required: true
default: 'portainer/agent:2.15.0'
environment_os:
description: 'OS or architecture: Specify `lin`(default), `win`, `arm` or `amd`'
required: true
default: 'lin'
type: choice
options:
- lin
- win
- arm
- amd
environment_orchestration:
description: 'Orchestration: Specify `swarm`(default), `standalone`, `kubernetes` or `nomad`'
required: true
default: 'swarm'
type: choice
options:
- swarm
- standalone
- kubernetes
- nomad
kubernetes_version:
description: 'Kubernetes version: `1.24`, `1.25`, `1.26` (default) or `1.27`'
required: true
default: '1.25.6'
type: choice
options:
- '1.24'
- '1.25'
- '1.26'
- '1.27'
apptemplates:
description: 'Use Portainer-in-Portainer App Templates: true or false'
required: true
default: 'false'
type: choice
options:
- 'false'
- 'true'
environment_duration:
description: 'Duration of the environment: Specify `8h` (default), `1d`, `3d`, `5d` or `10d`'
required: true
default: '8h'
type: choice
options:
- '8h'
- '1d'
- '3d'
- '5d'
- '10d'
jobs:
preparation:
runs-on: ubuntu-latest
steps:
- name: '[Preparation] ENV Initialisation'
shell: bash
env:
TIA_ORCHESTRATION: ${{ github.event.inputs.environment_orchestration }}
TIA_ENVIRONMENT_OS: ${{ github.event.inputs.environment_os }}
TIA_ENVIRONMENT_DURATION: ${{ github.event.inputs.environment_duration }}
run: |
if [[ ${TIA_ORCHESTRATION} == "kubernetes" && ${TIA_ENVIRONMENT_OS} == "lin" ]]; then
echo "TIA_PREFIX=paas$(echo $(uuidgen) | cut -d - -f 5)" >> $GITHUB_ENV
else
echo "TIA_PREFIX=iaas$(echo $(uuidgen) | cut -d - -f 5)" >> $GITHUB_ENV
fi
DURATION_REGEX="^(5d$|10d$)"
if [[ ${TIA_ENVIRONMENT_DURATION} =~ $DURATION_REGEX ]]; then
echo "TIA_DEPLOY_STAGE_ENVIRONMENT=environment-inf" >> $GITHUB_ENV
else
echo "TIA_DEPLOY_STAGE_ENVIRONMENT=environment-staging" >> $GITHUB_ENV
fi
outputs:
TIA_PREFIX: ${{ env.TIA_PREFIX }}
TIA_DEPLOY_STAGE_ENVIRONMENT: ${{ env.TIA_DEPLOY_STAGE_ENVIRONMENT }}
deploy:
runs-on: ubuntu-latest
environment: ${{ needs.preparation.outputs.TIA_DEPLOY_STAGE_ENVIRONMENT }}
needs: [ preparation ]
steps:
- name: '[Preparation] Checkout the Current Branch'
uses: actions/checkout@v3
- name: "[Preparation] set up node.js 18.x"
uses: actions/setup-node@v3
- name: '[Preparation] Install Octokit Library'
run: npm install @octokit/core @octokit/auth-app node-fetch
- name: '[Preparation] Fetch GitHub App Token'
uses: actions/github-script@v6
id: portainer-bot
env:
PORTAINER_BOT_ID: ${{ secrets.PORTAINER_BOT_ID }}
PORTAINER_BOT_KEY: ${{ secrets.PORTAINER_BOT_KEY }}
PORTAINER_BOT_INSTALLATION_ID: ${{ secrets.PORTAINER_BOT_INSTALLATION_ID }}
with:
script: |
const { Octokit } = require("@octokit/core");
const { createAppAuth, createOAuthUserAuth } = require("@octokit/auth-app");
const appId = process.env.PORTAINER_BOT_ID;
const privateKey = process.env.PORTAINER_BOT_KEY;
const installationId = process.env.PORTAINER_BOT_INSTALLATION_ID;
const appOctokit = new Octokit({
authStrategy: createAppAuth,
auth: {
appId: appId,
privateKey: privateKey,
},
request: {
fetch: fetch,
},
});
const resp = await appOctokit.auth({
type: 'installation',
installationId,
});
return resp.token;
result-encoding: string
- name: '[GH CLI] Execute TIA Deploy'
id: tia-deploy
env:
GH_TOKEN: ${{ steps.portainer-bot.outputs.result }}
TIA_PREFIX: ${{ needs.preparation.outputs.TIA_PREFIX }}
shell: bash
run: |
gh workflow run \
deploy.yml \
--repo https://github.com/portainer/infrastructure \
--raw-field portainer_image=${{ github.event.inputs.portainer_image }} \
--raw-field portainer_agent_image=${{ github.event.inputs.portainer_agent_image }} \
--raw-field environment_os=${{ github.event.inputs.environment_os }} \
--raw-field environment_orchestration=${{ github.event.inputs.environment_orchestration }} \
--raw-field kubernetes_version=${{ github.event.inputs.kubernetes_version }} \
--raw-field apptemplates=${{ github.event.inputs.apptemplates }} \
--raw-field test_automation=false \
--raw-field cypress_specs='' \
--raw-field environment_prefix=${TIA_PREFIX} \
--raw-field environment_owner=${{ github.actor }}
destroy:
runs-on: ubuntu-latest
environment: environment-${{ github.event.inputs.environment_duration }}
needs: [ preparation,deploy ]
steps:
- name: '[Preparation] Checkout the Current Branch'
uses: actions/checkout@v3
- name: '[Preparation] Generate a PortainerBot Access Token'
id: portainer-bot
uses: getsentry/action-github-app-token@v1
with:
app_id: ${{ secrets.PORTAINER_BOT_ID }}
private_key: ${{ secrets.PORTAINER_BOT_KEY }}
- name: '[GH CLI] Execute TIA Destroy'
env:
GH_TOKEN: ${{ steps.portainer-bot.outputs.token }}
TIA_PREFIX: ${{ needs.preparation.outputs.TIA_PREFIX }}
shell: bash
run: |
gh workflow run \
destroy.yml \
--repo https://github.com/portainer/infrastructure \
--raw-field destroy_id=${TIA_PREFIX}