This demo shows how to deploy a ruby application on ECS with the hoop agent.
Requirements
- ECS cluster
- Hoop Command Line
1. Login at Hoop and generate a client key
shellhoop login HOOP_DSN=$(hoop admin create agent ecs --mode embedded)
2. Create the application demo image
shell# https://github.com/hoophq/ruby-getting-started IMAGE=hoophq/ruby-getting-started
If you want to use your own image for this demo, build and push the image to your own registry. In a production setup use the Elastic Container Registry (ECR) service
Embeeded Agent
This demo requires that the hoop agent command is installed locally within your application. Refer to docker installation to learn how to install it.
1. Create the Task Definition
Before creating the task definition, make sure that you have:
- The Task Role ARN
- The log configuration group configured properly
shellHOOP_CONNECTION=demo-rails AWS_REGION=us-east-2 AWSLOG_GROUP=/ecs/webapp ROLE_ARN=arn:aws:iam::200074533906:role/ecsTaskExecutionRole cat <<EOF > /tmp/$HOOP_CONNECTION.json { "family": "$HOOP_CONNECTION", "containerDefinitions": [ { "name": "$HOOP_CONNECTION", "image": "$IMAGE", "portMappings": [{ "containerPort": 3000, "hostPort": 3000, "protocol": "tcp" }], "entryPoint": ["hoopstart", "--", "bundle", "exec", "puma", "-C", "config/puma.rb"], "environment": [ { "name": "HOOP_DSN", "value": "$HOOP_DSN" }, { "name": "HOOP_CONNECTION", "value": "$HOOP_CONNECTION" } ], "logConfiguration": { "logDriver": "awslogs", "options": { "awslogs-group": "$AWSLOG_GROUP", "awslogs-region": "$AWS_REGION", "awslogs-stream-prefix": "ecs" } } } ], "taskRoleArn": "$ROLE_ARN", "executionRoleArn": "$ROLE_ARN", "networkMode": "awsvpc", "requiresCompatibilities": [ "FARGATE" ], "cpu": "512", "memory": "1024" } EOF
shellaws ecs register-task-definition \ --region=$AWS_REGION \ --cli-input-json file:///tmp/$HOOP_CONNECTION.json
2. Create the Service
Before you proceed, make sure to add:
- The name of your cluster
- The VPC, subnets and the security group for the AWS VPC Configuration
shellCLUSTER=dev VPC_CONFIG="awsvpcConfiguration={subnets=[subnet-xxx01,subnet-xxx02],securityGroups=[sg-xxxx],assignPublicIp=ENABLED}"
shellaws ecs create-service --cluster $CLUSTER \ --service-name=$HOOP_CONNECTION \ --task-definition=$HOOP_CONNECTION \ --region=$AWS_REGION \ --desired-count=2 \ --launch-type FARGATE \ --platform-version LATEST \ --network-configuration=$VPC_CONFIG
Wait for the service to start the web application
3. Connect to the application via console (bash)
Create the connection before proceeding
shellhoop admin create connection $HOOP_CONNECTION
Now can to interact with it
Start a bash console
shellhoop connect $HOOP_CONNECTION
/bin/bash
Start a rails console
shellhoop connect $HOOP_CONNECTION -- -c 'rails console'
/bin/bash -c 'rails console'
Execute one off commands
shellhoop exec $HOOP_CONNECTION -i 'pp Rails.env' -- -c 'rails runner -'
echo -n 'pp Rails.env' | /bin/bash -c 'rails runner -'
Creating a connection that exposes
/bin/bash
as entrypoint could be danger. An alternative is defining directly which command to expose it, like rails console
, or rails runner -