diff --git a/.gitignore b/.gitignore index 0e18499..3d0a50c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,8 @@ # Ignore bundler config. /.bundle -/vendor/bundle +/vendor/bundle/* +.env # Ignore the default SQLite database. /db/*.sqlite3 diff --git a/.ruby-version b/.ruby-version index 4e34c4d..85588be 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -ruby-2.7.6 +ruby-3.0.0 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a69bd69 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,39 @@ +# Make sure it matches the Ruby version in .ruby-version and Gemfile +ARG RUBY_VERSION=3.0.0 +FROM ruby:$RUBY_VERSION + +# Install libvips for Active Storage preview support +RUN apt-get update -qq && \ + apt-get install -y build-essential libvips vim && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/man + +# Rails app lives here +WORKDIR /rails + +# Set production environment +ENV RAILS_LOG_TO_STDOUT="1" \ + RAILS_SERVE_STATIC_FILES="true" \ + RAILS_ENV="production" \ + BUNDLE_WITHOUT="development" + +# Install application gems +COPY Gemfile Gemfile.lock ./ +RUN bundle install + +# Copy application code +COPY . . + +# Precompile bootsnap code for faster boot times + +RUN bundle exec bootsnap precompile --gemfile app/ lib/ +RUN bundle config set force_ruby_platform true +# Precompiling assets for production without requiring secret RAILS_MASTER_KEY +RUN bundle exec rails assets:precompile + +# Entrypoint prepares the database. +ENTRYPOINT ["/rails/bin/docker-entrypoint"] + +# Start the server by default, this can be overwritten at runtime +EXPOSE 3000 +CMD ["./bin/rails", "server"] diff --git a/Gemfile b/Gemfile index 53b290c..3a7d6eb 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,8 @@ source "https://rubygems.org" +#source "https://gems.data.ruby.ci" git_source(:github) { |repo| "https://github.com/#{repo}.git" } -ruby "2.7.6" +ruby "3.0.0" # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" gem "rails", "~> 7.0.4" @@ -9,6 +10,8 @@ gem "rails", "~> 7.0.4" # The original asset pipeline for Rails [https://github.com/rails/sprockets-rails] gem "sprockets-rails" +gem "administrate" + # Use sqlite3 as the database for Active Record gem "sqlite3", "~> 1.4" diff --git a/Gemfile.lock b/Gemfile.lock index 0da0887..9de89b4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -68,6 +68,14 @@ GEM tzinfo (~> 2.0) addressable (2.8.1) public_suffix (>= 2.0.2, < 6.0) + administrate (0.18.0) + actionpack (>= 5.0) + actionview (>= 5.0) + activerecord (>= 5.0) + jquery-rails (>= 4.0) + kaminari (>= 1.0) + sassc-rails (~> 2.1) + selectize-rails (~> 0.6) bindex (0.8.1) bootsnap (1.14.0) msgpack (~> 1.2) @@ -90,6 +98,7 @@ GEM reline (>= 0.3.1) diff-lcs (1.5.0) erubi (1.11.0) + ffi (1.15.5) globalid (1.0.0) activesupport (>= 5.0) i18n (1.12.0) @@ -103,6 +112,22 @@ GEM jbuilder (2.11.5) actionview (>= 5.0.0) activesupport (>= 5.0.0) + jquery-rails (4.5.1) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) + kaminari (1.2.2) + activesupport (>= 4.1.0) + kaminari-actionview (= 1.2.2) + kaminari-activerecord (= 1.2.2) + kaminari-core (= 1.2.2) + kaminari-actionview (1.2.2) + actionview + kaminari-core (= 1.2.2) + kaminari-activerecord (1.2.2) + activerecord + kaminari-core (= 1.2.2) + kaminari-core (1.2.2) loofah (2.19.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) @@ -186,6 +211,15 @@ GEM rspec-support (~> 3.11) rspec-support (3.12.0) rubyzip (2.3.2) + sassc (2.4.0) + ffi (~> 1.9) + sassc-rails (2.1.2) + railties (>= 4.0.0) + sassc (>= 2.0) + sprockets (> 3.0) + sprockets-rails + tilt + selectize-rails (0.12.6) selenium-webdriver (4.6.1) childprocess (>= 0.5, < 5.0) rexml (~> 3.2, >= 3.2.5) @@ -208,6 +242,7 @@ GEM stimulus-rails (1.1.1) railties (>= 6.0.0) thor (1.2.1) + tilt (2.0.11) timeout (0.3.0) turbo-rails (1.3.2) actionpack (>= 6.0.0) @@ -236,6 +271,7 @@ PLATFORMS ruby DEPENDENCIES + administrate bootsnap capybara debug @@ -256,7 +292,7 @@ DEPENDENCIES webdrivers RUBY VERSION - ruby 2.7.6p219 + ruby 3.0.0p0 BUNDLED WITH - 2.1.4 + 2.2.3 diff --git a/README.md b/README.md index a31c431..06bb464 100644 --- a/README.md +++ b/README.md @@ -23,3 +23,4 @@ Things you may want to cover: * Deployment instructions * ... + diff --git a/app/controllers/health_controller.rb b/app/controllers/health_controller.rb new file mode 100644 index 0000000..73fa40c --- /dev/null +++ b/app/controllers/health_controller.rb @@ -0,0 +1,7 @@ +class HealthController < ApplicationController + rescue_from(Exception) { render head: 503 } + + def show + render head: 200 + end +end diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index cab1405..21eab1b 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -4,6 +4,7 @@ class ItemsController < ApplicationController # GET /items or /items.json def index @items = Item.all + @items = Item.all end # GET /items/1 or /items/1.json diff --git a/app/helpers/health_helper.rb b/app/helpers/health_helper.rb new file mode 100644 index 0000000..21e809a --- /dev/null +++ b/app/helpers/health_helper.rb @@ -0,0 +1,2 @@ +module HealthHelper +end diff --git a/app/views/health/show.html.erb b/app/views/health/show.html.erb new file mode 100644 index 0000000..7d12773 --- /dev/null +++ b/app/views/health/show.html.erb @@ -0,0 +1,2 @@ +
Find me in app/views/health/show.html.erb
diff --git a/bin/docker-entrypoint b/bin/docker-entrypoint new file mode 100755 index 0000000..1fd12f1 --- /dev/null +++ b/bin/docker-entrypoint @@ -0,0 +1,8 @@ +#!/bin/bash + +# If running the rails server then create or migrate existing database +if [ "${*}" == "./bin/rails server" ]; then + ./bin/rails db:prepare +fi + +exec "${@}" \ No newline at end of file diff --git a/config/credentials.yml.enc b/config/credentials.yml.enc index fca1235..4ac27fb 100644 --- a/config/credentials.yml.enc +++ b/config/credentials.yml.enc @@ -1 +1 @@ -qhV4QM5XHhfopSMHPQOnCbd6aOnQOF6+/kNB0arsN9G0B7PLlEwRHJRglfEsKZxvzzv0KEhJLtm2Ei6GYSmdx72hg6aCeNMKI8SrkpBLLQ7kdqj/05kTkSlYw1WeoWuIlxRXiOUywStOrL0QGNla/xRYsSpk1RS/+o6457Rd8yPUdWOC5ORjUhYWm5SgDii3vV7Z2Y9pOhtNsF/CZj5vu8wpfm/SI223gDryZ9ZE6X1DGDfBnJ1uVDsScqQlubz9ZRYmAXmqLySgDpIWE/jU4xBPKHZJ1Gh1ZKrX3icw1brgOLsgquYf9842sw3wP59upXrG7f82xXDhrU37+xvs1zvGkyJExGSi1n9d+lhc1ATQFqipb3CnU3mnH1L4Krr7iEQu/0Au6MTw5UONZ7wlOtRjqjkLHOILLjK5--+U1aMORLTomguj1a--FDN7kbBv3sr911kx6mQFSA== \ No newline at end of file +Sfe68WvrD7utpNrlblSMy5Y3GZIhAlSjliVRMGqRcy5etWRIN5jh15KB2Bj/t+wu7qqdGTbms3ivhWQqE0ssJWpqA7vVAx57DrLLtqCIXYxQnNFd0JADhHZPeDRa2h2Cnj7qcwMzkTe+NdJZH0RHg4Vb76y6CaJmxJ3YXlitpfp0Z3BzdlPfv26dfsoH6ZfKQ68/QD+oRrm4cQnBKO+j+eMDSbqIgq+ib9gaYv2uCqenrEF69yt3DZaBQvjbAkd1JTKiyD5H0Y4t5CpQ92hQ/rTa4zym9GshfExOygHRDYvi68wIZifYc55gkV10R8KG8gvwGZ2MAzlceeRWGD7D9bwALX0QLQhF4ao5a7Qbwn9mTcCbo/JRyXTbk9YgsJoyfWz/kYnduwlK6EGlS5UfJneJRX+monmy7cQb--JwxEUFZ2PggAQa41--1p6beAXEHbxqKhHzu3FxDA== \ No newline at end of file diff --git a/config/deploy.yml b/config/deploy.yml new file mode 100644 index 0000000..ea05237 --- /dev/null +++ b/config/deploy.yml @@ -0,0 +1,17 @@ +service: basicapp +image: kolosek/basicapp +servers: + - 5.161.63.224 +registry: + username: kolosek + password: + - MRSK_REGISTRY_PASSWORD +env: + secret: + - RAILS_MASTER_KEY +builder: + multiarch: false +traefik: + host_port: 81 + labels: + traefik.http.routers.basicapp.rule: Host(\'basic.kolosek.me\'') diff --git a/config/environments/production.rb b/config/environments/production.rb index 065a412..1a5ce78 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -46,7 +46,8 @@ # config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ] # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. - # config.force_ssl = true + #config.force_ssl = true + config.assume_ssl = true # Include generic and useful information about system operation, but avoid logging too much # information to avoid inadvertent exposure of personally identifiable information (PII). diff --git a/config/routes.rb b/config/routes.rb index 7871dd5..b0fdf5b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,9 @@ Rails.application.routes.draw do + get 'health/show' resources :items # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html # Defines the root path route ("/") # root "articles#index" + get '/up', to: 'health#show' end