A set of Dockerfiles and a docker-compose yml file to facilitate the running of the VIP SMS tool.
First, you'll need some tools to get the system built:
- Docker: Docker for Mac is nice; otherwise install both
docker
anddocker-compose
with your favorite package manager - VALID AWS credentials with write permissions to both S3 and SQS
- AWS CLI tool (also available in Homebrew)
In addition to cloning this repository, you'll need to clone the sms-web repository and the sms-worker repository. Make sure these three repositories are checked out in the same parent directory as this repo; it should look similar to this:
$ tree -L 2 ~/src/vip/
~/src/vip
├── sms-compose
│ ├── LICENSE
│ ├── README.md
│ ├── docker-compose.yml
│ └── release
├── sms-web
│ ├── Dockerfile
| ...
│ ├── sms-web.go
│ └── status
├── sms-worker
│ ├── Dockerfile
| ....
│ ├── test_helpers
│ ├── users
│ └── util
Requires docker-compose 1.3 or higher.
Create a .env
file with the following values set appropriately:
ACCESS_KEY_ID
SECRET_ACCESS_KEY
ENVIRONMENT
QUEUE_PREFIX=vip-sms-app
DB_PREFIX=vip-sms-app-users
CIVIC_API_KEY
CIVIC_API_ELECTION_ID
CIVIC_API_OFFICIAL_ONLY
TWILIO_SID
TWILIO_TOKEN
TWILIO_NUMBER
PROCS=24
ROUTINES=4
LOGGLY_TOKEN
NEWRELIC_TOKEN
If you installed awscli
, you can check and create new queues easily.
$ aws sqs list-queues
{
"QueueUrls": [
"https://queue.amazonaws.com/123456789012/data-suite-staging",
"https://queue.amazonaws.com/123456789012/data-suite-staging-fail",
"https://queue.amazonaws.com/123456789012/data-suite-development",
"https://queue.amazonaws.com/123456789012/data-suite-development-fail",
"https://queue.amazonaws.com/123456789012/data-suite-production",
"https://queue.amazonaws.com/123456789012/data-suite-production-fail",
]
}
$ aws sqs create-queue --queue-name productionlike-test
{
"QueueUrl": "https://queue.amazonaws.com/123456789012/productionlike-test"
}
Similarly, if you need to create a bucket, use
aws s3 mb s3://productionlike-test
Build the projects: docker-compose build
.
Then run them: docker-compose up
.
You can simulate a user sending a text message to the SMS tool by
sending a message to the running web app. Check the output of
docker ps
to find the exposed port for the web app and make a POST
request like the following:
curl -X POST -d "From=+15555555555" -d "Body=HELP" -d "AccountSid=AC7..." http://localhost:32775
Be sure to set the same Twilio AccountSid as in the .env file. And use a real phone number so you can receive the message(s).
To run the versions of sms-web and sms-worker that are pushed to
quay.io without having the projects cloned locally, you can use the
docker-compose.yml file in the release
directory.
Create the .env file in the release
directory with the values listed
above and add in DEPLOYED_BY=<your initials>
; then run as usual:
docker-compose up
The deployed containers of SMS Worker and SMS Web come from images pushed to a docker repository (Quay). To deploy a new version of either one, you'll need to build an apporpriately tagged image and push it to the repository.
For example, if you wanted to deploy a new version of SMS Worker, from the SMS Worker directory, you would build and push a new image like so:
$ docker build -t quay.io/votinginfoproject/sms-worker:master .
$ docker push quay.io/votinginfoproject/sms-worker:master
The SMS apps are deployed on a Docker Swarm
cluster. In order to deploy to it, you'll need to set three
environment variables so that your Docker client communicates with the
swarm: DOCKER_HOST
, DOCKER_CERT_PATH
, and DOCKER_TLS_VERIFY
.
DOCKER_HOST
should include the protocoltcp
, and the port. (e.g.:tcp://123.456.789.101:3376
); this will be the IP address of the ec2 instance that is the swarm master.DOCKER_CERT_PATH
is a path to a directory containing the certificates for authentication with that server.DOCKER_TLS_VERIFY
should be1
.
With those Docker environment variables set, cd
into the "release"
directory.
Create a .env
file with the production values.
Any usual docker
or docker-compose
commands will run in the
context of the Swarm.
To deploy a new version of SMS Worker, for example, you need to pull the image to the Swarm, then replace the existing containers with new ones:
$ docker pull quay.io/votinginfoproject/sms-worker:master
$ docker-compose up --no-deps -d worker
Replace "worker" with "web" above for a SMS Web deploy.
To confirm the dpeloyment was success, you can text an address to GO VOTE (468683) and if you get a response back the SMS app is up and running.
Don't forget to unset DOCKER_HOST
and DOCKER_CERT_PATH
when you
finish (or close the terminal).