Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy release branches to staging ECS environment #4758

Merged
merged 9 commits into from
Nov 5, 2018
54 changes: 54 additions & 0 deletions .circleci/bin/ecs-deploy-feature-branch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

sudo apt-get -y install python3-pip wget
sudo pip3 install awscli

export ENVIRONMENT=feat
export CLUSTER=core
export SERVICE_SUFFIX=$CIRCLE_BRANCH
export SERVICE1=reaction-core
export CONTAINER1=core
export core_CIRCLE_SHA1=$CIRCLE_SHA1

PROPEL_CONFIG_FILE="propel-feat.yaml"
if [ ! -f ${PROPEL_CONFIG_FILE} ]; then
echo "Propel configuration file not found!"
exit 1
fi

if [ -z "${AWS_REGION}" ]; then
export AWS_REGION=us-west-2
fi

ENV_NAME_UPPERCASE=$(echo $ENVIRONMENT | awk '{print toupper($0)}')
AWS_ACCESS_KEY_ID_VAR_NAME=CLOUDFORMATION_${ENV_NAME_UPPERCASE}_AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY_VAR_NAME=CLOUDFORMATION_${ENV_NAME_UPPERCASE}_AWS_SECRET_ACCESS_KEY

if [ "${!AWS_ACCESS_KEY_ID_VAR_NAME}" ]; then
export AWS_ACCESS_KEY_ID=${!AWS_ACCESS_KEY_ID_VAR_NAME}
fi

if [ "${!AWS_SECRET_ACCESS_KEY_VAR_NAME}" ]; then
export AWS_SECRET_ACCESS_KEY=${!AWS_SECRET_ACCESS_KEY_VAR_NAME}
fi

echo Running aws s3 cp s3://${S3_PROPEL_ARTIFACTS_BUCKET}/propel-linux-amd64 ./propel
aws s3 cp s3://${S3_PROPEL_ARTIFACTS_BUCKET}/propel-linux-amd64 ./propel

sudo mv propel /usr/local/bin/propel
sudo chmod +x /usr/local/bin/propel

RELEASE_DESCRIPTION="CircleCI build URL: ${CIRCLE_BUILD_URL}"
propel param copy -f ${PROPEL_CONFIG_FILE} --env $ENVIRONMENT --cluster $CLUSTER --service $SERVICE1 --container $CONTAINER1 --suffix $SERVICE_SUFFIX --overwrite
propel param set ROOT_URL=https://${SERVICE1}-${SERVICE_SUFFIX}.$ENVIRONMENT.reactioncommerce.com/ -f ${PROPEL_CONFIG_FILE} --env $ENVIRONMENT --cluster $CLUSTER --service $SERVICE1 --container $CONTAINER1 --suffix $SERVICE_SUFFIX --overwrite
propel release create --deploy -f ${PROPEL_CONFIG_FILE} --env $ENVIRONMENT --cluster $CLUSTER --descr "${RELEASE_DESCRIPTION}" --service $SERVICE1 --suffix $SERVICE_SUFFIX

