OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
docker dev and test setup fixes (#9135)
Markus Kahlc375646dc00d
diff --git a/bin/compose b/bin/composeindex 3d00deef07a..2baefb2b4c0 100755--- a/bin/compose+++ b/bin/compose@@ -15,13 +15,25 @@ if [ $# -eq 0 ]; thenechoecho "Commands:"echo " setup - Has to be run once initially. Installs backend and frontend dependencies. "+ echo " reset - Resets everything by removing all containers and deleting all volumes. You need to run \`setup\` again afterwards. "echo " start - Starts both backend and frontend in the background. Access via http://localhost:3000/ by default."echo " run - Starts the frontend in the background and backend in the foreground. Useful for debugging using pry."+ echo " rspec - Runs rspec inside the \`backend-test\` container which will be started if it's not running yet."echo " * - Everything else will be passed straight to \`docker-compose\`."echoexit 1-elif [[ "$@" = "start" ]]; then+fi++if [ -f config/database.yml ]; then+ echo+ printf "\033[0;31mError\033[0m: Found local \`config/database.yml\` - The docker setup will not work with this file present."+ echo " You could delete it or rename it for the time being."++ exit 1+fi++if [[ "$@" = "start" ]]; then# backend will be started automatically as a dependency of the frontenddocker-compose -f $COMPOSE_FILE up -d frontendelif [[ "$@" = "run" ]]; then@@ -32,6 +44,23 @@ elif [[ "$@" = "run" ]]; thenelif [[ "$1" = "setup" ]]; thendocker-compose -f $COMPOSE_FILE run backend setupyes no | docker-compose -f $COMPOSE_FILE run frontend npm install+elif [[ "$1" = "reset" ]]; then+ docker-compose -f $COMPOSE_FILE down && docker volume rm `docker volume ls -q | grep ${PWD##*/}_`+elif [[ "$1" = "rspec" ]]; then+ if ! docker ps | grep ${PWD##*/}_backend-test_1 > /dev/null; then+ echo "Test backend not running yet. Starting it..."++ docker-compose -f $COMPOSE_FILE up -d backend-test++ while ! docker logs --since 1m ${PWD##*/}_backend-test_1 | grep "Ready for tests" > /dev/null; do+ sleep 1+ printf "."+ done++ echo "Ready for tests"+ fi++ docker-compose -f $COMPOSE_FILE exec backend-test bundle exec rspec "${@:2}"elsedocker-compose -f $COMPOSE_FILE $*fidiff --git a/docker-compose.yml b/docker-compose.ymlindex c01fe0fb83e..d50a4994c4e 100644--- a/docker-compose.yml+++ b/docker-compose.yml@@ -113,7 +113,7 @@ services:frontend-test:build:<<: *frontend-build- command: "npm run build-test"+ command: "npm run serve-test"volumes:- ".:/home/dev/openproject"- "fedata-test:/home/dev/openproject/public/assets/frontend"@@ -143,7 +143,7 @@ services:CAPYBARA_SERVER_PORT: 3000CAPYBARA_DYNAMIC_BIND_IP: 1CAPYBARA_APP_HOSTNAME: backend-test- OPENPROJECT_DISABLE_DEV_ASSET_PROXY: 1+ OPENPROJECT_CLI_PROXY: http://frontend-test:4200OPENPROJECT_TESTING_NO_HEADLESS: "true"volumes:- ".:/home/dev/openproject"diff --git a/docker/dev/backend/Dockerfile b/docker/dev/backend/Dockerfileindex 10795c9fdb0..9572e254469 100644--- a/docker/dev/backend/Dockerfile+++ b/docker/dev/backend/Dockerfile@@ -48,9 +48,7 @@ RUN apt-get update -qq && \DEBIAN_FRONTEND=noninteractive apt-get install -y \jq-COPY ./docker/dev/backend/scripts/run-test /usr/sbin/run-test-COPY ./docker/dev/backend/scripts/setup-tests /usr/sbin/setup-tests+COPY ./docker/dev/backend/scripts/run-test /usr/bin/run-test+COPY ./docker/dev/backend/scripts/setup-tests /usr/bin/setup-tests-USER $USER--ENTRYPOINT [ "/usr/sbin/run-test" ]+ENTRYPOINT [ "run-test" ]diff --git a/docker/dev/backend/scripts/run-test b/docker/dev/backend/scripts/run-testindex 04b449c3ca6..6cf30021eb5 100755--- a/docker/dev/backend/scripts/run-test+++ b/docker/dev/backend/scripts/run-test@@ -5,10 +5,12 @@ set -ucmd="$@"+chown -R $USER:$USER public/assets+echo 'Waiting for the Grid...'while ! curl -sSL "${SELENIUM_GRID_URL}/status" 2>&1 \| jq -r '.value.ready' 2>&1 | grep "true" > /dev/null; dosleep 1done-exec $cmd+exec su $USER -c $cmddiff --git a/docs/development/development-environment-docker/README.md b/docs/development/development-environment-docker/README.mdindex 48387fe1151..02d67279026 100644--- a/docs/development/development-environment-docker/README.md+++ b/docs/development/development-environment-docker/README.md@@ -21,7 +21,16 @@ bin/compose startOnce the containers are done booting you can access the application under http://localhost:3000.-If there is an `.env` file (see below) `bin/compose` will source it.+### Tests++You can run tests using `bin/compose rspec`. You can run specific tests too. For instance:++```+bin/compose rspec spec/features/work_package_show_spec.rb+```++***+More details and options follow in the next section.<div class="alert alert-info" role="alert">@@ -32,7 +41,7 @@ Signs of lacking memory include an "Exit status 137" in the frontend container.</div>-## Setup+## Step-by-step Setup### 1) Checkout the code@@ -58,6 +67,8 @@ cp .env.example .envAfterwards, set the environment variables to your liking. `DEV_UID` and `DEV_GID` are required to be set so your projectdirectory will not end up with files owned by root.+Both `docker-compose` and `bin/compose` will load the env from this file.+### 3) Setup database and install dependencies```@@ -140,6 +151,12 @@ or for running a particular testbin/compose run backend-test bundle exec rspec path/to/some_spec.rb```+You can run specific tests too. For instance:++```+docker-compose run backend-test bundle exec rspec spec/features/work_package_show_spec.rb+```+Tests are ran within Selenium containers, on a small local Selenium grid. You can connect to the containers via VNC ifyou want to see what the browsers are doing. `gvncviewer` on Linux is a good tool for this. Check out the docker-composefile to see which port each browser container is exposed on. The password is `secret` for all.diff --git a/spec/support/browsers/chrome.rb b/spec/support/browsers/chrome.rbindex e491de8ae4a..2d7ceb4f5cd 100644--- a/spec/support/browsers/chrome.rb+++ b/spec/support/browsers/chrome.rb@@ -45,20 +45,26 @@ def register_chrome(language, name: :"chrome_#{language}")client.read_timeout = 180client.open_timeout = 180- service = ::Selenium::WebDriver::Service.chrome(args: { verbose: true, log_path: '/tmp/chromedriver.log' })+ is_grid = ENV['SELENIUM_GRID_URL'].present?- driver = Capybara::Selenium::Driver.new(- app,- # browser: ENV['SELENIUM_GRID_URL'] ? :remote : :chrome,- browser: :chrome,- url: ENV['SELENIUM_GRID_URL'],+ driver_opts = {+ browser: is_grid ? :remote : :chrome,desired_capabilities: capabilities,http_client: client,options: options,- service: service- )+ }++ if is_grid+ driver_opts[:url] = ENV['SELENIUM_GRID_URL']+ else+ driver_opts[:service] = ::Selenium::WebDriver::Service.chrome(+ args: { verbose: true, log_path: '/tmp/chromedriver.log' }+ )+ end++ driver = Capybara::Selenium::Driver.new app, **driver_opts- if !ENV['SELENIUM_GRID_URL']+ if !is_grid# Enable file downloads in headless mode# https://bugs.chromium.org/p/chromium/issues/detail?id=696481bridge = driver.browser.send :bridgediff --git a/spec/support/browsers/firefox.rb b/spec/support/browsers/firefox.rbindex dce2ac47afa..c39b179cdf2 100644--- a/spec/support/browsers/firefox.rb+++ b/spec/support/browsers/firefox.rb@@ -42,23 +42,21 @@ def register_firefox(language, name: :"firefox_#{language}")options.args << "--headless"end- driver = if ENV['SELENIUM_GRID_URL']- Capybara::Selenium::Driver.new(- app,- browser: :remote,- url: ENV['SELENIUM_GRID_URL'],- desired_capabilities: capabilities,- options: options- )- else- Capybara::Selenium::Driver.new(- app,- browser: :firefox,- desired_capabilities: capabilities,- options: options,- http_client: client- )- end+ is_grid = ENV['SELENIUM_GRID_URL'].present?++ driver_opts = {+ browser: is_grid ? :remote : :firefox,+ url: ENV['SELENIUM_GRID_URL'],+ desired_capabilities: capabilities,+ http_client: client,+ options: options,+ }++ if is_grid+ driver_opts[:url] = ENV['SELENIUM_GRID_URL']+ end++ driver = Capybara::Selenium::Driver.new app, **driver_optsCapybara::Screenshot.register_driver(name) do |driver, path|driver.browser.save_screenshot(path)