diff --git a/Gemfile b/Gemfile index 670e035..b53fea0 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -source 'https://rubygems.org' +source 'https://gems.ruby-china.com' git_source(:github) { |repo| "https://github.com/#{repo}.git" } ruby '2.6.2' @@ -22,16 +22,6 @@ gem 'coffee-rails', '~> 4.2' gem 'turbolinks', '~> 5' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 2.5' -# Use Redis adapter to run Action Cable in production -# gem 'redis', '~> 4.0' -# Use ActiveModel has_secure_password -# gem 'bcrypt', '~> 3.1.7' - -# Use ActiveStorage variant -# gem 'mini_magick', '~> 4.8' - -# Use Capistrano for deployment -# gem 'capistrano-rails', group: :development # Reduces boot times through caching; required in config/boot.rb gem 'bootsnap', '>= 1.1.0', require: false @@ -47,6 +37,7 @@ group :development do gem 'listen', '>= 3.0.5', '< 3.2' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' + gem 'pry-rails' gem 'spring-watcher-listen', '~> 2.0.0' end diff --git a/Gemfile.lock b/Gemfile.lock index 32b1bb0..ee386ae 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,5 +1,5 @@ GEM - remote: https://rubygems.org/ + remote: https://gems.ruby-china.com/ specs: actioncable (5.2.3) actionpack (= 5.2.3) @@ -65,6 +65,7 @@ GEM chromedriver-helper (2.1.1) archive-zip (~> 0.10) nokogiri (~> 1.8) + coderay (1.1.2) coffee-rails (4.2.2) coffee-script (>= 2.2.0) railties (>= 4.0.0) @@ -104,6 +105,11 @@ GEM nio4r (2.4.0) nokogiri (1.10.3) mini_portile2 (~> 2.4.0) + pry (0.12.2) + coderay (~> 1.1.0) + method_source (~> 0.9.0) + pry-rails (0.3.9) + pry (>= 0.10.4) public_suffix (3.1.1) puma (3.12.1) rack (2.0.7) @@ -198,6 +204,7 @@ DEPENDENCIES coffee-rails (~> 4.2) jbuilder (~> 2.5) listen (>= 3.0.5, < 3.2) + pry-rails puma (~> 3.11) rails (~> 5.2.3) sass-rails (~> 5.0) diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..52c1db1 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,22 @@ +version: '3' +volumes: + sqlite_data: {} +services: + app: + build: + context: . + dockerfile: ./docker/app/DockerFile + depends_on: + - db + db: + image: sqlite3 + volumes: + - sqlite_data:/var/lib/sqlite/data + web: + build: + context: . + dockerfile: ./docker/web/DockerFile + depends_on: + - app + ports: + - 80:80 diff --git a/docker/app/DockerFile b/docker/app/DockerFile new file mode 100644 index 0000000..4d53663 --- /dev/null +++ b/docker/app/DockerFile @@ -0,0 +1,15 @@ +FROM ruby:2.6.2 +RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs + +ENV RAILS_ROOT /var/www/app_name +RUN mkdir -p $RAILS_ROOT +WORKDIR $RAILS_ROOT +ENV RAILS_ENV='production' +ENV RACK_ENV='production' +COPY Gemfile Gemfile +COPY Gemfile.lock Gemfile.lock +RUN bundle install --jobs 20 --retry 5 --without development test +COPY . . +RUN bundle exec rake assets:precompile +EXPOSE 3000 +CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"] diff --git a/docker/web/DockerFile b/docker/web/DockerFile new file mode 100644 index 0000000..eae66d4 --- /dev/null +++ b/docker/web/DockerFile @@ -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;" ] diff --git a/docker/web/nginx.conf b/docker/web/nginx.conf new file mode 100644 index 0000000..9906324 --- /dev/null +++ b/docker/web/nginx.conf @@ -0,0 +1,47 @@ +upstream rails_app { + server app:3000; +} +server { + # define your domain + server_name invote.learnerhub.net; + # define the public application root + root $RAILS_ROOT/public; + index index.html; + # define where Nginx should write its logs + access_log $RAILS_ROOT/log/nginx.access.log; + error_log $RAILS_ROOT/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; + + 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; + } +}