75 Commits

Author SHA1 Message Date
dandds
7ad97403ba Don't check output status from ACR login in CI/CD. 2020-02-21 15:35:27 -05:00
dandds
ce9540d755 Set shell for failing docker login command.
On my last PR to fix this, I didn't notice that CircleCI was setting the
shell to execute with `/bin/sh -eo pipefail`, which means that the
commands will fail if any part of the command exits with 1, regardless
of whether the result is being piped anywhere else. This updates the
shell that that section of the config uses.

https://circleci.com/docs/2.0/configuration-reference/#default-shell-options
2020-02-18 15:57:19 -05:00
dandds
9e501c1067 Update Azure CLI login to container registry.
The Azure CLI now returns an exit code of "1" if there are any warnings
when logging into a container registry. Since our longterm goal is to
move away from CircleCI, I chose to fix this in-place rather than
integrate a credentials store or pass more config values to a `docker
login` command. Instead, this just grep the output from the Azure CLI
command to ensure it succeeded.
2020-02-18 11:55:19 -05:00
dandds
4ba652868d Fix Redis config in CI.
Missed a few instances of the old connection string parameter in the
CircleCI config.
2019-12-04 14:21:36 -05:00
dandds
20c7e943c8 Compose REDIS_URI from component parts.
This updates the configuration handling for the Redis connection string.
The motivation is so that the Redis password can be managed separately
via Azure Key Vault and eventually be rotated independently of the rest
of the connection URI.

This also tweaks the method we use to build the DATABASE_URI and removes
some stale config from the CI config file.
2019-12-04 13:28:26 -05:00
dandds
b1814db50b Limit integration tests to only run on protected branches.
Because of limitations with CircleCI, we should limit Ghost Inspector
tests to only run on merge commits to our protected branches. This will
allow us to build every commit in CI without exhausting our monthly
allotment of Ghost Inspector test runs. Once that setting has been
enabled in CircleCI ("build every commit") we will not longer have to
worry about what our default branch in the Github repo is.
2019-12-03 09:27:10 -05:00
dandds
c577815b0d Try different CircleCI config.
Seems like the branch filters don't work like I thought they did. For
now, we will not bother building the frontend asssets with the CDN URL
and will branch builds like we were previously.
2019-11-26 11:41:07 -05:00
dandds
41bab4f594 Do not run test workflow for merges to main branches.
We should not run a redundant testing workflow on merges to master or
staging.

This also includes a quick fix to configure the FLASK_ENV for the main
site.
2019-11-22 12:56:17 -05:00
dandds
c6187466a3 Configure staging with different FLASK_ENV, include sub-route for CDN_URL. 2019-11-21 16:43:22 -05:00
dandds
293854ece6 CircleCI config for passing CDN url to the Docker image.
The workflows need to split since we're passing different parameters to
the Docker build at the beginning of the workflow.
2019-11-21 16:42:42 -05:00
dandds
387f957aa4 Add CircleCI config for staging deployment.
This generalizes the deploy step into a configurable CircleCI command.
The available parameters are:

- `namespace`: the K8s namespace to alter
- `tag`: the docker tag to apply to the image

The script for applying migrations to the K8s environment and the
corresponding K8s Job config have been generalized so that they can be
configured to run in the specified namespace.

The main workflow has been updated so that the appropriate deployment
will happen, depending on whether we are merging to staging or master.
In the future, we could look to add an additional workflow based around
Git tags for production.

Note that this also removes the creation of the `latest` tag from CD.
That tag is no longer hard-coded into our K8s config and so there's no
longer a need to update it in our container registry.
2019-11-13 09:56:36 -05:00
dandds
3e0b7b1c5f CD sets image for Kubernetes CRLs CronJob.
This ensures that the CronJon responsible for updating CRLs is using the
most up-to-date image. Previously, it used the "latest" tag. Since the
K8s Docker environment caches image tags, "latest" would not always be
up-to-date.
2019-11-04 08:44:21 -05:00
dandds
0b5acde4c4 Stream-parse CRLs for caching file locations.
AT-AT needs to maintain a key-value CRL cache where each key is the DER
byte-string of the issuer and the value is a dictionary of the CRL file
path and expiration. This way when it checks a client certificate, it
can load the correct CRL by comparing the issuers. This is preferable to
loading all of the CRLs in-memory. However, it still requires that AT-AT
load and parse each CRL when the application boots. Because of the size
of the CRLs and their parsed, in-memory size, this leads to the
application spiking to use nearly 900MB of memory (resting usage is
around 50MB).

