Skip to content

Instantly share code, notes, and snippets.

View nathanpeck's full-sized avatar
📦
Bin packing containers onto hosts

Nathan Peck nathanpeck

📦
Bin packing containers onto hosts
View GitHub Profile
run:
docker-compose up -d
build:
docker-compose build client
docker-compose up --no-deps -d client
test:
docker-compose build client
docker-compose build test
version: "3"
networks:
chat:
services:
# Launch the Redis used for syncing messages between copies of the client app
redis:
image: redis
networks:
- chat
$ time docker-compose build client
Building client
Step 1/9 : FROM node:9 AS build
---> 814364d36f69
Step 2/9 : WORKDIR /srv
---> Using cache
---> 031927a1a5ab
Step 3/9 : ADD package.json .
---> Using cache
---> 9cd95ef4d4ce
FROM node:9 AS build
WORKDIR /srv
ADD package.json .
RUN npm install
FROM node:9-slim
COPY --from=build /srv .
ADD . .
EXPOSE 3000
CMD ["node", "index.js"]
# A role for the service so it can access the tables
ChatServiceRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service: "ecs-tasks.amazonaws.com"
Action: ['sts:AssumeRole']
messages = await this.dynamoDB.query({
TableName: this.tableName,
KeyConditionExpression: 'room = :room',
Limit: 20,
ExpressionAttributeValues: {
':room': where.room
},
ExclusiveStartKey: where.message ? where : undefined,
ScanIndexForward: false // Always return newest items first
}).promise();
<div id="content" class="content">
<room-details></room-details>
<messages></messages>
<typing></typing>
</div>
var store = {
data: {
typing: []
},
addTyper: function(typer) {
this.data.typing.push(typer);
}
};
# Enable autoscaling for the service
ScalableTarget:
Type: AWS::ApplicationAutoScaling::ScalableTarget
DependsOn: Service
Properties:
ServiceNamespace: 'ecs'
ScalableDimension: 'ecs:service:DesiredCount'
ResourceId:
Fn::Join:
- '/'
TaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
Family: !Ref 'ServiceName'
Cpu: !Ref 'ContainerCpu'
Memory: !Ref 'ContainerMemory'
NetworkMode: awsvpc
RequiresCompatibilities:
- FARGATE
ExecutionRoleArn: