Mirror this repo into new repo
- Replace all "default-node-proj-template" with your new project name (i.e. media-services)
- Change PROJECT_URL in urlPaths.js to be the desired URL (i.e. Project: media-services, PROJECT_URL: media)
- Change the resources in health.acl.json to match the URL above
- Update the variables in .env.example with the staging values in LastPass
cp .env.example .env
- Generate a KEY
openssl rand -base64 32
- Use KEY from previous step to encrypt file
openssl aes-256-cbc -e -in .env -out ./.circleci/env/{staging|demo|prod} -k {KEY}
openssl aes-256-cbc -e -in .env -out ./.circleci/env/staging -k jk49aleo4p1-dksf
- Save key in Last pass
This project is set up for CircleCI, more will need to be done to set up CI/CD if you use another service or if you want to customize the circleCI config.
To set up CircleCI, first add environment variables in CircleCI console:
AWS_ACCESS_KEY_ID
, (AWS Console for deployment-nonprod user - entry AWS Access Key Automated Deployment)
AWS_SECRET_ACCESS_KEY
, (Same as above)
AWS_ACCOUNT_ID
, (AWS Console, in upper right corner)
DATADOG_API_KEY
(DataDog => Integrations => API)
CIPHER_KEY_STAGING
(Created in Update Environment variable file
steps above)
CIPHER_KEY_DEMO
(Created in Update Environment variable file
steps above)
CIPHER_KEY_PRODUCTION
(Created in Update Environment variable file
steps above)
- Open project settings (direct link: https://circleci.com/gh/Twiage/default-node-proj-template/edit#hooks)
- Paste
https://circleci.com/gh/Twiage/api/edit#hooks
into "Slack Webhook URL" - Enable "Override room"
- Type "circleci" as room name
- Click Save
- Click & Test Hook
- Open Slack circleci channel and make sure you see "Hello from CircleCI" message.
Only need to do once in staging
- Create Repository with new project name in ECS
- Run
yarn deploy:patch
- Create Staging Log Group - Naming convention is {project name}-{env}
- Wait until service deploys in staging => delete the new service created in staging ECS
Create Fargate Service with new project name in ECS for each environment
- Choose family, should be the name of the service
- Service name should match project name given above.
- Choose number of tasks
- Choose VPC for appropriate env
- Choose the 2 private subnets
- Security group should be {ENV}_application-instances
- Disable Auto assign public IP
- Application Load balancer {ENV}-api-load-balancer
- Click Add to load balancer
- Listener port 443:HTTPS
- Create new target group with name {project name}-{env}
- Target group protocol should be HTTP
- Path pattern should be the same as health check
- Evaluation order should increment the evaluation order table below
- Confirm health check URL. (ie for the media-services project => /media/health)
- Uncheck Enable service discovery integration
- Next => Next => Create
If you need to add any additional rules to route to our new container
- Go to {ENV}-api-load-balancer => Listener tab => View/edit rules
- Add new rule, If : put in new path (or path pattern, ie /project-name*)
- Then: put forward to your new target group (named {project name}-{env})
!!!NOTE DO NOT COMMIT UNENCRYPTED ENVIRONMENT FILES!!!
- Install nvm
macOS or Ubuntu using bash
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
or if you are using zsh
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | zsh
- Install Node
nvm install 10.11 && nvm use 10.11
- Install yarn globally
https://yarnpkg.com/lang/en/docs/install/#mac-stable
need homebrew if you're on MacOS & don't already have it
Change your platform if needed.
We use ESlint as a linter
To run linter:
yarn lint
To automatically fix some lint errors:
yarn lint:fix
We are using Jest for unit testing.
We put out tests at the same directory with testing code.
__system-tests__
- directory name for system tests
__unit-tests__
- directory name for unit tests
yarn
- install dependencies
yarn test:unit
yarn test:unit -- ./src/modules/notifications/mediators/__unit-tests__/NotificationMediator.test.js
you can also run unit tests in watch mode
yarn test:unit:watch
For mac users
You need to install watchman using brew
brew update && brew install watchman
We use AVA as a testing framework for system tests.
yarn
yarn test:system
WebStorm users can use run configuration for both unit and system tests. Run configurations are already in repo
Create and encrypt environment variables:
Copy example and edit .env file
.env file should contain new line at the end
cp .env.example .env
Generate a KEY
openssl rand -base64 32
Use KEY from previous step to encrypt file
openssl aes-256-cbc -e -in .env -out ./.circleci/env/{stage|demo|prod} -k {KEY}
Add key to CircleCi as [default-node-proj-template]CIPHER_KEY_{STAGING|DEMO|PRODUCTION}
!!!NOTE DO NOT COMMIT UNENCRYPTED ENVIRONMENT FILES!!!
- Use npm to manage versions
npm version patch
Follow Semiver. See npm version --help
for more information. This will update version in package.json, and add a tag in git.
- Push tag
git push --follow-tags
CircleCI will trigger deployment by this tag. We use workflows from CircleCI. This will automatically deploy to staging.
- Go to Workflows
- Choose your tagged build.
- Choose demo_release or production_release job
- Expand
ecs-cli compose
section. Task definition will be in the console outputINFO[0000] Using ECS task definition TaskDefinition="default-node-proj-template:203"
- Change
taskDefinition
in JSON above - Click “Test” and you’re done.
Go to this link: https://console.aws.amazon.com/lambda/home?region=us-east-1#/functions Click into the lambda_demo_deploy function. At the top of the screen, there is a dropdown - choose that and Configure test events. Overwrite the text in there with the JSON below and give it a name (e.g. MessageProcessor). You can create one of these for each component to deploy.
{
"taskDefinition": "default-node-proj-template:288",
"service": "default-node-proj-template"
}
TBD
- Login to AWS CLI using your account
aws configure
Region: us-east-1
Default Output: json
- List task definitions and update service
aws ecs list-task-definitions
aws ecs update-service --cluster {staging-app-servers|demo-app-servers|production-ECSCluster-5JKJVZ4KUU75} --service default-node-proj-template --task-definition {revision}` - update service, where revision is ARN like `default-node-proj-template:{REVISION_NUMBER}
- Verify service has been updated
aws ecs describe-services --cluster {staging-app-servers|demo-app-servers|production-ECSCluster-5JKJVZ4KUU75} --services default-node-proj-template:{REVISION_NUMBER}
check status
and taskDefinition
There should be 2 object in deployment
section.
Install awscli
aws configure
- configure AWS
eval $(aws ecr get-login --region us-east-1)
- login to Docker registry inside AWS (ECR)
Now you are able to list images and pull it
aws ecr list-images --repository-name default-node-proj-template
- to list images
docker pull 363852383723.dkr.ecr.us-east-1.amazonaws.com/default-node-proj-template:{TAG}
- to pull particular image