These are generic npm scripts that you can copy & paste into your
package.json file as-is and get access to convinience scripts to upload and release your Docker images in spectacular, no-downtime, blue-green fashion.
Looking for npm scripts for Docker? Go here!
Don't know how to create your own AWS ECS Cluster? Go here.
Docker Containers for Static or Angular/React/Vue/etc SPA Websites
docker pull duluca/minimal-nginx-web-server
docker pull duluca/minimal-node-web-server
- Cross-Platform: Works on Windows 10 and macOS.
aws:login: Using your AWS credentials, gets the Docker for your ECS Container Repository and configures your Docker CLI instance to point at your private repository.
aws:deploy: Kicks-off the blue-green deployment your already published image.
aws:release: Points Docker to your private ECS repository, publishes your latest build image and then kicks-off deployment.
Configuring Package.json in 2-steps
- A correctly configured AWS ECS Cluster. Instructions are here.
- On your project, first setup npm scripts for Docker and then come back here.
.env file and set
- Install AWS CLI
brew install awscli
choco install awscli
- Log in to AWS CLI with your credentials
- You'll need your Access Key ID and Secret Access Key
- Default region name:
Make sure to update
package.json from when you configured npm scripts for Docker, so that the
imageRepo property has the address of your new ECS repository.
package.json file, under the config property, add three new properties using your own values, as shown below:
Copy & paste these new scripts under the
scripts property in
"aws:login:win": "cross-conf-env aws ecr get-login --no-include-email --region $npm_package_config_awsRegion > dockerLogin.cmd && call dockerLogin.cmd && del dockerLogin.cmd",
"aws:login:mac": "eval $(aws ecr get-login --no-include-email --region $npm_package_config_awsRegion)",
"aws:login": "run-p -cs aws:login:win aws:login:mac",
"aws:deploy": "cross-conf-env docker run --env-file ./.env duluca/ecs-deploy-fargate -c $npm_package_config_awsEcsCluster -n $npm_package_config_awsService -i $npm_package_config_imageRepo:latest -r $npm_package_config_awsRegion --timeout 1000",
"aws:release": "run-s -cs aws:login docker:publish aws:deploy",
Note the duluca/ecs-deploy-fargate blue-green deployment script is a fork of the original silintl/ecs-deploy image with AWS ECS Fargate support with this PR https://github.com/silinternational/ecs-deploy/pull/129 integrated. Once silintl/ecs-deploy merges this change, I recommend using silintl/ecs-deploy for your blue-green deployments.
You're done. Now run your scripts. To build and publish an image you only need to use two of the commands frequently.
npm run docker:debug: [Test], Build, Tag, Run, Tail and launch your app in a browser to test.
npm run aws:release: Configure Docker with AWS, publish your latest image build and release it on ECS.
Be patient! Things won't work right away. AWS is a complicated beast, however once everything is configured correctly, it is an immensely powerful tool. Go through AWS ECS setup instructions here.