Skip to content

Instantly share code, notes, and snippets.

@sandeepk17
Forked from satendra02/app.DockerFile
Created March 8, 2018 20:00
Show Gist options
  • Select an option

  • Save sandeepk17/d3c42e72aaed8eaa6f774708c6d17d63 to your computer and use it in GitHub Desktop.

Select an option

Save sandeepk17/d3c42e72aaed8eaa6f774708c6d17d63 to your computer and use it in GitHub Desktop.

Revisions

  1. @satendra02 satendra02 revised this gist Feb 23, 2018. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion DockerFile_app
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,6 @@ RUN bundle install --jobs 20 --retry 5 --without development test
    # Adding project files
    COPY . /app_name
    RUN bundle exec rake assets:precompile
    RUN bundle exec rake db:setup

    EXPOSE 3000
    CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"]
  2. @satendra02 satendra02 revised this gist Feb 22, 2018. 2 changed files with 2 additions and 9 deletions.
    8 changes: 0 additions & 8 deletions database.yml
    Original file line number Diff line number Diff line change
    @@ -10,11 +10,3 @@ default: &default
    production:
    <<: *default
    database: app_name_production

    development:
    <<: *default
    database: app_name_development

    test:
    <<: *default
    database: app_name_test
    3 changes: 2 additions & 1 deletion readme.txt
    Original file line number Diff line number Diff line change
    @@ -11,4 +11,5 @@ Create docker folder in app root
    -DockerFile_app
    -web
    -DockerFile_web
    -nginx.conf
    -nginx.conf
    -docker-compose.yml
  3. @satendra02 satendra02 revised this gist Feb 22, 2018. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions nginx.conf
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,3 @@
    # From http://chrisstump.online/2016/02/20/docker-existing-rails-application/

    upstream rails_app {
    server app:3000;
    }
  4. @satendra02 satendra02 revised this gist Feb 19, 2018. No changes.
  5. @satendra02 satendra02 revised this gist Feb 19, 2018. No changes.
  6. @satendra02 satendra02 revised this gist Feb 18, 2018. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions database.yml
    Original file line number Diff line number Diff line change
    @@ -5,18 +5,16 @@ default: &default
    username: postgres
    password:
    pool: 5
    host: db

    production:
    <<: *default
    host: db
    database: app_name_production

    development:
    <<: *default
    host: localhost
    database: app_name_development

    test:
    <<: *default
    host: localhost
    database: app_name_test
  7. @satendra02 satendra02 created this gist Feb 17, 2018.
    23 changes: 23 additions & 0 deletions DockerFile_app
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    FROM ruby:2.3.1
    RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs

    # Configuring main directory
    RUN mkdir -p /app_name
    WORKDIR /app_name

    # Setting env up
    ENV RAILS_ENV='production'
    ENV RAKE_ENV='production'

    # Adding gems
    COPY Gemfile /app_name/Gemfile
    COPY Gemfile.lock /app_name/Gemfile.lock
    RUN bundle install --jobs 20 --retry 5 --without development test

    # Adding project files
    COPY . /app_name
    RUN bundle exec rake assets:precompile
    RUN bundle exec rake db:setup

    EXPOSE 3000
    CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"]
    20 changes: 20 additions & 0 deletions DockerFile_web
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    # Base image:
    FROM nginx
    # Install dependencies
    RUN apt-get update -qq && apt-get -y install apache2-utils
    # establish where Nginx should look for files
    ENV RAILS_ROOT /var/www/app_name
    # Set our working directory inside the image
    WORKDIR $RAILS_ROOT
    # create log directory
    RUN mkdir log
    # copy over static assets
    COPY public public/
    # Copy Nginx config template
    COPY docker/web/nginx.conf /tmp/docker.nginx
    # substitute variable references in the Nginx config template for real values from the environment
    # put the final config in its place
    RUN envsubst '$RAILS_ROOT' < /tmp/docker.nginx > /etc/nginx/conf.d/default.conf
    EXPOSE 80
    # Use the "exec" form of CMD so Nginx shuts down gracefully on SIGTERM (i.e. `docker stop`)
    CMD [ "nginx", "-g", "daemon off;" ]
    22 changes: 22 additions & 0 deletions database.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@

    default: &default
    adapter: postgresql
    encoding: unicode
    username: postgres
    password:
    pool: 5

    production:
    <<: *default
    host: db
    database: app_name_production

    development:
    <<: *default
    host: localhost
    database: app_name_development

    test:
    <<: *default
    host: localhost
    database: app_name_test
    23 changes: 23 additions & 0 deletions docker-compose.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    version: '3'
    volumes:
    postgres_data: {}

    services:
    app:
    build:
    context: .
    dockerfile: ./docker/app/Dockerfile_app
    depends_on:
    - db
    db:
    image: postgres
    volumes:
    - postgres_data:/var/lib/postgresql/data
    web:
    build:
    context: .
    dockerfile: ./docker/web/Dockerfile_web
    depends_on:
    - app
    ports:
    - 80:80
    58 changes: 58 additions & 0 deletions nginx.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,58 @@
    # From http://chrisstump.online/2016/02/20/docker-existing-rails-application/

    upstream rails_app {
    server app:3000;
    }

    server {
    # define your domain
    server_name www.example.com;

    # define the public application root
    root /app_name/public;
    index index.html;

    # define where Nginx should write its logs
    access_log /var/www/app_name/log/nginx.access.log;
    error_log /var/www/app_name/log/nginx.error.log;

    # deny requests for files that should never be accessed
    location ~ /\. {
    deny all;
    }

    location ~* ^.+\.(rb|log)$ {
    deny all;
    }

    # serve static (compiled) assets directly if they exist (for rails production)
    location ~ ^/(assets|images|javascripts|stylesheets|swfs|system)/ {
    try_files $uri @rails;

    access_log off;
    gzip_static on; # to serve pre-gzipped version

    expires max;
    add_header Cache-Control public;

    # Some browsers still send conditional-GET requests if there's a
    # Last-Modified header or an ETag header even if they haven't
    # reached the expiry date sent in the Expires header.
    add_header Last-Modified "";
    add_header ETag "";
    break;
    }

    # send non-static file requests to the app server
    location / {
    try_files $uri @rails;
    }

    location @rails {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://rails_app;
    }
    }
    14 changes: 14 additions & 0 deletions readme.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    Create docker folder in app root

    -app_name
    -app
    -db
    -config
    -database.yml
    ...
    -docker
    -app
    -DockerFile_app
    -web
    -DockerFile_web
    -nginx.conf