GW Treasure Map
- Python Version > 3.6.8
(that you will probably have to
python -m pip install -r requirements.txt
Configuration is handled via environmental variables. At a minimum, the following env vars must be present:
DB_PWD MAIL_PASSWORD RECAPTCHA_PUBLIC_KEY RECAPTCHA_PRIVATE_KEY ZENODO_ACCESS_KEY AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY REDIS_URL ...
See gwtmconfig.py for other configration options and defaults for other values.
Env vars can be set by using export:
export MAIL_PASSWORD=ASecretPassword export RECAPTCHA_PUBLIC_KEY=ASecretPassword2
Or by using a utility like direnv.
Redis is a fast in memory key/value store. It is used in this project for both caching and as a message broker for the Celery task worker (next section).
Running redis with Docker is easy:
docker run --name redis -p6379:6379 -d redis
This will start a server listening on localhost:6379, which is the default value Treasuremap will look for, so no other configuration should be necessary.
Running the Celery worker
In order to run certain code off the main HTTP thread we use celery to be able to run tasks in the background. This requires Redis to be running (previous section).
Once redis is up, we can start a worker:
celery -A src.tasks.celery worker
You can test this is working but using the probability calculator for an event.
The application can be built and deployed as a docker image.
To build and run the docker image locally, use docker compose:
docker compose up
To build the image only, use the build command:
docker build -t gwtm_web .
To deploy an image, it first must be pushed up to the Elastic Cloud Registry endpoint. First, tag the image with the repository name:
docker tag gwtm_web:latest 929887798640.dkr.ecr.us-east-2.amazonaws.com/gwtreasuremap:latest
Then make sure you are logged into the registry:
Finally, push the image:
docker push 929887798640.dkr.ecr.us-east-2.amazonaws.com/gwtreasuremap:latest
Now, log into the Amazon dashboard and navigate to the ECS (Elastic Container Service). Find the Tasks Definitions section and create a new revision of gwtm_web. Leave all the values as they are, unless there is something specific about the deployment that you want to change.
Once the new task is created, go the gwtmweb service definition and edit it, changing the revision of the task to the latest one (the one we just created). After clicking update, the service should pull the new image and deploy the new version of the code.