diff --git a/docker/Dockerfile b/docker/Dockerfile index 5ab396ca44..3d89ef9349 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -88,5 +88,8 @@ COPY start_worker.sh ${INVENTREE_HOME}/start_worker.sh RUN chmod 755 ${INVENTREE_HOME}/start_server.sh RUN chmod 755 ${INVENTREE_HOME}/start_worker.sh +# exec commands should be executed from the "src" directory +WORKDIR ${INVENTREE_SRC_DIR} + # Let us begin -CMD ["bash", "./start_server.sh"] +CMD ["bash", "../start_server.sh"] diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 839128738d..14f6108527 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -34,12 +34,13 @@ services: branch: "django-q" image: inventree/inventree:latest container_name: inventree_server - ports: - - "8080:8080" + expose: + - 8080 depends_on: - db volumes: - data:/home/inventree/data + - static:/home/inventree/static environment: - INVENTREE_DB_ENGINE=postgresql - INVENTREE_DB_NAME=inventree @@ -49,6 +50,21 @@ services: - INVENTREE_DB_HOST=db restart: unless-stopped + # nginx acts as a reverse proxy + # static files are served by nginx + # web requests are redirected to gunicorn + nginx: + build: + context: nginx + container_name: inventree_proxy + depends_on: + - inventree + ports: + - 1337:80 + volumes: + - static:/home/inventree/static + + # background worker process handles long-running or periodic tasks worker: build: context: . @@ -63,6 +79,7 @@ services: - inventree volumes: - data:/home/inventree/data + - static:/home/inventree/static environment: - INVENTREE_DB_ENGINE=postgresql - INVENTREE_DB_NAME=inventree @@ -73,6 +90,9 @@ services: restart: unless-stopped volumes: + # Static files, shared between containers + static: + # Persistent data, stored externally data: driver: local driver_opts: diff --git a/docker/nginx/Dockerfile b/docker/nginx/Dockerfile new file mode 100644 index 0000000000..e754597f02 --- /dev/null +++ b/docker/nginx/Dockerfile @@ -0,0 +1,14 @@ +FROM nginx:1.19.0-alpine + +# Create user account +RUN addgroup -S inventreegroup && adduser -S inventree -G inventreegroup + +ENV HOME=/home/inventree +WORKDIR $HOME + +# Create the "static" volume directory +RUN mkdir $HOME/static + +RUN rm /etc/nginx/conf.d/default.conf +COPY nginx.conf /etc/nginx/conf.d + diff --git a/docker/nginx/nginx.conf b/docker/nginx/nginx.conf new file mode 100644 index 0000000000..0f25f51674 --- /dev/null +++ b/docker/nginx/nginx.conf @@ -0,0 +1,21 @@ +upstream inventree { + server inventree:8080; +} + +server { + + listen 80; + + location / { + proxy_pass http://inventree; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $host; + proxy_redirect off; + client_max_body_size 100M; + } + + location /static/ { + alias /home/inventree/static/; + } + +} \ No newline at end of file