This change introduces a small function to ad-hoc parse the CRL and
obtain the information in the CRL we need: the issuer and the
expiration. It does this by reading the CRL byte-by-byte until it
reaches the ASN1 sequence that corresponds to the issuer, and then looks
ahead to find the nextUpdate field (i.e., the expiration date). The
CRLCache class uses this function to build its cache and JSON-serializes
the cache to disk. If another AT-AT application process finds the
serialized version, it will load that copy instead of rebuilding it. It
also entails a change to the function signature for the init method of
CRLCache: now it expects the CRL directory as its second argument,
instead of a list of locations.

The Python script invoked by `script/sync-crls` will rebuild the
location cache each time it's run. This means that when the Kubernetes
CronJob for CRLs runs, it will refresh the cache each time. When a new
application container boots, it will get the refreshed cache.

This also adds a nightly CircleCI job to sync the CRLs and test that the
ad-hoc parsing function returns the same result as a proper parsing
using the Python cryptography library. This provides extra insurance
that the function is returning correct results on real data.
2019-11-04 08:36:03 -05:00
dandds
23c4ba32eb CI/CD uses Docker containers exclusively and removes CircleCI Orbs.
The CircleCI Orbs were useful for getting started, but now that we only
have to deploy to one provider our pipeline should be tailored to
efficiently push to just that environment. This inlines all the relevant
pieces from the Orbs we were relying on as bash/sh commands instead.

This builds the Docker images upfront. Since we have a multi-stage
Dockerfile, it builds the first stage as a separate image and then
proceeds to build the complete image. This is done so that the first
stage (called "builder") can be used for testing. It retains executables
like pipenv that we need to install development dependencies needed for
tests.

Other notes:
- CircleCI does not persist Docker images between jobs. As a
  work-around, we use the CircleCI caching mechanism to create a named
  cache with *.tar copies of the images. Subsequent jobs use the cache
  and load the images.
- Both the test and integration-tests jobs need to make minor
  modifications to the container to run correctly. The test job needs to
  install the development Python dependencies, and the integration-tests
  job needs to rebuild the JS bundle so that it uses the mock uploader
  (the container is build to use the Azure uploader by default).
- The test and integration-tests jobs run in parallel.
- This adjusts the Dockerfile so that the TZ environment variable is set
  for both stages of the build.
2019-10-30 12:04:21 -04:00
dandds
85da084cd7 Update CI and remove AWS config.
This does the following:
- Consolidates the app_setup and test jobs into one. The test job was
  only one additional step, so it's not worth separating.
- Updates the Postgres image used to reflect what we're using for the
  deployed version of the site (i.e., v 10).
- Removes some unnecessary steps from the first job.
- Removes all AWS config so that CD will only push to the Azure
  container registry, run migrations against the Azure-hosted database,
  and rotate the container images in the Azure k8s cluster.