export SERVICE2=storefront
export CONTAINER2=storefront
propel param copy -f ${PROPEL_CONFIG_FILE} --env $ENVIRONMENT --cluster $CLUSTER --service $SERVICE2 --container $CONTAINER2 --suffix $SERVICE_SUFFIX --overwrite
propel param set CANONICAL_URL=https://${SERVICE1}-${SERVICE_SUFFIX}.$ENVIRONMENT.reactioncommerce.com -f ${PROPEL_CONFIG_FILE} --env $ENVIRONMENT --cluster $CLUSTER --service $SERVICE2 --container $CONTAINER2 --suffix $SERVICE_SUFFIX --overwrite
propel param set OAUTH2_REDIRECT_URL=https://${SERVICE2}-${SERVICE_SUFFIX}.$ENVIRONMENT.reactioncommerce.com/callback -f ${PROPEL_CONFIG_FILE} --env $ENVIRONMENT --cluster $CLUSTER --service $SERVICE2 --container $CONTAINER2 --suffix $SERVICE_SUFFIX --overwrite
propel param set OAUTH2_IDP_HOST_URL=https://${SERVICE1}-${SERVICE_SUFFIX}.$ENVIRONMENT.reactioncommerce.com -f ${PROPEL_CONFIG_FILE} --env $ENVIRONMENT --cluster $CLUSTER --service $SERVICE2 --container $CONTAINER2 --suffix $SERVICE_SUFFIX --overwrite
propel param set EXTERNAL_GRAPHQL_URL=https://${SERVICE1}-${SERVICE_SUFFIX}.$ENVIRONMENT.reactioncommerce.com/graphql-alpha -f ${PROPEL_CONFIG_FILE} --env $ENVIRONMENT --cluster $CLUSTER --service $SERVICE2 --container $CONTAINER2 --suffix $SERVICE_SUFFIX --overwrite
propel param set INTERNAL_GRAPHQL_URL=https://${SERVICE1}-${SERVICE_SUFFIX}.$ENVIRONMENT.reactioncommerce.com/graphql-alpha -f ${PROPEL_CONFIG_FILE} --env $ENVIRONMENT --cluster $CLUSTER --service $SERVICE2 --container $CONTAINER2 --suffix $SERVICE_SUFFIX --overwrite
propel release create --deploy -f ${PROPEL_CONFIG_FILE} --env $ENVIRONMENT --cluster $CLUSTER --descr "${RELEASE_DESCRIPTION}" --service $SERVICE2 --suffix $SERVICE_SUFFIX
39 changes: 39 additions & 0 deletions .circleci/bin/ecs-deploy-release-branch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

sudo apt-get -y install python3-pip wget
sudo pip3 install awscli

export ENVIRONMENT=staging
export CLUSTER=core
export core_CIRCLE_SHA1=$CIRCLE_SHA1

PROPEL_CONFIG_FILE="propel.yaml"
if [ ! -f ${PROPEL_CONFIG_FILE} ]; then
echo "Propel configuration file not found!"
exit 1
fi

if [ -z "${AWS_REGION}" ]; then
export AWS_REGION=us-west-2
fi

ENV_NAME_UPPERCASE=$(echo $ENVIRONMENT | awk '{print toupper($0)}')
AWS_ACCESS_KEY_ID_VAR_NAME=CLOUDFORMATION_${ENV_NAME_UPPERCASE}_AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY_VAR_NAME=CLOUDFORMATION_${ENV_NAME_UPPERCASE}_AWS_SECRET_ACCESS_KEY

if [ "${!AWS_ACCESS_KEY_ID_VAR_NAME}" ]; then
export AWS_ACCESS_KEY_ID=${!AWS_ACCESS_KEY_ID_VAR_NAME}
fi

if [ "${!AWS_SECRET_ACCESS_KEY_VAR_NAME}" ]; then
export AWS_SECRET_ACCESS_KEY=${!AWS_SECRET_ACCESS_KEY_VAR_NAME}
fi

echo Running aws s3 cp s3://${S3_PROPEL_ARTIFACTS_BUCKET}/propel-linux-amd64 ./propel
aws s3 cp s3://${S3_PROPEL_ARTIFACTS_BUCKET}/propel-linux-amd64 ./propel

sudo mv propel /usr/local/bin/propel
sudo chmod +x /usr/local/bin/propel

RELEASE_DESCRIPTION="CircleCI build URL: ${CIRCLE_BUILD_URL}"
propel release create --deploy --env $ENVIRONMENT --cluster $CLUSTER --descr "${RELEASE_DESCRIPTION}"
64 changes: 0 additions & 64 deletions .circleci/bin/ecs-deploy.sh

This file was deleted.

28 changes: 22 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,24 @@ jobs:
echo "No deploy for forks"
fi

deploy-to-ecs:
deploy-to-ecs-release-branch:
<<: *defaults
steps:
- checkout
- run:
name: Deploy new task definition and update service in ECS
command: |
.circleci/bin/ecs-deploy.sh
.circleci/bin/ecs-deploy-release-branch.sh
no_output_timeout: 30m

deploy-to-ecs-feature-branch:
<<: *defaults
steps:
- checkout
- run:
name: Deploy new task definition and update service in ECS
command: |
.circleci/bin/ecs-deploy-feature-branch.sh
no_output_timeout: 30m

