From 0b82cf2f655d0672f89640739602243efd61d0b4 Mon Sep 17 00:00:00 2001 From: wudongze Date: Mon, 15 Jul 2024 15:40:09 +0800 Subject: [PATCH] install postgres --- Dockerfile | 4 ++++ app/app/calc.py | 2 +- app/app/tests.py | 3 ++- docker-compose.yml | 21 +++++++++++++++++++++ requirements.txt | 1 + 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index b2e65af..572cc10 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,11 +12,15 @@ EXPOSE 8000 ARG DEV=false RUN python -m venv /py && \ /py/bin/pip install --upgrade pip && \ + apk add --update --no-cache postgresql-client && \ + apk add --update --no-cache --virtual .tmp-build-deps \ + build-base postgresql-dev musl-dev && \ /py/bin/pip install -r /tmp/requirements.txt && \ if [ $DEV = "true" ]; \ then /py/bin/pip install -r /tmp/requirements.dev.txt ; \ fi && \ rm -rf /tmp && \ + apk del .tmp-build-deps && \ adduser \ --disabled-password \ --no-create-home \ diff --git a/app/app/calc.py b/app/app/calc.py index 5af971e..c222731 100644 --- a/app/app/calc.py +++ b/app/app/calc.py @@ -4,4 +4,4 @@ def add(x,y): return x + y def subtract(x,y): - return x - y \ No newline at end of file + return x - y diff --git a/app/app/tests.py b/app/app/tests.py index d682a4e..f9b899a 100644 --- a/app/app/tests.py +++ b/app/app/tests.py @@ -12,4 +12,5 @@ def test_add_numbers(self): def test_subtract_numbers(self): res = calc.subtract(10, 5) - self.assertEqual(res, 5) \ No newline at end of file + self.assertEqual(res, 5) + \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 13624eb..1ccb2bd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,3 +12,24 @@ services: - ./app:/app command: > sh -c "python manage.py runserver 0.0.0.0:8000" + environment: + - DB_HOST=db + - DB_NAME=devdb + - DB_USER=devuser + - DB_PASSWORD=changeme + depends_on: + - db + + db: + image: postgres:13-alpine + volumes: + - dev-db-data:/var/lib/postgresql/data + environment: + - POSTGRES_DB=devdb + - POSTGRES_USER=devuser + - POSTGRES_PASSWORD=changeme + + +volumes: + dev-db-data: + diff --git a/requirements.txt b/requirements.txt index 4c9c02a..8138010 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ Django>=3.2.4,<3.3 djangorestframework>=3.12.4,<3.13 +psycopg2>=2.8.6,<2.9