From 84893f47b8d61c699d76abcca790c8915546000e Mon Sep 17 00:00:00 2001 From: Andrei Rumiantsau Date: Wed, 24 Apr 2024 19:05:30 +0300 Subject: [PATCH 01/14] RT-Test-deployment (#9) --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index f23822d..f8e405a 100644 --- a/README.md +++ b/README.md @@ -31,9 +31,13 @@ Things you may want to cover: * ... curl -v -X POST http://localhost:3001/api/users/sign_up -H 'Content-Type: application/json' -H 'Accept: application/json' -d '{"api_user": {"email":"api_user_example@test.com", "password":"123456", "password_confirmation":"123456"}}' + curl -v -X POST http://localhost:3001/api/users/sign_in -H 'Content-Type: application/json' -H 'Accept: application/json' -d '{"api_user": {"email":"api_user_example@test.com", "password":"123456"}}' + curl -v -X DELETE http://localhost:3001/api/users/sign_out -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer XYZ' curl -X GET 'localhost:3001/api/v1/users' -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer XYZ' + curl -X GET 'localhost:3001/api/v1/users/1' -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer XYZ' + curl -X GET 'localhost:3001/api/v1/current_user' -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer XYZ' From 55b046fb5bd8972c4985cb549014732e4c88f992 Mon Sep 17 00:00:00 2001 From: Andrei Rumiantsau Date: Wed, 24 Apr 2024 21:35:11 +0300 Subject: [PATCH 02/14] RT-AWS-beanstalk (#10) * RT-AWS-beanstalk --- .elasticbeanstalk/system.config | 17 +++++++++++++++++ .../hooks/prebuild/01_gem_install_bundler.sh | 6 ++++++ .ruby-version | 2 +- Gemfile | 2 +- Gemfile.lock | 7 ++++++- 5 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 .elasticbeanstalk/system.config create mode 100644 .platform/hooks/prebuild/01_gem_install_bundler.sh diff --git a/.elasticbeanstalk/system.config b/.elasticbeanstalk/system.config new file mode 100644 index 0000000..f636d04 --- /dev/null +++ b/.elasticbeanstalk/system.config @@ -0,0 +1,17 @@ +packages: + yum: + git: [] +commands: + create_swapfile: + test: test ! -e /var/swapfile + command: | + dd if=/dev/zero of=/var/swapfile bs=1M count=2048 + chmod 600 /var/swapfile + mkswap /var/swapfile + swapon /var/swapfile + create_home_webapp: + test: mkdir /home/webapp + command: | + sudo mkdir -p /home/webapp + sudo chown webapp:webapp /home/webapp + sudo chmod 700 /home/webapp diff --git a/.platform/hooks/prebuild/01_gem_install_bundler.sh b/.platform/hooks/prebuild/01_gem_install_bundler.sh new file mode 100644 index 0000000..b2429b1 --- /dev/null +++ b/.platform/hooks/prebuild/01_gem_install_bundler.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +EB_APP_STAGING_DIR=$(sudo /opt/elasticbeanstalk/bin/get-config platformconfig -k AppStagingDir) +cd $EB_APP_STAGING_DIR + +gem install bundler --no-document -v 2.5.3 diff --git a/.ruby-version b/.ruby-version index 03463f3..9e79f6c 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -ruby-3.3.0 +ruby-3.2.2 diff --git a/Gemfile b/Gemfile index 65f4efd..9096f31 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } -ruby '3.3.0' +ruby '3.2.2' gem 'rails', '~> 7.1', '>= 7.1.3' diff --git a/Gemfile.lock b/Gemfile.lock index 71ee7a6..474e2d7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -213,6 +213,11 @@ GEM globalid (1.2.1) activesupport (>= 6.1) google-protobuf (3.25.2) + google-protobuf (3.25.2-aarch64-linux) + google-protobuf (3.25.2-arm64-darwin) + google-protobuf (3.25.2-x86-linux) + google-protobuf (3.25.2-x86_64-darwin) + google-protobuf (3.25.2-x86_64-linux) hashie (5.0.0) honeybadger (5.4.1) httparty (0.21.0) @@ -692,7 +697,7 @@ DEPENDENCIES wicked_pdf (~> 2.7) RUBY VERSION - ruby 3.3.0p0 + ruby 3.2.2p53 BUNDLED WITH 2.5.3 From f7f696d8851d26762d26e2b1772d1cea272f9403 Mon Sep 17 00:00:00 2001 From: Andrei Rumiantsau Date: Wed, 24 Apr 2024 22:35:25 +0300 Subject: [PATCH 03/14] RT-Letter-opener-for-dev-only (#11) --- config/initializers/letter_opener.rb | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/config/initializers/letter_opener.rb b/config/initializers/letter_opener.rb index a7099b1..f26ac00 100644 --- a/config/initializers/letter_opener.rb +++ b/config/initializers/letter_opener.rb @@ -1,19 +1,21 @@ # frozen_string_literal: true -require 'letter_opener' +if Rails.env.development? + require 'letter_opener' -LetterOpener.configure do |config| - # To overrider the location for message storage. - # Default value is `tmp/letter_opener` - # config.location = Rails.root.join('tmp', 'my_mails') + LetterOpener.configure do |config| + # To overrider the location for message storage. + # Default value is `tmp/letter_opener` + # config.location = Rails.root.join('tmp', 'my_mails') - # To render only the message body, without any metadata or extra containers or styling. - # Default value is `:default` that renders styled message with showing useful metadata. - config.message_template = :default + # To render only the message body, without any metadata or extra containers or styling. + # Default value is `:default` that renders styled message with showing useful metadata. + config.message_template = :default - # To change default file URI scheme you can provide `file_uri_scheme` config. - # It might be useful when you use WSL (Windows Subsystem for Linux) and default - # scheme doesn't work for you. - # Default value is blank - # config.file_uri_scheme = 'file://///wsl$/Ubuntu-18.04' + # To change default file URI scheme you can provide `file_uri_scheme` config. + # It might be useful when you use WSL (Windows Subsystem for Linux) and default + # scheme doesn't work for you. + # Default value is blank + # config.file_uri_scheme = 'file://///wsl$/Ubuntu-18.04' + end end From 7fc1f171ab6a8a4ab265c4963fffd509b1b4392a Mon Sep 17 00:00:00 2001 From: Andrei Rumiantsau Date: Wed, 24 Apr 2024 23:56:22 +0300 Subject: [PATCH 04/14] RT-AWS-ebextensions (#12) --- .ebextensions/00_setup_swap.config | 8 ++++++++ .ebextensions/01_set_vars.config | 6 ++++++ .ebextensions/02_install_yarn.config | 7 +++++++ .ebextensions/03_alb_default_process.config | 12 ++++++++++++ .elasticbeanstalk/system.config | 17 ----------------- .../hooks/prebuild/01_gem_install_bundler.sh | 6 ------ 6 files changed, 33 insertions(+), 23 deletions(-) create mode 100644 .ebextensions/00_setup_swap.config create mode 100644 .ebextensions/01_set_vars.config create mode 100644 .ebextensions/02_install_yarn.config create mode 100644 .ebextensions/03_alb_default_process.config delete mode 100644 .elasticbeanstalk/system.config delete mode 100644 .platform/hooks/prebuild/01_gem_install_bundler.sh diff --git a/.ebextensions/00_setup_swap.config b/.ebextensions/00_setup_swap.config new file mode 100644 index 0000000..341509c --- /dev/null +++ b/.ebextensions/00_setup_swap.config @@ -0,0 +1,8 @@ +commands: + 01setup_swap: + test: test ! -e /var/swapfile + command: | + /bin/dd if=/dev/zero of=/var/swapfile bs=1M count=2048 + /bin/chmod 600 /var/swapfile + /sbin/mkswap /var/swapfile + /sbin/swapon /var/swapfile diff --git a/.ebextensions/01_set_vars.config b/.ebextensions/01_set_vars.config new file mode 100644 index 0000000..6c338ba --- /dev/null +++ b/.ebextensions/01_set_vars.config @@ -0,0 +1,6 @@ +commands: + set_env_vars: + command: /opt/elasticbeanstalk/bin/get-config environment | jq -r 'to_entries | .[] | "export \(.key)=\"\(.value)\""' > /etc/profile.d/sh.local +packages: + yum: + jq: [] diff --git a/.ebextensions/02_install_yarn.config b/.ebextensions/02_install_yarn.config new file mode 100644 index 0000000..4a188c8 --- /dev/null +++ b/.ebextensions/02_install_yarn.config @@ -0,0 +1,7 @@ +commands: + 01_install_yarn: + command: | + set -e + npm i -g yarn + ln -s "$(npm bin --global)"/yarn /usr/bin/yarn + test: "! yarn -v" diff --git a/.ebextensions/03_alb_default_process.config b/.ebextensions/03_alb_default_process.config new file mode 100644 index 0000000..104bfeb --- /dev/null +++ b/.ebextensions/03_alb_default_process.config @@ -0,0 +1,12 @@ +option_settings: + aws:elasticbeanstalk:environment:process:default: + DeregistrationDelay: '20' + HealthCheckInterval: '15' + HealthCheckPath: /okcomputer + HealthCheckTimeout: '5' + HealthyThresholdCount: '3' + UnhealthyThresholdCount: '5' + Port: '80' + Protocol: HTTP + StickinessEnabled: 'true' + StickinessLBCookieDuration: '43200' diff --git a/.elasticbeanstalk/system.config b/.elasticbeanstalk/system.config deleted file mode 100644 index f636d04..0000000 --- a/.elasticbeanstalk/system.config +++ /dev/null @@ -1,17 +0,0 @@ -packages: - yum: - git: [] -commands: - create_swapfile: - test: test ! -e /var/swapfile - command: | - dd if=/dev/zero of=/var/swapfile bs=1M count=2048 - chmod 600 /var/swapfile - mkswap /var/swapfile - swapon /var/swapfile - create_home_webapp: - test: mkdir /home/webapp - command: | - sudo mkdir -p /home/webapp - sudo chown webapp:webapp /home/webapp - sudo chmod 700 /home/webapp diff --git a/.platform/hooks/prebuild/01_gem_install_bundler.sh b/.platform/hooks/prebuild/01_gem_install_bundler.sh deleted file mode 100644 index b2429b1..0000000 --- a/.platform/hooks/prebuild/01_gem_install_bundler.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -EB_APP_STAGING_DIR=$(sudo /opt/elasticbeanstalk/bin/get-config platformconfig -k AppStagingDir) -cd $EB_APP_STAGING_DIR - -gem install bundler --no-document -v 2.5.3 From 9ab1c6e2c9a0acadbd7ff0258b4367bf17678841 Mon Sep 17 00:00:00 2001 From: Andrei Rumiantsau Date: Thu, 25 Apr 2024 00:20:14 +0300 Subject: [PATCH 05/14] RT-Staging-unforce-ssl (#13) --- config/environments/staging.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/environments/staging.rb b/config/environments/staging.rb index fa8a20d..f64176b 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -49,7 +49,7 @@ # config.assume_ssl = true # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. - config.force_ssl = true + config.force_ssl = false # Log to STDOUT by default config.logger = ActiveSupport::Logger.new(STDOUT) From 70c8fdadafad1ecfdefb65cccde36e01414a11b7 Mon Sep 17 00:00:00 2001 From: Andrei Rumiantsau Date: Thu, 25 Apr 2024 01:09:39 +0300 Subject: [PATCH 06/14] RT-Use-AWS-eb-puma (#14) --- Gemfile | 2 +- Procfile | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 Procfile diff --git a/Gemfile b/Gemfile index 9096f31..0012ac4 100644 --- a/Gemfile +++ b/Gemfile @@ -63,7 +63,7 @@ gem 'jsonapi-serializer', '~> 2.2' # Concurrency and processes # Simple, fast, threaded, and highly parallel HTTP 1.1 server for Ruby/Rack applications -gem 'puma', '~> 6.4', '>= 6.4.2' +gem 'puma', '~> 6.4', '>= 6.4.2', groups: %i(development test) # Popen, but with stderr, too gem 'open3', '~> 0.2.1' diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..d757c56 --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: puma -C /var/app/current/config/puma.rb From ad4d762f9ce7912378d241f284a8370363805688 Mon Sep 17 00:00:00 2001 From: Andrei Rumiantsau Date: Thu, 25 Apr 2024 01:25:41 +0300 Subject: [PATCH 07/14] RT-AWS-eb-revert-puma-server (#15) --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 0012ac4..9096f31 100644 --- a/Gemfile +++ b/Gemfile @@ -63,7 +63,7 @@ gem 'jsonapi-serializer', '~> 2.2' # Concurrency and processes # Simple, fast, threaded, and highly parallel HTTP 1.1 server for Ruby/Rack applications -gem 'puma', '~> 6.4', '>= 6.4.2', groups: %i(development test) +gem 'puma', '~> 6.4', '>= 6.4.2' # Popen, but with stderr, too gem 'open3', '~> 0.2.1' From faac606874b72c76bf0b87b48f94f7572a2fe324 Mon Sep 17 00:00:00 2001 From: Andrei Rumiantsau Date: Thu, 25 Apr 2024 02:02:20 +0300 Subject: [PATCH 08/14] RT-AWS-deploy-launch (#16) --- Procfile | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Procfile diff --git a/Procfile b/Procfile deleted file mode 100644 index d757c56..0000000 --- a/Procfile +++ /dev/null @@ -1 +0,0 @@ -web: puma -C /var/app/current/config/puma.rb From 3b1b9f5e1138ce9bb1e73fba5271d06adb73df65 Mon Sep 17 00:00:00 2001 From: Andrei Rumiantsau Date: Thu, 25 Apr 2024 08:50:10 +0300 Subject: [PATCH 09/14] RT-Default-url-options-host (#17) --- config/environments/staging.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/environments/staging.rb b/config/environments/staging.rb index f64176b..3a8a9e8 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -71,6 +71,8 @@ # config.active_job.queue_adapter = :resque # config.active_job.queue_name_prefix = "rails_template_production" + Rails.application.routes.default_url_options[:host] = "#{ENV['URL_PROTOCOL']}://#{ENV['URL_HOST']}/" + config.action_mailer.delivery_method = :smtp config.action_mailer.default_url_options = { host: ENV['URL_HOST'], From ba249c8e219923a948d9207342262fefd7672052 Mon Sep 17 00:00:00 2001 From: Andrei Rumiantsau Date: Thu, 25 Apr 2024 08:59:56 +0300 Subject: [PATCH 10/14] RT-Trigger-deploy (#18) From 954778dc3cebaec10a505ace426c6290a2492997 Mon Sep 17 00:00:00 2001 From: Andrei Rumiantsau Date: Thu, 25 Apr 2024 10:17:04 +0300 Subject: [PATCH 11/14] RT-Trigger-deploy-2 (#19) --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f8e405a..0331a2e 100644 --- a/README.md +++ b/README.md @@ -36,8 +36,8 @@ curl -v -X POST http://localhost:3001/api/users/sign_in -H 'Content-Type: applic curl -v -X DELETE http://localhost:3001/api/users/sign_out -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer XYZ' -curl -X GET 'localhost:3001/api/v1/users' -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer XYZ' +curl -X GET http://localhost:3001/api/v1/users -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer XYZ' -curl -X GET 'localhost:3001/api/v1/users/1' -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer XYZ' +curl -X GET http://localhost:3001/api/v1/users/1 -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer XYZ' -curl -X GET 'localhost:3001/api/v1/current_user' -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer XYZ' +curl -X GET http://localhost:3001/api/v1/current_user -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer XYZ' From 916507baaabf028c67372f0971db9fee5bb9fae5 Mon Sep 17 00:00:00 2001 From: Andrei Rumiantsau Date: Thu, 25 Apr 2024 10:54:15 +0300 Subject: [PATCH 12/14] RT-Init-charts-controller (#20) --- .ebextensions/00_setup_swap.config | 2 +- .ebextensions/02_install_yarn.config | 2 +- .ebextensions/04_update_bundler.config | 3 +++ app/controllers/api/v1/charts_controller.rb | 11 +++++++++++ config/initializers/devise.rb | 2 +- config/routes.rb | 2 ++ 6 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 .ebextensions/04_update_bundler.config create mode 100644 app/controllers/api/v1/charts_controller.rb diff --git a/.ebextensions/00_setup_swap.config b/.ebextensions/00_setup_swap.config index 341509c..43ea924 100644 --- a/.ebextensions/00_setup_swap.config +++ b/.ebextensions/00_setup_swap.config @@ -1,5 +1,5 @@ commands: - 01setup_swap: + setup_swap: test: test ! -e /var/swapfile command: | /bin/dd if=/dev/zero of=/var/swapfile bs=1M count=2048 diff --git a/.ebextensions/02_install_yarn.config b/.ebextensions/02_install_yarn.config index 4a188c8..0800973 100644 --- a/.ebextensions/02_install_yarn.config +++ b/.ebextensions/02_install_yarn.config @@ -1,5 +1,5 @@ commands: - 01_install_yarn: + install_yarn: command: | set -e npm i -g yarn diff --git a/.ebextensions/04_update_bundler.config b/.ebextensions/04_update_bundler.config new file mode 100644 index 0000000..15d9707 --- /dev/null +++ b/.ebextensions/04_update_bundler.config @@ -0,0 +1,3 @@ +commands: + update_bundler: + command: /usr/bin/gem install bundler -v 2.5.3 diff --git a/app/controllers/api/v1/charts_controller.rb b/app/controllers/api/v1/charts_controller.rb new file mode 100644 index 0000000..cf73932 --- /dev/null +++ b/app/controllers/api/v1/charts_controller.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module Api + module V1 + class ChartsController < AuthenticatedApplicationController + def data + render json: { chart_1: { a: 1, b: 2 }, chart_2: { a: 3, b: 4 } }, status: :ok + end + end + end +end diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 641dce9..d639302 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -379,6 +379,6 @@ ['DELETE', %r{^/api/users/sign_out$}] ] - jwt.expiration_time = 30.minutes.to_i + jwt.expiration_time = 300.minutes.to_i end end diff --git a/config/routes.rb b/config/routes.rb index 34d95fd..0662aa6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -54,6 +54,8 @@ defaults format: :json do resources :users, only: %i(index show) get '/current_user', to: 'users#current_user' + + get '/charts_data', to: 'charts#data' end end end From a882ce50cb543496671c2a1f26d8b9141c9e53b4 Mon Sep 17 00:00:00 2001 From: Andrei Rumiantsau Date: Thu, 25 Apr 2024 11:46:10 +0300 Subject: [PATCH 13/14] RT-Mock-charts-data (#21) --- app/controllers/api/v1/charts_controller.rb | 41 ++++++++++++++++++++- config/initializers/devise.rb | 2 +- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/charts_controller.rb b/app/controllers/api/v1/charts_controller.rb index cf73932..2d5b696 100644 --- a/app/controllers/api/v1/charts_controller.rb +++ b/app/controllers/api/v1/charts_controller.rb @@ -4,7 +4,46 @@ module Api module V1 class ChartsController < AuthenticatedApplicationController def data - render json: { chart_1: { a: 1, b: 2 }, chart_2: { a: 3, b: 4 } }, status: :ok + render json: { + target: 46, + current: 34, + baseline: 452.18, + targetTonnes: 300, + firstStage: 55, + firstStageVehicle: 27, + firstStagePropulsion: 33, + firstStageAvionics: 20, + firstStageThermal: 10, + firstStageAuxiliary: 10, + firstStageDesign: 32, + firstStageManufacture: 20, + firstStageTesting: 5, + firstStageFlight: 15, + firstStageEnd: 28, + secondStage: 26, + secondStageVehicle: 33, + secondStagePropulsion: 20, + secondStageAvionics: 27, + secondStageThermal: 15, + secondStageAuxiliary: 5, + secondStageDesign: 18, + secondStageManufacture: 42, + secondStageTesting: 17, + secondStageFlight: 3, + secondStageEnd: 20, + fairing: 19, + fairingStageVehicle: 21, + fairingStagePropulsion: 39, + fairingStageAvionics: 7, + fairingStageThermal: 20, + fairingStageAuxiliary: 13, + fairingStageDesign: 10, + fairingStageManufacture: 50, + fairingStageTesting: 5, + fairingStageFlight: 10, + fairingStageEnd: 25, + accuracy: 64 + }, status: :ok end end end diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index d639302..693a0c5 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -379,6 +379,6 @@ ['DELETE', %r{^/api/users/sign_out$}] ] - jwt.expiration_time = 300.minutes.to_i + jwt.expiration_time = 600.minutes.to_i end end From 22f6f539df79cb9257695b76eb3cd304d0b0b2fb Mon Sep 17 00:00:00 2001 From: Andrei Rumiantsau Date: Thu, 25 Apr 2024 12:14:17 +0300 Subject: [PATCH 14/14] RT-Show-api-users-for-api (#22) --- app/controllers/api/v1/users_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index 2844433..d8eedc8 100644 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -4,11 +4,11 @@ module Api module V1 class UsersController < AuthenticatedApplicationController def index - render json: User.all.order(:created_at).map { |user| serialize!(user) }, status: :ok + render json: ApiUser.all.order(:created_at).map { |user| serialize!(user) }, status: :ok end def show - render json: serialize!(User.find_by_id(params[:id])), status: :ok + render json: serialize!(ApiUser.find_by_id(params[:id])), status: :ok end def current_user