Skip to content

Commit

Permalink
set up parameter store for sensitive env vars and add versioning to d…
Browse files Browse the repository at this point in the history
…emo images
  • Loading branch information
sharkySharks committed Apr 10, 2019
1 parent c3da586 commit 07e51ba
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 18 deletions.
19 changes: 14 additions & 5 deletions .codebuild/buildspec.deploy.demo.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
# buildspec for deploying latest changes to main development branch
version: 0.2
env:
parameter-store:
BRAINTREE_TOKEN: "/pwa/BRAINTREE_TOKEN"
MAGENTO_BACKEND_URL: "/pwa/MAGENTO_BACKEND_URL"
phases:
install:
commands:
- echo install step...
pre_build:
commands:
- echo logging in to AWS ECR...
- $(aws ecr get-login --no-include-email --region us-east-1)
- echo copying env vars to env file
- sed -i "s%MAGENTO_BACKEND_URL=redacted%MAGENTO_BACKEND_URL=${MAGENTO_BACKEND_URL}%g" ./docker/.env.docker.prod
- sed -i "s/BRAINTREE_TOKEN=redacted/BRAINTREE_TOKEN=${BRAINTREE_TOKEN}/g" ./docker/.env.docker.prod
- VERSION=$CODEBUILD_RESOLVED_SOURCE_VERSION
- echo VERSION=$VERSION
build:
commands:
- echo build Docker image on `date`
- docker build -f Dockerfile.prod -t pwa-demo:latest .
- docker tag pwa-demo:latest 276375911640.dkr.ecr.us-east-1.amazonaws.com/pwa-demo
- docker tag pwa-demo:latest 276375911640.dkr.ecr.us-east-1.amazonaws.com/pwa-demo:latest
- docker tag pwa-demo:latest 276375911640.dkr.ecr.us-east-1.amazonaws.com/pwa-demo:$VERSION
post_build:
commands:
- echo build Docker image complete `date`
- echo push latest Docker images to ECR...
- docker push 276375911640.dkr.ecr.us-east-1.amazonaws.com/pwa-demo
- docker push 276375911640.dkr.ecr.us-east-1.amazonaws.com/pwa-demo:latest
- docker push 276375911640.dkr.ecr.us-east-1.amazonaws.com/pwa-demo:$VERSION
- sed -i "s/:latest/:${VERSION}/g" Dockerrun.aws.json
artifacts:
files:
- Dockerrun.aws.json
7 changes: 7 additions & 0 deletions .codebuild/buildspec.pr.build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
version: 0.2
env:
parameter-store:
BRAINTREE_TOKEN: "/pwa/BRAINTREE_TOKEN"
MAGENTO_BACKEND_URL: "/pwa/MAGENTO_BACKEND_URL"
phases:
pre_build:
commands:
Expand All @@ -7,6 +11,9 @@ phases:
- echo getting PR ID... PR_ID_TAG = $PR_ID_TAG
- echo logging in to AWS ECR...
- $(aws ecr get-login --no-include-email --region us-east-1)
- echo copying env vars to env file
- sed -i "s%MAGENTO_BACKEND_URL=redacted%MAGENTO_BACKEND_URL=${MAGENTO_BACKEND_URL}%g" ./docker/.env.docker.prod
- sed -i "s/BRAINTREE_TOKEN=redacted/BRAINTREE_TOKEN=${BRAINTREE_TOKEN}/g" ./docker/.env.docker.prod
build:
commands:
- echo build Docker image on `date` for github branch $CODEBUILD_SOURCE_VERSION
Expand Down
20 changes: 20 additions & 0 deletions .codebuild/buildspec.pr.test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
version: 0.2
env:
parameter-store:
BRAINTREE_TOKEN: "/pwa/BRAINTREE_TOKEN"
MAGENTO_BACKEND_URL: "/pwa/MAGENTO_BACKEND_URL"
DANGER_GITHUB_API_TOKEN: "/pwa/DANGER_GITHUB_API_TOKEN"
BUNDLESIZE_GITHUB_TOKEN: "/pwa/BUNDLESIZE_GITHUB_TOKEN"
COVERALLS_REPO_TOKEN: "/pwa/COVERALLS_REPO_TOKEN"
phases:
install:
commands:
Expand All @@ -8,6 +15,19 @@ phases:
- echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
- apt-get update -y
- apt-get install -y yarn
pre_build:
commands:
- echo setting environment variables for CI test check services for Coveralls, BundleSize...
- COVERALLS_SERVICE_NAME=codebuild
- CI=true
- CI_PULL_REQUEST=$(echo $CODEBUILD_SOURCE_VERSION | cut -d'/' -f 2)
- CI_PULL_REQUEST_NUMBER=${CI_PULL_REQUEST}
- CI_REPO_OWNER=magento-research
- CI_REPO_NAME=pwa-studio
- CI_COMMIT_SHA=${CODEBUILD_RESOLVED_SOURCE_VERSION}
- echo copying env vars needed for build to env file...
- sed -i "s%MAGENTO_BACKEND_URL=redacted%MAGENTO_BACKEND_URL=${MAGENTO_BACKEND_URL}%g" ./docker/.env.docker.prod
- sed -i "s/BRAINTREE_TOKEN=redacted/BRAINTREE_TOKEN=${BRAINTREE_TOKEN}/g" ./docker/.env.docker.prod
build:
commands:
- echo running pr-checks script `date`
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ services:
restart: unless-stopped

