Skip to content

Chapter IV: Contain Your Enthusiasm

To self-host 3515.games in a way that doesn't make you want to tear your hair out, you'll need to stuff it and all its dependencies into a nice little package that you can run on any operating system with next-to-zero effort.

The kind of package in question? It's called a container.

Prerequsites

Before proceeding, make sure you have the following:

Building the Image

Warning

Make sure Docker is running before proceeding.

There should be a Dockerfile at the root of your project. If it's somehow missing, create one with the following contents:

FROM python:3.11.1

ENV POETRY_HOME=/opt/poetry
ENV PATH="${PATH}:${POETRY_HOME}/bin:/root/.local/bin"

COPY . /app

WORKDIR /app

RUN curl -sSL https://cli.doppler.com/install.sh | sh && \
    curl -sSL https://install.python-poetry.org | python - --version $(cat .poetry-version) && \
    poetry install --only main

WORKDIR /app/bot

CMD ["doppler", "run", "--", "poetry", "run", "python", "main.py"]

There should also be a .dockerignore file at the root of your project. If that's somehow missing, create one with the following contents:

*

!bot/
!gps.py
!COPYING
!.poetry-version
!poetry.lock
!pyproject.toml
docker build . -t 3515.games:latest

This will build a Docker image of 3515.games. Think of it as an executable that starts 3515.games whenever you run it. You can take this image to any machine with Docker installed and it will always work in exactly the same way, every single time.

Try it out:

docker run --rm -it -e DOPPLER_TOKEN="$(doppler configs tokens create docker --max-age 1m --plain)" 3515.games:latest
docker run --rm -it -e DOPPLER_TOKEN=(doppler configs tokens create docker --max-age 1m --plain) 3515.games:latest

Pretty cool, right?

Now it's time for the final step: taking this image and deploying it to the cloud.