From 3e42182551389877eba4cb207299717e2082d67a Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 14 Nov 2017 04:33:05 -0600 Subject: [PATCH] added Dockerfile and docker-compose.yml --- Dockerfile | 37 +++++++++++++++++++++++++++++++++++++ Gemfile | 3 ++- config/database.yml.example | 8 +++++--- docker-compose.yml | 28 ++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..9d47c6d9b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,37 @@ +# # Select ubuntu as the base image +FROM coreapps/ruby2.3 + +# Install essential Linux packages +RUN apt-get update -qq && apt-get install -y build-essential libpq-dev postgresql-client nodejs + + + +# Define where our application will live inside the image +ENV RAILS_ROOT /var/www/consul + +# Create application home. App server will need the pids dir so just create everything in one shot +RUN mkdir -p $RAILS_ROOT/tmp/pids + +# Set our working directory inside the image +WORKDIR $RAILS_ROOT + +# Use the Gemfiles as Docker cache markers. Always bundle before copying app src. +# (the src likely changed and we don't want to invalidate Docker's cache too early) +# http://ilikestuffblog.com/2014/01/06/how-to-skip-bundle-install-when-deploying-a-rails-app-to-docker/ +COPY Gemfile Gemfile + +COPY Gemfile.lock Gemfile.lock + +# Prevent bundler warnings; ensure that the bundler version executed is >= that which created Gemfile.lock +RUN gem install bundler + +# Finish establishing our Ruby enviornment +RUN bundle install --full-index + +# Copy the Rails application into place +COPY . . + +# Define the script we want run once the container boots +# Use the "exec" form of CMD so our script shuts down gracefully on SIGTERM (i.e. `docker stop`) +#CMD [ "config/containers/app_cmd.sh" ] +CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"] diff --git a/Gemfile b/Gemfile index 409f763e9..da8c87841 100644 --- a/Gemfile +++ b/Gemfile @@ -92,4 +92,5 @@ group :development do gem 'web-console', '~> 3.3.0' end -eval_gemfile './Gemfile_custom' +#this is crashing with the Dockerfile +#eval_gemfile './Gemfile_custom' diff --git a/config/database.yml.example b/config/database.yml.example index 2f8b7463f..dc1efbd7e 100644 --- a/config/database.yml.example +++ b/config/database.yml.example @@ -1,10 +1,12 @@ default: &default adapter: postgresql encoding: unicode - host: localhost + #host: localhost + host: database #<--the name of the db in the docker-compose pool: 5 - username: - password: + port: 5432 + username: postgres + password: <%= ENV['POSTGRES_PASSWORD'] %> development: &development <<: *default diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..701653da1 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,28 @@ +# service configuration for our database +database: + + # use the preferred version of the official Postgres image + # see https://hub.docker.com/_/postgres/ + image: postgres:9.4.5 + + # persist the database between containers by storing it in a volume + volumes: + - docker-example-postgres:/var/lib/postgresql/data + +# service configuration for our dockerized Rails app +app: + + # use the Dockerfile next to this file + build: . + + # rely on the RAILS_ENV value of the host machine + # environment: + #RAILS_ENV: $RAILS_ENV + + # makes the app container aware of the DB container + links: + - database + + # expose the port we configured Unicorn to bind to + ports: + - "3000:3000"