Add support for custom domains and auto-deployment

- Docs and config files for setting up custom domain name

- Add deploy_dev job to successful build & test runs on master branch in CI

- Temporarily switch to a specific commit of serverless to address upstream issue:
  https://github.com/serverless/serverless/issues/4957

- Temporarily switch to a specific branch of serverless-domain-manager to address upstream issue:
  https://github.com/amplify-education/serverless-domain-manager/issues/64#issuecomment-370102422

Issue #11
This commit is contained in:
Les Orchard 2018-05-21 16:48:50 -04:00
Родитель 60e9c754ec
Коммит 53d2778c21
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 6DA657B1385DFCAE
6 изменённых файлов: 1734 добавлений и 1162 удалений

Просмотреть файл

@ -17,8 +17,27 @@ jobs:
key: v1-dependencies-{{ checksum "package.json" }} key: v1-dependencies-{{ checksum "package.json" }}
- run: npm run lint - run: npm run lint
- run: npm test - run: npm test
- persist_to_workspace:
root: .
paths:
- ./*
deploy_dev:
docker:
- image: circleci/node:8.11.2@sha256:495a13db597b5306f05ae728489fedb9faa4defbac24ca0e00e8cc1eca95396d
working_directory: ~/repo
steps:
- attach_workspace:
at: .
- run: npm run deploy:master
workflows: workflows:
version: 2 version: 2
test: test_and_deploy:
jobs: jobs:
- test - test
- deploy_dev:
requires:
- test
filters:
branches:
only: master

Просмотреть файл

@ -111,12 +111,26 @@ If you want to remove this stack from AWS and delete everything, run `npm run re
The [Serverless docs on workflow are useful](https://serverless.com/framework/docs/providers/aws/guide/workflow/). The [Serverless docs on workflow are useful](https://serverless.com/framework/docs/providers/aws/guide/workflow/).
### Custom stable domain name for local development
By default, no custom domain name is created. You can use the semi-random domain name serverless offers on deployment and with `serverless info`.
If you want to create a domain name for local development (e.g. `watchdog-proxy-lmorchard.dev.mozaws.net`):
1. Edit your `serverless.local.yml` to contain an enabled `customDomain` section with appropriate details
1. Run `npx serverless create_domain` - this only needs to be done once, to create the new custom domain name in Route53 and an accompanying CloudFront distribution
1. Run `npm run deploy:dev` to update your stack
Read this Serverless Blog post for more details: https://serverless.com/blog/serverless-api-gateway-domain/
## Deployment ## Deployment
### Environment variables ### Environment variables
When using `serverless deploy` to deploy the stack, you can use several environment variables to alter configuration: When using `serverless deploy` to deploy the stack, you can use several environment variables to alter configuration:
- `STAGE` - Stage for building and deploying - e.g. `dev`, `stage`, `production`
- `DOMAIN` - Custom domain config selection for Route 53 and CloudFront distribution - e.g. `local`, `dev`, `stage`, `production`. If omitted, custom domain handling is disabled
- `NODE_ENV` - Use `production` for a more optimized production build, `development` for a development build with more verbose logging and other conveniences - `NODE_ENV` - Use `production` for a more optimized production build, `development` for a development build with more verbose logging and other conveniences
- `GIT_COMMIT` - The value reported by the `__version__` resource as `commit`. If not set, Serverless config will attempt to run the `git` command to discover the current commit. - `GIT_COMMIT` - The value reported by the `__version__` resource as `commit`. If not set, Serverless config will attempt to run the `git` command to discover the current commit.
- `UPSTREAM_SERVICE_URL` - the URL of the production upstream web service (i.e. PhotoDNA) - `UPSTREAM_SERVICE_URL` - the URL of the production upstream web service (i.e. PhotoDNA)

2809
package-lock.json сгенерированный

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -6,6 +6,7 @@
"precommit": "lint-staged && npm run test:js", "precommit": "lint-staged && npm run test:js",
"deploy": "cross-env NODE_ENV=production serverless deploy", "deploy": "cross-env NODE_ENV=production serverless deploy",
"deploy:dev": "cross-env NODE_ENV=development ENABLE_DEV_AUTH=1 serverless deploy", "deploy:dev": "cross-env NODE_ENV=development ENABLE_DEV_AUTH=1 serverless deploy",
"deploy:master": "cross-env STAGE=dev DOMAIN=dev NODE_ENV=development ENABLE_DEV_AUTH=1 UPSTREAM_SERVICE_URL=__MOCK__ UPSTREAM_SERVICE_KEY=__MOCK__ serverless deploy",
"info": "serverless info", "info": "serverless info",
"lint": "npm-run-all lint:*", "lint": "npm-run-all lint:*",
"lint:js": "eslint functions lib test", "lint:js": "eslint functions lib test",
@ -50,8 +51,9 @@
"nsp": "3.2.1", "nsp": "3.2.1",
"onchange": "4.0.0", "onchange": "4.0.0",
"prettier": "1.12.1", "prettier": "1.12.1",
"serverless": "1.27.2", "serverless": "github:serverless/serverless#0001b7e5fe0bc6f2a9e0684e147d183163a05c80",
"serverless-apigw-binary": "0.4.4", "serverless-apigw-binary": "0.4.4",
"serverless-domain-manager": "github:lmorchard/serverless-domain-manager#certificateArn-config",
"serverless-s3-remover": "0.4.1", "serverless-s3-remover": "0.4.1",
"serverless-sqs-alarms-plugin": "0.1.7", "serverless-sqs-alarms-plugin": "0.1.7",
"sinon": "5.0.7" "sinon": "5.0.7"

Просмотреть файл

@ -6,3 +6,14 @@ stage: your-name-here-dev
upstreamService: upstreamService:
url: __MOCK__ url: __MOCK__
key: __MOCK__ key: __MOCK__
# Uncomment and change the following properties to set up a custom domain for
# your own dev stack
customDomain:
enabled: false
# enabled: true
# stage: your-name-here-dev
# domainName: watchdog-proxy-your-name.dev.mozaws.net
# certificateArn: 'arn:aws:acm:us-east-1:927034868273:certificate/61e462bd-410e-48b6-95da-fa5501430d1d'
# basePath: ''
# createRoute53Record: true

Просмотреть файл

@ -3,6 +3,7 @@ service: watchdog-proxy
plugins: plugins:
- serverless-s3-remover - serverless-s3-remover
- serverless-apigw-binary - serverless-apigw-binary
- serverless-domain-manager
custom: custom:
localConfig: ${file(serverless.local.yml)} localConfig: ${file(serverless.local.yml)}
@ -15,6 +16,40 @@ custom:
credentials: ${self:custom.prefix}-credentials credentials: ${self:custom.prefix}-credentials
sqs: ${self:custom.prefix}-messages sqs: ${self:custom.prefix}-messages
contentBucket: ${self:custom.prefix}-content contentBucket: ${self:custom.prefix}-content
# This customDomain stuff is a little complicated to allow switching between
# deployment stages / modes
customDomain: ${self:custom.customDomainVariants.${env:DOMAIN, "local"}}
customDomainDisabled:
enabled: false
customDomainVariants:
local: ${file(serverless.local.yml):customDomain, self:custom.customDomainDisabled}
disabled:
enabled: false
dev:
domainName: ${self:service}.dev.mozaws.net
certificateArn: 'arn:aws:acm:us-east-1:927034868273:certificate/61e462bd-410e-48b6-95da-fa5501430d1d'
basePath: ''
stage: ${self:provider.stage}
createRoute53Record: true
enabled: true
stage:
# TODO: Tweak this so it has the right properties for staging, even if all pulled from env
domainName: ${self:service}-stage.dev.mozaws.net
certificateArn: 'arn:aws:acm:us-east-1:927034868273:certificate/61e462bd-410e-48b6-95da-fa5501430d1d'
basePath: ''
stage: ${self:provider.stage}
createRoute53Record: true
enabled: true
production:
# TODO: Tweak this so it has the right properties for production, even if all pulled from env
domainName: ${self:service}-prod.dev.mozaws.net
certificateArn: 'arn:aws:acm:us-east-1:927034868273:certificate/61e462bd-410e-48b6-95da-fa5501430d1d'
basePath: ''
stage: ${self:provider.stage}
createRoute53Record: true
enabled: true
remover: remover:
buckets: buckets:
- ${self:custom.contentBucket} - ${self:custom.contentBucket}
@ -39,7 +74,7 @@ custom:
provider: provider:
name: aws name: aws
runtime: nodejs8.10 runtime: nodejs8.10
stage: ${self:custom.localConfig.stage, opt:stage, 'dev'} stage: ${env:STAGE, self:custom.localConfig.stage, opt:stage, 'dev'}
region: us-east-1 region: us-east-1
memorySize: 128 memorySize: 128
iamRoleStatements: iamRoleStatements: