-
Notifications
You must be signed in to change notification settings - Fork 43
Getting started (development cheatsheet)
docker-compose build
docker-compose up
docker attach solutions_app
To see what data was seeded, view the seeds file in db/seeds.rb
docker-compose run --rm solutions_app rails db:create
docker-compose run --rm solutions_app rails db:migrate
docker-compose run --rm solutions_app rails db:seed
this step needs to be done only once and should take anywhere between 5 - 20 minutes to complete.
docker-compose run --rm solutions_app rails assets:precompile
visit localhost:80
, lvh.me:5250
or localhost:5250
to see your app!
- To Login, visit
lvh.me:5250/admin
use the following credentials (created by seeds.rb) - user:
[email protected]
- password:
123456
There are 2 admin tiers. Domain admins (aka global admin) can control all the subdomains in an app. Subdomain admins are confined to managing their own subdomain.
- to access the subdomain admin, visit
lvh.me:5250/admin
orsubdomain.lvh.me:5250/admin
- to access domain admin visit
lvh.me:5250/sysadmin
running a console
docker-compose run --rm solutions_app rails c
running the full test suite on a pristine database
./clean_run_tests.sh
running the rails test suite
docker-compose run --rm solutions_test rails test
# or
./run_tests.sh
run a single test
docker-compose run --rm solutions_test rails test path/to/test
Create a file to set the variables at the application root called .env.development
. Since we are using docker in development, the following variable set will work right out of the box. Copy paste it into your .env.development
file.
RAILS_ENV=development
DATABASE_HOST=solutions_db
DATABASE_USERNAME=postgres
DATABASE_PASSWORD=password
DATABASE_NAME=r_solutions_development
DATABASE_PORT=5432
APP_HOST=localhost
REDIS_URL=redis://solutions_redis:6379/12
RACK_TIMEOUT_SERVICE_TIMEOUT=200
Environment variables are slightly different for each environment, the ones that are maintained by Restarone are checked into version control: Github CI configuration file or the local .env.test
file if you want to see the latest variables the app is using.
please refrain from committing the changes you make to your .env.development file (unless you are introducing a new feature and adding a variable)
Make sure you have docker-compose up
running the app in a separate terminal window and run
docker attach solutions_app
Now you will see your rails log and it will let you use byebug/pry when you hit your breakpoints
to attach to sidekiq to read logs or hit a breakpoint:
docker attach solutions_sidekiq
Since Violet is multi-tenant, tasks need to run on each schema. Do accomplish this, you will need to iterate over each subdomain and open an execution context inside each of them:
desc "example task"
task :my_task => [:environment] do
subdomains = Subdomain.all_with_public_schema
subdomains.each do |subdomain|
Apartment::Tenant.switch subdomain.name do
# ... your code here
end
end
end
example: https://github.com/restarone/violet_rails/blob/master/lib/tasks/maintenance.rake
To view the emails sent by the app in development mode, we use mailcatcher. Visit the following URL to see what emails have been sent from the app:
http://localhost:1080/
teardown, further reading: https://stackoverflow.com/questions/34658836/docker-is-in-volume-in-use-but-there-arent-any-docker-containers
docker-compose stop solutions_app \
&& docker-compose rm -f solutions_app \
&& docker-compose build \
&& docker-compose up -d solutions_app
To view application routes:
visit http://somesubdomain.lvh.me:5250/rails/info/routes
connect to psql
psql -h ec2-3-83-199-128.compute-1.amazonaws.com -p 5432 -d postgres -U postgres
kill existing connections
REVOKE CONNECT ON DATABASE violet_staging FROM public;
SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'violet_staging';
If you are running parts of the app outside of docker (ie; capistrano deploy), you will need to specify a local postgres DB connection that is available for activerecord to hook into. Temporarily replace the contents of database.yml with the following (replace the database
username
and password
with the credentials for your local postgres database:
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
host: localhost
port: 5432
database: solutions_development
username: postgres
password: postgres
test:
<<: *default
host: localhost
port: 5432
database: solutions_development
username: postgres
password: postgres
staging:
<<: *default
host: localhost
port: 5432
database: solutions_development
username: postgres
password: postgres
production:
<<: *default
host: localhost
port: 5432
database: solutions_development
username: postgres
password: postgres
clear assets from docker
docker-compose run --rm solutions_app rails assets:clobber
deploy to environment
BRANCH=branch bundle exec cap staging deploy
To use the application as a starting point, you will need to make a few changes to the docker configuration. To start, clone the repo
git clone [email protected]:restarone/violet_rails.git
follow this PR and make the necessary changes to the docker config: https://github.com/restarone/violet_rails/pull/290 and then change the docker commands to the names you specified in docker-compose.yml
docker-compose build
docker-compose up
docker-compose run --rm app rails db:create
docker-compose run --rm test rails db:create
docker-compose run --rm app rails db:migrate
docker-compose run --rm test rails db:migrate
# make sure docker-compose up is working and run this test:
docker-compose run --rm test rails test test/controllers/admin/sidekiq_controller_test.rb