|
| 1 | +### Interacting with the app |
| 2 | + |
| 3 | +You'll notice we wrapped `docker-compose` earlier, but you'll generally want to use this to interact with the app. |
| 4 | + |
| 5 | +- `bundle exec rails console` → `docker-compose run web rails console` |
| 6 | +- `bundle exec rake db:migrate` → `docker-compose run web rake db:migrate` |
| 7 | +- `bundle exec rake db:test:prepare` → `docker-compose run web rake db:test:prepare` |
| 8 | +- and so on... |
| 9 | + |
| 10 | +We do have a couple other helper scripts: |
| 11 | + |
| 12 | +- `bin/setup` → sets up the app |
| 13 | +- `bin/migrate` → migrates your database |
| 14 | +- `bin/reseed` → re-runs `rake db:seed_fu` to re-seed your database |
| 15 | + |
| 16 | + |
| 17 | +### Guard and tests |
| 18 | + |
| 19 | +You'll also notice that the `test` container we mentioned above is running `guard`. This means that file changes will be observed and tests re-run on those files. |
| 20 | + |
| 21 | +You can certainly run `docker-console run test rspec spec`, but `guard` can help you by constantly watching for failing specs. |
| 22 | + |
| 23 | + |
| 24 | +### Stopping and starting the server |
| 25 | + |
| 26 | +Need to stop the containers? Either `Ctrl+C` or in a seperate prompt run `docker-compose stop`. |
| 27 | + |
| 28 | +To start the services again you can run `docker-compose up`, or `docker-compose start` to start the containers in a detached state. |
| 29 | + |
| 30 | + |
| 31 | +### Rebuilding Docker containers |
| 32 | + |
| 33 | +If you ever need to rebuild you can run `docker-compose up --build`. Unless you've destroyed your Docker container images, this should be faster than the first run. |
| 34 | + |
| 35 | + |
| 36 | +### Pushing changes |
| 37 | + |
| 38 | +You can use `git` as you normally would, either on your own host machine or in Docker's `web` container. |
| 39 | + |
| 40 | + |
| 41 | +### Serving Ember |
| 42 | + |
| 43 | +The Code Corps API is intended to work alongside a client written in Ember. For that purpose, the Rails application exposes all of its API endpoints behind an `api.` subdomain. |
| 44 | + |
| 45 | +On the Ember client side of things, we use [`ember-cli-deploy`](https://github.com/ember-cli/ember-cli-deploy) with a `redis` plugin to deploy the client application to redis. Multiple revisions are maintained this way. |
| 46 | + |
| 47 | +Any server request pointing to the main domain and not the `api.` subdomain is redirected to the API's `ember_index_controller#index`. There, depending on the remainder of the request path and the current environment, a specific revision of the Ember app's `index.html` is retrieved from redis and rendered. This `index.html` can be: |
| 48 | +* the development revision, if the current environment is development |
| 49 | +* a specific deployed revision in production if the request contains a revision parameter in SHORT_UUID format |
| 50 | +* the latest deployed revision in production if the request does not contain a revision parameter |
| 51 | +* a plain text string containing "INDEX NOT FOUND" if a revision was specified, but the key for the specified revision was not found by redis |
| 52 | + |
| 53 | + |
| 54 | +### Debugging |
| 55 | + |
| 56 | +Because the app is running `foreman`, debugging using `pry` won't work the same way. If you want to use `pry`, you'll need to [debug remotely](https://github.com/nixme/pry-debugger#remote-debugging). |
| 57 | + |
| 58 | +Add `binding.remote_pry` where you want to pause: |
| 59 | + |
| 60 | +```ruby |
| 61 | +class UsersController < ApplicationController |
| 62 | + def index |
| 63 | + binding.remote_pry |
| 64 | + ... |
| 65 | + end |
| 66 | +end |
| 67 | +``` |
| 68 | + |
| 69 | +Load a page or make a request that triggers the code. Connect to the session: |
| 70 | + |
| 71 | +```shell |
| 72 | +$ docker-compose run web pry-remote |
| 73 | +``` |
0 commit comments