Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tested and verified a method for pushing the bot onto heroku using docker. #473

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ ENV/
env.bak/
venv.bak/
environment
environment.environment

# Spyder project settings
.spyderproject
Expand Down
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ RUN apt-get update
RUN apt-get install -y git apt-utils sqlite3
RUN DEBIAN_FRONTEND="noninteractive" apt-get install -y libcairo2-dev libgirepository1.0-dev libpango1.0-dev pkg-config python3-dev gir1.2-pango-1.0 python3.8-venv libpython3.8-dev libjpeg-dev zlib1g-dev python3-pip
RUN python3.8 -m pip install poetry

COPY ./poetry.lock ./poetry.lock
COPY ./pyproject.toml ./pyproject.toml

RUN ls
COPY ./ ./
RUN python3.8 -m poetry install

COPY . .

ENTRYPOINT ["/TLE/run.sh"]

RUN chmod +x /TLE && /TLE/run.sh
1 change: 1 addition & 0 deletions ProcFile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
worker: bash run.sh
6 changes: 6 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: "3.8"

services:
corona-discord-bot:
build: ./
env_file: .env
44 changes: 44 additions & 0 deletions heroku-docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# How to push docker-image and deploy on Heroku
## Reason to do it
Deploying docker image via Heroku is a faster method than deploying the whole project on Heroku and requires less effort.

## Prior Knowledge
- Deploy the bot on Discord.

## Create Environment file
- Create a copy of file `environment.template` and name it `.env` file.
- Replace `xxxxxxxxx.xxxxxxxxx` with your credentials.

## Build Docker Image
Follow the steps written in the `Docker.md` file or use the alternative method listed below.
```bash
docker-compose up --build -d
```

To check if your docker image is running or not:
```bash
docker-compose logs -f
```
this will print the log
press `Ctrl+C` to get out of it

run `docker ps` or docker images to get the name of docker image, which will look like this.
```
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
123123 <docker-image name_1> latest <docker-image name>
```
- Open Heroku now and create an app or use heroku cli for it.
```bash
heroku create <heroku app-name>
```
- Push the docker image onto heroku
```bash
heroku container:push <docker-image name> -a <heroku app name>
```

- Release the docker image
```bash
heroku container:release <docker-image name> -a <heroku app name>
```

- Open heroku dashboard, then open the Resources tab and turn on the worker.
7 changes: 7 additions & 0 deletions heroku.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
build:
docker:
worker: Dockerfile
setup:
addons:
- plan: heroku-postgresql
as: DATABASE
1 change: 0 additions & 1 deletion run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ while true; do
git pull
poetry install
FONTCONFIG_FILE=$PWD/extra/fonts.conf poetry run python -m tle

(( $? != 42 )) && break

echo '==================================================================='
Expand Down