Skip to content
This repository was archived by the owner on Oct 28, 2024. It is now read-only.

Commit 545ce95

Browse files
committed
add docker-compose instructions.
1 parent 3757ef2 commit 545ce95

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

Dockerfile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM python:3.11-slim
2+
3+
ENV PYTHONUNBUFFERED 1
4+
5+
COPY requirements.txt requirements.txt
6+
RUN pip install -r requirements.txt
7+
8+
COPY oas.yaml oas.yaml
9+
COPY waitlist waitlist
10+
COPY src src
11+
WORKDIR /src

src/.env.exp api.env.exp

File renamed without changes.

docker-compose.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
version: '3.9'
2+
3+
services:
4+
api:
5+
build: .
6+
command: >
7+
sh -c "python /waitlist/wait_for_postgres.py &&
8+
python manage.py migrate &&
9+
python manage.py runserver 0.0.0.0:8000"
10+
env_file:
11+
- api.env
12+
ports:
13+
- '8000:8000'
14+
depends_on:
15+
- db
16+
17+
db:
18+
image: postgres
19+
environment:
20+
- POSTGRES_PASSWORD=admin
21+
volumes:
22+
- posts-db:/var/lib/postgresql/data
23+
24+
volumes:
25+
posts-db:

waitlist/wait_for_postgres.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import time
2+
3+
import psycopg2
4+
from environs import Env
5+
6+
env = Env()
7+
env.read_env()
8+
9+
10+
def wait_for_postgres_to_come_up():
11+
deadline = time.time() + 120
12+
while time.time() < deadline:
13+
try:
14+
return psycopg2.connect(env.str('DJANGO_DATABASE_URL'))
15+
except psycopg2.OperationalError:
16+
time.sleep(0.5)
17+
raise Exception('Postgres never came up')
18+
19+
20+
if __name__ == '__main__':
21+
wait_for_postgres_to_come_up()
22+

0 commit comments

Comments
 (0)