2019-04-10 18:17:24 +02:00
|
|
|
version: 2
|
2019-04-11 15:48:36 +02:00
|
|
|
|
2019-09-09 20:01:22 +02:00
|
|
|
build_preconditions: &build_preconditions
|
2019-07-05 19:54:54 +02:00
|
|
|
requires:
|
|
|
|
- server
|
|
|
|
- vault
|
|
|
|
- script
|
|
|
|
- auditorium
|
|
|
|
- packages
|
|
|
|
filters:
|
|
|
|
branches:
|
2019-09-14 14:30:00 +02:00
|
|
|
only:
|
|
|
|
- master
|
|
|
|
- development
|
2019-07-05 19:54:54 +02:00
|
|
|
|
2019-09-09 20:01:22 +02:00
|
|
|
deploy_preconditions: &deploy_preconditions
|
|
|
|
requires:
|
|
|
|
- build
|
2019-07-26 13:26:14 +02:00
|
|
|
filters:
|
|
|
|
branches:
|
2019-09-14 14:30:00 +02:00
|
|
|
only:
|
|
|
|
- master
|
|
|
|
- development
|
2019-07-26 13:26:14 +02:00
|
|
|
|
2019-04-10 18:17:24 +02:00
|
|
|
jobs:
|
2019-04-11 15:48:36 +02:00
|
|
|
server:
|
2019-04-10 18:17:24 +02:00
|
|
|
docker:
|
|
|
|
- image: circleci/golang:1.12
|
2019-04-12 09:04:31 +02:00
|
|
|
environment:
|
2019-09-11 12:44:51 +02:00
|
|
|
POSTGRES_CONNECTION_STRING: postgres://circle:test@localhost:5432/circle_test?sslmode=disable
|
|
|
|
PORT: 8080
|
|
|
|
EVENT_RETENTION_PERIOD: 4464h
|
|
|
|
COOKIE_EXCHANGE_SECRET: VswgMshC4mPDfey8o+yScg==
|
2019-04-12 09:04:31 +02:00
|
|
|
- image: circleci/postgres:11.2-alpine
|
|
|
|
environment:
|
|
|
|
- POSTGRES_USER=circle
|
|
|
|
- POSTGRES_PASSWORD=test
|
2019-04-11 15:48:36 +02:00
|
|
|
working_directory: ~/offen/server
|
2019-04-10 18:17:24 +02:00
|
|
|
steps:
|
2019-04-11 15:48:36 +02:00
|
|
|
- checkout:
|
|
|
|
path: ~/offen
|
2019-04-10 18:17:24 +02:00
|
|
|
- restore_cache:
|
2019-04-11 20:19:57 +02:00
|
|
|
key: offen-server-{{ checksum "go.mod" }}
|
2019-04-10 18:17:24 +02:00
|
|
|
- run:
|
|
|
|
name: Download modules
|
|
|
|
command: go mod download
|
|
|
|
- save_cache:
|
|
|
|
paths:
|
|
|
|
- /go/pkg/mod
|
2019-04-11 20:19:57 +02:00
|
|
|
key: offen-server-{{ checksum "go.mod" }}
|
2019-04-20 01:37:26 +02:00
|
|
|
- run:
|
|
|
|
name: Waiting for Postgres to be ready
|
|
|
|
command: |
|
|
|
|
for i in `seq 1 10`;
|
|
|
|
do
|
|
|
|
nc -z localhost 5432 && echo Success && exit 0
|
|
|
|
echo -n .
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
echo Failed waiting for Postgres && exit 1
|
2019-04-10 18:17:24 +02:00
|
|
|
- run:
|
|
|
|
name: Run tests
|
2019-07-13 22:04:12 +02:00
|
|
|
command: |
|
|
|
|
cp ~/offen/bootstrap.yml .
|
|
|
|
make test-ci
|
2019-04-11 15:48:36 +02:00
|
|
|
|
2019-04-20 04:50:49 +02:00
|
|
|
vault:
|
|
|
|
docker:
|
2019-04-20 17:06:06 +02:00
|
|
|
- image: circleci/node:10-browsers
|
2019-04-20 04:50:49 +02:00
|
|
|
working_directory: ~/offen/vault
|
|
|
|
steps:
|
|
|
|
- checkout:
|
|
|
|
path: ~/offen
|
|
|
|
- restore_cache:
|
|
|
|
key: offen-vault-{{ checksum "package.json" }}
|
|
|
|
- run:
|
|
|
|
name: Install dependencies
|
|
|
|
command: npm install
|
|
|
|
- save_cache:
|
|
|
|
paths:
|
|
|
|
- ~/offen/vault/node_modules
|
|
|
|
key: offen-vault-{{ checksum "package.json" }}
|
|
|
|
- run:
|
|
|
|
name: Run tests
|
2019-04-27 04:35:53 +02:00
|
|
|
command: npm test
|
2019-04-20 04:50:49 +02:00
|
|
|
|
2019-05-10 12:54:39 +02:00
|
|
|
script:
|
|
|
|
docker:
|
|
|
|
- image: circleci/node:10-browsers
|
|
|
|
working_directory: ~/offen/script
|
|
|
|
steps:
|
|
|
|
- checkout:
|
|
|
|
path: ~/offen
|
|
|
|
- restore_cache:
|
|
|
|
key: offen-script-{{ checksum "package.json" }}
|
2019-06-07 15:56:57 +02:00
|
|
|
- run:
|
|
|
|
name: Install lsof
|
|
|
|
command: sudo apt-get install lsof
|
2019-05-10 12:54:39 +02:00
|
|
|
- run:
|
|
|
|
name: Install dependencies
|
|
|
|
command: npm install
|
|
|
|
- save_cache:
|
|
|
|
paths:
|
|
|
|
- ~/offen/script/node_modules
|
|
|
|
key: offen-script-{{ checksum "package.json" }}
|
|
|
|
- run:
|
|
|
|
name: Run tests
|
|
|
|
command: npm test
|
|
|
|
|
2019-05-21 16:58:40 +02:00
|
|
|
auditorium:
|
|
|
|
docker:
|
|
|
|
- image: circleci/node:10-browsers
|
|
|
|
working_directory: ~/offen/auditorium
|
|
|
|
steps:
|
|
|
|
- checkout:
|
|
|
|
path: ~/offen
|
|
|
|
- restore_cache:
|
|
|
|
key: offen-auditorium-{{ checksum "package.json" }}
|
2019-07-07 13:21:20 +02:00
|
|
|
- run:
|
|
|
|
name: Install lsof
|
|
|
|
command: sudo apt-get install lsof
|
2019-05-21 16:58:40 +02:00
|
|
|
- run:
|
|
|
|
name: Install dependencies
|
|
|
|
command: npm install
|
|
|
|
- save_cache:
|
|
|
|
paths:
|
|
|
|
- ~/offen/auditorium/node_modules
|
|
|
|
key: offen-auditorium-{{ checksum "package.json" }}
|
|
|
|
- run:
|
|
|
|
name: Run tests
|
|
|
|
command: npm test
|
|
|
|
|
2019-05-23 16:36:21 +02:00
|
|
|
packages:
|
|
|
|
docker:
|
|
|
|
- image: circleci/node:10-browsers
|
|
|
|
working_directory: ~/offen/packages
|
|
|
|
steps:
|
|
|
|
- checkout:
|
|
|
|
path: ~/offen
|
|
|
|
- restore_cache:
|
|
|
|
key: offen-packages-{{ checksum "package.json" }}
|
2019-06-07 15:01:39 +02:00
|
|
|
- run:
|
|
|
|
name: Install lsof
|
|
|
|
command: sudo apt-get install lsof
|
2019-05-23 16:36:21 +02:00
|
|
|
- run:
|
|
|
|
name: Install dependencies
|
|
|
|
command: npm install
|
|
|
|
- save_cache:
|
|
|
|
paths:
|
|
|
|
- ~/offen/packages/node_modules
|
|
|
|
key: offen-packages-{{ checksum "package.json" }}
|
|
|
|
- run:
|
|
|
|
name: Run tests
|
|
|
|
command: npm test
|
|
|
|
|
2019-09-09 20:01:22 +02:00
|
|
|
build:
|
2019-07-25 16:14:37 +02:00
|
|
|
docker:
|
2019-09-09 20:01:22 +02:00
|
|
|
- image: docker:18-git
|
|
|
|
working_directory: ~/offen
|
2019-07-25 16:14:37 +02:00
|
|
|
steps:
|
2019-09-09 20:01:22 +02:00
|
|
|
- checkout
|
|
|
|
- setup_remote_docker
|
2019-07-25 16:14:37 +02:00
|
|
|
- restore_cache:
|
2019-09-09 20:01:22 +02:00
|
|
|
keys:
|
|
|
|
- v1-{{ .Branch }}
|
|
|
|
paths:
|
|
|
|
- /caches/proxy.tar
|
|
|
|
- /caches/server.tar
|
2019-07-25 16:14:37 +02:00
|
|
|
- run:
|
2019-09-09 20:01:22 +02:00
|
|
|
name: Load Docker image layer cache
|
2019-07-25 16:14:37 +02:00
|
|
|
command: |
|
2019-09-09 20:01:22 +02:00
|
|
|
set +o pipefail
|
2019-09-11 13:54:22 +02:00
|
|
|
docker load -i /caches/proxy.tar | true
|
|
|
|
docker load -i /caches/server.tar | true
|
2019-08-30 12:33:00 +02:00
|
|
|
- run:
|
2019-09-09 20:01:22 +02:00
|
|
|
name: Build application Docker image
|
2019-08-30 12:33:00 +02:00
|
|
|
command: |
|
2019-09-14 14:55:04 +02:00
|
|
|
if [ "${CIRCLE_BRANCH}" == "master" ]; then
|
|
|
|
export SITEURL="https://www.offen.dev"
|
|
|
|
export DOCKER_IMAGE_TAG="stable"
|
|
|
|
else
|
|
|
|
export SITEURL="https://staging.offen.dev"
|
|
|
|
export DOCKER_IMAGE_TAG="latest"
|
|
|
|
fi
|
2019-09-12 13:28:52 +02:00
|
|
|
docker build -t offen/server:$DOCKER_IMAGE_TAG -f build/server/Dockerfile .
|
|
|
|
docker build --build-arg siteurl=$SITEURL -t offen/proxy:$DOCKER_IMAGE_TAG -f build/proxy/Dockerfile .
|
2019-07-25 16:14:37 +02:00
|
|
|
- run:
|
2019-09-09 20:01:22 +02:00
|
|
|
name: Save Docker image layer cache
|
2019-07-25 16:14:37 +02:00
|
|
|
command: |
|
2019-09-09 20:01:22 +02:00
|
|
|
mkdir -p /caches
|
|
|
|
docker save -o /caches/proxy.tar offen/proxy
|
|
|
|
docker save -o /caches/server.tar offen/server
|
|
|
|
- save_cache:
|
|
|
|
key: v1-{{ .Branch }}-{{ epoch }}
|
|
|
|
paths:
|
2019-09-11 20:37:18 +02:00
|
|
|
- /caches/proxy.tar
|
|
|
|
- /caches/server.tar
|
2019-09-09 20:01:22 +02:00
|
|
|
- deploy:
|
|
|
|
name: Push application Docker image
|
|
|
|
command: |
|
2019-09-14 14:55:04 +02:00
|
|
|
if [ "${CIRCLE_BRANCH}" == "master" ]; then
|
|
|
|
export DOCKER_IMAGE_TAG="stable"
|
|
|
|
else
|
|
|
|
export DOCKER_IMAGE_TAG="latest"
|
|
|
|
fi
|
2019-09-09 20:01:22 +02:00
|
|
|
echo "$DOCKER_PASS" | docker login --username $DOCKER_USER --password-stdin
|
2019-09-11 13:27:15 +02:00
|
|
|
docker push offen/server:$DOCKER_IMAGE_TAG
|
|
|
|
docker push offen/proxy:$DOCKER_IMAGE_TAG
|
2019-07-25 16:14:37 +02:00
|
|
|
|
2019-09-09 20:01:22 +02:00
|
|
|
deploy:
|
|
|
|
working_directory: ~/offen
|
|
|
|
docker:
|
2019-09-13 20:21:23 +02:00
|
|
|
- image: circleci/golang:1.12
|
2019-09-09 20:01:22 +02:00
|
|
|
steps:
|
|
|
|
- checkout
|
2019-09-14 14:30:00 +02:00
|
|
|
- run:
|
|
|
|
name: Define target environment
|
|
|
|
command: |
|
|
|
|
if [ "${CIRCLE_BRANCH}" == "master" ]; then
|
|
|
|
echo 'export TARGET_ENVIRONMENT="production"' >> $BASH_ENV
|
|
|
|
else
|
|
|
|
echo 'export TARGET_ENVIRONMENT="staging"' >> $BASH_ENV
|
|
|
|
fi
|
2019-09-09 20:01:22 +02:00
|
|
|
- run:
|
2019-09-13 20:21:23 +02:00
|
|
|
name: Install deployment dependencies
|
2019-09-09 20:01:22 +02:00
|
|
|
command: |
|
2019-09-13 20:21:23 +02:00
|
|
|
sudo apt-get update && sudo apt-get install -qq -y python-pip libpython-dev
|
|
|
|
curl -O https://bootstrap.pypa.io/get-pip.py && sudo python get-pip.py
|
|
|
|
sudo pip install -q awscli --upgrade
|
2019-09-09 20:01:22 +02:00
|
|
|
sudo pip install awsebcli --upgrade
|
|
|
|
- run:
|
2019-09-13 20:21:23 +02:00
|
|
|
name: Run database migrations
|
|
|
|
working_directory: ~/offen/server
|
|
|
|
command: |
|
2019-09-14 14:30:00 +02:00
|
|
|
go run cmd/offen/main.go migrate -conn $(aws secretsmanager get-secret-value --secret-id $TARGET_ENVIRONMENT/postgresConnectionString | jq -r '.SecretString')
|
2019-09-13 20:21:23 +02:00
|
|
|
- run:
|
|
|
|
name: Deploy
|
2019-09-11 12:44:51 +02:00
|
|
|
command: |
|
2019-09-14 14:30:00 +02:00
|
|
|
cp Dockerrun.aws.json.$TARGET_ENVIRONMENT Dockerrun.aws.json
|
2019-09-11 12:44:51 +02:00
|
|
|
eb deploy
|
2019-07-25 16:14:37 +02:00
|
|
|
|
2019-04-11 15:48:36 +02:00
|
|
|
workflows:
|
|
|
|
version: 2
|
2019-06-28 15:02:48 +02:00
|
|
|
test_build_deploy:
|
2019-04-11 15:48:36 +02:00
|
|
|
jobs:
|
2019-09-09 20:01:22 +02:00
|
|
|
- server
|
|
|
|
- vault
|
|
|
|
- script
|
|
|
|
- auditorium
|
|
|
|
- packages
|
|
|
|
- build:
|
2019-07-26 13:26:14 +02:00
|
|
|
<<: *build_preconditions
|
2019-09-09 20:01:22 +02:00
|
|
|
- deploy:
|
2019-07-25 16:14:37 +02:00
|
|
|
<<: *deploy_preconditions
|