Skip to content

Commit

Permalink
Added PostreSQL adaptor.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemVasylchuck committed Jul 24, 2023
1 parent 77261ca commit f94f243
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions .idea/recipe-app-api.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 32 additions & 28 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
FROM python:3.9-alpine3.13
LABEL maintainer="[email protected]"

ENV PYTHONUNBUFFERED 1

COPY ./requirements.txt /tmp/requirements.txt
COPY ./requirements.dev.txt /tmp/requirements.dev.txt
COPY ./app /app
WORKDIR /app
EXPOSE 8000

ARG DEV=false
RUN python -m venv /py && \
/py/bin/pip install --upgrade pip && \
/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 && \
adduser \
--disabled-password \
--no-create-home \
django-user

ENV PATH="/py/bin:$PATH"

USER django-user

FROM python:3.9-alpine3.13
LABEL maintainer="[email protected]"

ENV PYTHONUNBUFFERED 1

COPY ./requirements.txt /tmp/requirements.txt
COPY ./requirements.dev.txt /tmp/requirements.dev.txt
COPY ./app /app
WORKDIR /app
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 \
django-user

ENV PATH="/py/bin:$PATH"

USER django-user

13 changes: 13 additions & 0 deletions app/app/calc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""
Calculator functions
"""


def add(x, y):
""" Add two numbers."""
return x + y


def subtract(x, y):
""" Subtracting x from y """
return x - y
20 changes: 20 additions & 0 deletions app/app/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
Sample tests
"""
from django.test import SimpleTestCase

from . import calc


class CalculatorTests(SimpleTestCase):
""" Test the calc module """
def test_add_numbers(self):
""" Test adding two numbers """
res = calc.add(3, 6)
self.assertEqual(res, 9)

def test_subtract_numbers(self):
""" Testing subtracting two numbers """
res = calc.subtract(10, 5)

self.assertEqual(res, 5)
49 changes: 34 additions & 15 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
version: "3.9"

services:
app:
build:
context: .
args:
- DEV=true
ports:
- "8000:8000"
volumes:
- ./app:/app
command: >
sh -c "python manage.py runserver 0.0.0.0:8000"
version: "3.9"

services:
app:
build:
context: .
args:
- DEV=true
ports:
- "8000:8000"
volumes:
- ./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_PASS=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:
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Django>=3.2.4,<3.3
djangorestframework>=3.12.4,<3.13
Django>=3.2.4,<3.3
djangorestframework>=3.12.4,<3.13
psycopg2>=2.8.6,<2.9

0 comments on commit f94f243

Please sign in to comment.