Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devops/2337 deploy develop on pr merge #2401

Merged
merged 9 commits into from
Feb 15, 2023
9 changes: 6 additions & 3 deletions .circleci/base_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ executors:
image: ubuntu-2204:2022.10.1

parameters:
develop_branch_deploy:
type: boolean
default: false
run_dev_deployment:
type: boolean
default: false
George-Hudson marked this conversation as resolved.
Show resolved Hide resolved
run_nightly_owasp_scan:
type: boolean
default: false
run_owasp_scan:
type: boolean
default: false
target_env:
type: string
default: ''
run_nightly_owasp_scan:
type: boolean
default: false
1 change: 1 addition & 0 deletions .circleci/build-and-test/workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
unless:
or:
- << pipeline.parameters.run_dev_deployment >>
- << pipeline.parameters.develop_branch_deploy >>
- << pipeline.parameters.run_owasp_scan >>
jobs:
- secrets-check
Expand Down
9 changes: 6 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@ orbs:

# parameters from github actions
parameters:
develop_branch_deploy:
type: boolean
default: false
run_dev_deployment:
type: boolean
default: false
run_nightly_owasp_scan:
type: boolean
default: false
run_owasp_scan:
type: boolean
default: false
target_env:
type: string
default: ''
run_nightly_owasp_scan:
type: boolean
default: false

jobs:
setup:
Expand Down
17 changes: 17 additions & 0 deletions .circleci/deployment/jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@
cf-space: tanf-staging
cf-username: CF_USERNAME_STAGING

test-deployment-e2e:
executor: machine-executor
working_directory: ~/tdp-apps
steps:
- checkout
- install-nodejs-machine
- disable-npm-audit
- install-nodejs-packages:
app-dir: tdrs-frontend
- run:
name: Run Cypress e2e tests
command: cd tdrs-frontend; npm run test:e2e-develop
- store_artifacts:
path: tdrs-frontend/cypress/screenshots/
- store_artifacts:
path: tdrs-frontend/cypress/videos/

deploy-production:
executor: docker-executor
working_directory: ~/tdp-deploy
Expand Down
7 changes: 7 additions & 0 deletions .circleci/deployment/workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@
branches:
only:
- develop
- test-deployment-e2e:
requires:
- deploy-develop
filters:
branches:
only:
- develop

production-deployment:
unless: << pipeline.parameters.run_dev_deployment >>
Expand Down
48 changes: 48 additions & 0 deletions .github/workflows/deploy-develop-on-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
###########################################################################
# GitHub Action Workflow
# On push to the develop branch (which should only be done through PR)
# in GitHub this action will trigger a deploy job within CircleCI for the
# deployment and e2e testing of the develop environment.
#
# Step 0: Checkout latest commit on develop
#
# Step 1: Makes a request to the V2 CircleCI API to initiate the project,
# which will filter based upon the branch to initiate the
# workflow/jobs listed here:
# staging-deployment:[
# deploy-project-updates-site,
# deploy-infrastructure-develop,
# deploy-develop,
# test-deployment-e2e
# ]
#
# Leverages the open source GitHub Action:
# https://github.com/promiseofcake/circleci-trigger-action
###########################################################################
name: Deploy Develop on PR Merge
on:
push:
branches:
- develop
paths_ignore:
- 'docs/**'
- '**.md'
- '**.txt'
- '.gitattributes'
- '.gitignore'
- 'LICENSE'
jobs:
merge_deployment:
if: github.ref == 'refs/heads/develop'
runs-on: ubuntu-latest
name: Initiate deploy job in CircleCI
steps:
- uses: actions/checkout@v2
- name: Circle CI Deployment Trigger
id: curl-circle-ci
uses: promiseofcake/circleci-trigger-action@v1
with:
user-token: ${{ secrets.CIRCLE_CI_V2_TOKEN }}
project-slug: raft-tech/TANF-app
branch: ${{ github.ref }}
payload: '{"develop_branch_deploy": true, "target_env": "develop"}'
1 change: 1 addition & 0 deletions docs/Technical-Documentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This directory contains system and architecture documentation including diagrams
- [buildpack-changelog.md](./buildpack-changelog.md) : A running log of updates to our Cloud.gov buildpacks in use.
- [circle-ci-audit-template.md](./circle-ci-audit-template.md) : This is a checklist document used during audits of our continuous intergration pipeline tool.
- [circle-ci.md](./circle-ci.md) : Overview of our CI/CD platform jobs.
- [cypress-integration-tests.md](./cypress-integration-tests.md) : Shows how we use Cypress to manage our end to end integration testing.
- [data-file-downloads.md](./data-file-downloads.md) : Provides an architecture-level view of data file storage and downloading.
- [django-admin-logging.md](./django-admin-logging.md) : Outlines sections of the Django Administrator Console and details what should be logged.
- [jwt-key-rotation.md](./jwt-key-rotation.md) : Describes the process for rotating JWT keys in Login.gov.
Expand Down
15 changes: 15 additions & 0 deletions docs/Technical-Documentation/circle-ci.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,18 @@ These all have defaults set in their respective settings modules, but may be ove
* Bind the backend application to the S3 and RDS services in Cloud.gov
* Run `/scripts/set-backend-env-vars.sh` (detailed above)
* Restage the application to make environment variable and bound services live.

