-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
95 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
# Deployment | ||
## Deployment | ||
|
||
ebmbot is deployed on smallweb1 and is managed by systemd. | ||
Deployment uses `dokku` and requires the environment variables defined in `dotenv-sample`. | ||
It is deployed to our `dokku3` instance. | ||
|
||
* To deploy: `fab deploy` | ||
* To view logs: `sudo journalctl -u app.ebmbot.* -b -f` | ||
It runs as a single dokku app named `bennettbot`, with multiple processes for each | ||
service (bot, dispatcher and webserver) as defined in the `Procfile`. | ||
|
||
## Creating the Slack app | ||
(This should only need to be done once). | ||
|
@@ -71,10 +72,27 @@ events. We need to add some more: | |
If you update any scopes after installing the app, you'll need to reinstall it (slack will | ||
usually prompt for this). | ||
|
||
### Set environment variables | ||
## Configuring the dokku app | ||
(This should only need to be done once). | ||
|
||
### Create app | ||
|
||
On dokku3, as the `dokku` user: | ||
|
||
```sh | ||
dokku$ dokku apps:create bennettbot | ||
``` | ||
|
||
Copy `dotenv-sample` to `.env` and update with relevant environment variables. See also | ||
comments in `ebmbot/settings.py`. | ||
### Create storage for sqlite db and logs | ||
```sh | ||
dokku$ mkdir -p /var/lib/dokku/data/storage/bennettbot/logs | ||
dokku$ chown dokku:dokku /var/lib/dokku/data/storage/bennettbot | ||
dokku$ dokku storage:mount bennettbot /var/lib/dokku/data/storage/bennettbot/:/storage | ||
``` | ||
|
||
### Configure app environment variables | ||
|
||
See also comments in `ebmbot/settings.py`. | ||
|
||
The following slack environment variables need to be set: | ||
- `SLACK_LOGS_CHANNEL`: channel where scheduled job notifications will be posted | ||
|
@@ -98,3 +116,68 @@ project information. | |
This is the path to credentials for the [email protected] | ||
service account: | ||
- `GCP_CREDENTIALS_PATH` | ||
|
||
The path for logs; set this to a directory in the dokku mounted storage so the logs | ||
persist outside of the containers. | ||
- LOGS_DIR | ||
|
||
The path for the sqlite db file; set this to a file in the dokku mounted storage | ||
- DB_PATH | ||
|
||
Set each env varible with: | ||
```sh | ||
dokku$ dokku config:set bennettbot ENVVAR_NAME=value | ||
``` | ||
|
||
e.g. | ||
```sh | ||
dokku$ dokku config:set bennettbot LOG_DIR=/storage/logs | ||
dokku$ dokku config:set bennettbot LOG_DIR=/storage/bennettbod. | ||
``` | ||
|
||
### Configure network | ||
|
||
(If creating the app, deploy first before doing this step.) | ||
|
||
|
||
``` | ||
dokku network:create bennettbot-network | ||
dokku network:set bennettbot attach-post-deploy bennettbot-network | ||
dokku config:set bennettbot WEBSERVER_URL=bennettbot.webserver:9999 | ||
``` | ||
https://dokku.com/docs/networking/network/#attaching-an-app-to-a-network | ||
https://www.joseferben.com/posts/running-multiple-services-on-dokku/ | ||
|
||
### Map port 9999 for incoming github hooks | ||
https://dokku.com/docs/networking/port-management/ | ||
|
||
dokku ports:add bennettbot http:9999:9999 | ||
|
||
|
||
## Deployment | ||
|
||
Merges to the `main` branch will trigger an auto-deploy via GitHub actions. | ||
|
||
Note this deploys by building the prod docker image (see `docker/docker-compose.yaml`) and using the dokku [git:from-image](https://dokku.com/docs/deployment/methods/git/#initializing-an-app-repository-from-a-docker-image) command. | ||
|
||
|
||
### Manually deploying | ||
|
||
To deploy manually: | ||
|
||
``` | ||
# build prod image locally | ||
just docker/build prod | ||
# tag image and push | ||
docker tag bennettbot ghcr.io/ebmdatalab/bennettbot:latest | ||
docker push ghcr.io/ebmdatalab/bennettbot:latest | ||
# get the SHA for the latest image | ||
SHA=$(docker inspect --format='{{index .RepoDigests 0}}' ghcr.io/ebmdatalab/bennettbot:latest) | ||
``` | ||
|
||
On dokku3, as the `dokku` user: | ||
``` | ||
dokku$ dokku git:from-image bennettbot <SHA> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
bot: python -m ebmbot.bot | ||
dispatcher: python -m ebmbot.dispatcher | ||
web: python -m ebmbot.webserver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters