Skip to content

Commit

Permalink
Moving from foreman to docker-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
hugocorbucci committed Feb 21, 2017
1 parent 6d500d2 commit e85cd71
Show file tree
Hide file tree
Showing 15 changed files with 394 additions and 90 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ capybara-*.html
/public/system
/coverage/
/spec/tmp
bin/timeout
**/.DS_Store
**.orig
rerun.txt
Expand All @@ -33,3 +34,4 @@ bower.json

# Don't share your local environment configs.
.env
Gemfile.md5.new
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM ruby:2.4.0
MAINTAINER [email protected]

WORKDIR /app
ENV HOME=/app PATH=/app/bin:$PATH
CMD [ "bundle", "exec", "puma", "--bind", "tcp://0.0.0.0:3000" ]
EXPOSE 3000

RUN gem install bundler
COPY Gemfile Gemfile.lock ./
COPY vendor ./vendor
RUN bundle install --without development test

COPY . ./

USER nobody
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ gem 'omniauth-twitter'
# gem 'omniauth2-gitlab'
gem 'rails', '~> 5.0'
gem 'sass-rails', '~>5.0'
gem 'therubyracer'
gem 'turbolinks'
gem 'uglifier', '~>3.0'
gem 'will_paginate', '~> 3.1'
Expand All @@ -55,6 +56,7 @@ group :development do
gem 'foreman'
gem 'lol_dba'
gem 'pry'
gem 'rack-livereload'
gem 'web-console'
end

Expand Down
9 changes: 9 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ GEM
jwt (1.5.6)
launchy (2.4.3)
addressable (~> 2.3)
libv8 (3.16.14.17-x86_64-linux)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
Expand Down Expand Up @@ -223,6 +224,8 @@ GEM
pry (>= 0.9.10)
public_suffix (2.0.5)
rack (2.0.1)
rack-livereload (0.3.16)
rack
rack-test (0.6.3)
rack (>= 1.0)
rails (5.0.1)
Expand Down Expand Up @@ -258,6 +261,7 @@ GEM
rb-fsevent (0.9.8)
rb-inotify (0.9.8)
ffi (>= 0.5.0)
ref (2.0.0)
responders (2.3.0)
railties (>= 4.2.0, < 5.1)
rspec (3.5.0)
Expand Down Expand Up @@ -328,6 +332,9 @@ GEM
sprockets (>= 3.0.0)
sqlite3 (1.3.13)
terminal-notifier-guard (1.7.0)
therubyracer (0.12.3)
libv8 (~> 3.16.14.15)
ref
thor (0.19.4)
thread_safe (0.3.5)
tilt (2.0.6)
Expand Down Expand Up @@ -390,6 +397,7 @@ DEPENDENCIES
poltergeist
pry
pry-rails
rack-livereload
rails (~> 5.0)
rails_12factor
rb-fsevent
Expand All @@ -406,6 +414,7 @@ DEPENDENCIES
spring-commands-rspec
sqlite3
terminal-notifier-guard
therubyracer
turbolinks
uglifier (~> 3.0)
web-console
Expand Down
1 change: 1 addition & 0 deletions Gemfile.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e0866c4c7e419af8f227821c593ecba9
2 changes: 0 additions & 2 deletions Procfile.dev

This file was deleted.

56 changes: 56 additions & 0 deletions bin/setup-dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash
set -e
# set -x # Uncomment to debug

MY_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"

cd "${MY_DIR}"

OSX="false"
if (uname -a | grep -q Darwin); then
OSX="true"
fi

export PATH="${PATH}:${MY_DIR}/bin"

if [ "${OSX}" == "true" ] && [ -z "$(which brew)" ]; then
echo "Installing brew. This will ask for your password..."
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi

if [ "${OSX}" == "false" ] && [ -z "$(which apt-get)" ]; then
echo "This setup is only ready for apt-get based linuxes and OSX. You'll have to open and edit this file to fix it for your distribution."
exit 1
fi

if [ -z "$(which docker)" ]; then
if [ "${OSX}" == "true" ]; then
echo "Updating brew..."
brew update &> /dev/null
echo "Installing docker-machine, docker-compose and docker..."
brew install docker-machine docker-compose docker &> /dev/null
else
echo "Installing docker-compose and docker..."
wget -qO- https://get.docker.com/ | sh
sudo usermod -aG docker "$(whoami)"
sudo apt-get -y install python-pip
sudo pip install docker-compose
fi
fi

# Used by wait-for-it
if [ -z "$(which timeout)" ]; then
if [ "${OSX}" == "true" ]; then
if [ -z "$(which gtimeout)" ]; then
echo "Installing coreutils (for gtimeout)..."
brew install coreutils &> /dev/null
fi

