From b907edad8314ce05b8a0a42405dfc76da3cbce63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20Ara=C3=BAjo?= Date: Thu, 24 Nov 2022 13:52:17 -0300 Subject: [PATCH 1/7] Using new hosting --- Gemfile | 12 ++++++++---- Gemfile.lock | 2 ++ bin/render-build.sh | 8 ++++++++ config/database.yml | 3 ++- config/environments/production.rb | 2 +- config/puma.rb | 4 ++-- render.yaml | 18 ++++++++++++++++++ 7 files changed, 41 insertions(+), 8 deletions(-) create mode 100755 bin/render-build.sh create mode 100644 render.yaml diff --git a/Gemfile b/Gemfile index 8d9dd91..d3928cc 100644 --- a/Gemfile +++ b/Gemfile @@ -11,9 +11,6 @@ gem 'rails', '~> 7.0.4' # The original asset pipeline for Rails [https://github.com/rails/sprockets-rails] gem 'sprockets-rails' -# Use sqlite3 as the database for Active Record -gem 'sqlite3', '~> 1.4' - # Use the Puma web server [https://github.com/puma/puma] gem 'puma', '~> 5.0' @@ -54,6 +51,9 @@ gem 'bootsnap', require: false # gem "image_processing", "~> 1.2" group :development, :test do + # Use sqlite3 as the database for Active Record + gem 'sqlite3', '~> 1.4' + # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem gem 'debug', platforms: %i[mri mingw x64_mingw] end @@ -68,10 +68,10 @@ group :development do # Speed up commands on slow machines / big apps [https://github.com/rails/spring] # gem "spring" - gem 'solargraph' gem 'reek', '~> 6.1' gem 'rubocop', '~> 1.37' gem 'rubocop-rails', '~> 2.17' + gem 'solargraph' end group :test do @@ -81,6 +81,10 @@ group :test do gem 'webdrivers' end +group :production do + gem 'pg', '~> 1.4' +end + gem 'pagy', '~> 5.10' gem 'rack-cors', '~> 1.1' gem 'ransack', '~> 3.2' diff --git a/Gemfile.lock b/Gemfile.lock index 5d94768..f77b7ee 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -141,6 +141,7 @@ GEM parallel (1.22.1) parser (3.1.2.1) ast (~> 2.4.1) + pg (1.4.5) public_suffix (5.0.0) puma (5.6.5) nio4r (~> 2.0) @@ -288,6 +289,7 @@ DEPENDENCIES jbuilder jsbundling-rails pagy (~> 5.10) + pg (~> 1.4) puma (~> 5.0) rack-cors (~> 1.1) rails (~> 7.0.4) diff --git a/bin/render-build.sh b/bin/render-build.sh new file mode 100755 index 0000000..00700a0 --- /dev/null +++ b/bin/render-build.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +# exit on error +set -o errexit + +bundle install +bundle exec rake assets:precompile +bundle exec rake assets:clean +bundle exec rake db:migrate diff --git a/config/database.yml b/config/database.yml index fcba57f..83a6543 100644 --- a/config/database.yml +++ b/config/database.yml @@ -22,4 +22,5 @@ test: production: <<: *default - database: db/production.sqlite3 + adapter: postgresql + url: <%= ENV['DATABASE_URL'] %> diff --git a/config/environments/production.rb b/config/environments/production.rb index a154870..66f4c04 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -22,7 +22,7 @@ # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. - config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? + config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? || ENV['RENDER'].present? # Compress CSS using a preprocessor. # config.assets.css_compressor = :sass diff --git a/config/puma.rb b/config/puma.rb index daaf036..81dae67 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -30,14 +30,14 @@ # Workers do not work on JRuby or Windows (both of which do not support # processes). # -# workers ENV.fetch("WEB_CONCURRENCY") { 2 } +workers ENV.fetch("WEB_CONCURRENCY") { 4 } # Use the `preload_app!` method when specifying a `workers` number. # This directive tells Puma to first boot the application and load code # before forking the application. This takes advantage of Copy On Write # process behavior so workers use less memory. # -# preload_app! +preload_app! # Allow puma to be restarted by `bin/rails restart` command. plugin :tmp_restart diff --git a/render.yaml b/render.yaml new file mode 100644 index 0000000..f439d05 --- /dev/null +++ b/render.yaml @@ -0,0 +1,18 @@ +databases: + - name: rails-7-fullstack + databaseName: rails-7-fullstack + user: rails-7-fullstack + +services: + - type: web + name: rails-7-fullstack + env: ruby + buildCommand: "./bin/render-build.sh" + startCommand: "bundle exec puma -C config/puma.rb" + envVars: + - key: DATABASE_URL + fromDatabase: + name: rails-7-fullstack + property: connectionString + - key: RAILS_MASTER_KEY + sync: false From a11c97fea2bb63fec9f68849ffa4befcc2b99c7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20Ara=C3=BAjo?= Date: Thu, 24 Nov 2022 13:57:30 -0300 Subject: [PATCH 2/7] Using new hosting --- render.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/render.yaml b/render.yaml index f439d05..99df0ea 100644 --- a/render.yaml +++ b/render.yaml @@ -1,7 +1,7 @@ databases: - name: rails-7-fullstack - databaseName: rails-7-fullstack - user: rails-7-fullstack + databaseName: rails_7_fullstack + user: rails_7_fullstack_user services: - type: web From 6076db8152e18d4da4d5f1b8b791d827a72336d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20Ara=C3=BAjo?= Date: Thu, 24 Nov 2022 14:14:19 -0300 Subject: [PATCH 3/7] Using new hosting --- Gemfile.lock | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Gemfile.lock b/Gemfile.lock index f77b7ee..fd909e6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -136,6 +136,8 @@ GEM nio4r (2.5.8) nokogiri (1.13.9-arm64-darwin) racc (~> 1.4) + nokogiri (1.13.9-x86_64-linux) + racc (~> 1.4) pagy (5.10.1) activesupport parallel (1.22.1) @@ -242,6 +244,7 @@ GEM activesupport (>= 5.2) sprockets (>= 3.0.0) sqlite3 (1.5.3-arm64-darwin) + sqlite3 (1.5.3-x86_64-linux) stimulus-rails (1.1.0) railties (>= 6.0.0) thor (1.2.1) @@ -280,6 +283,7 @@ GEM PLATFORMS arm64-darwin-21 + x86_64-linux DEPENDENCIES bootsnap From 3663634de27821db150371ae79a1ded7ed3cc072 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20Ara=C3=BAjo?= Date: Thu, 24 Nov 2022 14:19:40 -0300 Subject: [PATCH 4/7] Using new hosting --- db/migrate/20221022131756_create_kit_components.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20221022131756_create_kit_components.rb b/db/migrate/20221022131756_create_kit_components.rb index 32a5cb1..910d264 100644 --- a/db/migrate/20221022131756_create_kit_components.rb +++ b/db/migrate/20221022131756_create_kit_components.rb @@ -3,7 +3,7 @@ class CreateKitComponents < ActiveRecord::Migration[7.0] def change create_table(:kit_components) do |t| - t.references(:product, null: false, foreign_key: true) + t.references(:kit_product, null: false, foreign_key: true) t.string(:name) t.timestamps From 184b19b0f7f4b5542706347046a1e64f8e2f5c7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20Ara=C3=BAjo?= Date: Thu, 24 Nov 2022 14:56:12 -0300 Subject: [PATCH 5/7] Using new hosting --- app/components/search_list_form_component.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/components/search_list_form_component.rb b/app/components/search_list_form_component.rb index cda2cc5..98a3f39 100644 --- a/app/components/search_list_form_component.rb +++ b/app/components/search_list_form_component.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'ransack/helpers' + module SearchListFormHelper def form_tag(options = {}, &) options.merge!({ builder: SearchListBuilder }) From 898b7b5177b194ee692940d3320682532c4f7dc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20Ara=C3=BAjo?= Date: Thu, 24 Nov 2022 15:43:53 -0300 Subject: [PATCH 6/7] Using new hosting --- .../20221022131756_create_kit_components.rb | 2 +- db/schema.rb | 26 +++++++++---------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/db/migrate/20221022131756_create_kit_components.rb b/db/migrate/20221022131756_create_kit_components.rb index 910d264..795ca19 100644 --- a/db/migrate/20221022131756_create_kit_components.rb +++ b/db/migrate/20221022131756_create_kit_components.rb @@ -3,7 +3,7 @@ class CreateKitComponents < ActiveRecord::Migration[7.0] def change create_table(:kit_components) do |t| - t.references(:kit_product, null: false, foreign_key: true) + t.references(:product, null: false, foreign_key: { to_table: :kit_products }) t.string(:name) t.timestamps diff --git a/db/schema.rb b/db/schema.rb index 59cddb3..7ea3aba 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,5 +1,3 @@ -# frozen_string_literal: true - # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -12,20 +10,20 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 20_221_022_131_756) do - create_table 'kit_components', force: :cascade do |t| - t.integer('product_id', null: false) - t.string('name') - t.datetime('created_at', null: false) - t.datetime('updated_at', null: false) - t.index(['product_id'], name: 'index_kit_components_on_product_id') +ActiveRecord::Schema[7.0].define(version: 2022_10_22_131756) do + create_table "kit_components", force: :cascade do |t| + t.integer "product_id", null: false + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["product_id"], name: "index_kit_components_on_product_id" end - create_table 'kit_products', force: :cascade do |t| - t.string('name') - t.datetime('created_at', null: false) - t.datetime('updated_at', null: false) + create_table "kit_products", force: :cascade do |t| + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - add_foreign_key 'kit_components', 'kit_products', column: 'product_id' + add_foreign_key "kit_components", "kit_products", column: "product_id" end From 64649170137ecdd9e9cf08c640f7cbcafd072f61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20Ara=C3=BAjo?= Date: Fri, 25 Nov 2022 07:21:31 -0300 Subject: [PATCH 7/7] Using env variables --- frontend/src/services.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/services.ts b/frontend/src/services.ts index 4bc6b12..8b3f63d 100644 --- a/frontend/src/services.ts +++ b/frontend/src/services.ts @@ -1,7 +1,7 @@ import axios from "axios"; const api = axios.create({ - baseURL: "http://localhost:3000/api/", + baseURL: process.env.NEXT_PUBLIC_API_URL, timeout: 5000, headers: { Accept: "application/json",