Skip to content

Commit 8261650

Browse files
George-HudsonGeorge Hudsonandrew-jameson
authored
Devops/2337 deploy develop on pr merge (#2401)
* added Action to kick off deploys to develop on merges to develop, with additional job of running e2e tests on deployed environment * fixed wrong parameter name in workflow * don't need to run tests in circleCI before deploy (should already have been run in PR to develop) and temporarily change branch tracked for develop env * update deploy script to add in DJANGO_DEBUG and CYPRESS_TOKEN to env for develop deploys * updated to track develop branch before PR to develop. Added to documentation * added empty line at and of file * added empty line at and of file * moved base and api url prefixes to env vars --------- Co-authored-by: George Hudson <[email protected]> Co-authored-by: Andrew <[email protected]>
1 parent 030fb2b commit 8261650

File tree

11 files changed

+110
-6
lines changed

11 files changed

+110
-6
lines changed

.circleci/base_config.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,18 @@ executors:
1616
image: ubuntu-2204:2022.10.1
1717

1818
parameters:
19+
develop_branch_deploy:
20+
type: boolean
21+
default: false
1922
run_dev_deployment:
2023
type: boolean
2124
default: false
25+
run_nightly_owasp_scan:
26+
type: boolean
27+
default: false
2228
run_owasp_scan:
2329
type: boolean
2430
default: false
2531
target_env:
2632
type: string
2733
default: ''
28-
run_nightly_owasp_scan:
29-
type: boolean
30-
default: false

.circleci/build-and-test/workflows.yml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
unless:
44
or:
55
- << pipeline.parameters.run_dev_deployment >>
6+
- << pipeline.parameters.develop_branch_deploy >>
67
- << pipeline.parameters.run_owasp_scan >>
78
jobs:
89
- secrets-check

.circleci/config.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,21 @@ orbs:
1313

1414
# parameters from github actions
1515
parameters:
16+
develop_branch_deploy:
17+
type: boolean
18+
default: false
1619
run_dev_deployment:
1720
type: boolean
1821
default: false
22+
run_nightly_owasp_scan:
23+
type: boolean
24+
default: false
1925
run_owasp_scan:
2026
type: boolean
2127
default: false
2228
target_env:
2329
type: string
2430
default: ''
25-
run_nightly_owasp_scan:
26-
type: boolean
27-
default: false
2831

2932
jobs:
3033
setup:

.circleci/deployment/jobs.yml

+17
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,23 @@
3232
cf-space: tanf-staging
3333
cf-username: CF_USERNAME_STAGING
3434

35+
test-deployment-e2e:
36+
executor: machine-executor
37+
working_directory: ~/tdp-apps
38+
steps:
39+
- checkout
40+
- install-nodejs-machine
41+
- disable-npm-audit
42+
- install-nodejs-packages:
43+
app-dir: tdrs-frontend
44+
- run:
45+
name: Run Cypress e2e tests
46+
command: cd tdrs-frontend; npm run test:e2e-develop
47+
- store_artifacts:
48+
path: tdrs-frontend/cypress/screenshots/
49+
- store_artifacts:
50+
path: tdrs-frontend/cypress/videos/
51+
3552
deploy-production:
3653
executor: docker-executor
3754
working_directory: ~/tdp-deploy

.circleci/deployment/workflows.yml

+7
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@
4242
branches:
4343
only:
4444
- develop
45+
- test-deployment-e2e:
46+
requires:
47+
- deploy-develop
48+
filters:
49+
branches:
50+
only:
51+
- develop
4552

4653
production-deployment:
4754
unless: << pipeline.parameters.run_dev_deployment >>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
###########################################################################
2+
# GitHub Action Workflow
3+
# On push to the develop branch (which should only be done through PR)
4+
# in GitHub this action will trigger a deploy job within CircleCI for the
5+
# deployment and e2e testing of the develop environment.
6+
#
7+
# Step 0: Checkout latest commit on develop
8+
#
9+
# Step 1: Makes a request to the V2 CircleCI API to initiate the project,
10+
# which will filter based upon the branch to initiate the
11+
# workflow/jobs listed here:
12+
# staging-deployment:[
13+
# deploy-project-updates-site,
14+
# deploy-infrastructure-develop,
15+
# deploy-develop,
16+
# test-deployment-e2e
17+
# ]
18+
#
19+
# Leverages the open source GitHub Action:
20+
# https://github.com/promiseofcake/circleci-trigger-action
21+
###########################################################################
22+
name: Deploy Develop on PR Merge
23+
on:
24+
push:
25+
branches:
26+
- develop
27+
paths_ignore:
28+
- 'docs/**'
29+
- '**.md'
30+
- '**.txt'
31+
- '.gitattributes'
32+
- '.gitignore'
33+
- 'LICENSE'
34+
jobs:
35+
merge_deployment:
36+
if: github.ref == 'refs/heads/develop'
37+
runs-on: ubuntu-latest
38+
name: Initiate deploy job in CircleCI
39+
steps:
40+
- uses: actions/checkout@v2
41+
- name: Circle CI Deployment Trigger
42+
id: curl-circle-ci
43+
uses: promiseofcake/circleci-trigger-action@v1
44+
with:
45+
user-token: ${{ secrets.CIRCLE_CI_V2_TOKEN }}
46+
project-slug: raft-tech/TANF-app
47+
branch: ${{ github.ref }}
48+
payload: '{"develop_branch_deploy": true, "target_env": "develop"}'

docs/Technical-Documentation/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This directory contains system and architecture documentation including diagrams
1212
- [buildpack-changelog.md](./buildpack-changelog.md) : A running log of updates to our Cloud.gov buildpacks in use.
1313
- [circle-ci-audit-template.md](./circle-ci-audit-template.md) : This is a checklist document used during audits of our continuous intergration pipeline tool.
1414
- [circle-ci.md](./circle-ci.md) : Overview of our CI/CD platform jobs.
15+
- [cypress-integration-tests.md](./cypress-integration-tests.md) : Shows how we use Cypress to manage our end to end integration testing.
1516
- [data-file-downloads.md](./data-file-downloads.md) : Provides an architecture-level view of data file storage and downloading.
1617
- [django-admin-logging.md](./django-admin-logging.md) : Outlines sections of the Django Administrator Console and details what should be logged.
1718
- [jwt-key-rotation.md](./jwt-key-rotation.md) : Describes the process for rotating JWT keys in Login.gov.

docs/Technical-Documentation/circle-ci.md

+15
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,18 @@ These all have defaults set in their respective settings modules, but may be ove
101101
* Bind the backend application to the S3 and RDS services in Cloud.gov
102102
* Run `/scripts/set-backend-env-vars.sh` (detailed above)
103103
* Restage the application to make environment variable and bound services live.
104+
105+
## CI/CD Pipeline
106+
107+
The Frontend and Backend deploy Workflows are triggered automatically on pushes to the `develop` branch and on labeled PRs.
108+
* GitHub Actions are used to notify CircleCI to run if criteria are met and pass along variables to the workflows as needed.
109+
* Documentation for what each Action does can be found in each actions workflow action-name.yml file.
110+
* These files are located in [.github/workflows](../../.github/workflows/).
111+
* merges to the `develop` branch will deploy to the develop environment.
112+
* on successful develop deploys, end to end integration tests will then be run against that environment.
113+
* for details, refer to the [Cypress Integration Tests](./cypress-integration-tests.md) documentation.
114+
* PRs given the explicit label `Deploy with CircleCI` will deploy to the tanf-dev environment selected
115+
* `Deploy with CircleCI` is the prefix part of the label which triggers the build. It needs the environment added as a suffix
116+
* To select the environment, add the name after a hyphen following the `Deploy with CircleCI` prefix
117+
* e.g. `Deploy with CircleCI-raft` will deploy your branch build to the tanf-dev Cloud Foundry space, tdp-raft environment
118+
* tdp-frontend-raft & tdp-backend-raft

docs/Technical-Documentation/cypress-integration-tests.md

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
[Cypress](https://cypress.io) is a browser-automation testing suite that we use for end-to-end tests. See [ADR019 - Integration Tests](./Architecture-Decision-Record/019-integration-tests.md) for some additional background on testing goals and decisions.
66

7+
## CI/CD Pipeline
8+
9+
All tests added into the `tdrs-frontend/cypress/e2e/` folder will be run against the newly deployed develop environment as part of our pipeline to help ensure site reliability and that no bugs have been introduced. These are run against the actual deployed environment and so might catch issues connecting with real backend services instead of having everything local.
10+
711
## Running tests
812

913
1. Have both the backend and frontend running in separate terminal processes, the app needs to be reachable and usable at `localhost:3000` when testing locally

scripts/deploy-backend.sh

+4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ set_cf_envs()
4242
"AV_SCAN_URL"
4343
"BASE_URL"
4444
"CLAMAV_NEEDED"
45+
"CYPRESS_TOKEN"
4546
"DJANGO_CONFIGURATION"
47+
"DJANGO_DEBUG"
4648
"DJANGO_SECRET_KEY"
4749
"DJANGO_SETTINGS_MODULE"
4850
"DJANGO_SU_NAME"
@@ -171,6 +173,8 @@ elif [ "$CF_SPACE" = "tanf-staging" ]; then
171173
DJANGO_CONFIGURATION="Staging"
172174
else
173175
DJANGO_CONFIGURATION="Development"
176+
DJANGO_DEBUG="Yes"
177+
CYPRESS_TOKEN=$CYPRESS_TOKEN
174178
fi
175179

176180
if [ "$DEPLOY_STRATEGY" = "rolling" ] ; then

tdrs-frontend/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"test:accessibility": "concurrently -k -s first 'REACT_APP_PA11Y_TEST=true npm run start:ci' 'wait-on http://localhost:3000/ && npm run pa11y-ci'",
4040
"test:e2e": "cypress open",
4141
"test:e2e-ci": "cypress run --headless -b chrome --env cypressToken=${CYPRESS_TOKEN}",
42+
"test:e2e-develop": "cypress run --headless -b chrome --config baseUrl=https://${BASE_URL_PREFIX}-develop.app.cloud.gov --env cypressToken=${CYPRESS_TOKEN},apiUrl=https://${API_URL_PREFIX}-develop.app.cloud.gov/v1",
4243
"eject": "react-scripts eject",
4344
"lint": "eslint src/ && echo 'Lint complete.'",
4445
"pa11y-ci": "pa11y-ci --config .pa11yci.json"

0 commit comments

Comments
 (0)