diff --git a/.dockerignore b/.dockerignore index ec2bdfae60..7011dd8196 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,4 @@ -# frontend/* -app/* docs/* tmp/* -server/node_modules/* -server/dist/* +**/node_modules/* +**/dist/* diff --git a/deploy/docker/docker-compose.yaml b/deploy/docker/docker-compose.yaml index ad435f747b..26f1f823bb 100644 --- a/deploy/docker/docker-compose.yaml +++ b/deploy/docker/docker-compose.yaml @@ -26,9 +26,8 @@ services: - 3000 env_file: .env environment: - RAILS_LOG_TO_STDOUT: "true" SERVE_CLIENT: "false" - command: ['npm', 'run', '--prefix', 'server', 'start:prod'] + command: npm run start:prod volumes: certs: diff --git a/docker/client.Dockerfile b/docker/client.Dockerfile index 04c470f401..2e1dd654d4 100644 --- a/docker/client.Dockerfile +++ b/docker/client.Dockerfile @@ -1,5 +1,6 @@ # pull official base image -FROM node:14.17.0-alpine AS builder +FROM node:14.17.3-alpine AS builder +ENV NODE_ENV=production # set working directory WORKDIR /app @@ -11,9 +12,9 @@ ENV PATH /app/node_modules/.bin:$PATH ENV NODE_OPTIONS="--max-old-space-size=2048" # install app dependencies -COPY package.json package-lock.json ./ +COPY ./frontend/package.json ./frontend/package-lock.json ./ RUN npm install --only=production -COPY . . +COPY ./frontend . RUN NODE_ENV=production npm run-script build @@ -29,6 +30,6 @@ RUN mkdir /etc/resty-auto-ssl /var/log/openresty /var/www /etc/fallback-certs COPY --from=builder /app/build /var/www -COPY ./config/nginx.conf.template /etc/openresty/nginx.conf.template -COPY ./config/entrypoint.sh /entrypoint.sh +COPY ./frontend/config/nginx.conf.template /etc/openresty/nginx.conf.template +COPY ./frontend/config/entrypoint.sh /entrypoint.sh ENTRYPOINT ["./entrypoint.sh"] diff --git a/docker/client.Dockerfile.dev b/docker/client.Dockerfile.dev index 196eebd797..d86a2f8895 100644 --- a/docker/client.Dockerfile.dev +++ b/docker/client.Dockerfile.dev @@ -1,5 +1,7 @@ # pull official base image -FROM node:14.17.0-alpine +FROM node:14.17.3-alpine + +ENV NODE_ENV=development # set working directory WORKDIR /app @@ -18,7 +20,6 @@ RUN npm install react-scripts@3.4.1 -g --silent # add app COPY . ./ - # start app CMD ["npm", "start"] diff --git a/docker/production.Dockerfile b/docker/production.Dockerfile index bb99fe2c81..0cb13aacdc 100644 --- a/docker/production.Dockerfile +++ b/docker/production.Dockerfile @@ -1,4 +1,4 @@ -FROM node:14.17.0-buster +FROM node:14.17.3-buster # Fix for JS heap limit allocation issue ENV NODE_OPTIONS="--max-old-space-size=2048" diff --git a/docker/server.Dockerfile b/docker/server.Dockerfile index 2eb1272401..af065d76a3 100644 --- a/docker/server.Dockerfile +++ b/docker/server.Dockerfile @@ -1,5 +1,7 @@ FROM node:14.17.3-buster +ENV NODE_ENV=production + # Fix for JS heap limit allocation issue ENV NODE_OPTIONS="--max-old-space-size=2048" @@ -8,17 +10,15 @@ RUN apt update && apt install -y \ postgresql \ freetds-dev +RUN npm install -g @nestjs/cli + RUN mkdir -p /app WORKDIR /app -ENV NODE_ENV=production # Building ToolJet server -COPY ./server/package.json ./server/package-lock.json ./server/ -RUN npm --prefix server install -COPY ./server/ ./server/ -RUN npm install -g @nestjs/cli -RUN npm --prefix server run build +COPY ./server/package.json ./server/package-lock.json ./ +RUN npm install --only=production +COPY ./server/ ./ +RUN npm run build -COPY ./docker/ ./docker/ - -RUN ["chmod", "755", "./server/entrypoint.sh"] +RUN ["chmod", "755", "./entrypoint.sh"] diff --git a/docker/server.Dockerfile.dev b/docker/server.Dockerfile.dev index c25f83f705..667d3dc487 100644 --- a/docker/server.Dockerfile.dev +++ b/docker/server.Dockerfile.dev @@ -1,5 +1,7 @@ # pull official base image -FROM node:14.17.0-buster +FROM node:14.17.3-buster + +ENV NODE_ENV=development RUN apt update && apt install -y \ build-essential \ @@ -11,13 +13,8 @@ WORKDIR /app COPY ./server/package.json ./server/package-lock.json ./ RUN npm install - -ENV NODE_ENV=development - COPY ./server/ ./ -COPY ./docker/ ./docker/ - COPY ./.env ../.env COPY ./.env.test ../.env.test diff --git a/docs/docs/contributing-guide/setup/docker.md b/docs/docs/contributing-guide/setup/docker.md index b7c317b56c..70204f9ebe 100644 --- a/docs/docs/contributing-guide/setup/docker.md +++ b/docs/docs/contributing-guide/setup/docker.md @@ -78,9 +78,9 @@ We recommend: 5. ToolJet server is built using NestJS and the data such as application definitions are persisted on a postgres database. You have to create and migrate the database if building for the first time. ```bash - docker-compose run server npm run db:create - docker-compose run server npm run db:migrate - docker-compose run server npm run db:seed + docker-compose run --rm server npm run db:create + docker-compose run --rm server npm run db:migrate + docker-compose run --rm server npm run db:seed ``` 6. Run ToolJet @@ -147,25 +147,25 @@ Test config picks up config from `.env.test` file at the root of the project. Run the following command to create and migrate data for test db ```bash -docker-compose run -e NODE_ENV=test server npm run db:create -docker-compose run -e NODE_ENV=test server npm run db:migrate +docker-compose run --rm -e NODE_ENV=test server npm run db:create +docker-compose run --rm -e NODE_ENV=test server npm run db:migrate ``` To run the unit tests ```bash -$ docker-compose run server npm run test +$ docker-compose --rm run server npm run test ``` To run e2e tests ```bash -docker-compose run server npm run test:e2e +docker-compose run --rm server npm run test:e2e ``` To run a specific unit test ```bash -docker-compose run server npm run test +docker-compose run --rm server npm run test ``` ## Troubleshooting diff --git a/frontend/config/nginx.conf.template b/frontend/config/nginx.conf.template index d8560d5cc6..aa271c699a 100644 --- a/frontend/config/nginx.conf.template +++ b/frontend/config/nginx.conf.template @@ -54,9 +54,19 @@ http ssl_certificate /etc/fallback-certs/resty-auto-ssl-fallback.crt; ssl_certificate_key /etc/fallback-certs/resty-auto-ssl-fallback.key; - location / { + root /var/www; + try_files $uri $uri/ /index.html @proxy; + error_page 405 @proxy; + } + + location /api/ + { + try_files /_bypass_to_proxy @proxy; + } + + location @proxy { proxy_pass http://${SERVER_HOST}:3000; proxy_redirect off; proxy_set_header Host $host; @@ -76,6 +86,17 @@ http location / { + root /var/www; + try_files $uri $uri/ /index.html @proxy; + error_page 405 @proxy; + } + + location /api/ + { + try_files /_bypass_to_proxy @proxy; + } + + location @proxy { proxy_pass http://${SERVER_HOST}:3000; proxy_redirect off; proxy_set_header Host $host;