docker dev and test setup fixes (#9135)

* docker dev and test setup fixes

* added missing >

* include test instructions in quickstart

* fixed typo

Co-authored-by: Philipp Tessenow <tessi@bitcrowd.net>

* removed obsolete comment

Co-authored-by: Philipp Tessenow <tessi@bitcrowd.net>

* amendments

Co-authored-by: Benjamin Bädorf <b.baedorf@openproject.com>
Co-authored-by: Philipp Tessenow <tessi@bitcrowd.net>
pull/9150/head
Markus Kahl 4 years ago committed by GitHub
parent b2b307c4e2
commit c375646dc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 31
      bin/compose
  2. 4
      docker-compose.yml
  3. 8
      docker/dev/backend/Dockerfile
  4. 4
      docker/dev/backend/scripts/run-test
  5. 21
      docs/development/development-environment-docker/README.md
  6. 24
      spec/support/browsers/chrome.rb
  7. 32
      spec/support/browsers/firefox.rb

@ -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

@ -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"

@ -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" ]

@ -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

@ -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.

@ -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

@ -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)

Loading…
Cancel
Save