Documentation: https://as10896.github.io/codepraise-clone-notifier-python
Source Code: https://github.com/as10896/codepraise-clone-notifier-python
Daily clone report notifier for codepraise-app-python and codepraise-api-python, based on Heroku Scheduler.
Make sure you have the latest version of Docker 🐳 installed on your local machine.
Placing secret values in files is a common pattern to provide sensitive configuration to an application. A secret file follows the same principal as a .env
file except it only contains a single value and the file name is used as the key.
A secret file will look like the following:
/var/run/database_password
:
super_secret_database_password
Here we create secret files under the secret directories (config/secrets/<env>/
) and place secret values into the files.
You can also set up environment variables directly.
The variables you set in this way would take precedence over those loaded from a secret file.
For more info, check the pydantic official document.
- Create an AWS account and an IAM user (Ref).
- Create
AWS_ACCESS_KEY_ID
andAWS_SECRET_ACCESS_KEY
underconfig/secrets/<env>/
with the generated credentials (or just setting environment variablesAWS_ACCESS_KEY_ID
andAWS_SECRET_ACCESS_KEY
). - Select a region where FIFO Queues are available (e.g.
us-east-1
, see here for more info), then creatingAWS_REGION
underconfig/secrets/<env>/
with the region name (or just setting the environment variableAWS_REGION
). - Create a FIFO Amazon SQS queue (Ref).
- Notice that the name of a FIFO queue must end with the
.fifo
suffix.
- Notice that the name of a FIFO queue must end with the
- Create
REPORT_QUEUE
underconfig/secrets/<env>/
with the created queue's name (or just setting the environment variableREPORT_QUEUE
).
- Follow this tutorial to create a Slack App and get your Webhook URL.
- Create
SLACK_WEBHOOK_URL
underconfig/secrets/<env>/
with the webhook url (or just setting the environment variableSLACK_WEBHOOK_URL
).
You can use the notifier easily with Docker Compose.
Before that, make sure you have all the configurations set up as mentioned before.
For convenience, you can use a .env
file with all the necessary variables configured as follows:
export AWS_ACCESS_KEY_ID=<aws credentials>
export AWS_SECRET_ACCESS_KEY=<aws credentials>
export AWS_REGION=<aws credentials>
export CLONE_QUEUE=<aws sqs queue>
export SLACK_WEBHOOK_URL=<slack webhook url>
Then source
the configuration file:
source .env
Notice that it is not recommended to export
all these credentials directly in the shell since these will be logged into shell history if not inserted through secure input.
Don't do that especially when you're using a shared device that might be accessed by multiple users.
docker compose run --rm worker # send daily clone reports based on development configurations
ENV=production docker compose run --rm worker # send daily clone reports based on production configurations
docker compose run --rm console # run console
After execution, the clone report will be sent to your Slack channel.
Here we use Invoke as our task management tool.
You can use the container's bash to test these commands.
docker compose run --rm bash
inv -l # show all tasks
inv [task] -h # show task help message
inv console -e [env] # run application console (ipython)
inv worker -e [env] # execute the scheduled worker
inv quality.style # examine coding style with flake8
inv quality.metric # measure code metric with radon
inv quality.all # run all quality tasks (style + metric)
inv quality.reformat # reformat your code using isort and the black coding style
inv quality.typecheck # check type with mypy
inv quality # same as `inv quality.all`