-
Notifications
You must be signed in to change notification settings - Fork 1
204 lines (191 loc) · 7.97 KB
/
build-and-deploy-dev-waf.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
name: Update Dev WAF
on:
schedule:
- cron: "0 5 * * 4"
jobs:
checkVersion:
name: Check versions
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set env.BRANCH
run: echo "BRANCH=dev" >> $GITHUB_ENV
- name: Install basic dependancies
run: ./scripts/pipeline/deb-basic-deps.sh
- name: Install Cloudfoundry CLI
run: ./scripts/pipeline/deb-cf-install.sh
- name: Cloud.gov login
env:
CF_USER: "${{ secrets.CF_USER }}"
CF_PASSWORD: "${{ secrets.CF_PASSWORD }}"
CF_ORG: "${{ secrets.CF_ORG }}"
PROJECT: "${{ secrets.PROJECT }}"
run: source ./scripts/pipeline/cloud-gov-login.sh
- name: Check version
id: version
env:
PROJECT: "${{ secrets.PROJECT }}"
run: |
ubuntu_version=${{ vars.UBUNTU_VERSION }}
modsecurity_nginx_version=${{ vars.MODSECURITY_NGINX_VERSION }}
source ./scripts/pipeline/cloud-gov-waf-version.sh
outputs:
current_nginx_version: ${{ steps.version.outputs.current_nginx_version }}
new_nginx_version: ${{ steps.version.outputs.new_nginx_version }}
cloudgov_wf_version: ${{ steps.version.outputs.cloudgov_wf_version }}
cloudgov_bp_version: ${{ steps.version.outputs.cloudgov_bp_version }}
update: ${{ steps.version.outputs.update }}
updateWAF:
name: Update WAF
runs-on: ubuntu-latest
needs: checkVersion
if: needs.checkVersion.outputs.update == 'true'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set env.BRANCH
run: echo "BRANCH=dev" >> $GITHUB_ENV
- name: Install basic dependancies
run: ./scripts/pipeline/deb-basic-deps.sh
- name: Install Cloudfoundry CLI
run: ./scripts/pipeline/deb-cf-install.sh
- name: Cloud.gov login
env:
CF_USER: "${{ secrets.CF_USER }}"
CF_PASSWORD: "${{ secrets.CF_PASSWORD }}"
CF_ORG: "${{ secrets.CF_ORG }}"
PROJECT: "${{ secrets.PROJECT }}"
TF_BASTION: "${{ secrets.TF_BASTION }}"
TF_BACKEND_SPACE: "${{ secrets.TF_BACKEND_SPACE }}"
run: |
source ./scripts/pipeline/cloud-gov-login.sh
cf target -s "${TF_BACKEND_SPACE}" >/dev/null 2>&1
- name: Start Bastion
env:
TF_BASTION: "${{ secrets.TF_BASTION }}"
run: |
cf start "${TF_BASTION}" >/dev/null 2>&1
./scripts/pipeline/cloud-gov-wait-for-app-start.sh "${TF_BASTION}"
- name: Cloud.gov bastion git checkout
env:
TF_BASTION: "${{ secrets.TF_BASTION }}"
run: |
declare -a commands=("rm -rf px-benefit-finder" "git clone https://github.com/GSA/px-benefit-finder.git && cd px-benefit-finder && git checkout ${BRANCH}")
for command in "${commands[@]}"; do
./scripts/pipeline/cloud-gov-remote-command.sh "${TF_BASTION}" "${command}" 1
done
- name: Build nginx WAF Plugin
env:
ubuntu_version: "${{ vars.UBUNTU_VERSION }}"
modsecurity_nginx_version: "${{ vars.MODSECURITY_NGINX_VERSION }}"
new_nginx_version: ${{ needs.checkVersion.outputs.new_nginx_version }}
TF_BASTION: "${{ secrets.TF_BASTION }}"
run: |
source ./scripts/pipeline/terraform-build-waf-plugin.sh
- name: Configure Terraform
env:
CF_USER: "${{ secrets.CF_USER }}"
CF_PASSWORD: "${{ secrets.CF_PASSWORD }}"
CF_ORG: "${{ secrets.CF_ORG }}"
PROJECT: "${{ secrets.PROJECT }}"
TF_BASTION: "${{ secrets.TF_BASTION }}"
run: |
CWD=$(pwd)
cd terraform/infra
envsubst < terraform.tfvars.tmpl > terraform.tfvars
${CWD}/scripts/pipeline/cloud-gov-scp-file.sh "${TF_BASTION}" "terraform.tfvars" "px-benefit-finder/terraform/infra"
cd "${CWD}"
- name: Terraform Init
env:
TF_BASTION: "${{ secrets.TF_BASTION }}"
id: init
run: ./scripts/pipeline/cloud-gov-remote-command.sh "${TF_BASTION}" "tofu -chdir=px-benefit-finder/terraform/infra init" 1
- name: Terraform Validate
env:
TF_BASTION: "${{ secrets.TF_BASTION }}"
id: validate
run: |
stdout=$(./scripts/pipeline/cloud-gov-remote-command.sh ${TF_BASTION} "TF_WORKSPACE=${BRANCH} tofu -chdir=px-benefit-finder/terraform/infra validate -no-color" 1)
stdout=$(echo $stdout | sed '$ d')
echo ${stdout}
echo "stdout=${stdout}" >> $GITHUB_OUTPUT
- name: Terraform Plan
env:
TF_BASTION: "${{ secrets.TF_BASTION }}"
id: plan
run: |
stdout=$(./scripts/pipeline/cloud-gov-remote-command.sh "${TF_BASTION}" "TF_WORKSPACE=${BRANCH} tofu -chdir=px-benefit-finder/terraform/infra plan -no-color" 1)
stdout=$(echo $stdout | sed '$ d')
echo ${stdout}
echo "stdout=${stdout}" >> $GITHUB_OUTPUT
- name: Terraform Apply
env:
TF_BASTION: "${{ secrets.TF_BASTION }}"
id: apply
run: |
stdout=$(./scripts/pipeline/cloud-gov-remote-command.sh "${TF_BASTION}" "TF_WORKSPACE=${BRANCH} tofu -chdir=px-benefit-finder/terraform/infra apply -auto-approve" 1)
stdout=$(echo $stdout | sed '$ d')
echo ${stdout}
echo "stdout=${stdout}" >> $GITHUB_OUTPUT
- name: Create Issue For Review
id: issue
uses: dacbd/create-issue-action@main
with:
token: ${{ secrets.ADD_TO_PROJECT_PAT }}
assignees: ${{ vars.TECH_LEAD }}
title: "Update to NGINX v${{ needs.checkVersion.outputs.new_nginx_version }} (dev)"
body: |
## Automated update of NGINX WAF
This is an automated build and deploy of the NGINX WAF application in dev.
Build pack: ${{ needs.checkVersion.outputs.cloudgov_wf_version }} => ${{ needs.checkVersion.outputs.cloudgov_bp_version }}
NGINX: ${{ needs.checkVersion.outputs.current_nginx_version }} => ${{ needs.checkVersion.outputs.new_nginx_version }}
#### Terraform Initialization ⚙`${{ steps.init.outcome }}`
#### Terraform Validation 🤖`${{ steps.validate.outcome }}`
<details><summary>Validation Output</summary>
```
${{ steps.validate.outputs.stdout }}
```
</details>
#### Terraform Plan 📅`${{ steps.plan.outcome }}`
<details><summary>Show Plan</summary>
```
${{ steps.plan.outputs.stdout }}
```
</details>
#### Terraform Apply 🚀`${{ steps.apply.outcome }}`
# - name: Update Project Status
# env:
# GH_PROJECT_NUMBER: ${{ secrets.GH_PROJECT_NUMBER }}
# GH_TOKEN: ${{ secrets.ADD_TO_PROJECT_PAT }}
# ISSUE_NUMBER: ${{ steps.issue.outputs.number }}
# run: source ./scripts/pipeline/github-update-issue-status.sh
stopBastion:
name: Stop Bastion
runs-on: ubuntu-latest
needs: updateWAF
if: ${{ always() }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set env.BRANCH
run: echo "BRANCH=dev" >> $GITHUB_ENV
- name: Install basic dependancies
run: ./scripts/pipeline/deb-basic-deps.sh
- name: Install Cloudfoundry CLI
run: ./scripts/pipeline/deb-cf-install.sh
- name: Cloud.gov login
env:
CF_USER: "${{ secrets.CF_USER }}"
CF_PASSWORD: "${{ secrets.CF_PASSWORD }}"
CF_ORG: "${{ secrets.CF_ORG }}"
PROJECT: "${{ secrets.PROJECT }}"
TF_BASTION: "${{ secrets.TF_BASTION }}"
TF_BACKEND_SPACE: "${{ secrets.TF_BACKEND_SPACE }}"
run: |
source ./scripts/pipeline/cloud-gov-login.sh
cf target -s "${TF_BACKEND_SPACE}" >/dev/null 2>&1
- name: Stop Bastion
env:
TF_BASTION: "${{ secrets.TF_BASTION }}"
run: cf stop "${TF_BASTION}" >/dev/null 2>&1