diff --git a/.idea/misc.xml b/.idea/misc.xml index a4652f3..6a48157 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/.idea/recipe-app-api.iml b/.idea/recipe-app-api.iml index d0876a7..1a23ee9 100644 --- a/.idea/recipe-app-api.iml +++ b/.idea/recipe-app-api.iml @@ -1,8 +1,8 @@ - - - - - - - + + + + + + + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 8144c23..5670b01 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,28 +1,32 @@ -FROM python:3.9-alpine3.13 -LABEL maintainer="artem.vasylchuck@gmail.com" - -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="artem.vasylchuck@gmail.com" + +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 + diff --git a/app/app/calc.py b/app/app/calc.py new file mode 100644 index 0000000..fa9dcfa --- /dev/null +++ b/app/app/calc.py @@ -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 diff --git a/app/app/tests.py b/app/app/tests.py new file mode 100644 index 0000000..8fff507 --- /dev/null +++ b/app/app/tests.py @@ -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) diff --git a/docker-compose.yml b/docker-compose.yml index 2cd1bb9..3116425 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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: diff --git a/requirements.txt b/requirements.txt index ba00276..e78ea71 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ -Django>=3.2.4,<3.3 -djangorestframework>=3.12.4,<3.13 \ No newline at end of file +Django>=3.2.4,<3.3 +djangorestframework>=3.12.4,<3.13 +psycopg2>=2.8.6,<2.9 \ No newline at end of file