Merge pull request #2127 from denialtorres/master
Add a Dockerfile config file
This commit is contained in:
40
Dockerfile
Normal file
40
Dockerfile
Normal file
@@ -0,0 +1,40 @@
|
||||
# # 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
|
||||
|
||||
COPY Gemfile_custom Gemfile_custom
|
||||
|
||||
# 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"]
|
||||
1
Gemfile
1
Gemfile
@@ -93,4 +93,5 @@ group :development do
|
||||
gem 'web-console', '~> 3.3.0'
|
||||
end
|
||||
|
||||
#this is crashing with the Dockerfile
|
||||
eval_gemfile './Gemfile_custom'
|
||||
|
||||
52
README.md
52
README.md
@@ -76,3 +76,55 @@ Code published under AFFERO GPL v3 (see [LICENSE-AGPLv3.txt](LICENSE-AGPLv3.txt)
|
||||
## Contributions
|
||||
|
||||
See [CONTRIBUTING.md](CONTRIBUTING.md)
|
||||
|
||||
|
||||
## Working with Docker
|
||||
|
||||
Prerequisites
|
||||
-------------
|
||||
|
||||
You should have installed Docker and Docker Compose in your machine.
|
||||
|
||||
Also if you are going to work with docker first replace the database.yml with the preconfigured file made it to work it
|
||||
|
||||
|
||||
cp config/database-docker.yml.example config/database.yml
|
||||
|
||||
|
||||
The First step is to build the container
|
||||
|
||||
sudo docker build -t consul .
|
||||
Then run
|
||||
|
||||
|
||||
sudo docker-compose up -d database
|
||||
to create your application and database images.
|
||||
|
||||
Once built you can initialize your development DB and populate it with
|
||||
|
||||
sudo docker-compose run app rake db:create
|
||||
sudo docker-compose run app rake db:migrate
|
||||
sudo docker-compose run app rake db:seed
|
||||
sudo docker-compose run app rake db:dev_seed
|
||||
|
||||
If you want to run the rails console just run in another terminal:
|
||||
|
||||
|
||||
`sudo docker-compose run app rails console`
|
||||
|
||||
|
||||
Now we can finally run the application with
|
||||
|
||||
|
||||
sudo docker-compose up
|
||||
|
||||
To verify the containers are up execute **sudo docker ps .** You should see output similar to this:
|
||||
|
||||

|
||||
|
||||
now you can enter to localhost:3000
|
||||
|
||||
to verify that CONSUL is running
|
||||
|
||||

|
||||
|
||||
|
||||
28
config/database-docker.yml.example
Normal file
28
config/database-docker.yml.example
Normal file
@@ -0,0 +1,28 @@
|
||||
default: &default
|
||||
adapter: postgresql
|
||||
encoding: unicode
|
||||
#host: localhost
|
||||
host: database #<--the name of the db in the docker-compose
|
||||
pool: 5
|
||||
port: 5432
|
||||
username: postgres
|
||||
password: <%= ENV['POSTGRES_PASSWORD'] %>
|
||||
|
||||
development: &development
|
||||
<<: *default
|
||||
database: consul_development
|
||||
|
||||
# The staging, preproduction and production dbs are only needed
|
||||
# for running rake assets:precompile locally before deploying
|
||||
staging:
|
||||
<<: *development
|
||||
|
||||
preproduction:
|
||||
<<: *development
|
||||
|
||||
production:
|
||||
<<: *development
|
||||
|
||||
test:
|
||||
<<: *default
|
||||
database: consul_test
|
||||
@@ -6,7 +6,7 @@ Devise.setup do |config|
|
||||
# confirmation, reset password and unlock tokens in the database.
|
||||
# Devise will use the `secret_key_base` on Rails 4+ applications as its `secret_key`
|
||||
# by default. You can change it below and use your own secret key.
|
||||
# config.secret_key = Rails.application.secrets.secret_key_base
|
||||
config.secret_key = Rails.application.secrets.secret_key_base
|
||||
|
||||
# ==> Mailer Configuration
|
||||
# Configure the e-mail address which will be shown in Devise::Mailer,
|
||||
|
||||
31
docker-compose.yml
Normal file
31
docker-compose.yml
Normal file
@@ -0,0 +1,31 @@
|
||||
# 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"
|
||||
# map our application source code, in full, to the application root of our container
|
||||
volumes:
|
||||
- .:/var/www/consul
|
||||
Reference in New Issue
Block a user