deploy-docs:
Expand Down Expand Up @@ -336,12 +346,18 @@ workflows:
context: reaction-publish-docker
requires:
- docker-build
- deploy-to-ecs:
- deploy-to-ecs-release-branch:
requires:
- docker-push
# filters:
# branches:
# only: /^release-2\.0.\d+$/
filters:
branches:
only: /^release-2.*/
- deploy-to-ecs-feature-branch:
requires:
- docker-push
filters:
branches:
only: /^feat.*/
- deploy-docs:
requires:
- test-unit
Expand Down
11 changes: 11 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
REACTION_EMAIL=me@example.com
REACTION_AUTH=somepassword
REACTION_USER=ReactionAdmin
MONGO_URL=mongodb://mongo:27017/reaction
MONGO_OPLOG_URL=mongodb://mongo:27017/local
ROOT_URL=http://localhost:3000
HYDRA_ADMIN_URL=http://hydra:4445
HYDRA_TOKEN_URL=http://hydra:4444/oauth2/token
HYDRA_OAUTH2_INTROSPECT_URL=http://hydra:4445/oauth2/introspect
OAUTH2_CLIENT_DOMAINS=http://localhost:4000
SKIP_FIXTURES=1
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
.fileStorage/
.vscode
.idea
.env
.env*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an open issue to add a .env file for this repo for local development, and that will involve creating a file named .env.example which will need to be committed (same pattern as in other repos). Can you change this ignore rule so that .env.example will be committed when we add that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

!.env.example
.c9
*.csv
*.dat
Expand Down
33 changes: 0 additions & 33 deletions .reaction/devops/aws/services/service-reaction/propel-staging.yaml

This file was deleted.

6 changes: 0 additions & 6 deletions .reaction/devops/aws/services/service-starterkit/.env

This file was deleted.

This file was deleted.

76 changes: 76 additions & 0 deletions propel-feat.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
services:
- name: reaction-core
certificate_arn: arn:aws:acm:us-west-2:773713188930:certificate/c2979a7a-7b84-43ed-b3a7-24b0256a1b9f
root_domain: staging.reactioncommerce.com
dns_name: reaction-core
desired_task_count: 2
min_task_count: 0
max_task_count: 2
min_healthy_percent: 100
max_percent: 200
alb_listener_port: 80
alb_listener_path: /
alb_health_check_path: /health
task-definition:
name: staging-core
containers:
- name: core
cpu: 500
memory: 1800
port_mappings:
- container_port: 3000
host_port: 3000
image: reactioncommerce/reaction
image_tag: release-2.0.0-rc.5
env_params:
- name: REACTION_AUTH
- name: REACTION_EMAIL
- name: REACTION_USER
- name: MONGO_URL
- name: ROOT_URL
- name: HYDRA_ADMIN_URL
- name: HYDRA_OAUTH2_INTROSPECT_URL
- name: SKIP_FIXTURES
- name: storefront
certificate_arn: arn:aws:acm:us-west-2:773713188930:certificate/c2979a7a-7b84-43ed-b3a7-24b0256a1b9f
root_domain: staging.reactioncommerce.com
dns_name: storefront
desired_task_count: 1
min_task_count: 0
max_task_count: 8
min_healthy_percent: 100
max_percent: 200
alb_listener_port: 80
alb_listener_path: /
alb_health_check_path: /
task-definition:
name: staging-storefront
containers:
- name: storefront
cpu: 500
memory: 1800
port_mappings:
- container_port: 4000
host_port: 4000
image: reactioncommerce/reaction-next-starterkit
image_tag: develop
env_params:
- name: INTERNAL_GRAPHQL_URL
- name: EXTERNAL_GRAPHQL_URL
- name: FAVICON_URL
- name: PLACEHOLDER_IMAGE_URL_GALLERY
- name: PLACEHOLDER_IMAGE_URL_GRID
- name: SEGMENT_ANALYTICS_SKIP_MINIMIZE
- name: SEGMENT_ANALYTICS_WRITE_KEY
- name: KEYCLOAK_REALM
- name: KEYCLOAK_CLIENT_ID
- name: KEYCLOAK_URL
- name: KEYCLOAK_REDIRECT_URI
- name: STRIPE_PUBLIC_API_KEY
- name: OAUTH2_AUTH_URL
- name: OAUTH2_TOKEN_URL
- name: OAUTH2_CLIENT_ID
- name: OAUTH2_CLIENT_SECRET
- name: OAUTH2_REDIRECT_URL
- name: PASSPORT_SESSION_SECRET
- name: CANONICAL_URL
Loading