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
|
|
|
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-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:
|
2019-10-10 10:00:02 +02:00
|
|
|
- /caches/website.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-10-10 10:00:02 +02:00
|
|
|
docker load -i /caches/website.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"
|
2019-09-29 16:08:41 +02:00
|
|
|
export ROBOTS_FILE="robots.txt.production"
|
2019-09-14 14:55:04 +02:00
|
|
|
else
|
|
|
|
export SITEURL="https://staging.offen.dev"
|
|
|
|
export DOCKER_IMAGE_TAG="latest"
|
2019-09-29 16:08:41 +02:00
|
|
|
export ROBOTS_FILE="robots.txt.staging"
|
2019-09-14 14:55:04 +02:00
|
|
|
fi
|
2019-10-10 10:00:02 +02:00
|
|
|
docker build --build-arg siteurl=$SITEURL --build-arg robots=$ROBOTS_FILE -t offen/website:$DOCKER_IMAGE_TAG -f build/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
|
2019-10-10 10:00:02 +02:00
|
|
|
docker save -o /caches/website.tar offen/website
|
2019-09-09 20:01:22 +02:00
|
|
|
- save_cache:
|
|
|
|
key: v1-{{ .Branch }}-{{ epoch }}
|
|
|
|
paths:
|
2019-10-10 10:00:02 +02:00
|
|
|
- /caches/website.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-12-16 17:06:32 +01:00
|
|
|
echo "$DOCKER_ACCESSTOKEN" | docker login --username $DOCKER_USER --password-stdin
|
2019-10-10 10:05:19 +02:00
|
|
|
docker push offen/website:$DOCKER_IMAGE_TAG
|
2019-07-25 16:14:37 +02:00
|
|
|
|
2019-09-09 20:01:22 +02:00
|
|
|
deploy:
|
|
|
|
docker:
|
2019-10-10 09:34:43 +02:00
|
|
|
- image: circleci/golang:1.13
|
2019-10-10 09:25:16 +02:00
|
|
|
working_directory: ~/offen
|
2019-09-09 20:01:22 +02:00
|
|
|
steps:
|
|
|
|
- checkout
|
2019-10-10 09:25:16 +02:00
|
|
|
- setup_remote_docker
|
|
|
|
- run:
|
|
|
|
name: Install deployment dependencies
|
|
|
|
command: |
|
|
|
|
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
|
|
|
|
sudo pip install awsebcli --upgrade
|
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
|
2019-10-10 10:13:46 +02:00
|
|
|
echo 'export DOCKER_IMAGE_TAG="stable"' >> $BASH_ENV
|
2019-09-14 14:30:00 +02:00
|
|
|
else
|
|
|
|
echo 'export TARGET_ENVIRONMENT="staging"' >> $BASH_ENV
|
2019-10-10 10:13:46 +02:00
|
|
|
echo 'export DOCKER_IMAGE_TAG="latest"' >> $BASH_ENV
|
2019-09-14 14:30:00 +02:00
|
|
|
fi
|
2019-09-09 20:01:22 +02:00
|
|
|
- run:
|
2019-09-13 20:21:23 +02:00
|
|
|
name: Run database migrations
|
2019-11-03 22:59:32 +01:00
|
|
|
command: docker run -it offen/offen:offen@sha256:4c0d2d5db9bc749d21ad8659008658bf25318074b7c813b0a694e64816df750d 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-10-08 19:46:02 +02:00
|
|
|
build_deploy:
|
2019-04-11 15:48:36 +02:00
|
|
|
jobs:
|
2019-09-09 20:01:22 +02:00
|
|
|
- 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
|