-
Notifications
You must be signed in to change notification settings - Fork 1
238 lines (235 loc) · 11.2 KB
/
build-and-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
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
name: Build and deploy
on:
push:
branches:
- dev
- main
permissions:
contents: read
packages: write
jobs:
php-lint:
name: PHP Lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Nodejs
uses: actions/setup-node@v4
with:
node-version-file: "./benefit-finder/package.json"
- name: Set env.BRANCH
run: |
echo "BRANCH=$(echo $GITHUB_REF | cut -d'/' -f 3)" >> $GITHUB_ENV
- name: Install PHP
run: bash ./scripts/pipeline/deb-php-install.sh
# - name: Install Node.js
# run: |
# bash ./scripts/pipeline/deb-nodejs-install.sh
- name: Init submodule
run: |
git submodule init
git submodule update
cd usagov-2021
git checkout prod
cd ..
- name: Install Linters and Sniffers
run: |
composer global config --no-plugins allow-plugins.dealerdirect/phpcodesniffer-composer-installer false
composer global require --dev drupal/coder php-parallel-lint/php-parallel-lint squizlabs/php_codesniffer=*
COMPOSER_DIR=$(composer -n config --global home)
$COMPOSER_DIR/vendor/bin/phpcs --config-set installed_paths $COMPOSER_DIR/vendor/drupal/coder/coder_sniffer,$COMPOSER_DIR/vendor/sirbrillig/phpcs-variable-analysis,$COMPOSER_DIR/vendor/slevomat/coding-standard
mkdir -p /tmp/results
touch /tmp/results/php-lint.log
touch /tmp/results/php-cs.log
touch /tmp/results/theme-lint.log
- name: PHP Lint
run: |
COMPOSER_DIR=$(composer -n config --global home)
$COMPOSER_DIR/vendor/bin/parallel-lint -e php,module,inc,install,test,profile,theme ./usagov_benefit_finder # | tee /tmp/results/php-lint.log
- name: PHP CodeSniff (Ignore warnings)
run: |
COMPOSER_DIR=$(composer -n config --global home)
$COMPOSER_DIR/vendor/bin/phpcs --standard=./usagov-2021/.phpcs.xml.dist -v --warning-severity=0 ./usagov_benefit_finder # | tee /tmp/results/php-cs.log
# backup-database-dev:
# needs: php-lint
# uses: ./.github/workflows/database-backup-dev.yml
# if: github.ref == 'refs/heads/dev'
# secrets: inherit
backup-database-main:
needs: php-lint
uses: ./.github/workflows/database-backup-main.yml
if: github.ref == 'refs/heads/main'
secrets: inherit
component-library:
# needs: [backup-database-dev, backup-database-main]
needs: [backup-database-main]
if: always() && contains(needs.*.result, 'success') && !contains(needs.*.result, 'failure')
name: Build and deploy component library
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Nodejs
uses: actions/setup-node@v4
with:
node-version-file: "./benefit-finder/package.json"
- name: Set env.BRANCH
run: |
echo "BRANCH=$(echo $GITHUB_REF | cut -d'/' -f 3)" >> $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: Init submodule
run: |
git submodule init
git submodule update
cd usagov-2021
git checkout prod
cd ..
- name: Deploy Storybook
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
cd benefit-finder
mv manifest.yml manifest.yml.tpl
envsubst < manifest.yml.tpl > manifest.yml
npm ci
npm run build:storybook
mv manifest.yml storybook-static/
mv Staticfile storybook-static/
mv nginx storybook-static/
cd storybook-static
echo "${{ secrets.STORYBOOK_USERNAME }}:${{ secrets.STORYBOOK_PASSWORD }}" > Staticfile.auth
cf push benefit-finder-storybook-${BRANCH}
build-and-deploy:
# needs: [backup-database-dev, backup-database-main]
needs: [backup-database-main]
if: always() && contains(needs.*.result, 'success') && !contains(needs.*.result, 'failure')
name: Build and deploy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Nodejs
uses: actions/setup-node@v4
with:
node-version-file: "./benefit-finder/package.json"
- name: Set env.BRANCH
run: |
echo "BRANCH=$(echo $GITHUB_REF | cut -d'/' -f 3)" >> $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: Init submodule
run: |
git submodule init
git submodule update
cd usagov-2021
git checkout prod
- name: Insert rewrite rules in alphabetical order
run: |
sed -i '/^ rewrite \^\/benefits-grants-loans/a\ rewrite ^/benefit-finder/([^/]+)/[^/]+$ /benefit-finder/$1 permanent;' ./usagov-2021/.docker/src-cms/etc/nginx/partials/internal_redirects.conf
sed -i '/^ rewrite \^\/espanol\/beneficios-familias-militares/a\ rewrite ^/espanol/benefit-finder/([^/]+)/[^/]+$ /espanol/benefit-finder/$1 permanent;' ./usagov-2021/.docker/src-cms/etc/nginx/partials/internal_redirects.conf
cat ./usagov-2021/.docker/src-cms/etc/nginx/partials/internal_redirects.conf
sed -i 's/^[[:space:]]*# include partials\/internal_redirects.conf;/ include partials\/internal_redirects.conf;/' ./usagov-2021/.docker/src-cms/etc/nginx/partials/cms.conf.tmpl
cat ./usagov-2021/.docker/src-cms/etc/nginx/partials/cms.conf.tmpl
- name: Merge files into module
run: |
bash ./scripts/pipeline/mv-benefit-finder-app.sh
rm -r usagov-2021/web/modules/custom/usagov_benefit_finder/*
mv usagov_benefit_finder/* usagov-2021/web/modules/custom/usagov_benefit_finder/
mv ./scripts/application/* usagov-2021/scripts/
- name: Configure application
run: |
cd usagov-2021
sed -i "s/memory_limit = 1G/memory_limit = 500M/g" .docker/src-cms/etc/php81/php.ini
mv .docker/Dockerfile-cms .
sed -i 's/80/8080/g' Dockerfile-cms
sed -i 's/ENTRYPOINT/CMD/' Dockerfile-cms
sed -i 's/\["s3"\]\[\]?/s3\[\]/g' scripts/tome-run.sh scripts/tome-sync.sh
sed -i "s|/var/www/scripts/tome-run.sh \$URI \$@||" .docker/src-cms/etc/periodic/1min/generate-static-site
sed -i 's/80/8080/g' .docker/src-cms/etc/nginx/partials/cms.conf.tmpl
sed -i '/listen 8080 default_server;/a\ port_in_redirect off;' .docker/src-cms/etc/nginx/partials/cms.conf.tmpl
sed -i "s/\$service\['name'\] === 'database'/stristr(\$service\['name'\], 'mysql')/" web/sites/default/settings.php
sed -i "s/\$settings\['hash_salt'\] = \$service\['credentials'\]\['HASH_SALT'\]/\$settings\['hash_salt'\] = \$service\['credentials'\]\['hash_salt'\]/" web/sites/default/settings.php
sed -i "s/\$service\['name'\] === 'storage'/stristr(\$service\['name'\], 'storage')/" web/sites/default/settings.php
sed -i "s/\$service\['name'\] === 'secrets'/stristr(\$service\['name'\], 'secrets')/" web/sites/default/settings.php
- name: Docker login
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ secrets.CR_USERNAME }}
password: ${{ secrets.CR_PAT }}
- name: Docker tag
id: meta
uses: docker/[email protected]
with:
images: ghcr.io/${{ vars.CR_REPOSITORY }}
tags: |
type=sha,enable=true,priority=100,prefix=,suffifx=,format=short
- name: Build and push Docker image
# uses: docker/[email protected]
uses: docker/[email protected]
with:
context: ./usagov-2021
file: ./usagov-2021/Dockerfile-cms
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Configure manifest.yml
env:
PROJECT: "${{ secrets.PROJECT }}"
run: |
declare MEMORY
[ "${BRANCH}" = "dev" ] && MEMORY=${{ vars.CMS_MEMORY_DEV }}
[ "${BRANCH}" = "main" ] && MEMORY=${{ vars.CMS_MEMORY_MAIN }}
cd usagov-2021
sed -i "s#^ image: .*cms-latest*# image: ghcr.io/${{ vars.CR_REPOSITORY }}:${{ steps.meta.outputs.tags }}#" manifest.yml
sed -i "s#^ - secauthsecrets##" manifest.yml
sed -i "s#- name: cms#- name: ${PROJECT}-cms-${BRANCH}#" manifest.yml
sed -i "s#^ memory: 1.5G# memory: ${MEMORY}#" manifest.yml
sed -i "s#^ - database# - ${PROJECT}-mysql-${BRANCH}#" manifest.yml
sed -i "s#^ - secrets# - ${PROJECT}-secrets-${BRANCH}#" manifest.yml
sed -i "s#^ - storage# - ${PROJECT}-storage-${BRANCH}#" manifest.yml
sed -i "s#^ - dbstorage# - ${PROJECT}-static-${BRANCH}#" manifest.yml
sed -i '16i\ command: /var/www/scripts/entrypoint.sh' manifest.yml
- name: Deploy application
env:
CF_USER: "${{ secrets.CF_USER }}"
CF_PASSWORD: "${{ secrets.CF_PASSWORD }}"
CF_ORG: "${{ secrets.CF_ORG }}"
CR_PAT: "${{ secrets.CR_PAT }}"
CR_USERNAME: "${{ secrets.CR_USERNAME }}"
PROJECT: "${{ secrets.PROJECT }}"
TEST_USER_PASS: "${{ secrets.TEST_USER_PASS }}"
TEST_USER_NAMES: "${{ secrets.TEST_USER_NAMES }}"
run: |
source ./scripts/pipeline/cloud-gov-login.sh
cd usagov-2021
cf delete ${PROJECT}-cms-${BRANCH} -f
CF_DOCKER_PASSWORD=${CR_PAT} cf push ${PROJECT}-cms-${BRANCH} --docker-image "${{ steps.meta.outputs.tags }}" --docker-username "${CF_USER}" && docker logout
../scripts/pipeline/cloud-gov-wait-for-application.sh ${PROJECT}-cms-${BRANCH}
cf add-network-policy ${PROJECT}-waf-${BRANCH} ${PROJECT}-cms-${BRANCH} -s ${PROJECT}-${BRANCH} -o ${CF_ORG} --protocol tcp --port 61443
cf map-route benefit-finder-cms-${BRANCH} apps.internal --hostname benefit-finder-cms-${BRANCH} --app-protocol http1
cd ..
# Split the USERS_LIST into an array
IFS=',' read -ra users <<< "${TEST_USER_NAMES}"
# Generate the password reset commands
password_reset_commands=""
for user in "${users[@]}"; do
password_reset_commands+="drush user:password $user \"TU_PASS\"\n"
done
# Make replacement in the drush post deploy with user change password commands
sed -i "s|### USER_PASSWORD_RESET_PLACEHOLDER ###|$password_reset_commands|" ./scripts/drush-post-deploy.sh
# Set the test user's passwords to the value of the github secret value for TEST_USER_PASS.
sed -i "s#TU_PASS#${TEST_USER_PASS}#g" ./scripts/drush-post-deploy.sh
# Execute the drush command script
source ./scripts/pipeline/cloud-gov-post-deploy.sh