Contexto
The Contexto gem gives you information about the current state of ECS resources and more specifically the internal IP address of specific containers.
Installation
Install via the command line.
$ gem install contexto
Usage
Run the binary to check on the status of a cluster or service.
Cluster
$ contexto -c sandbox
** Contexto Contextualizes **
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Cluster sandbox
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
┃ Name ┃ Status ┃ Instances ┃ Services ┃ RunningTasks ┃ PendingTasks ┃
┣━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━┫
┃ sandbox ┃ ACTIVE ┃ 4 ┃ 3 ┃ 3 ┃ 0 ┃
┗━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┛
Service
$ contexto -c sandbox -s backend-app
** Contexto Contextualizes **
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Cluster sandbox
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
┃ Name ┃ Status ┃ Instances ┃ Services ┃ RunningTasks ┃ PendingTasks ┃
┣━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━┫
┃ sandbox ┃ ACTIVE ┃ 4 ┃ 3 ┃ 3 ┃ 0 ┃
┗━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┛
Service backend-app
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
┃ Name ┃ Status ┃ Desired ┃ Running ┃ Pending ┃
┣━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━┫
┃ backend-app ┃ ACTIVE ┃ 1 ┃ 1 ┃ 0 ┃
┗━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┛
Containers
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
┃ Container ┃ Status ┃ IP ┃
┣━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━┫
┃ sidekiq ┃ RUNNING ┃ 10.2.1.218 ┃
┣━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━╊━━━━━━━━━━━━━━┫
┃ app ┃ RUNNING ┃ 10.2.1.218 ┃
┗━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━┛
SSH
You can also get Contexto to connect via SSH to a Bash shell, Rails console or run a rake task.
Bash shell on container
To connect to a Bash shell in a specific container, specify the cluster, service and container and the --bash flag.
$ contexto -c sandbox -s backend-app -t app --bash
** Contexto Contextualizes **
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
circleci@4e65666c9414:/usr/src/app$
Rails console
To connect to a Rails console, specify the cluster, service and container and the --console flag.
$ contexto -c sandbox -s backend-app -t app --console
** Contexto Contextualizes **
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
I, [2017-03-28T22:36:35.555604 #181] INFO -- sentry: ** [Raven] Raven 2.4.0 ready to catch errors
Loading sandbox environment (Rails 5.0.1)
irb(main):001:0>
Rake tasks
You can run rake tasks. To run the test task you would do:
$ contexto -c sandbox -s backend-app -t sidekiq --rake test
** Contexto Contextualizes **
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Run options: --seed 52808
# Running:
................................................E
Shell on Docker host
You can get an SSH shell on the Docker host too using the --ssh task.
$ contexto -c sandbox -s backend-app -t sidekiq --ssh
** Contexto Contextualizes **
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Last login: Sat Apr 1 18:58:38 2017 from ip-172-31-12-234.ec2.internal
__| __| __|
_| ( \__ \ Amazon ECS-Optimized Amazon Linux AMI 2016.09.f
____|\___|____/
For documentation visit, http://aws.amazon.com/documentation/ecs
9 package(s) needed for security, out of 19 available
Run "sudo yum update" to apply all updates.
[ec2-user@ip-10-2-1-221 ~]$
Development
After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/jamtur01/contexto. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
License
The gem is available as open source under the terms of the MIT License.