From faceaac8742bddb2d58a772eb83f4e0a1bc243f8 Mon Sep 17 00:00:00 2001 From: Matt Rogers Date: Fri, 27 Apr 2018 09:13:35 -0500 Subject: [PATCH] Modify the binstubs to run things in docker --- bin/bundle | 3 +++ bin/cucumber | 3 +++ bin/rails | 4 ++++ bin/rake | 3 +++ bin/setup | 3 +++ bin/spring | 3 +++ script/docker-environment | 16 ++++++++++++++++ 7 files changed, 35 insertions(+) create mode 100755 script/docker-environment diff --git a/bin/bundle b/bin/bundle index 66e9889e..414e0c9a 100755 --- a/bin/bundle +++ b/bin/bundle @@ -1,3 +1,6 @@ #!/usr/bin/env ruby +if ENV["RAILS_ENV"] != "production" + exec("#{__dir__}/../script/docker-environment", $PROGRAM_NAME, *ARGV) unless File.exist?("/etc/app-env") +end ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) load Gem.bin_path('bundler', 'bundle') diff --git a/bin/cucumber b/bin/cucumber index 12971cdc..5b4487c6 100755 --- a/bin/cucumber +++ b/bin/cucumber @@ -1,4 +1,7 @@ #!/usr/bin/env ruby +if ENV["RAILS_ENV"] != "production" + exec("#{__dir__}/../script/docker-environment", $PROGRAM_NAME, *ARGV) unless File.exist?("/etc/app-env") +end begin load File.expand_path("../spring", __FILE__) rescue LoadError diff --git a/bin/rails b/bin/rails index 5191e692..3ea4cfa0 100755 --- a/bin/rails +++ b/bin/rails @@ -1,4 +1,8 @@ #!/usr/bin/env ruby +if ENV["RAILS_ENV"] != "production" + exec("#{__dir__}/../script/docker-environment", $PROGRAM_NAME, *ARGV) unless File.exist?("/etc/app-env") +end + APP_PATH = File.expand_path('../../config/application', __FILE__) require_relative '../config/boot' require 'rails/commands' diff --git a/bin/rake b/bin/rake index 17240489..36d60756 100755 --- a/bin/rake +++ b/bin/rake @@ -1,4 +1,7 @@ #!/usr/bin/env ruby +if ENV["RAILS_ENV"] != "production" + exec("#{__dir__}/../script/docker-environment", $PROGRAM_NAME, *ARGV) unless File.exist?("/etc/app-env") +end require_relative '../config/boot' require 'rake' Rake.application.run diff --git a/bin/setup b/bin/setup index acdb2c13..3eb1ec60 100755 --- a/bin/setup +++ b/bin/setup @@ -1,4 +1,7 @@ #!/usr/bin/env ruby +if ENV["RAILS_ENV"] != "production" + exec("#{__dir__}/../script/docker-environment", $PROGRAM_NAME, *ARGV) unless File.exist?("/etc/app-env") +end require 'pathname' # path to your application root. diff --git a/bin/spring b/bin/spring index 253ec37c..3d225a65 100755 --- a/bin/spring +++ b/bin/spring @@ -1,4 +1,7 @@ #!/usr/bin/env ruby +if ENV["RAILS_ENV"] != "production" + exec("#{__dir__}/../script/docker-environment", $PROGRAM_NAME, *ARGV) unless File.exist?("/etc/app-env") +end # This file loads spring without using Bundler, in order to be fast # It gets overwritten when you run the `spring binstub` command diff --git a/script/docker-environment b/script/docker-environment new file mode 100755 index 00000000..a1ee4736 --- /dev/null +++ b/script/docker-environment @@ -0,0 +1,16 @@ +#!/bin/sh +# Run a command in the app's environment + +set -e + +# Find our app dir and just run the command in we're in the container since the +# container is built with an /etc/app-env file inside of it. +appdir=$(cd $(dirname "$0")/.. && pwd) +[ -f /etc/app-env ] && exec "$@" + +# Otherwise, run docker compose to run our command in the container +cmd="$@"; [ "$#" -eq 0 ] && cmd=bash +export VOLUME="$appdir:/app" +image=${DOCKER_IMAGE:=web} + +exec docker-compose run --rm $image $cmd