## CI/CD Pipeline

George-Hudson marked this conversation as resolved.
Show resolved Hide resolved
The Frontend and Backend deploy Workflows are triggered automatically on pushes to the `develop` branch and on labeled PRs.
* GitHub Actions are used to notify CircleCI to run if criteria are met and pass along variables to the workflows as needed.
* Documentation for what each Action does can be found in each actions workflow action-name.yml file.
* These files are located in [.github/workflows](../../.github/workflows/).
* merges to the `develop` branch will deploy to the develop environment.
* on successful develop deploys, end to end integration tests will then be run against that environment.
* for details, refer to the [Cypress Integration Tests](./cypress-integration-tests.md) documentation.
* PRs given the explicit label `Deploy with CircleCI` will deploy to the tanf-dev environment selected
* `Deploy with CircleCI` is the prefix part of the label which triggers the build. It needs the environment added as a suffix
* To select the environment, add the name after a hyphen following the `Deploy with CircleCI` prefix
* e.g. `Deploy with CircleCI-raft` will deploy your branch build to the tanf-dev Cloud Foundry space, tdp-raft environment
* tdp-frontend-raft & tdp-backend-raft
4 changes: 4 additions & 0 deletions docs/Technical-Documentation/cypress-integration-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

[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.

## CI/CD Pipeline

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.

## Running tests

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
Expand Down
4 changes: 4 additions & 0 deletions scripts/deploy-backend.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ set_cf_envs()
"AV_SCAN_URL"
"BASE_URL"
"CLAMAV_NEEDED"
"CYPRESS_TOKEN"
"DJANGO_CONFIGURATION"
"DJANGO_DEBUG"
Comment on lines +45 to +47
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were these added to CircleCI env vars? Having missing/empty env vars has given us problems in the past.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CYPRESS_TOKEN is already in there, yes. It's actually being used to populate the CYPRESS_TOKEN below. DJANGO_DEBUG is also in there, but I'm not trying to grab it, instead just explicitly setting to "yes"

"DJANGO_SECRET_KEY"
"DJANGO_SETTINGS_MODULE"
"DJANGO_SU_NAME"
Expand Down Expand Up @@ -171,6 +173,8 @@ elif [ "$CF_SPACE" = "tanf-staging" ]; then
DJANGO_CONFIGURATION="Staging"
else
DJANGO_CONFIGURATION="Development"
DJANGO_DEBUG="Yes"
CYPRESS_TOKEN=$CYPRESS_TOKEN
fi

if [ "$DEPLOY_STRATEGY" = "rolling" ] ; then
Expand Down
1 change: 1 addition & 0 deletions tdrs-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"test:accessibility": "concurrently -k -s first 'REACT_APP_PA11Y_TEST=true npm run start:ci' 'wait-on http://localhost:3000/ && npm run pa11y-ci'",
"test:e2e": "cypress open",
"test:e2e-ci": "cypress run --headless -b chrome --env cypressToken=${CYPRESS_TOKEN}",
"test:e2e-develop": "cypress run --headless -b chrome --config baseUrl=https://tdp-frontend-develop.app.cloud.gov --env cypressToken=${CYPRESS_TOKEN},apiUrl=https://tdp-backend-develop.app.cloud.gov/v1",
George-Hudson marked this conversation as resolved.
Show resolved Hide resolved
"eject": "react-scripts eject",
"lint": "eslint src/ && echo 'Lint complete.'",
"pa11y-ci": "pa11y-ci --config .pa11yci.json"
Expand Down