From e0c6433e5fbd74988d45fc78eb293adf9ef347e2 Mon Sep 17 00:00:00 2001 From: Frederik Ring Date: Sat, 14 Sep 2019 14:30:00 +0200 Subject: [PATCH] introduce staging environment --- .circleci/config.yml | 33 ++++++++++++++++++++++++++------- .elasticbeanstalk/config.yml | 5 +++-- Dockerrun.aws.json.staging | 31 +++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 Dockerrun.aws.json.staging diff --git a/.circleci/config.yml b/.circleci/config.yml index 0ebea19..61e5294 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -9,14 +9,18 @@ build_preconditions: &build_preconditions - packages filters: branches: - only: /^master$/ + only: + - master + - development deploy_preconditions: &deploy_preconditions requires: - build filters: branches: - only: /^master$/ + only: + - master + - development jobs: server: @@ -152,13 +156,20 @@ jobs: build: docker: - image: docker:18-git - environment: - SITEURL: https://www.offen.dev - DOCKER_IMAGE_TAG: stable working_directory: ~/offen steps: - checkout - setup_remote_docker + - run: + name: Define target environment + command: | + if [ "${CIRCLE_BRANCH}" == "master" ]; then + echo 'export SITEURL="https://www.offen.dev"' >> $BASH_ENV + echo 'export DOCKER_IMAGE_TAG="stable"' >> $BASH_ENV + else + echo 'export SITEURL="https://staging.offen.dev"' >> $BASH_ENV + echo 'export DOCKER_IMAGE_TAG="latest"' >> $BASH_ENV + fi - restore_cache: keys: - v1-{{ .Branch }} @@ -200,6 +211,14 @@ jobs: - image: circleci/golang:1.12 steps: - checkout + - 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 - run: name: Install deployment dependencies command: | @@ -211,11 +230,11 @@ jobs: name: Run database migrations working_directory: ~/offen/server command: | - go run cmd/offen/main.go migrate -conn $(aws secretsmanager get-secret-value --secret-id production/postgresConnectionString | jq -r '.SecretString') + go run cmd/offen/main.go migrate -conn $(aws secretsmanager get-secret-value --secret-id $TARGET_ENVIRONMENT/postgresConnectionString | jq -r '.SecretString') - run: name: Deploy command: | - cp Dockerrun.aws.json.production Dockerrun.aws.json + cp Dockerrun.aws.json.$TARGET_ENVIRONMENT Dockerrun.aws.json eb deploy workflows: diff --git a/.elasticbeanstalk/config.yml b/.elasticbeanstalk/config.yml index 38d4188..222b50e 100644 --- a/.elasticbeanstalk/config.yml +++ b/.elasticbeanstalk/config.yml @@ -1,9 +1,10 @@ branch-defaults: - local-proxy: - environment: production master: environment: production group_suffix: null + development: + environment: staging + group_suffix: null global: application_name: offen branch: null diff --git a/Dockerrun.aws.json.staging b/Dockerrun.aws.json.staging new file mode 100644 index 0000000..725c3de --- /dev/null +++ b/Dockerrun.aws.json.staging @@ -0,0 +1,31 @@ +{ + "AWSEBDockerrunVersion": 2, + "volumes": [], + "containerDefinitions": [ + { + "name": "proxy", + "image": "offen/proxy:latest", + "essential": true, + "memory": 128, + "portMappings": [ + { + "hostPort": 80, + "containerPort": 80 + } + ], + "dependsOn": [ + { + "containerName": "server", + "condition": "START" + } + ], + "links": ["server"] + }, + { + "name": "server", + "image": "offen/server:latest", + "essential": true, + "memory": 256 + } + ] +}