Skip to content

Development Environment Tips & Tricks

Dany Marcoux edited this page Sep 19, 2019 · 42 revisions

This page is collection of tips & tricks about our development environment. For and introduction how to setup the development environment check out our contribution guide.

This will not and can not replace docker and docker-compose documentation. You are strongly encouraged get familiar with those tools!

Services

Start/Stop/Restart all services

  • docker-compose up
  • docker-compose stop
  • docker-compose restart

Start/Stop/Restart a single service

  • docker-compose up cache
  • docker-compose stop backend
  • docker-compose restart db

Check running services

docker-compose ps

Attach to a running service

docker-compose exec frontend /bin/bash -l

Running commands in services

You can run any command in running services by calling docker-compose exec. This command needs two parameters, the service you want to use and the command you want to execute.

For example, to run a single test call

docker-compose exec frontend rspec spec/mixins/statistics_calculations_spec.rb

Debugging an rspec spec with pry

  1. docker-compose up
  2. Add binding.pry to some spec
  3. docker-compose exec frontend rspec spec/mixins/statistics_calculations_spec.rb

Debugging the rails app with pry

Debugging the running rails application will start the pry session in the rails output so you need to start the rails server on it's own.

  1. Add binding.pry to some code path
  2. docker-compose up -d worker backend cache db
  3. docker-compose run --rm --service-ports frontend rails server -b 0.0.0.0
  4. Access your code path and pry will run

Run a single rspec feature (using selenium)

To run the features, you will need selenium up and running. To run a single rspec you can do the following:

docker-compose -f docker-compose.yml -f docker-compose.selenium.yml run --service-ports --use-aliases --rm frontend rspec spec/features/my_cool_feature_spec.rb

Do not forget to prepare the database before. To do it run in the container the following commands:

bundle exec rake dev:bootstrap RAILS_ENV=test
bundle exec rake db:seed RAILS_ENV=test

Connect via VNC to Capybara's Driver

While working on feature specs, you can follow what is happening live in Capybara's driver.

Steps:

  1. Launch our Docker Compose setup for Capybara
docker-compose -f docker-compose.yml -f docker-compose.selenium.yml run --service-ports --use-aliases --rm frontend bash -l
  1. Connect to Capybara's driver with your VNC client at localhost. For example, in TigerVNC viewer, you type localhost in the VNC Server field and then press the Connect button.
  2. Optional: Set a breakpoint in your feature specs with Pry: binding.pry
  3. Run some feature specs, for example: bundle exec rspec spec/features/something_spec.rb. You will now start to see in your VNC client that Capybara is running.
  4. Optional: Debug with the usual Pry (+ byebug) commands, such as: next, continue, etc...

Run the old test suite like we run it in CI with:

This is for the minitest and spider tests.

docker-compose -f docker-compose.yml -f docker-compose.minitest.yml run --rm minitest bundle exec rake test

Run a single test file in the old api test suite

docker-compose -f docker-compose.yml -f docker-compose.minitest.yml run --rm minitest bundle exec ruby test/mytest_test.rb

Run a single test in the old api test suite

docker-compose -f docker-compose.yml -f docker-compose.minitest.yml run --rm minitest bundle exec ruby test/mytest_test.rb -n test_method_name

(Re)create your database

docker-compose run --rm frontend rake db:drop dev:bootstrap

Containers

Remove all containers

  1. docker-compose stop
  2. docker-compose rm

Remove a single container

  1. docker-compose stop frontend
  2. docker-compose rm frontend

Images

Remove all images

docker image prune

Remove a single image

docker image rm openbuildservice/frontend-base

Change a static image

If you need to change one of the static images/Dockerfiles you can rebuild your local images with

rake docker:maintainer:rebuild

To publish the containers to the docker hub (you need access to the openbuildservice organization). Note that new docker images are automatically built whenever master changes. This happens via the GitHub docker service.

If needed, you can manually publish the built docker files with

rake docker:maintainer:publish

Change the frontend image

If you need to change the frontend Dockerfile you can rebuild your local image with

docker-compose build frontend

in your pull request that changed the Dockerfile let the other developers (@openSUSE/open-build-service) know that they need to rebuild their frontend container...

Rake tasks

There are a couple of rake tasks that you can run in your git checkout.

Run all linters

rake dev:lint runs from src/api

Run haml-lint

rake haml_lint runs from src/api

Autocorrect rubocop

rake dev:lint:rubocop:auto_correct runs from src/api

Setup testdata for development

Please note that this needs to get executed inside the frontend container.

rake dev:development_testdata:create

This will create some projects, a submit request, an interconnect to build.o.o and a maintenance project.

Reset everything and start from scratch 💣

Sometimes you just have to go back to where you have started....

  1. docker-compose stop
  2. docker-compose rm
  3. docker image prune -a
  4. rake docker:build
  5. docker-compose up

Fake Workers on Monitor Page

If you ever wanted to have a lot of workers on the monitor page, but without building tons of packages, this is how you can achieve this. Props to @vpereira.

  1. Replace the delta lines by delta = rand(1..100). This will enable different colors for the progress bars.
  2. Download this file and save it under src/api/tmp/ and replace this line by @workerstatus = Xmlhash.parse(File.read(File.join(Rails.root, 'tmp', 'worker_status.xml'))). This file is only the output of WorkerStatus.hidden.to_xml which we ran in rails console.

Troubleshooting

Stale Rails server pid file

The frontend fails to start and you see a message like

frontend_1  | 09:25:14 web.1     | A server is already running. Check /obs/src/api/tmp/pids/server.pid.
...
openbuildservice_frontend_1 exited with code 1

That can happen if a docker instance forcefully get's shut down and thus doesn't clean up properly. To solve this delete the pid file with

rm  tmp/pids/server.pid

The bundle is outdated

The frontend fails to start and you see a message like

frontend_1  | 10:53:17 web.1     | /usr/lib64/ruby/gems/2.4.0/gems/bundler-1.13.6/lib/bundler/definition.rb:179:in
`rescue in specs': Your bundle is locked to mail (2.7.0), but that version could not be found in any of the sources
listed in your Gemfile. If you haven't changed sources, that means the author of mail (2.7.0) has removed it. You'll 
need to update your bundle to a different version of mail (2.7.0) that hasn't been removed in order to install. 
(Bundler::GemNotFound)
...
openbuildservice_frontend_1 exited with code 1

That can happen if you or someone else changed our bundle by updating a gem version or introducing a new gem. You have to bundle install again in your frontend container. You can do this simply by

docker-compose up --build

Error in sphinx

The frontend fails to start and you see a message starting sphinx. The indexes must be rebuild. You can do this with:

docker-compose run frontend bash

> rake ts:index
Clone this wiki locally