mirror of
https://github.com/offen/website.git
synced 2024-12-27 23:10:22 +01:00
111 lines
3.5 KiB
YAML
111 lines
3.5 KiB
YAML
version: 2
|
|
|
|
build_preconditions: &build_preconditions
|
|
filters:
|
|
branches:
|
|
only:
|
|
- master
|
|
- development
|
|
|
|
deploy_preconditions: &deploy_preconditions
|
|
requires:
|
|
- build
|
|
filters:
|
|
branches:
|
|
only:
|
|
- master
|
|
- development
|
|
|
|
jobs:
|
|
build:
|
|
docker:
|
|
- image: docker:18-git
|
|
working_directory: ~/offen
|
|
steps:
|
|
- checkout
|
|
- setup_remote_docker
|
|
- restore_cache:
|
|
keys:
|
|
- v1-{{ .Branch }}
|
|
paths:
|
|
- /caches/website.tar
|
|
- run:
|
|
name: Load Docker image layer cache
|
|
command: |
|
|
set +o pipefail
|
|
docker load -i /caches/website.tar | true
|
|
- run:
|
|
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 .
|
|
- run:
|
|
name: Save Docker image layer cache
|
|
command: |
|
|
mkdir -p /caches
|
|
docker save -o /caches/website.tar offen/website
|
|
- save_cache:
|
|
key: v1-{{ .Branch }}-{{ epoch }}
|
|
paths:
|
|
- /caches/website.tar
|
|
- 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_PASS" | docker login --username $DOCKER_USER --password-stdin
|
|
docker push offen/website:$DOCKER_IMAGE_TAG
|
|
|
|
deploy:
|
|
docker:
|
|
- image: circleci/golang:1.13
|
|
working_directory: ~/offen
|
|
steps:
|
|
- checkout
|
|
- 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
|
|
- 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
|
|
else
|
|
echo 'export TARGET_ENVIRONMENT="staging"' >> $BASH_ENV
|
|
echo 'export DOCKER_IMAGE_TAG="latest"' >> $BASH_ENV
|
|
fi
|
|
- run:
|
|
name: Run database migrations
|
|
command: docker run -it offen/offen:offen@sha256:4c0d2d5db9bc749d21ad8659008658bf25318074b7c813b0a694e64816df750d migrate -conn $(aws secretsmanager get-secret-value --secret-id $TARGET_ENVIRONMENT/postgresConnectionString | jq -r '.SecretString')
|
|
- run:
|
|
name: Deploy
|
|
command: |
|
|
cp Dockerrun.aws.json.$TARGET_ENVIRONMENT Dockerrun.aws.json
|
|
eb deploy
|
|
|
|
workflows:
|
|
version: 2
|
|
build_deploy:
|
|
jobs:
|
|
- build:
|
|
<<: *build_preconditions
|
|
- deploy:
|
|
<<: *deploy_preconditions
|