-
Notifications
You must be signed in to change notification settings - Fork 441
Development Environment Tips & Tricks
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!
- Control services
- Run commands in service
- Test Suites
- Create data to play with in development
- Debugging
- Reset your Environment
- Troubleshooting
You can bring up/tear down services
docker compose up -d
docker compose stop backend
docker compose restart
check their status
docker compose ps
or view the output of services
docker compose logs
If you need to update the frontend service you can rebuild your local image with
docker compose build --pull frontend
You can run any command in a service by calling exec
. This command needs two parameters, the service you want to use and the command you want to execute.
docker compose exec frontend hostname
You can also start an interactive shell inside the service and run any command you like from it.
docker compose exec frontend /bin/bash -l
Be sure to have the seeds in your test database with RAILS_ENV=test bundle exec rake db:seed
.
If you want to start with a fresh test database, run RAILS_ENV=test bundle exec rake db:reset db:seed
.
Run all specs
docker compose exec frontend rspec
or just a single spec
docker compose exec frontend rspec spec/models/package_spec.rb
While working on feature specs, by default the tests are running for desktop (large viewport). If you want to run it for mobile (small viewport), you need to set the environment variable CAPYBARA_DRIVER
to mobile
.
docker compose exec frontend /bin/bash -l
CAPYBARA_DRIVER=mobile rspec spec/feature/beta/something_spec.rb
You can run all tests (including spider)
docker compose -f docker-compose.yml -f docker-compose.minitest.yml run --rm minitest bundle exec rake test
Run a single test file
docker compose -f docker-compose.yml -f docker-compose.minitest.yml run --rm minitest bundle exec ruby test/mytest_test.rb
Or run a single test from a test file
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
docker compose run --rm frontend rake dev:lint:all
More details on RuboCop here.
This will create some projects, a submit request, an interconnect to build.o.o and a maintenance project.
docker compose run --rm frontend rake dev:test_data:create
If you need some random objects to play around, you can use our factories. For this you can include the FactoryBot
syntax on a rails console
and use all the commands you usually use in rspec.
include FactoryBot::Syntax::Methods
create_list(:package_with_file, 100)
- Add binding.pry to some spec
docker compose run --rm frontend rspec spec/mixins/statistics_calculations_spec.rb
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.
docker compose run --rm --service-ports frontend bash -c "bundle exec rake ts:start && bundle exec rails s -b 0.0.0.0"
- Add binding.pry to some code path
- Access your code path and
pry
will run
docker compose run --rm frontend rake db:drop dev:bootstrap
docker-compose stop backend; docker-compose rm -f backend; docker-compose up -d backend
You want to recreate your database too afterward...
You can remove a single image
docker image rm openbuildservice/frontend-base
or all of them
docker image prune
Sometimes you just have to go back to where you have started....
docker compose stop
docker compose rm
docker image prune -a
rake docker:build
docker compose up
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 src/api/tmp/pids/server.pid
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
The frontend fails to start and you you get the following error trying to create objects via console:
Traceback (most recent call last):
2: from (irb):1
1: from app/mixins/populate_sphinx.rb:5:in `populate_sphinx'
ThinkingSphinx::ConnectionError (Error connecting to Sphinx via the MySQL protocol. Can't connect to MySQL server on '127.0.0.1' (115))
Please make sure that you didn't start the frontend with docker compose up
but with the following command:
docker compose run --rm --service-ports frontend bash -c "(bundle exec rails sphinx:start_for_development &) && rails s -b 0.0.0.0"
Be sure to have the latest Thinking Sphinx configuration.
Running specs in RSpec might take minutes before finally starting. This can be caused by the strategy used by DatabaseCleaner. As the time of writing, we use truncation
. This strategy can be slow depending on the filesystem you use. Switching the strategy to deletion
can greatly decrease the time it takes for RSpec to start running specs.
Recommended strategy depending on the filesystem you use:
-
deletion
forext4
-
truncation
forbtrfs
Your experience might differ, so be sure to give both strategies a try.
- Development Environment Overview
- Development Environment Tips & Tricks
- Spec-Tips
- Code Style
- Rubocop
- Testing with VCR
- Authentication
- Authorization
- Autocomplete
- BS Requests
- Events
- ProjectLog
- Notifications
- Feature Toggles
- Build Results
- Attrib classes
- Flags
- The BackendPackage Cache
- Maintenance classes
- Cloud uploader
- Delayed Jobs
- Staging Workflow
- StatusHistory
- OBS API
- Owner Search
- Search
- Links
- Distributions
- Repository
- Data Migrations
- next_rails
- Ruby Update
- Rails Profiling
- Installing a local LDAP-server
- Remote Pairing Setup Guide
- Factory Dashboard
- osc
- Setup an OBS Development Environment on macOS
- Run OpenQA smoketest locally
- Responsive Guidelines
- Importing database dumps
- Problem Statement & Solution
- Kickoff New Stuff
- New Swagger API doc
- Documentation and Communication
- GitHub Actions
- How to Introduce Software Design Patterns
- Query Objects
- Services
- View Components
- RFC: Core Components
- RFC: Decorator Pattern
- RFC: Backend models