diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..adfc146f4 --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/Gemfile b/Gemfile index b0c7f2e9a..811cfae4f 100644 --- a/Gemfile +++ b/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' diff --git a/README.md b/README.md index 48f6bfcb8..70cd5ed06 100644 --- a/README.md +++ b/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: + +![enter image description here](https://i.imgur.com/ASvzXrd.png) + +now you can enter to localhost:3000 + +to verify that CONSUL is running + +![enter image description here](https://i.imgur.com/Fl3XOIg.png) + diff --git a/config/database-docker.yml.example b/config/database-docker.yml.example new file mode 100644 index 000000000..dc1efbd7e --- /dev/null +++ b/config/database-docker.yml.example @@ -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 diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index a0b6ac249..6acce5068 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -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, diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..d5399089e --- /dev/null +++ b/docker-compose.yml @@ -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