pwa:
hostname: ${PWA_STUDIO_HOST}
hostname: ${PWA_STUDIO_PUBLIC_PATH}
# build pwa using the Dockerfile from the PWD
build:
context: .
dockerfile: Dockerfile.dev
args:
HOST: ${PWA_STUDIO_HOST}
HOST: ${PWA_STUDIO_PUBLIC_PATH}
ENVFILEPATH: ${ENVFILEPATH}
# list of directories and files on the host system to volume mount into the container
# changes made to files in the container and on the host file system are mapped to one another
Expand All @@ -42,7 +42,7 @@ services:
- nginx-proxy
environment:
# environment variables consumed by the nginx-proxy service
VIRTUAL_HOST: ${PWA_STUDIO_HOST}
VIRTUAL_HOST: ${PWA_STUDIO_PUBLIC_PATH}
VIRTUAL_PORT: ${PWA_STUDIO_PORTS_DEVELOPMENT}
expose:
- ${PWA_STUDIO_PORTS_DEVELOPMENT}
2 changes: 1 addition & 1 deletion docker/.env.docker.dev
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
###############################################################################

PWA_STUDIO_HOST=pwa-docker.localhost
PWA_STUDIO_PUBLIC_PATH=pwa-docker.localhost
PWA_STUDIO_PORTS_DEVELOPMENT=8080
ENABLE_SERVICE_WORKER_DEBUGGING=0
PWA_STUDIO_HOT_RELOAD_WITH_POLLING=0
Expand Down
8 changes: 4 additions & 4 deletions docker/.env.docker.prod
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

NODE_ENV=production
PORT=8080
PWA_STUDIO_HOST=localhost
# magento enterprise edition - in production mode
MAGENTO_BACKEND_URL=https://m231-pwa-ent-1.testsonfire.com/
PWA_STUDIO_PUBLIC_PATH=localhost
# magento graphql backend set to production mode
MAGENTO_BACKEND_URL=redacted
MAGENTO_BUILDPACK_PROVIDE_SECURE_HOST=0
UPWARD_JS_UPWARD_PATH=venia-upward.yml
UPWARD_JS_BIND_LOCAL=1
UPWARD_JS_LOG_URL=1
BRAINTREE_TOKEN=sandbox_8yrzsvtm_s2bg8fs563crhqzk
BRAINTREE_TOKEN=redacted
2 changes: 1 addition & 1 deletion docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ After `docker/run-docker` is executed from the root of the repository, the defau

## Configure a custom domain

The domain is configurable. Just set `PWA_STUDIO_HOST` key to the new domain under `docker/.env.docker`, or pass a custom .env file with the `PWA_STUDIO_HOST` key set. All required fields can be found in `docker/.env.docker`. See how to pass the custom .env file below.
The domain is configurable. Just set `PWA_STUDIO_PUBLIC_PATH` key to the new domain under `docker/.env.docker`, or pass a custom .env file with the `PWA_STUDIO_PUBLIC_PATH` key set. All required fields can be found in `docker/.env.docker`. See how to pass the custom .env file below.

## Pass custom .env file configuration through cli args (optional)

Expand Down
2 changes: 1 addition & 1 deletion docker/run-docker
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ env_setup () {
echo "ENVFILEPATH=$CONFIG_ENV_FILE" >> $ENVFILE
cat $ENVFILE
. $ENVFILE
DOMAIN=$PWA_STUDIO_HOST
DOMAIN=$PWA_STUDIO_PUBLIC_PATH
}

create_certificate () {
Expand Down
2 changes: 1 addition & 1 deletion packages/pwa-buildpack/src/WebpackTools/PWADevServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const PWADevServer = {
debug('configure() invoked', config);
PWADevServer.validateConfig('.configure(config)', config);
const devServerConfig = {
public: process.env.PWA_STUDIO_HOST || '',
public: process.env.PWA_STUDIO_PUBLIC_PATH || '',
contentBase: false, // UpwardPlugin serves static files
compress: true,
hot: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/venia-concept/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"venia": "./bin/venia.js"
},
"scripts": {
"build": "yarn run clean && yarn run build:esm && yarn run build:prod",
"build": "yarn run clean && yarn run build:esm && yarn run validate-queries && yarn run build:prod",
"build:analyze": "yarn run clean && mkdir dist && yarn run validate-queries && yarn run build:stats",
"build:dev": "echo 'Skipping venia-concept build...'",
"build:esm": "BABEL_ENV=development babel src --out-dir esm --root-mode 'upward' --source-maps --copy-files",
Expand Down
2 changes: 1 addition & 1 deletion pwa-devdocs/_drafts/docker-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

## Configure a custom domain

The domain is configurable. Just set `PWA_STUDIO_HOST` key to the new domain under `docker/.env.docker`, or pass a custom .env file with the `PWA_STUDIO_HOST` key set. All required fields can be found in `docker/.env.docker`. See how to pass the custom .env file below.
The domain is configurable. Just set `PWA_STUDIO_PUBLIC_PATH` key to the new domain under `docker/.env.docker`, or pass a custom .env file with the `PWA_STUDIO_PUBLIC_PATH` key set. All required fields can be found in `docker/.env.docker`. See how to pass the custom .env file below.

## Pass custom .env file configuration through cli args (optional)

Expand Down

0 comments on commit 07e51ba

Please sign in to comment.