Skip to content

Commit

Permalink
Merge pull request #72 from mlibrary/docker-compose-debugging
Browse files Browse the repository at this point in the history
Debugging assistance for docker-compose.
  • Loading branch information
bertrama authored Feb 16, 2022
2 parents 8abbce7 + 235cd32 commit d885b51
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ RUN gem install bundler:1.17.3

USER $UNAME

COPY Gemfile* ${APP_HOME}/
COPY local-gems/ ${APP_HOME}/local-gems/
COPY --chown=${UNAME}:${UNAME} Gemfile* ${APP_HOME}/
COPY --chown=${UNAME}:${UNAME} local-gems/ ${APP_HOME}/local-gems/

RUN bundle install

Expand Down
54 changes: 37 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,51 +10,71 @@ Clone the repository
git clone git@github.com:mlibrary/spectrum.git spectrum
cd spectrum
```
Copy .env-example to .env
```

Copy `.env-example` to `.env`
```bash
cp .env-example .env
```

Get the actual values for the `.env` file from one of the developers. Update `.env` with those values.

Build it.
```
docker-compose build
Build it:
```bash
docker-compose up --build --no-start
```

Install the gems into the gem-cache
```
Install the gems into the gem-cache:
```bash
docker-compose run --rm web bundle install
```

Pull the latest version of the search front end
```
Pull the latest version of the search front end:
```bash
docker-compose run --rm web bundle exec rake 'search[latest,local]'
```

Load up the catalog with some example data. To do that you need to start up catalog solr and then index the data.

On a fresh install it is necessary to first manually pull the `catalog-solr` image, which will be used to hold the local example data:
```bash
docker-compose pull catalog-solr
```

Load up the catalog with some example data. To do that you need to start up `catalog-solr` and then index the data.
```bash
docker-compose start catalog-solr
docker-compose exec catalog-solr bash /examples/load_into_solr.sh
```

Then start it

```
```bash
docker-compose up
```
In the browser go to `http://localhost:3000`
In the browser go to [http://localhost:3000](http://localhost:3000)


### Running Tests
```
```bash
docker-compose run --rm web bundle exec rspec
```

### Debugging
To use a debugger like `byebug`, first start the app with `docker-compose up`. Then in another terminal:
Puma doesn't always play nicely with pry. Worker timeouts can end sessions early, and multi-threading can make taking input from the terminal troublesome.

To address these issues, the `script/docker-startup` file will run in WEBrick when started with the environment variable `RAILS_SERVER` set to webrick.
To set `RAILS_SERVER` add it to your `.env` file:
```
docker attach "$(docker-compose ps -q web)"
RAILS_SERVER=webrick
```

Additionally, WEBrick needs to run in development mode. Add `RAILS_ENV` to your `.env` to ensure it does:
```
RAILS_ENV=development
```

Changing environment variables in `docker-compose` gets updated when running `docker-compose up` so, to pick up environment variable changes every time, and attach for use with a debugger:
```bash
docker-compose up --no-start web && \
docker-compose start web && \
docker attach "$(docker-compose ps -q web)"
```

## Overview of Spectrum
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:
args:
- UID=${UID}
- GID=${GID}
command: bash -c 'rm -f tmp/pids/server.pid && bundle exec rails s -p ${BIND_PORT} -b ${BIND_IP}'
command: script/docker-startup
env_file:
- .env-dev-values
- .env
Expand Down
8 changes: 8 additions & 0 deletions script/docker-startup
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

rm -f tmp/pids/server.pid

bundle exec rackup \
-s "${RAILS_SERVER:-puma}" \
-p "${BIND_PORT}" \
-o "${BIND_IP}"
4 changes: 4 additions & 0 deletions script/run-tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

docker-compose run --rm web bundle exec rspec

0 comments on commit d885b51

Please sign in to comment.