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:
|
|
|
|
- /caches/proxy.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
|
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-09-29 16:08:41 +02:00
|
|
|
docker build --build-arg siteurl=$SITEURL --build-arg robots=$ROBOTS_FILE -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
|
|
|
|
- save_cache:
|
|
|
|
key: v1-{{ .Branch }}-{{ epoch }}
|
|
|
|
paths:
|
2019-09-11 20:37:18 +02:00
|
|
|
- /caches/proxy.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/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
|
|
|
|
command: |
|
2019-10-08 19:46:02 +02:00
|
|
|
echo "TBD"
|
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
|