Deployment on Amazon ECS - LibraryOfCongress/scribeAPI GitHub Wiki
Deploy Scribe Web App on Amazon ECS
Security Groups
Create the following security groups:
- beyond-words-load-balancer (HTTP/TCP/80/Anywhere)
- beyond-words-ecs-cluster (All TCP/TCP/0 - 65535/beyond-words-load-balancer)
- beyond-words-mongodb (Custom TCP/TCP/27017/beyond-words-ecs-cluster?)
Centralized Container Logs
Create CloudWatch Log Group named beyond-words-web
, set Expire Events After to something appropriate, for example 1 week.
Create Task Definition
Under ECS, create a task definition with the following settings:
- Task Definition Name: beyond-words-web
- Network Mode: Bridge
Within the Container Definitions section, add a container:
- Container Name: beyond-words-web
- Image: (examples:
tongwang/scribeapi_loc:1.0
or1234566789012.dkr.ecr.us-east-1.amazonaws.com/scribeapi_loc:1.0
) - CPU Units: 1024
- Hard/Soft memory limits (MB): 4000/500
- Port Mappings: 0:80
- Environment Variables:
- RAILS_ENV=production
- MONGOLAB_URI=mongodb://scribe:password@hostname:27017/scribe_loc
- DEVISE_SECRET_TOKEN=
- SECRET_KEY_BASE_TOKEN=
- GOOGLE_ID=
- GOOGLE_SECRET=
- Log driver: awslogs
- awslogs-group: beyond-words-web (the one you just created)
- awslogs-region: us-east-1
- awslogs-stream-prefix: (e.g. beyond-words)
Create an ECS Cluster
Create a Cluster with the following settings:
- Cluster name: beyond-words-web
- EC2 instance type: m4.large
- Number of Instances: 3
- EBS storage (GiB): 22 (default)
- Key pair: your key pair (if you want to ssh into it)
- VPC: (your vpc)
- Subnets: (add all your subnets on different AZs)
- Security group: beyond-words-ecs-cluster
Create a Load Balancer
Select "Application Load Balancer", then click "Continue".
- Name: beyond-words
- Scheme: internet-facing
- Load Balancer Protocol and Port: HTTP 80
- Availability Zones: select all AZs
- Security Group: beyond-words-load-balancer
- Target group: (New target group)
- Advanced health check settings
- Healthy threshold: 3
- Unhealthy threshold: 3
- Timeout: 30 (sec)
- Interval: 120 (sec)
Create Services
Create a Service within the cluster, with the following settings:
- Task Definition: beyond-words-web:1 (1 is the revision number)
- Service Name: beyond-words-web
- Number of tasks: 12
Click next:
- ELB type: Application Load Balancer
- ELB Name: beyond-words (the Application Load Balancer you just created)
- Select a Container: (select the right container
beyond-words-web:0:80
), then click "Add to ELB") - Listener port: 80:HTTP
- Target group name: (the target group you created in your Application Load Balancer)
Now the application can be reached by the DNS name of your load balancer.
Setup MongoDB
Follow Install MongoDB on AWS to install MongoDB. Make sure to use security group beyond-words-mongodb
.
Add the user with the userAdminAnyDatabase
role, and only that role, replacing password with your own:
mongo
use admin
db.addUser( { user: "root",
pwd: "password",
roles: [ "userAdminAnyDatabase" ] } )
Login as root
user, add the user for Scribe app, replacing password with your own:
mongo -u root -p password admin
# switched to db scribe_loc
use scribe_loc
db.addUser( { user: "scribe",
pwd: "password",
roles: [ "readWrite", "dbAdmin" ]
} )
Restart:
sudo service mongod restart
Before load a large set of subjects, create the following indexes in mongodb:
db.subjects.createIndex({subject_set_id: 1, "location.standard": 1, type: 1})
db.subject_sets.createIndex({group_id: 1, key: 1})
Set Up Scribe Project
Inside of a Scribe docker container (docker exec -it <container id> bash
), run the following command:
rake project:load[loc]
rake project:create_lc_indexes
You can also load project content, workflow or subjects only:
rake project:load[loc,content]
rake project:load[loc,workflows]
rake project:load[loc,subjects]
Upgrade
Create a new revision of the task definition, update the Docker image tag. Update the service to use the new revision. Kill the existing tasks.