cvat-ui in docker (serve using nginx) (#658)
parent
eaede02824
commit
8359db3580
@ -0,0 +1,2 @@
|
||||
build
|
||||
node_modules
|
||||
@ -0,0 +1,9 @@
|
||||
REACT_APP_VERSION=${npm_package_version}
|
||||
|
||||
REACT_APP_API_PROTOCOL=http
|
||||
REACT_APP_API_HOST=localhost
|
||||
REACT_APP_API_PORT=8080
|
||||
REACT_APP_API_HOST_URL=${REACT_APP_API_PROTOCOL}://${REACT_APP_API_HOST}:${REACT_APP_API_PORT}
|
||||
REACT_APP_API_FULL_URL=${REACT_APP_API_PROTOCOL}://${REACT_APP_API_HOST}:${REACT_APP_API_PORT}/api/v1
|
||||
|
||||
SKIP_PREFLIGHT_CHECK=true
|
||||
@ -0,0 +1,36 @@
|
||||
FROM ubuntu:18.04 AS cvat-ui
|
||||
|
||||
ARG http_proxy
|
||||
ARG https_proxy
|
||||
ARG no_proxy
|
||||
ARG socks_proxy
|
||||
|
||||
ENV TERM=xterm \
|
||||
http_proxy=${http_proxy} \
|
||||
https_proxy=${https_proxy} \
|
||||
no_proxy=${no_proxy} \
|
||||
socks_proxy=${socks_proxy}
|
||||
|
||||
ENV LANG='C.UTF-8' \
|
||||
LC_ALL='C.UTF-8'
|
||||
|
||||
# Install necessary apt packages
|
||||
RUN apt update && apt install -yq nodejs npm curl && \
|
||||
npm install -g n && n 10.16.3
|
||||
|
||||
# Create output directory
|
||||
RUN mkdir /tmp/cvat-ui
|
||||
WORKDIR /tmp/cvat-ui/
|
||||
|
||||
# Install dependencies
|
||||
COPY package*.json /tmp/cvat-ui/
|
||||
RUN npm install
|
||||
|
||||
# Build source code
|
||||
COPY . /tmp/cvat-ui/
|
||||
RUN mv .env.production .env && npm run build
|
||||
|
||||
FROM nginx
|
||||
# Replace default.conf configuration to remove unnecessary rules
|
||||
COPY react_nginx.conf /etc/nginx/conf.d/default.conf
|
||||
COPY --from=cvat-ui /tmp/cvat-ui/build /usr/share/nginx/html/
|
||||
@ -0,0 +1,7 @@
|
||||
server {
|
||||
root /usr/share/nginx/html;
|
||||
# Any route that doesn't have a file extension (e.g. /devices)
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.core import signing
|
||||
from furl import furl
|
||||
import hashlib
|
||||
|
||||
QUERY_PARAM = 'sign'
|
||||
MAX_AGE = 30
|
||||
|
||||
# Got implementation ideas in https://github.com/marcgibbons/drf_signed_auth
|
||||
class Signer:
|
||||
@classmethod
|
||||
def get_salt(cls, url):
|
||||
normalized_url = furl(url).remove(QUERY_PARAM).url.encode('utf-8')
|
||||
salt = hashlib.sha256(normalized_url).hexdigest()
|
||||
return salt
|
||||
|
||||
def sign(self, user, url):
|
||||
"""
|
||||
Create a signature for a user object.
|
||||
"""
|
||||
data = {
|
||||
'user_id': user.pk,
|
||||
'username': user.get_username()
|
||||
}
|
||||
|
||||
return signing.dumps(data, salt=self.get_salt(url))
|
||||
|
||||
def unsign(self, signature, url):
|
||||
"""
|
||||
Return a user object for a valid signature.
|
||||
"""
|
||||
User = get_user_model()
|
||||
data = signing.loads(signature, salt=self.get_salt(url), max_age=MAX_AGE)
|
||||
|
||||
if not isinstance(data, dict):
|
||||
raise signing.BadSignature()
|
||||
|
||||
try:
|
||||
return User.objects.get(**{
|
||||
'pk': data.get('user_id'),
|
||||
User.USERNAME_FIELD: data.get('username')
|
||||
})
|
||||
except User.DoesNotExist:
|
||||
raise signing.BadSignature()
|
||||
Loading…
Reference in New Issue