2
0
mirror of https://github.com/offen/website.git synced 2024-11-22 17:10:29 +01:00
website/.circleci/config.yml

111 lines
3.5 KiB
YAML
Raw Normal View History

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/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
docker load -i /caches/website.tar | true
- run:
2019-09-09 20:01:22 +02:00
name: Build application Docker image
command: |
if [ "${CIRCLE_BRANCH}" == "master" ]; then
export SITEURL="https://www.offen.dev"
export DOCKER_IMAGE_TAG="stable"
export ROBOTS_FILE="robots.txt.production"
else
export SITEURL="https://staging.offen.dev"
export DOCKER_IMAGE_TAG="latest"
export ROBOTS_FILE="robots.txt.staging"
fi
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
docker save -o /caches/website.tar offen/website
2019-09-09 20:01:22 +02:00
- save_cache:
key: v1-{{ .Branch }}-{{ epoch }}
paths:
- /caches/website.tar
2019-09-09 20:01:22 +02:00
- deploy:
name: Push application Docker image
command: |
if [ "${CIRCLE_BRANCH}" == "master" ]; then
export DOCKER_IMAGE_TAG="stable"
else
export DOCKER_IMAGE_TAG="latest"
fi
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
echo 'export DOCKER_IMAGE_TAG="stable"' >> $BASH_ENV
2019-09-14 14:30:00 +02:00
else
echo 'export TARGET_ENVIRONMENT="staging"' >> $BASH_ENV
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