Skip to content

add simple Dockerfile and docker-compose file #1

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM python:3.12
WORKDIR /app


# install python dependencies

COPY requirements.txt requirements.txt

RUN pip3 install --no-cache-dir -r requirements.txt

COPY lobby/ lobby/

## add finalization arguments

HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 CMD curl -f -X GET http://localhost:1717/health

EXPOSE 1717

CMD [ "python3", "lobby/main.py", "prod"]
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,30 @@
# The Lob(b)y Server Everybody Asked For!

More to come here...


## Deploy with docker compose

You need a running docker service and docker compose installed


Then build the image:

```bash
docker build -t obpf-lobby .
```

Now you can run the docker compose file.

```bash
docker compose up -d
```
Note: the port is 1717 to proxy it through something like nginx.


Other common docker compose comands include:
```bash
docker compose down # stop all containers
docker compose ps # get details about running containers
docker compose logs -f # see the logs of all containers (-f watches them)
```
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "3.8"
name: "obpf-lobby"
services:
flask:
container_name: obpf-lobby
image: obpf-lobby:latest
ports:
- "1717:1717"
volumes:
- "./files/:/app/files/"
15 changes: 14 additions & 1 deletion lobby/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os.path
import sys
import time
import typing
from dataclasses import dataclass
Expand Down Expand Up @@ -81,6 +82,11 @@ def from_id(cls, id_: str) -> Self:
return cls(id_, user.username)


@app.route("/health", methods=["GET"])
def health_check():
return create_ok_response({})


@app.route("/lobbies", methods=["GET"])
def lobby_list():
@dataclass
Expand Down Expand Up @@ -198,4 +204,11 @@ class RegisterRequest(JsonSchemaMixin):
return create_response(HTTPStatus.CREATED, {"id": new_user.id})


app.run(debug=True)
# this runs, when you launch this file manually, otherwise flask imports this file and ignores this
if __name__ == "__main__":
print(sys.argv)
if len(sys.argv) >= 2 and sys.argv[1] == "prod":
from waitress import serve
serve(app, host="0.0.0.0", port=1717)
else:
app.run(debug=True)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ setuptools==69.0.3
six==1.16.0
SQLAlchemy==2.0.25
typing_extensions==4.9.0
waitress==2.1.2
Werkzeug==3.0.1