Skip to content

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

docker dev and test setup fixes (#9135)

Markus Kahlc375646dc00d
diff --git a/bin/compose b/bin/compose
index 3d00deef07a..2baefb2b4c0 100755
--- a/bin/compose
+++ b/bin/compose
@@ -15,13 +15,25 @@ if [ $# -eq 0 ]; then
echo
echo "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\`."
echo
exit 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 frontend
docker-compose -f $COMPOSE_FILE up -d frontend
elif [[ "$@" = "run" ]]; then
@@ -32,6 +44,23 @@ elif [[ "$@" = "run" ]]; then
elif [[ "$1" = "setup" ]]; then
docker-compose -f $COMPOSE_FILE run backend setup
yes 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}"
else
docker-compose -f $COMPOSE_FILE $*
fi
diff --git a/docker-compose.yml b/docker-compose.yml
index 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: 3000
CAPYBARA_DYNAMIC_BIND_IP: 1
CAPYBARA_APP_HOSTNAME: backend-test
- OPENPROJECT_DISABLE_DEV_ASSET_PROXY: 1
+ OPENPROJECT_CLI_PROXY: http://frontend-test:4200
OPENPROJECT_TESTING_NO_HEADLESS: "true"
volumes:
- ".:/home/dev/openproject"
diff --git a/docker/dev/backend/Dockerfile b/docker/dev/backend/Dockerfile
index 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-test
index 04b449c3ca6..6cf30021eb5 100755
--- a/docker/dev/backend/scripts/run-test
+++ b/docker/dev/backend/scripts/run-test
@@ -5,10 +5,12 @@ set -u
cmd="$@"
+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; do
sleep 1
done
-exec $cmd
+exec su $USER -c $cmd
diff --git a/docs/development/development-environment-docker/README.md b/docs/development/development-environment-docker/README.md
index 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 start
Once 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 .env
Afterwards, set the environment variables to your liking. `DEV_UID` and `DEV_GID` are required to be set so your project
directory 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 test
bin/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 if
you want to see what the browsers are doing. `gvncviewer` on Linux is a good tool for this. Check out the docker-compose
file 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.rb
index 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 = 180
client.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=696481
bridge = driver.browser.send :bridge
diff --git a/spec/support/browsers/firefox.rb b/spec/support/browsers/firefox.rb
index 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_opts
Capybara::Screenshot.register_driver(name) do |driver, path|
driver.browser.save_screenshot(path)