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.
238 lines
7.3 KiB
YAML
238 lines
7.3 KiB
YAML
version: 2.1
|
|
|
|
orbs:
|
|
azure-acr: circleci/azure-acr@0.1.2
|
|
azure-aks: circleci/azure-aks@0.2.0
|
|
kubernetes: circleci/kubernetes@0.3.0
|
|
|
|
defaults:
|
|
appEnvironment: &appEnvironment
|
|
KEEP_EXISTING_VENV: true
|
|
PGHOST: localhost
|
|
PGUSER: postgres
|
|
PGDATABASE: circle_test
|
|
REDIS_URI: redis://localhost:6379
|
|
PIP_VERSION: 18.*
|
|
|
|
commands:
|
|
migration_setup:
|
|
parameters:
|
|
container_image:
|
|
type: string
|
|
steps:
|
|
- attach_workspace:
|
|
at: .
|
|
- run:
|
|
name: Setup Environment Variables
|
|
command: |
|
|
echo 'export CONTAINER_IMAGE="<< parameters.container_image >>"' >> $BASH_ENV
|
|
- run: sudo apt-get update
|
|
- run: sudo apt-get install gettext
|
|
- kubernetes/install
|
|
migration_apply:
|
|
steps:
|
|
- run:
|
|
command: ./script/cluster_migration
|
|
name: Apply Migrations and Seed Roles
|
|
|
|
jobs:
|
|
test:
|
|
docker:
|
|
- image: circleci/python:3.7.3-stretch-node
|
|
environment: *appEnvironment
|
|
- image: circleci/postgres:10-alpine-ram
|
|
- image: circleci/redis:4-alpine3.8
|
|
steps:
|
|
- checkout
|
|
- run: sudo apt-get update
|
|
- run: sudo apt-get install postgresql-client
|
|
- attach_workspace:
|
|
at: .
|
|
- run: ./script/setup
|
|
- save_cache:
|
|
name: "Save Cache: Pipenv References"
|
|
paths:
|
|
- ~/.local/share
|
|
key: pipenv-v1-{{ .Branch }}-{{ checksum "Pipfile.lock" }}
|
|
- save_cache:
|
|
name: "Save Cache: Python Venv"
|
|
paths:
|
|
- ./.venv
|
|
key: venv-v1-{{ .Branch }}-{{ checksum "Pipfile.lock" }}
|
|
- save_cache:
|
|
name: "Save Cache: Yarn"
|
|
paths:
|
|
- ~/.cache/yarn
|
|
key: yarn-v1-{{ .Branch }}-{{ checksum "yarn.lock" }}
|
|
- save_cache:
|
|
name: "Save Cache: Node Modules"
|
|
paths:
|
|
- ./node_modules
|
|
key: node-v1-{{ .Branch }}-{{ checksum "yarn.lock" }}
|
|
- run:
|
|
name: "Run Tests"
|
|
command: ./script/cibuild
|
|
- persist_to_workspace:
|
|
root: .
|
|
paths:
|
|
- .
|
|
|
|
integration-tests:
|
|
docker:
|
|
- image: docker:18.06.0-ce-git
|
|
- image: circleci/postgres:10-alpine-ram
|
|
- image: circleci/redis:4-alpine3.8
|
|
steps:
|
|
- attach_workspace:
|
|
at: .
|
|
- setup_remote_docker:
|
|
version: 18.06.0-ce
|
|
- run:
|
|
name: Remove existing font symlink
|
|
command: rm static/fonts
|
|
- run:
|
|
name: Set up temporary docker network
|
|
command: docker network create atat
|
|
- run:
|
|
name: Build image
|
|
command: docker build . -t atat:latest
|
|
- run:
|
|
name: Start redis
|
|
command: docker run -d --network atat --link redis:redis -p 6379:6379 --name redis circleci/redis:4-alpine3.8
|
|
- run:
|
|
name: Start postgres
|
|
command: docker run -d --network atat --link postgres:postgres -p 5432:5432 --name postgres circleci/postgres:10-alpine-ram
|
|
- run:
|
|
name: Start application container
|
|
command: |
|
|
docker run -d \
|
|
-e DISABLE_CRL_CHECK=true \
|
|
-e PGHOST=postgres \
|
|
-e REDIS_URI=redis://redis:6379 \
|
|
-p 8000:8000 \
|
|
--network atat \
|
|
--name test-atat \
|
|
atat:latest \
|
|
uwsgi \
|
|
--callable app \
|
|
--module app \
|
|
--plugin python3 \
|
|
--virtualenv /opt/atat/atst/.venv \
|
|
--http-socket :8000
|
|
- run:
|
|
name: Wait for containers
|
|
command: sleep 3
|
|
- run:
|
|
name: Create database
|
|
command: docker exec postgres createdb -U postgres atat
|
|
- run:
|
|
name: Apply migrations
|
|
command: docker exec test-atat .venv/bin/python .venv/bin/alembic upgrade head
|
|
- run:
|
|
name: Apply the default permission sets
|
|
command: docker exec test-atat .venv/bin/python script/seed_roles.py
|
|
- run:
|
|
name: Execute Ghost Inspector test suite
|
|
command: |
|
|
docker pull ghostinspector/test-runner-standalone:latest
|
|
docker run \
|
|
-e NGROK_TOKEN=$NGROK_TOKEN \
|
|
-e GI_API_KEY=$GI_API_KEY \
|
|
-e GI_SUITE=$GI_SUITE \
|
|
-e GI_PARAMS_JSON='{}' \
|
|
-e APP_PORT="test-atat:8000" \
|
|
--network atat \
|
|
ghostinspector/test-runner-standalone:latest
|
|
|
|
azure-migration:
|
|
executor: azure-aks/default
|
|
steps:
|
|
- migration_setup:
|
|
container_image: "$AZURE_SERVER_NAME/atat:atat-$CIRCLE_SHA1"
|
|
- azure-aks/update-kubeconfig-with-credentials:
|
|
cluster-name: atat-cluster
|
|
install-kubectl: true
|
|
perform-login: true
|
|
resource-group: atat
|
|
- migration_apply
|
|
|
|
# the azure-acr orb doesn't allow for multiple tags in the
|
|
# build-and-push-image step, so instead we wrap our own job around it and run
|
|
# some additional Docker commands
|
|
azure-build-and-push-image:
|
|
executor: azure-acr/default
|
|
steps:
|
|
- azure-acr/build-and-push-image:
|
|
extra-build-args: "--build-arg CSP=azure"
|
|
login-server-name: "${AZURE_SERVER_NAME}"
|
|
registry-name: pwatat
|
|
repo: atat
|
|
tag: "atat-${CIRCLE_SHA1}"
|
|
- run: "docker tag ${AZURE_SERVER_NAME}/atat:atat-${CIRCLE_SHA1} ${AZURE_SERVER_NAME}/atat:latest"
|
|
- run: "docker push ${AZURE_SERVER_NAME}/atat:latest"
|
|
|
|
workflows:
|
|
version: 2
|
|
run-tests:
|
|
jobs:
|
|
- test
|
|
- integration-tests:
|
|
requires:
|
|
- test
|
|
- azure-build-and-push-image:
|
|
requires:
|
|
- integration-tests
|
|
filters:
|
|
branches:
|
|
only:
|
|
- master
|
|
- azure-migration:
|
|
requires:
|
|
- azure-build-and-push-image
|
|
filters:
|
|
branches:
|
|
only:
|
|
- master
|
|
- azure-aks/update-container-image:
|
|
cluster-name: atat-cluster
|
|
container-image-updates: "atst=${AZURE_SERVER_NAME}/atat:atat-${CIRCLE_SHA1}"
|
|
namespace: atat
|
|
resource-name: deployment.apps/atst
|
|
resource-group: atat
|
|
# uncomment below for debugging
|
|
# show-kubectl-command: true
|
|
requires:
|
|
- azure-migration
|
|
filters:
|
|
branches:
|
|
only:
|
|
- master
|
|
- azure-aks/update-container-image:
|
|
cluster-name: atat-cluster
|
|
container-image-updates: "atst-worker=${AZURE_SERVER_NAME}/atat:atat-${CIRCLE_SHA1}"
|
|
namespace: atat
|
|
resource-name: deployment.apps/atst-worker
|
|
resource-group: atat
|
|
# uncomment below for debugging
|
|
# show-kubectl-command: true
|
|
requires:
|
|
- azure-migration
|
|
filters:
|
|
branches:
|
|
only:
|
|
- master
|
|
- azure-aks/update-container-image:
|
|
cluster-name: atat-cluster
|
|
container-image-updates: "atst-beat=${AZURE_SERVER_NAME}/atat:atat-${CIRCLE_SHA1}"
|
|
namespace: atat
|
|
resource-name: deployment.apps/atst-beat
|
|
resource-group: atat
|
|
# uncomment below for debugging
|
|
# show-kubectl-command: true
|
|
requires:
|
|
- azure-migration
|
|
filters:
|
|
branches:
|
|
only:
|
|
- master
|