For local development, you can either use Docker, and potentially Devcontainers, or you can use your own installation of Ruby and/or PostgreSQL. The included setup can deploy these in Docker containers rather than needing to install them. Depending on your IDE or code editor, you may prefer to install Ruby locally.
The application has a Docker DevContainer setup. If you use VS Code, this is the easiest way to develop for Cobra.
To use it, first create the database.yml file:
$ cat config/database.example.app-in-docker.yml | sed s/localhost/db/ > config/database.ymlIf you open this folder in VS Code it will prompt you to re-open in the devcontainer. From there, your terminal will be in the container and you will have a self-contained, full-featured development environment.
If you want to develop with docker outside of VS Code, these instructions are for you. This set up is preferred over local environment dev to keep development and deployed versions consistent.
Local changes are live refreshed for both ruby and svelte aside from server-startup configuration.
- Set up config files
$ cat config/database.example.app-in-docker.yml | sed s/localhost/db/ > config/database.yml $ echo "POSTGRES_PASSWORD=cobra" > .env $ echo "RAILS_ENV=development" >> .env
- Start the application
$ docker compose up -d
To interact with the application, enter the app shell and run your commands in there.
$ docker compose exec app /bin/sh- Get the project
$ git clone https://github.com/Project-NISEI/cobra.git $ cd cobra - Install dependencies
$ bundle
- Set up config files
$ cp config/database.example.app-in-host.yml config/database.yml
- Set up database in Docker
$ echo "POSTGRES_PASSWORD=cobra" > .env $ echo "RAILS_ENV=development" >> .env $ bin/init-db-from-host
This will create a Docker container running PostgreSQL and set up the database there. If you prefer to install PostgreSQL locally instead, you can set up the database like this:
$ psql postgres
# create user cobra with password 'cobra' CREATEDB;
# \q
$ rails db:create db:migrateStart local server in your IDE, or with the Rails CLI (this was installed when you ran bundle):
$ rails server$ bundle exec rails ids:updateThis task queries the NRDB API and creates/updates identities as appropriate.
Identities not in the database are stripped out of ABR uploads to avoid errors.
This is run automatically by bin/deploy and bin/init-db-*.
$ bundle exec rails card_sets:updateFormats, tournament types, and prize kits are seeded by this task.
$ bundle exec rails tournament_metadata:seed$ bundle exec rspecNote that you will need to override the environment if you are running this in a Docker container:
$ RAILS_ENV=test bundle exec rspecFlipper is included to give the option to hide or disable features which are incomplete. This lets you make changes in smaller increments, while still being able to deploy to a production environment with your feature hidden.
You can enable or disable a feature for all development environments by editing development.rb.
That file can include code similar to the following, which will enable the feature when the app starts up. The rescue block handles cases where the database is not fully initialized, eg. in a Rails task.
Rails.application.configure do
# There should be other configuration here...
config.after_initialize do
begin
Flipper.enable :nrdb_deck_registration
rescue => e
Rails.logger.warn "Failed setting Flipper features: #{e.class}"
end
end
end