if [ ! -f "${MY_DIR}/bin/timeout" ]; then
ln -s "$(which gtimeout)" "${MY_DIR}/bin/timeout"
fi
else
echo "Ensure timeout is in your path before proceeding"
exit 1
fi
fi
161 changes: 161 additions & 0 deletions bin/wait-for-it
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
#!/usr/bin/env bash
# Use this script to test if a given TCP host/port are available

cmdname=$(basename $0)

echoerr() { if [[ $QUIET -ne 1 ]]; then echo "$@" 1>&2; fi }

usage()
{
cat << USAGE >&2
Usage:
$cmdname host:port [-s] [-t timeout] [-- command args]
-h HOST | --host=HOST Host or IP under test
-p PORT | --port=PORT TCP port under test
Alternatively, you specify the host and port as host:port
-s | --strict Only execute subcommand if the test succeeds
-q | --quiet Don't output any status messages
-t TIMEOUT | --timeout=TIMEOUT
Timeout in seconds, zero for no timeout
-- COMMAND ARGS Execute command with args after the test finishes
USAGE
exit 1
}

wait_for()
{
if [[ $TIMEOUT -gt 0 ]]; then
echoerr "$cmdname: waiting $TIMEOUT seconds for $HOST:$PORT"
else
echoerr "$cmdname: waiting for $HOST:$PORT without a timeout"
fi
start_ts=$(date +%s)
while :
do
(echo > /dev/tcp/$HOST/$PORT) >/dev/null 2>&1
result=$?
if [[ $result -eq 0 ]]; then
end_ts=$(date +%s)
echoerr "$cmdname: $HOST:$PORT is available after $((end_ts - start_ts)) seconds"
break
fi
sleep 1
done
return $result
}

wait_for_wrapper()
{
# In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692
if [[ $QUIET -eq 1 ]]; then
timeout $TIMEOUT $0 --quiet --child --host=$HOST --port=$PORT --timeout=$TIMEOUT &
else
timeout $TIMEOUT $0 --child --host=$HOST --port=$PORT --timeout=$TIMEOUT &
fi
PID=$!
trap "kill -INT -$PID" INT
wait $PID
RESULT=$?
if [[ $RESULT -ne 0 ]]; then
echoerr "$cmdname: timeout occurred after waiting $TIMEOUT seconds for $HOST:$PORT"
fi
return $RESULT
}

# process arguments
while [[ $# -gt 0 ]]
do
case "$1" in
*:* )
hostport=(${1//:/ })
HOST=${hostport[0]}
PORT=${hostport[1]}
shift 1
;;
--child)
CHILD=1
shift 1
;;
-q | --quiet)
QUIET=1
shift 1
;;
-s | --strict)
STRICT=1
shift 1
;;
-h)
HOST="$2"
if [[ $HOST == "" ]]; then break; fi
shift 2
;;
--host=*)
HOST="${1#*=}"
shift 1
;;
-p)
PORT="$2"
if [[ $PORT == "" ]]; then break; fi
shift 2
;;
--port=*)
PORT="${1#*=}"
shift 1
;;
-t)
TIMEOUT="$2"
if [[ $TIMEOUT == "" ]]; then break; fi
shift 2
;;
--timeout=*)
TIMEOUT="${1#*=}"
shift 1
;;
--)
shift
CLI="$@"
break
;;
--help)
usage
;;
*)
echoerr "Unknown argument: $1"
usage
;;
esac
done

if [[ "$HOST" == "" || "$PORT" == "" ]]; then
echoerr "Error: you need to provide a host and port to test."
usage
fi

TIMEOUT=${TIMEOUT:-15}
STRICT=${STRICT:-0}
CHILD=${CHILD:-0}
QUIET=${QUIET:-0}

if [[ $CHILD -gt 0 ]]; then
wait_for
RESULT=$?
exit $RESULT
else
if [[ $TIMEOUT -gt 0 ]]; then
wait_for_wrapper
RESULT=$?
else
wait_for
RESULT=$?
fi
fi

if [[ $CLI != "" ]]; then
if [[ $RESULT -ne 0 && $STRICT -eq 1 ]]; then
echoerr "$cmdname: strict mode, refusing to execute subprocess"
exit $RESULT
fi
exec $CLI
else
exit $RESULT
fi
21 changes: 2 additions & 19 deletions config/database.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
url: <%= ENV['DATABASE_URL'] %>

development:
<<: *default
database: db/development.sqlite3

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3

production:
adapter: postgresql
encoding: unicode
# For details on connection pooling, see rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: 5
<<: *default
4 changes: 4 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@

# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true

config.web_console.whitelisted_ips = '192.168.0.0/16'

config.middleware.insert_after ActionDispatch::Static, Rack::LiveReload
end
Loading

0 comments on commit e85cd71

Please sign in to comment.