-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #726 from ndlib/docker-compose-rails-with-sync
Add support for developing the rails app within Docker
- Loading branch information
Showing
20 changed files
with
374 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* text=auto | ||
*.sh text eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,3 +34,4 @@ spec/jetty_generator | |
.tags | ||
.byebug_history | ||
.DS_Store | ||
.docker-sync |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Developing CurateND with Docker | ||
|
||
## Installation Notes | ||
Install Docker: https://www.docker.com/ | ||
|
||
Install docker-sync: http://docker-sync.io/ | ||
|
||
Start the stack: | ||
```console | ||
docker-sync-stack start | ||
``` | ||
|
||
## Testing | ||
To execute the full test suite, run | ||
```console | ||
docker-compose exec rails bundle exec rake | ||
``` | ||
To run individual specs, run | ||
```console | ||
docker-compose exec rails bundle exec rspec spec/path/to/file_spec.rb | ||
``` | ||
|
||
## Debugging the application | ||
```console | ||
docker-compose exec rails bundle exec byebug --remote localhost:9876 | ||
``` | ||
|
||
## Rebuilding curate-jetty Docker image | ||
|
||
To rebuild the Docker image for running jetty, use the following command: | ||
|
||
```console | ||
docker build . -t ndlib/curate-jetty -f docker/Dockerfile.jetty | ||
``` | ||
|
||
To push your image to Dockerhub: | ||
|
||
```console | ||
docker login | ||
docker push ndlib/curate-jetty | ||
``` | ||
|
||
To rebuild the image with pre-generated seed data: | ||
```console | ||
# First reset to the base image | ||
docker stop curate-jetty && docker rm curate-jetty | ||
docker run -p 8983:8983 -d --name curate-jetty -t ndlib/curate-jetty | ||
# Run seed scripts from the project root directory | ||
bundle exec rake db:schema:load db:seed:dev | ||
# Commit these changes to your image | ||
docker commit curate-jetty ndlib/curate-jetty-devseed | ||
# Push it up as the dev seed image | ||
docker login | ||
docker push ndlib/curate-jetty-devseed | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
if Rails.env.development? | ||
require 'byebug/core' | ||
#Byebug.wait_connection = true | ||
port = ENV.fetch("BYEBUG_SERVER_PORT", 9876).to_i | ||
print "Starting byebug server for remote debugging on port #{port}\n" | ||
Byebug.start_server 'localhost', port | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,48 @@ | ||
version: '3' | ||
services: | ||
mysql: | ||
image: mariadb | ||
build: | ||
context: ./docker/ | ||
dockerfile: Dockerfile.mariadb | ||
ports: | ||
- "3306:3306" | ||
environment: | ||
MYSQL_ROOT_PASSWORD: password | ||
MYSQL_DATABASE: curate_nd_development | ||
volumes: | ||
- ./docker/mysql-utf8.cnf:/etc/mysql/conf.d/mysql-utf8.cnf | ||
healthcheck: | ||
interval: 30s | ||
timeout: 10s | ||
retries: 5 | ||
jetty: | ||
image: ndlib/curate-jetty-devseed | ||
ports: | ||
- "8983:8983" | ||
rails: | ||
build: | ||
context: . | ||
dockerfile: docker/Dockerfile.rails | ||
command: bash docker/rails_entry.sh | ||
environment: | ||
BUNDLE_PATH: "/bundle" | ||
FEDORA_HOST: jetty | ||
FEDORA_PORT: 8983 | ||
MYSQL_HOST: mysql | ||
SOLR_HOST: jetty | ||
SOLR_PORT: 8983 | ||
# Need to pass the user running docker into the container so that | ||
# config/admin_usernames.yml pulls in the user as an admin. This is | ||
# to replicate existing behavior on OSX and may not work correctly on | ||
# another OS | ||
USER: #{USER} | ||
ports: | ||
- "3000:3000" | ||
volumes: | ||
- curate_nd_rails_sync:/project_root:nocopy | ||
depends_on: | ||
- mysql | ||
- jetty | ||
volumes: | ||
curate_nd_rails_sync: | ||
external: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
version: "2" | ||
|
||
options: | ||
verbose: true | ||
syncs: | ||
curate_nd_rails_sync: | ||
src: '.' | ||
sync_excludes: ['.git', 'tmp', 'jetty', 'vendor/bundle', 'log'] |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FROM mariadb | ||
|
||
COPY mysql-healthcheck /usr/local/bin/ | ||
|
||
HEALTHCHECK CMD ["mysql-healthcheck"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
FROM ruby:2.1.10 | ||
|
||
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs unzip | ||
|
||
# Install Fits (which requires java) | ||
RUN apt-get install -y default-jre | ||
RUN mkdir /fits | ||
WORKDIR /fits | ||
RUN wget https://projects.iq.harvard.edu/files/fits/files/fits-0.6.2.zip | ||
RUN unzip fits-0.6.2.zip | ||
RUN chmod 755 /fits/fits-0.6.2/fits.sh | ||
ENV PATH="/fits/fits-0.6.2:${PATH}" | ||
|
||
# Put the installed gems outside of project_root so that the sync volume won't interfere | ||
RUN mkdir /bundle | ||
COPY Gemfile /bundle | ||
COPY Gemfile.lock /bundle | ||
WORKDIR /bundle | ||
RUN bundle install --without headless --path /bundle | ||
|
||
RUN mkdir /project_root | ||
WORKDIR /project_root | ||
COPY . /project_root | ||
|
||
# Gemfile.lock may have changed after bundling, copy it back into the project_root | ||
RUN cp /bundle/Gemfile.lock /project_root/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
docker-compose exec rails bundle exec byebug --remote localhost:9876 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
set -eo pipefail | ||
|
||
if [ "$MYSQL_RANDOM_ROOT_PASSWORD" ] && [ -z "$MYSQL_USER" ] && [ -z "$MYSQL_PASSWORD" ]; then | ||
# there's no way we can guess what the random MySQL password was | ||
echo >&2 'healthcheck error: cannot determine random root password (and MYSQL_USER and MYSQL_PASSWORD were not set)' | ||
exit 0 | ||
fi | ||
|
||
host="$(hostname --ip-address || echo '127.0.0.1')" | ||
user="${MYSQL_USER:-root}" | ||
export MYSQL_PWD="${MYSQL_PASSWORD:-$MYSQL_ROOT_PASSWORD}" | ||
|
||
args=( | ||
# force mysql to not use the local "mysqld.sock" (test "external" connectibility) | ||
-h"$host" | ||
-u"$user" | ||
--silent | ||
) | ||
|
||
if select="$(echo 'SELECT 1' | mysql "${args[@]}")" && [ "$select" = '1' ]; then | ||
exit 0 | ||
fi | ||
|
||
exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# All the things that will execute when starting the rails service | ||
# Copy the generated lock file back into the project root. This is to sync this change back to the | ||
# application after the container has mounted the sync volume | ||
cp /bundle/Gemfile.lock ./ | ||
bash docker/wait-for-it.sh mysql:3306 | ||
bundle exec rake db:schema:load | ||
# If we find people are ok with just starting a shell in the container and running the db create/load before running specs, then we can remove this | ||
RAILS_ENV=test bundle exec rake db:create db:schema:load | ||
|
||
exec bundle exec thin start -p 3000 --ssl --ssl-key-file dev_server_keys/server.key --ssl-cert-file dev_server_keys/server.crt |
Oops, something went wrong.