This repository has been archived by the owner on Jan 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add a login page and link frontend and backend * Replace basic authentication with JWT auth * Fix yarn timeout * Shared volume between api and nginx is now limited to django static files and the socket file * Change env variables management * The uwsgi server is run by a dedicated non root user
- Loading branch information
Showing
47 changed files
with
1,098 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# AVC Forms | ||
|
||
## Usage | ||
Run `docker-compose up -d` and visit `host:port` (default `localhost:8080`) | ||
Run `docker-compose up`. | ||
Visit `host:port` (default `localhost:8080`). | ||
Default user Admin credentials are `{ username: admin, password: admin }`. | ||
|
||
## Configuration | ||
Set up your custom configuration in the `.env` file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# DJANGO_SECRET should be a crypto secure random 50 bytes key | ||
DJANGO_SECRET_KEY=${DJANGO_SECRET_KEY:-secret} | ||
DJANGO_ALLOWED_HOSTS="${DJANGO_ALLOWED_HOST:-localhost 127.0.0.1}" | ||
DJANGO_CORS_ALLOWED_ORIGINS="${DJANGO_CORS_ALLOWED_ORIGINS:-http://localhost:8080 http://localhost:3000}" | ||
DJANGO_SUPERUSER_USERNAME=${DJANGO_SUPERUSER_USERNAME:-admin} | ||
DJANGO_SUPERUSER_PASSWORD=${DJANGO_SUPERUSER_PASSWORD:-admin} | ||
DJANGO_SUPERUSER_EMAIL=${DJANGO_SUPERUSER_EMAIL:[email protected]} | ||
# DJANGO_DEBUG should be equal to 0 in production | ||
DJANGO_DEBUG=${DJANGO_DEBUG:-1} | ||
POSTGRES_DB=${POSTGRES_DB:-postgres} | ||
POSTGRES_USER=${POSTGRES_USER:-postgres} | ||
POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-password} | ||
POSTGRES_HOST=${POSTGRES_HOST:-db} | ||
POSTGRES_PORT=${POSTGRES_PORT:-5432} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.env.local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
FROM python:3.9.0-slim-buster as builder | ||
WORKDIR /tmp | ||
ENV PYTHONDONTWRITEBYTECODE 1 | ||
ENV PYTHONUNBUFFERED 1 | ||
COPY ./requirements.txt . | ||
RUN apt-get update && apt-get install -y libpq-dev gcc | ||
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /tmp/wheels -r requirements.txt | ||
|
||
FROM python:3.9.0-slim-buster | ||
ENV DJANGO_SETTINGS_MODULE=avc_forms.settings | ||
ENV PYTHONPATH=/api | ||
RUN apt-get update && \ | ||
apt-get install -y --no-install-recommends netcat libpq-dev && \ | ||
apt-get autoremove -y && \ | ||
apt-get clean | ||
COPY --from=builder /tmp/wheels /wheels | ||
RUN pip install --no-cache /wheels/* | ||
WORKDIR /api | ||
COPY . . | ||
RUN groupadd -r api && useradd --create-home --no-log-init -r -g api api | ||
USER api:api | ||
WORKDIR /home/api | ||
ENV PYTHONDONTWRITEBYTECODE 1 | ||
ENV PYTHONUNBUFFERED 1 | ||
ENV PYTHONPATH=/home/api | ||
ENV PATH /home/api/.local/bin:${PATH} | ||
COPY --from=builder --chown=api:api /tmp/wheels wheels | ||
RUN pip install --user --no-cache wheels/* && rm -rf wheels | ||
COPY --chown=api:api . . | ||
ENTRYPOINT ["sh", "docker-entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,59 @@ | ||
# AVC Forms API | ||
|
||
## Recommended requirements | ||
* Python 3.9 | ||
* Pip 20.3.1 | ||
* Postresql 13.1 | ||
* Prerequesites for [psycopg](https://www.psycopg.org/docs/install.html) | ||
|
||
## Usage | ||
* Run a postgresql database `postgres` at `localhost:5432` (user `postgres`, no password) | ||
* Install dependencies `pip install -r requirements.txt` | ||
* Apply migration `python manage.py migrate` | ||
* Create an admin user `python manage.py createsuperuser` | ||
* Run `python manage.py runserver` | ||
* Visit `localhost:8080` and login | ||
|
||
* API root at `host:port/api` | ||
* Admin interface at `host:port/api/admin` | ||
## Base configuration override for local development | ||
* Add environment variables in a `.env.local` file in the API project directory | ||
|
||
## Routes | ||
* `/api-auth/login` accepts basic authentication | ||
* `/api-auth/logout` | ||
* API documentation at `host:port/api` | ||
* Admin interface at `host:port/api/admin` | ||
|
||
* `/token/` | ||
* `POST` request | ||
```json | ||
{ | ||
"username": "username", | ||
"password": "password" | ||
} | ||
``` | ||
* Response | ||
```json | ||
{ | ||
"refresh": "refresh_jwt_token", | ||
"access": "access_jwt_token" | ||
} | ||
``` | ||
* `/token/refresh/` | ||
* Request | ||
```shell script | ||
curl \ | ||
-X POST \ | ||
-H "Content-Type: application/json" \ | ||
-d '{"refresh":"refresh_token_jwt"}' \ | ||
http://host:port/api/token/refresh/ | ||
``` | ||
* Response | ||
```json | ||
{ "access": "access_jwt_token" } | ||
``` | ||
* `/users` | ||
* `/patients` | ||
```json | ||
{ | ||
"code": "unique_text_field", | ||
"data": { } | ||
} | ||
``` | ||
* Example request | ||
```shell script | ||
curl \ | ||
-H "Bearer access_jwt_token" | ||
http://host:port/api/patients | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Generated by Django 3.1.4 on 2020-12-09 15:24 | ||
|
||
from django.db import migrations, models | ||
import uuid | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('api', '0004_auto_20201125_1839'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='patient', | ||
name='code', | ||
field=models.TextField(default=uuid.uuid4, unique=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
[uwsgi] | ||
chdir=/api/avc_forms | ||
chdir=/home/api/avc_forms | ||
mount = /api=avc_forms.wsgi:application | ||
manage-script-name=true | ||
master=True | ||
pidfile=/tmp/project-master.pid | ||
vacuum=True | ||
max-requests=5000 | ||
env=LANG=en_US.UTF-8 | ||
processes=5 | ||
threads=2 | ||
socket=avc_forms.sock | ||
socket=/tmp/avc_forms.sock | ||
chmod-socket=666 | ||
uid=api | ||
gid=api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
asgiref==3.3.1 | ||
Django==3.1.3 | ||
Django==3.1.4 | ||
django-cors-headers==3.6.0 | ||
django-filter==2.4.0 | ||
djangorestframework==3.12.2 | ||
djangorestframework-simplejwt==4.6.0 | ||
Markdown==3.3.3 | ||
psycopg2==2.8.6 | ||
PyJWT==1.7.1 | ||
python-dotenv==0.15.0 | ||
pytz==2020.4 | ||
sqlparse==0.4.1 | ||
uWSGI==2.0.19.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
./node_modules | ||
./build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# REACT_APP_API_URL=${APP_API_URL} | ||
# REACT_APP_AUTH_API_URL=${APP_API_AUTH} | ||
|
||
REACT_APP_API_URL=http://localhost:8080/api | ||
REACT_APP_AUTH_API_URL=http://localhost:8080/api/token/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
network-timeout 600000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,13 @@ | ||
#FROM node:15.3.0-alpine3.10 as builder | ||
#WORKDIR /app | ||
#ENV PATH /app/node_modules/.bin:$PATH | ||
#COPY ./package.json . | ||
#RUN yarn | ||
#COPY . . | ||
#RUN yarn build | ||
# | ||
#FROM busybox | ||
#WORKDIR /app | ||
#COPY --from=builder /app/build . | ||
FROM node:15.3.0 as builder | ||
WORKDIR /app | ||
ENV PATH /app/node_modules/.bin:$PATH | ||
COPY ./package.json . | ||
COPY ./.yarnrc . | ||
COPY ./yarn.lock . | ||
RUN yarn | ||
COPY . . | ||
RUN yarn build | ||
|
||
FROM busybox | ||
FROM busybox:1.32.0 | ||
WORKDIR /app | ||
COPY ./build . | ||
COPY --from=builder /app/build build |
Oops, something went wrong.