2019-10-27 15:07:23 -04:00
dandds
62657b36ae Seed roles in the container used for integration tests. 2019-10-21 15:24:07 -04:00
dandds
7949c64b9b Initial set up for Ghost Inspector integration tests.
Adds a CircleCI integration for Ghost Inspector
(https://ghostinspector.com), a headless browser testing SaaS. The
README is updated with details about how to run GI locally.

Removes the bootstrap setup for Selenium testing with BrowserStack.
2019-10-14 16:32:38 -04:00
dandds
67ff70201e Add beat worker to the deployment.
We will run a separate pod for the beat worker. There should only ever
be a single beat worker (to avoid redundant work) so the number of
replicas needs to be managed independently.

This adds both the Kubernetes config for the new pod and additional
CircleCI config to swap a new image into the pod during CD.
2019-09-18 16:34:56 -04:00
dandds
78948797a8 Add prefix to Docker image tags.
With a prefix, it is easier to automatically sort and expire images
within the container registry.
2019-09-11 15:48:12 -04:00
dandds
ace222fe95 Push multiple Docker tags for image in CD.
This will allow Kubernetes resources that only pull images occasionally
(i.e., k8s jobs) to point to a static tag name, "latest", that is updated
regularly. It also means we can refer to that image in the k8s config
tracked in the repo, instead of out-of-date images.
2019-09-11 15:37:09 -04:00
dandds
485f578c78 Apply config changes for CSP file uploads.
This applies configuration changes for the Flask app and adds changes to
the Dockerfile so that the build can make a CSP-specific JS bundle. It
adds `write_dotenv` script that creates the appropriate `.env` file for
the `parcel` bundler depending on how the `CSP` environment variable is
set.

- Configure K8s environment variables for Flask CSP usage
- Supply default CSP config setting to Flask app
- Declare the CSP arg in the Dockerfile
- Supply extra Docker build args to CD
- Fix top-level reference to boto3 in file_upload module
- Add back missing sample NGINX config for docker-compose build
2019-08-09 08:05:20 -04:00
dandds
f3e032fc03 Finalize CD config and add k8s job for migrations.
Add CircleCI config for both CSPs to:
- build the Docker image and push it to the registry
- run a short-lived k8s job to apply migrations and see data
- update the images for the Flask pods and rq worker pods
2019-07-31 11:58:43 -04:00
dandds
4c70d59c5d Add k8s networking.
- bind static azure IPs
- Add load balancers for both CSPs
2019-07-31 11:58:08 -04:00
dandds
d056191b01 Working config for CD.
This adds the AWS and Azure CircleCI orbs for updating container images
in a cluster. It installs the clients for both CSPs, configures kubectl
with a programmatic user's auth information, and executes a `kubectl set
image` command to reset the cluster image to the one that was just
pushed to the container registry.
2019-07-31 11:58:08 -04:00
dandds
89852346f8 Push images to CSP registries during CD.
Add config (CircleCI Orb recipes) for building Docker images and pushing
the results to both AWS and Azure Docker registries.
2019-07-16 15:47:50 -04:00
dandds
6abbf4bac0 Upgrade Python to 3.7.3 and add PyYAML.
We should try and track mainline Python as much as possible.

PyYAML was a sub-dependency of a dev dependency but was being included
in the translations utility. Bundling only the production Python
dependencies was not working because of this.
2019-06-20 06:26:08 -04:00
dandds
99abf011d7 Remove CircleCI cache for now 2019-06-10 11:25:00 -04:00
dandds
b7b07ce89c Simpler CircleCI config for CI.
This relies on a CircleCI-supplied base image and removes CD for now.
2019-06-10 10:48:59 -04:00
dandds
75e863c671 update docker registry domain 2019-04-15 10:55:34 -04:00
dandds
c534ceda59 remove CRL caching from CircleCI config 2019-02-27 05:51:50 -05:00
dandds
725042ab76 modify crl storage config:
- make local container for libcloud storage if it does not exist
- separate config variables for CRL storage
2019-02-27 05:51:50 -05:00
Devon Mackay
ed418b61ba Pull the manifest for the newly pushed image 2019-01-17 12:51:49 -05:00
Devon Mackay
6dae283805 Dissuade docker push fomr using dynamicy output 2019-01-17 12:49:43 -05:00
Patrick Smith
88339e9d36 Use updated pip when building on CircleCI 2018-12-14 10:39:15 -05:00
dandds
f3c294659a refine test environment sample data script, add k8s role and role binding for updating sample data 2018-12-04 16:12:23 -05:00
dandds
bd0b7b9dcd script for rotating sample data on test env 2018-12-04 09:42:47 -05:00
dandds
bbeef23c45 test testing build 2018-12-03 16:34:39 -05:00
dandds
b54e3147c3 try scheduling nightly deploys for test env with CircleCI config 2018-12-03 09:11:25 -05:00
Patrick Smith
be632e0d4a Drop -circleci from generated image names 2018-10-25 15:58:09 -04:00
dandds
60cc49275b update circle ci build config 2018-10-24 11:21:22 -04:00
Patrick Smith
1f07b0fa33 Revert "Deploy this branch"
This reverts commit 2e4a8520a9a1f8a21ac5d2148f9902755663a850. `master`
will now be deployed.
2018-10-15 16:04:19 -04:00
Patrick Smith
0f658d5036 Add build step to generate build info 2018-10-15 16:02:35 -04:00
Patrick Smith
2e4a8520a9 Deploy this branch 2018-10-15 15:04:58 -04:00
Devon Mackay
b077ad9bac Make circleci image name unique 2018-10-15 14:48:03 -04:00
Devon Mackay
d52e92fddf Convert to only deploying master branch 2018-10-15 14:48:02 -04:00
Devon Mackay
f684990666 Set working directory to match final app location (fix venv issue) 2018-10-15 14:48:02 -04:00
Devon Mackay
43057e2fc0 Flush CRL cache 2018-10-15 14:48:02 -04:00
Devon Mackay
f6fdb44a87 Ensure permissions are preserved 2018-10-15 14:48:02 -04:00
Devon Mackay
1a68458a12 And also include /usr/bin, since the bin stubs for pip installed packages live there 2018-10-15 14:48:02 -04:00
Devon Mackay
82517e67d7 Fix site-packages reference 2018-10-15 14:48:02 -04:00