Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Az/cvat proxy #1177

Merged
merged 3 commits into from
Feb 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions Dockerfile.ui
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
FROM ubuntu:18.04 AS cvat-ui
FROM node:lts-alpine AS cvat-ui

ARG http_proxy
ARG https_proxy
ARG no_proxy
ARG socks_proxy
ARG REACT_APP_API_PORT
ARG REACT_APP_API_PROTOCOL
ARG REACT_APP_API_HOST

ENV TERM=xterm \
http_proxy=${http_proxy} \
Expand All @@ -17,13 +14,6 @@ ENV TERM=xterm \
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 directories
RUN mkdir /tmp/cvat-ui /tmp/cvat-core /tmp/cvat-canvas

# Install dependencies
COPY cvat-core/package*.json /tmp/cvat-core/
COPY cvat-canvas/package*.json /tmp/cvat-canvas/
Expand All @@ -47,7 +37,7 @@ COPY cvat-canvas/ /tmp/cvat-canvas/
COPY cvat-ui/ /tmp/cvat-ui/
RUN npm run build

FROM nginx
FROM nginx:stable-alpine
# Replace default.conf configuration to remove unnecessary rules
COPY cvat-ui/react_nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=cvat-ui /tmp/cvat-ui/dist /usr/share/nginx/html/
2 changes: 1 addition & 1 deletion cvat-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "src/index.tsx",
"scripts": {
"build": "webpack --config ./webpack.config.js",
"start": "webpack-dev-server --config ./webpack.config.js --mode=development",
"start": "REACT_APP_API_URL=http://localhost:7000 webpack-dev-server --config ./webpack.config.js --mode=development",
"type-check": "tsc --noEmit",
"type-check:watch": "npm run type-check -- --watch",
"lint": "eslint './src/**/*.{ts,tsx}'",
Expand Down
10 changes: 2 additions & 8 deletions cvat-ui/src/cvat-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@ import _cvat from '../../cvat-core/src/api';

const cvat: any = _cvat;

const protocol = typeof (process.env.REACT_APP_API_PROTOCOL) === 'undefined'
? 'http' : process.env.REACT_APP_API_PROTOCOL;
const host = typeof (process.env.REACT_APP_API_HOST) === 'undefined'
? 'localhost' : process.env.REACT_APP_API_HOST;
const port = typeof (process.env.REACT_APP_API_PORT) === 'undefined'
? '7000' : process.env.REACT_APP_API_PORT;

cvat.config.backendAPI = `${protocol}://${host}:${port}/api/v1`;
cvat.config.backendAPI = typeof (process.env.REACT_APP_API_URL) === 'undefined'
? '/api/v1' : `${process.env.REACT_APP_API_URL}/api/v1`;

export default function getCore(): any {
return cvat;
Expand Down
11 changes: 4 additions & 7 deletions cvat/apps/documentation/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,21 +262,18 @@ docker-compose down

### Advanced settings

If you want to access you instance of CVAT outside of your localhost you should
specify the [ALLOWED_HOSTS](https://docs.djangoproject.com/en/2.0/ref/settings/#allowed-hosts)
environment variable. The best way to do that is to create
If you want to access your instance of CVAT outside of your localhost you should
specify the `CVAT_HOST` environment variable. The best way to do that is to create
[docker-compose.override.yml](https://docs.docker.com/compose/extends/) and put
all your extra settings here.

```yml
version: "2.3"

services:
cvat:
cvat_proxy:
environment:
ALLOWED_HOSTS: .example.com
ports:
- "80:8080"
CVAT_HOST: .example.com
```

Please don't forget include this file to docker-compose commands using the `-f`
Expand Down
37 changes: 37 additions & 0 deletions cvat_proxy/conf.d/cvat.conf.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
server {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename the directory cvat_proxy to cvat-proxy just to be consistent

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's merge as is but it should be consistent. Agree.

listen 80;
server_name _ default;
return 404;
}

server {
listen 80;
server_name ${CVAT_HOST};

location ~* /api/.*|git/.*|tensorflow/.*|auto_annotation/.*|analytics/.*|static/.*|admin|admin/.*|documentation/.*|dextr/.*|reid/.* {
proxy_pass http://cvat:8080;
proxy_pass_header X-CSRFToken;
proxy_set_header Host $http_host;
proxy_pass_header Set-Cookie;
}

location / {
# workaround for match location by arguments
error_page 418 = @annotation_ui;

if ( $query_string ~ "^id=\d+.*" ) { return 418; }

proxy_pass http://cvat_ui;
proxy_pass_header X-CSRFToken;
proxy_set_header Host $http_host;
proxy_pass_header Set-Cookie;
}

# old annotation ui, will be removed in the future.
location @annotation_ui {
proxy_pass http://cvat:8080;
proxy_pass_header X-CSRFToken;
proxy_set_header Host $http_host;
proxy_pass_header Set-Cookie;
}
}
16 changes: 16 additions & 0 deletions cvat_proxy/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
worker_processes 2;


events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;

include /etc/nginx/conf.d/*.conf;
client_max_body_size 0;
}
30 changes: 17 additions & 13 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (C) 2018 Intel Corporation
# Copyright (C) 2018-2020 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
Expand Down Expand Up @@ -37,8 +37,6 @@ services:
depends_on:
- cvat_redis
- cvat_db
ports:
- "8080:8080"
build:
context: .
args:
Expand All @@ -54,11 +52,7 @@ services:
OPENVINO_TOOLKIT: "no"
environment:
DJANGO_MODWSGI_EXTRA_ARGS: ""
UI_SCHEME: http
UI_HOST: localhost
UI_PORT: 7080


ALLOWED_HOSTS: '*'
volumes:
- cvat_data:/home/django/data
- cvat_keys:/home/django/keys
Expand All @@ -67,7 +61,6 @@ services:

cvat_ui:
container_name: cvat_ui
image: nginx
restart: always
build:
context: .
Expand All @@ -76,9 +69,6 @@ services:
https_proxy:
no_proxy:
socks_proxy:
REACT_APP_API_PROTOCOL: http
REACT_APP_API_HOST: localhost
REACT_APP_API_PORT: 8080
dockerfile: Dockerfile.ui

networks:
Expand All @@ -87,8 +77,22 @@ services:
- ui
depends_on:
- cvat

cvat_proxy:
container_name: cvat_proxy
image: nginx:stable-alpine
restart: always
depends_on:
- cvat
- cvat_ui
environment:
CVAT_HOST: localhost
ports:
- "7080:80"
- "8080:80"
volumes:
- ./cvat_proxy/nginx.conf:/etc/nginx/nginx.conf:ro
- ./cvat_proxy/conf.d/cvat.conf.template:/etc/nginx/conf.d/cvat.conf.template:ro
command: /bin/sh -c "envsubst '$$CVAT_HOST' < /etc/nginx/conf.d/cvat.conf.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"

volumes:
cvat_db:
Expand Down