From 5b9c6d39574ca3b40ed05ecb3a382e90cfb3d3c6 Mon Sep 17 00:00:00 2001 From: Ivan Kuchin Date: Mon, 16 Sep 2024 15:16:57 +0200 Subject: [PATCH 01/18] cleanup puma config comments and configure host to default from HOST and default to 127.0.0.1 --- config/puma.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/config/puma.rb b/config/puma.rb index 4fe6d97c7c04..2b9f7a1fcba5 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -7,12 +7,13 @@ threads_max_count = OpenProject::Configuration.web_max_threads threads threads_min_count, [threads_min_count, threads_max_count].max -# Specifies the `port` that Puma will listen on to receive requests; default is 3000. -# +# Specifies the address on which Puma will listen on to receive requests; default is 127.0.0.1. +set_default_host ENV.fetch("HOST") { "127.0.0.1" } + +# Specifies the port that Puma will listen on to receive requests; default is 3000. port ENV.fetch("PORT") { 3000 }.to_i -# Specifies the `environment` that Puma will run in. -# +# Specifies the environment that Puma will run in. environment ENV.fetch("RAILS_ENV") { "development" } # Specifies the number of `workers` to boot in clustered mode. From 298e259192eca71c4a2b73f17d467ae951239b38 Mon Sep 17 00:00:00 2001 From: Ivan Kuchin Date: Mon, 16 Sep 2024 15:17:14 +0200 Subject: [PATCH 02/18] no need to configure port/host/environment in Procfile.dev --- Procfile.dev | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Procfile.dev b/Procfile.dev index 26ad472210c8..8c11a9c8489b 100644 --- a/Procfile.dev +++ b/Procfile.dev @@ -1,3 +1,3 @@ -web: bundle exec rails server -p 3000 -b ${HOST:="127.0.0.1"} --environment ${RAILS_ENV:="development"} +web: bundle exec rails server angular: npm run serve worker: bundle exec good_job start From 72dbeaeeb57d0a3bb58972858fa64342f99b6743 Mon Sep 17 00:00:00 2001 From: Ivan Kuchin Date: Mon, 16 Sep 2024 15:30:42 +0200 Subject: [PATCH 03/18] tell frontend about backend port --- frontend/cli_to_rails_proxy.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/cli_to_rails_proxy.js b/frontend/cli_to_rails_proxy.js index 1efa6e90cde0..ea7e984dea1e 100644 --- a/frontend/cli_to_rails_proxy.js +++ b/frontend/cli_to_rails_proxy.js @@ -1,9 +1,10 @@ const PROXY_HOSTNAME = process.env.PROXY_HOSTNAME || 'localhost'; +const PORT = process.env.PORT || '3000'; const PROXY_CONFIG = [ { "context": ['/**'], - "target": `http://${PROXY_HOSTNAME}:3000`, + "target": `http://${PROXY_HOSTNAME}:${PORT}`, "secure": false, "timeout": 360000, // "bypass": function (req, res, proxyOptions) { From 39a4fc7db2dd29b7dbe542c9c96110921116da68 Mon Sep 17 00:00:00 2001 From: Ivan Kuchin Date: Mon, 16 Sep 2024 16:14:06 +0200 Subject: [PATCH 04/18] tell backend about frontend host/port --- app/helpers/frontend_asset_helper.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/helpers/frontend_asset_helper.rb b/app/helpers/frontend_asset_helper.rb index f016772c4234..38772224edda 100644 --- a/app/helpers/frontend_asset_helper.rb +++ b/app/helpers/frontend_asset_helper.rb @@ -27,14 +27,19 @@ #++ module FrontendAssetHelper - CLI_DEFAULT_PROXY = "http://localhost:4200".freeze + CLI_DEFAULT_PROXY = begin + host = ENV.fetch("FE_HOST", "localhost") + port = ENV.fetch("FE_PORT", 4200) + "http://#{host}:#{port}" + end + CLI_PROXY = ENV.fetch("OPENPROJECT_CLI_PROXY", CLI_DEFAULT_PROXY) def self.assets_proxied? ENV["OPENPROJECT_DISABLE_DEV_ASSET_PROXY"].blank? && !Rails.env.production? && cli_proxy.present? end def self.cli_proxy - ENV.fetch("OPENPROJECT_CLI_PROXY", CLI_DEFAULT_PROXY) + CLI_PROXY end ## From fe3110561d1aa554dfe0cfd774391dc6657ffc9a Mon Sep 17 00:00:00 2001 From: Ivan Kuchin Date: Mon, 16 Sep 2024 16:15:36 +0200 Subject: [PATCH 05/18] default host_name setting to environment variables instead of hardcoded localhost:3000 --- config/constants/settings/definition.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/constants/settings/definition.rb b/config/constants/settings/definition.rb index e2bf418d9669..a5e4a46e5395 100644 --- a/config/constants/settings/definition.rb +++ b/config/constants/settings/definition.rb @@ -537,7 +537,7 @@ class Definition }, host_name: { format: :string, - default: "localhost:3000", + default: "#{ENV.fetch('HOST', 'localhost')}:#{ENV.fetch('PORT', 3000)}", default_by_env: { # We do not want to set a localhost host name in production production: nil From 86b16d19f3c9d760ffef7c2ffdf439e511795547 Mon Sep 17 00:00:00 2001 From: Ivan Kuchin Date: Mon, 16 Sep 2024 16:37:54 +0200 Subject: [PATCH 06/18] configure npmserve and serve:test to set host from FE_HOST and port from FE_PORT --- frontend/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/package.json b/frontend/package.json index 6f8167241ae2..6158f66f6b3d 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -166,8 +166,8 @@ "build": "node --max_old_space_size=4096 ./node_modules/@angular/cli/bin/ng build --configuration production --named-chunks --source-map", "build:watch": "node --max_old_space_size=4096 ./node_modules/@angular/cli/bin/ng build --watch --named-chunks", "tokens:generate": "theo src/app/spot/styles/tokens/tokens.yml --transform web --format sass,json --dest src/app/spot/styles/tokens/dist", - "serve": "node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng serve --host 0.0.0.0 --public-host http://${PROXY_HOSTNAME:-localhost}:4200", - "serve:test": "node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng serve --host 0.0.0.0 --disable-host-check --public-host http://frontend-test:4200", + "serve": "node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng serve --host ${FE_HOST:-localhost} --port ${FE_PORT:-4200} --public-host http://${PROXY_HOSTNAME:-localhost}:${FE_PORT:-4200}", + "serve:test": "node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng serve --host ${FE_HOST:-localhost} --port ${FE_PORT:-4200} --disable-host-check --public-host http://frontend-test:${FE_PORT:-4200}", "test": "ng test --watch=false", "test:watch": "ng test --watch=true", "lint": "esprint check", From 65ed6bc3b4d166658ad3d2e233132fcdec2cd306 Mon Sep 17 00:00:00 2001 From: Ivan Kuchin Date: Mon, 16 Sep 2024 16:39:24 +0200 Subject: [PATCH 07/18] host_name default has to use a proc, apparently file is read before dotenv-rails changes environment --- config/constants/settings/definition.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/constants/settings/definition.rb b/config/constants/settings/definition.rb index a5e4a46e5395..715707dd6b73 100644 --- a/config/constants/settings/definition.rb +++ b/config/constants/settings/definition.rb @@ -537,7 +537,7 @@ class Definition }, host_name: { format: :string, - default: "#{ENV.fetch('HOST', 'localhost')}:#{ENV.fetch('PORT', 3000)}", + default: -> { "#{ENV.fetch('HOST', 'localhost')}:#{ENV.fetch('PORT', 3000)}" }, default_by_env: { # We do not want to set a localhost host name in production production: nil From 03273b93706b767999d96bebfc03404d0501a7de Mon Sep 17 00:00:00 2001 From: Ivan Kuchin Date: Mon, 16 Sep 2024 16:40:34 +0200 Subject: [PATCH 08/18] use localhost instead of 127.0.0.1 in puma config --- config/puma.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/puma.rb b/config/puma.rb index 2b9f7a1fcba5..8f225b55914b 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -7,8 +7,8 @@ threads_max_count = OpenProject::Configuration.web_max_threads threads threads_min_count, [threads_min_count, threads_max_count].max -# Specifies the address on which Puma will listen on to receive requests; default is 127.0.0.1. -set_default_host ENV.fetch("HOST") { "127.0.0.1" } +# Specifies the address on which Puma will listen on to receive requests; default is localhost. +set_default_host ENV.fetch("HOST") { "localhost" } # Specifies the port that Puma will listen on to receive requests; default is 3000. port ENV.fetch("PORT") { 3000 }.to_i From 0108504725f87039c27db4d77112110c611724d4 Mon Sep 17 00:00:00 2001 From: Ivan Kuchin Date: Mon, 16 Sep 2024 16:45:28 +0200 Subject: [PATCH 09/18] change environment variables in .env.example --- .env.example | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index c31d0776cd69..c87652f32771 100644 --- a/.env.example +++ b/.env.example @@ -37,8 +37,12 @@ LOCAL_DEV_CHECK=1 # want to develop ckeditor locally. CKEDITOR_BUILD_DIR=./frontend/src/vendor/ckeditor/ -HOST=0.0.0.0 -PORT=4200 +# Local backend development host and port +HOST=localhost +PORT=3000 +# Local frontend development host and port +FE_HOST=localhost +FE_PORT=4200 # Use this variables to configure hostnames for frontend and backend, e.g. to enable HTTPS in docker development setup OPENPROJECT_DEV_HOST=localhost From 405e4da3cec53a7b5b9b03e1b496bc34d34f61c0 Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Wed, 18 Sep 2024 15:10:40 +0100 Subject: [PATCH 10/18] apply port config for docker dev env as well --- docker-compose.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index 5c3e420c8555..5bbd7396d102 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -38,6 +38,7 @@ x-op-backend: &backend environment: LOCAL_DEV_CHECK: "${LOCAL_DEV_CHECK:?The docker-compose file for OpenProject has moved to https://github.com/opf/openproject-deploy}" RAILS_ENV: development + OPENPROJECT_HOST__NAME: "${HOST:-localhost}:${PORT:-3000}" OPENPROJECT_CACHE__MEMCACHE__SERVER: cache:11211 OPENPROJECT_RAILS__CACHE__STORE: file_store OPENPROJECT_RAILS__RELATIVE__URL__ROOT: "${OPENPROJECT_RAILS__RELATIVE__URL__ROOT:-}" @@ -66,6 +67,8 @@ services: depends_on: - db - cache + ports: + - "${PORT}:3000" worker: <<: *backend @@ -87,6 +90,8 @@ services: - network depends_on: - backend + ports: + - "${FE_PORT}:4200" db: image: postgres:13 From 813f4ec481abbac57d31271241f2c3aa131efe31 Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Wed, 18 Sep 2024 15:12:29 +0100 Subject: [PATCH 11/18] fix dev proxy issue by using configured frontend port --- .env.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.example b/.env.example index c87652f32771..21a60e60d1f3 100644 --- a/.env.example +++ b/.env.example @@ -46,7 +46,7 @@ FE_PORT=4200 # Use this variables to configure hostnames for frontend and backend, e.g. to enable HTTPS in docker development setup OPENPROJECT_DEV_HOST=localhost -OPENPROJECT_DEV_URL=http://${OPENPROJECT_DEV_HOST}:${PORT} +OPENPROJECT_DEV_URL=http://${OPENPROJECT_DEV_HOST}:${FE_PORT} # Select edition from: ['standard','bim'] OPENPROJECT_EDITION=standard From 4768523f1564a79a06f38fb14ea3137a6cf05ddf Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Thu, 19 Sep 2024 11:16:50 +0100 Subject: [PATCH 12/18] Update docker-compose.yml Co-authored-by: Ivan Kuchin --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 5bbd7396d102..894a4c16c9dd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -68,7 +68,7 @@ services: - db - cache ports: - - "${PORT}:3000" + - "${PORT:-3000}:3000" worker: <<: *backend From 7c1b53963d7dbbf826700de4b2351ab6eda2f626 Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Thu, 19 Sep 2024 11:16:59 +0100 Subject: [PATCH 13/18] Update docker-compose.yml Co-authored-by: Ivan Kuchin --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 894a4c16c9dd..ff9fcc78de41 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -91,7 +91,7 @@ services: depends_on: - backend ports: - - "${FE_PORT}:4200" + - "${FE_PORT:-4200}:4200" db: image: postgres:13 From 8c70afc6a35c340b600cb06287307768571d39f5 Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Thu, 19 Sep 2024 11:17:18 +0100 Subject: [PATCH 14/18] Update frontend/cli_to_rails_proxy.js Co-authored-by: Ivan Kuchin --- frontend/cli_to_rails_proxy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/cli_to_rails_proxy.js b/frontend/cli_to_rails_proxy.js index ea7e984dea1e..ca52925bde70 100644 --- a/frontend/cli_to_rails_proxy.js +++ b/frontend/cli_to_rails_proxy.js @@ -1,4 +1,4 @@ -const PROXY_HOSTNAME = process.env.PROXY_HOSTNAME || 'localhost'; +const PROXY_HOSTNAME = process.env.PROXY_HOSTNAME || process.env.HOST || 'localhost'; const PORT = process.env.PORT || '3000'; const PROXY_CONFIG = [ From f8ef7982bdd518a8a91545de182a5fd20ae05c14 Mon Sep 17 00:00:00 2001 From: Ivan Kuchin Date: Thu, 19 Sep 2024 13:19:07 +0200 Subject: [PATCH 15/18] correct ports in compose override example --- docker-compose.override.example.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker-compose.override.example.yml b/docker-compose.override.example.yml index f1bf691b9fbe..edb5424fdeca 100644 --- a/docker-compose.override.example.yml +++ b/docker-compose.override.example.yml @@ -4,13 +4,13 @@ services: backend: environment: - OPENPROJECT_CLI_PROXY: "http://localhost:${PORT}" + OPENPROJECT_CLI_PROXY: "http://localhost:${FE_PORT:-4200}" ports: - - "3000:3000" + - "${PORT:-3000}:3000" frontend: ports: - - "${PORT}:4200" + - "${FE_PORT:-4200}:4200" db: ports: From c379b2edfcde48dca0969e7d833230ac3e563397 Mon Sep 17 00:00:00 2001 From: Ivan Kuchin Date: Mon, 30 Sep 2024 15:35:52 +0200 Subject: [PATCH 16/18] expose ports for docker compose in override file only --- docker-compose.override.example.yml | 1 + docker-compose.yml | 5 ----- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/docker-compose.override.example.yml b/docker-compose.override.example.yml index edb5424fdeca..d55e1f05c265 100644 --- a/docker-compose.override.example.yml +++ b/docker-compose.override.example.yml @@ -5,6 +5,7 @@ services: backend: environment: OPENPROJECT_CLI_PROXY: "http://localhost:${FE_PORT:-4200}" + OPENPROJECT_HOST__NAME: "${HOST:-localhost}:${PORT:-3000}" ports: - "${PORT:-3000}:3000" diff --git a/docker-compose.yml b/docker-compose.yml index ff9fcc78de41..5c3e420c8555 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -38,7 +38,6 @@ x-op-backend: &backend environment: LOCAL_DEV_CHECK: "${LOCAL_DEV_CHECK:?The docker-compose file for OpenProject has moved to https://github.com/opf/openproject-deploy}" RAILS_ENV: development - OPENPROJECT_HOST__NAME: "${HOST:-localhost}:${PORT:-3000}" OPENPROJECT_CACHE__MEMCACHE__SERVER: cache:11211 OPENPROJECT_RAILS__CACHE__STORE: file_store OPENPROJECT_RAILS__RELATIVE__URL__ROOT: "${OPENPROJECT_RAILS__RELATIVE__URL__ROOT:-}" @@ -67,8 +66,6 @@ services: depends_on: - db - cache - ports: - - "${PORT:-3000}:3000" worker: <<: *backend @@ -90,8 +87,6 @@ services: - network depends_on: - backend - ports: - - "${FE_PORT:-4200}:4200" db: image: postgres:13 From 7d2f684a2e41ef652f0f3473539538562c61275e Mon Sep 17 00:00:00 2001 From: Ivan Kuchin Date: Mon, 30 Sep 2024 15:36:40 +0200 Subject: [PATCH 17/18] mention possibility of port overriding instead of merging in compose file --- docs/development/development-environment/docker/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/development/development-environment/docker/README.md b/docs/development/development-environment/docker/README.md index a0131770acfc..e9f54ab237dc 100644 --- a/docs/development/development-environment/docker/README.md +++ b/docs/development/development-environment/docker/README.md @@ -106,8 +106,9 @@ directory will not end up with files owned by root. You also will want to create a `docker-compose.override.yml` file, which can contain the port exposure for your containers. Those are excluded from the main compose file `docker-compose.yml` for sanity reasons. If any port is -already in use, `docker compose` won't start and as you cannot disable the exposed port in -the `docker-compose.override.yml` file, you would have to alter the original `docker-compose.yml`. +already in use, `docker compose` won't start and will require explicit override in the `docker-compose.override.yml` +file (see instructions for [!reset](https://docs.docker.com/reference/compose-file/merge/#reset-value) and +[!override](https://docs.docker.com/reference/compose-file/merge/#replace-value)). There is an example you can use out of the box. From 1710ba7b8c9b109984c04d7ce3e6869a19c1042a Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Mon, 30 Sep 2024 14:42:50 +0100 Subject: [PATCH 18/18] remove host name and CLI proxy which are not necessary by default --- docker-compose.override.example.yml | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/docker-compose.override.example.yml b/docker-compose.override.example.yml index d55e1f05c265..85dc5a5a972b 100644 --- a/docker-compose.override.example.yml +++ b/docker-compose.override.example.yml @@ -3,24 +3,23 @@ services: backend: - environment: - OPENPROJECT_CLI_PROXY: "http://localhost:${FE_PORT:-4200}" - OPENPROJECT_HOST__NAME: "${HOST:-localhost}:${PORT:-3000}" + # use these ports to be able to access the stack under http://localhost:3000 ports: - "${PORT:-3000}:3000" frontend: + # use these ports to be able to access the stack under http://localhost:3000 ports: - "${FE_PORT:-4200}:4200" - db: - ports: - - '5432:5432' + # db: + # ports: + # - '5432:5432' - db-test: - ports: - - '5433:5432' + # db-test: + # ports: + # - '5433:5432' - chrome: - ports: - - '5900:5900' + # chrome: + # ports: + # - '5900:5900'