Skip to content
This repository was archived by the owner on Dec 3, 2019. It is now read-only.

refine the docker-compose config - #399

Merged
nellshamrell merged 2 commits into
OperationCode:masterfrom
robbkidd:docker-compose-moar-better
Sep 16, 2018
Merged

nellshamrell merged 2 commits into
OperationCode:masterfrom
robbkidd:docker-compose-moar-better

Conversation

@robbkidd

@robbkidd robbkidd commented Sep 14, 2018 •

Copy link
Copy Markdown
Contributor

Description of changes

  • allow the sidekiq service to reuse the image built for the web service
  • change the web service to bind to only the loopback interface (i.e. localhost) to avoid sharing your development backend with everyone in the coffee shop
  • update the PG and Redis services to also bind their ports to host's loopback to allow devs to run the Ruby bits on the host OS while reusing the docker'd database and Redis store (removed from this PR because of port conflicts in Travis)

Each of these bullets were added in separate commits, so each change is reviewable in isolation from the others.

The web service in docker-compose.yml creates an image named
"operationcodebackend_web". Much like the bundle service is configured
to reuse that already-built image, this configures the sidekiq service
to also reuse web. No need to also build a sidekiq image which takes up
time and disk space.

Signed-off-by: Robb Kidd <robb@thekidds.org>
The web service is updated to bind port 3000 to the loopback interface
(e.g. localhost) only, not all interfaces. No need to share your
development backend API to the whole coffee shop.

Signed-off-by: Robb Kidd <robb@thekidds.org>
@robbkidd

Copy link
Copy Markdown
Contributor Author

And the ⚠️ I left in one of the commit messages comes to pass:

ERROR: for operationcodebackend_operationcode-psql_1 
Cannot start service operationcode-psql: driver failed programming external connectivity on endpoint operationcodebackend_operationcode-psql_1 (704e9968cd9ea0a8ac4cb91257379d469a98072dc8c7606de4410fcf15d04ea9):
Error starting userland proxy: listen tcp 127.0.0.1:5432: bind: address already in use

Curses.

@robbkidd
robbkidd force-pushed the docker-compose-moar-better branch from 8ccb5bc to 8223ef3 Compare September 14, 2018 16:53
@robbkidd

Copy link
Copy Markdown
Contributor Author

Removed the commit that added PG and Redis host loopback port binding.

@apex-omontgomery

Copy link
Copy Markdown
Contributor

Could you explain the PG/ Redis host loopback port binding?

@robbkidd

Copy link
Copy Markdown
Contributor Author

Could you explain the PG/ Redis host loopback port binding?

Certainly! (Though at the time of this writing, that change is not present in the commits in this PR.) Basically, it would allow a dev to continue to run PG and Redis in Docker and have the option to run the Ruby/Railsy bits on their host OS, e.g. > bundle exec foreman start. Where I found this helpful recently was in experimenting with alternative JSON gems. I could add a gem to the Gemfile, bundle install in the project directory on my host, and then stop/start the web service again with foreman and have the new gem. I did not have to rebuild then rerun the web docker image to run an instance with the new gem in development.

It broke in Travis because the Travis builder has PostgreSQL already running so ports conflicted. There are a couple options to resolve that if everyone agrees that this flexibility of where a dev can run Ruby is worth it. This could be a step along the path of supporting a more native dev environment (#361).

Details

   operationcode-psql:
     image: postgres
+    ports:
+      - "127.0.0.1:5432:5432"
     env_file:
       - .env

   redis:
     image: redis:latest
+    ports:
+      - "127.0.0.1:6379:6379"

With this change and a clean docker-compose, I can do the standard setup.

> docker-compose ps --services
bundle
operationcode-psql
redis
web
sidekiq

> docker-compose ps
Name   Command   State   Ports
------------------------------

> make setup
docker-compose build
bundle uses an image, skipping
operationcode-psql uses an image, skipping
redis uses an image, skipping
Building web
Step 1/11 : FROM ruby:2.3.3
 ---> 0e1db669d557
[... blah blah buildy blah ...]
Step 10/11 : ADD . $APP_HOME/
 ---> 5ae7a56ef230
Step 11/11 : CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"]
 ---> Running in cec57544abcc
Removing intermediate container cec57544abcc
 ---> f767d05072d8
Successfully built f767d05072d8
Successfully tagged operationcodebackend_web:latest
sidekiq uses an image, skipping
docker-compose run web rake db:create
Creating operationcodebackend_bundle_1             ... done
Creating operationcodebackend_operationcode-psql_1 ... done
Creating operationcodebackend_redis_1              ... done
Created database 'operationcode_development'
Created database 'operationcode_test'
docker-compose run web rake db:migrate
Starting operationcodebackend_operationcode-psql_1 ... done
Starting operationcodebackend_bundle_1             ... done
Starting operationcodebackend_redis_1              ... done
[... database migrations ...]

What is left running is only the PG database and Redis.

> docker-compose ps
                  Name                                 Command               State             Ports
--------------------------------------------------------------------------------------------------------------
operationcodebackend_bundle_1               echo bundle data container       Exit 0
operationcodebackend_operationcode-psql_1   docker-entrypoint.sh postgres    Up       127.0.0.1:5432->5432/tcp
operationcodebackend_redis_1                docker-entrypoint.sh redis ...   Up       127.0.0.1:6379->6379/tcp

Note the ports. My desktop host's 127.0.0.1:5432 is mapped to the PG container's 5432. With a Ruby runtime on my desktop, I can ...

> bundle install
[... install all the gems ...]
Bundle complete! 33 Gemfile dependencies, 121 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.

> export POSTGRES_HOST=localhost

> rails console
I, [2018-09-14T16:39:51.886262 #19099]  INFO -- : Raven 2.5.3 configured not to capture errors: DSN not set
W, [2018-09-14T16:39:52.646391 #19099]  WARN -- : Creating scope :open. Overwriting existing method GitHubStatistic.open.
Loading development environment (Rails 5.0.2)
[1] pry(main)>
[2] pry(main)> exit

> RAILS_ENV=test rake db:test:prepare test
[... loooots of output ...]
.

Finished in 17.488195s, 10.6357 runs/s, 34.8807 assertions/s.
186 runs, 610 assertions, 1 failures, 0 errors, 2 skips

@nellshamrell
nellshamrell merged commit 06f6830 into OperationCode:master Sep 16, 2018
@robbkidd
robbkidd deleted the docker-compose-moar-better branch September 18, 2018 17:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants