-
Notifications
You must be signed in to change notification settings - Fork 1
191 lines (189 loc) · 8.33 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
name: Build and deploy
on:
push:
branches:
- dev
- main
- 1059-deprecate-circleci
jobs:
php-lint:
name: PHP Lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set env.BRANCH
run: |
#echo "BRANCH=$(echo $GITHUB_REF | cut -d'/' -f 3)" >> $GITHUB_ENV
echo "BRANCH=DEV" >> $GITHUB_ENV
- name: Install PHP
run: |
bash ./scripts/pipeline/deb-php-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: |
npm install --prefix ./benefit-finder
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 ./benefit-finder ./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:
needs: php-lint
uses: ./.github/workflows/database-backup.yml
secrets: inherit
component-library:
needs: backup-database
name: Build and deploy component library
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set env.BRANCH
run: |
#echo "BRANCH=$(echo $GITHUB_REF | cut -d'/' -f 3)" >> $GITHUB_ENV
echo "BRANCH=DEV" >> $GITHUB_ENV
- name: Install basic dependancies
run: |
./scripts/pipeline/deb-basic-deps.sh
#curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
- 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
source ~/.nvm/nvm.sh
cd benefit-finder
mv manifest.yml manifest.yml.tpl
envsubst < manifest.yml.tpl > manifest.yml
npm i @craco/craco
npm run build
bash ../scripts/pipeline/mv-uswds-usagov-theme.sh
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
name: Build and deploy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set env.BRANCH
run: |
#echo "BRANCH=$(echo $GITHUB_REF | cut -d'/' -f 3)" >> $GITHUB_ENV
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: Init submodule
run: |
git submodule init
git submodule update
cd usagov-2021
git checkout prod
- 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/80/8080/g' .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=,suffix=,format=short
- name: Build and push Docker image
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: |
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: 1G#" 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 }}'
run: |
source ./scripts/pipeline/cloud-gov-login.sh
cd usagov-2021
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 ..
source ./scripts/pipeline/cloud-gov-post-deploy.sh