-
Notifications
You must be signed in to change notification settings - Fork 0
Add JWT auth #3
Add JWT auth #3
Changes from 17 commits
7b1cf20
55fcb76
6c8a9d2
8f26924
140181a
e43cbe9
bfe27e3
142a92a
b5f61ab
a1d3d69
20c52aa
7c72b73
79a31a0
03fc181
ceed5c0
fb8808f
b0d830c
20dbc4f
e7c8337
5ace132
3841953
cb4b147
3b648fc
dc44112
d2b68aa
76cba8f
f4c4cb8
ba0d080
d5e8a6c
7fcc096
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
**/__pycache__ | ||
**.DS_Store | ||
**.iml | ||
**.local | ||
docker-compose.override.yml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
# AVC Forms | ||
|
||
## Usage | ||
Run `docker-compose up -d` and visit `host:port` (default `localhost:8080`) | ||
## Local development usage | ||
Use a `docker-compose.override.yml` at the root of the project to override the base configuration. | ||
Run `docker-compose up`. Only the api and the database will run. | ||
Visit `host:port/api` (default `localhost:8080/api`) to access the API interface. | ||
Default user Admin credentials are `{ username: admin, password: admin }`. | ||
|
||
## Configuration | ||
Set up your custom configuration in the `.env` file | ||
## Production or demo usage | ||
Run `docker-compose -f docker-compose.yml -f docker-compose.prod.yml up`. | ||
Visit `host:port` (default `localhost:8080`). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
DJANGO_SUPERUSER_PASSWORD=${DJANGO_SUPERUSER_PASSWORD:-admin} | ||
DJANGO_SUPERUSER_USERNAME=${DJANGO_SUPERUSER_USERNAME:-admin} | ||
DJANGO_SUPERUSER_EMAIL=${DJANGO_SUPERUSER_EMAIL:[email protected]} | ||
DJANGO_SECRET_KEY=${DJANGO_SECRET_KEY:-secret} | ||
DJANGO_DEBUG=${DJANGO_DEBUG:-0} | ||
DJANGO_ALLOWED_HOSTS="${DJANGO_ALLOWED_HOSTS:-localhost 127.0.0.1 [::1]}" | ||
DJANGO_CORS_ALLOWED_ORIGINS="${DJANGO_CORS_ALLOWED_ORIGINS:-http://localhost:8080 http://localhost:3000}" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,14 +7,17 @@ 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 PYTHONPATH=/home/api | ||
ENV PATH /home/api/.local/bin:${PATH} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this required ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warning supression such as |
||
ENV DJANGO_SETTINGS_MODULE=avc_forms.settings | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Putting this here is not required (use a default in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. django-admin returns There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use As a rule of thumb, use the |
||
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 was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
asgiref==3.3.1 | ||
Django==3.1.3 | ||
Django==3.1.4 | ||
django-cors-headers==3.5.0 | ||
django-filter==2.4.0 | ||
djangorestframework==3.12.2 | ||
djangorestframework-simplejwt==4.6.0 | ||
Markdown==3.3.3 | ||
psycopg2==2.8.6 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
PyJWT==1.7.1 | ||
pytz==2020.4 | ||
sqlparse==0.4.1 | ||
uWSGI==2.0.19.1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
./node_modules | ||
./build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
REACT_APP_API_URL=localhost:8080/api | ||
REACT_APP_AUTH_API_URL=http://localhost:8080/api/token/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
network-timeout 600000 |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of curiosity, why did you use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok I see. In terms of engineering, I think it would be best to try to reuse the same image at the company (namely But it is your call. |
||
WORKDIR /app | ||
COPY ./build . | ||
COPY --from=builder /app/build build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export const ID_TOKEN_STORAGE_KEY = "ARKHN_ID_TOKEN"; | ||
export const TOKEN_DATA_STORAGE_KEY = "ARKHN_TOKEN_DATA"; | ||
export const STATE_STORAGE_KEY = "ARKHN_AUTH_STATE"; | ||
|
||
export const { | ||
REACT_APP_API_URL: API_URL, | ||
REACT_APP_AUTH_API_URL: AUTH_API_URL, | ||
} = process.env; | ||
|
||
export const ACCES_TOKEN = "access"; | ||
export const REFRESH_TOKEN = "refresh"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is already the case if the cwd is
/home/api
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that it's not. uwsgi crash returning a
ModuleNotFoundError: No module named 'avc_forms'
if I don't specify the python path. PYTHONPATH is undefined in the container if I don't define it manually here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you problem. You can set
module=avc_forms.wsgi
in theuwsgi.ini
, which a pretty standard way.Note: regarding the
uwsgi.ini
file, there's a lot of stuff in there. Did you find that everything was required?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
module
and themount
attributes seem to be mutually exclusive. The others are either required (chdir, mount, manage-script-name, socket, chmod-socket, uid, guid) or standard server configuration. I did a bit of cleaning.