Improve installation process

This commit is contained in:
magicfixin 2025-07-23 23:42:41 +02:00 committed by cryptogopher
parent e12369cea1
commit 5ffc6974f0
8 changed files with 115 additions and 44 deletions

9
.gitignore vendored
View File

@ -3,10 +3,15 @@
/.cache /.cache
/.gem /.gem
# Ignore master key for decrypting credentials and more. # Ignore service startup scripts.
/bin/fixinme.service
# Ignore:
# * master key for decrypting credentials and encrypted credentials,
# * custom app, database and server settings (based on *.dist templates).
/config/application.rb /config/application.rb
/config/credentials.yml.enc
/config/database.yml /config/database.yml
/config/initializers/secret_token.rb
/config/master.key /config/master.key
/config/puma.rb /config/puma.rb

20
Gemfile
View File

@ -1,20 +1,28 @@
source "https://rubygems.org" source "https://rubygems.org"
ruby '>= 3.3.0'
# The requirement for the Ruby version comes from Rails
gem "rails", "~> 7.2.2" gem "rails", "~> 7.2.2"
gem "sprockets-rails" gem "sprockets-rails"
gem "mysql2", "~> 0.5"
gem "puma", "~> 6.0" gem "puma", "~> 6.0"
gem "sassc-rails" gem "sassc-rails"
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ] gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]
# TODO: select db gems automatically based on config/database.yml:adapter
group :mysql, optional: true do
gem "mysql2", "~> 0.5"
end
group :postgresql, optional: true do
gem "pg", "~> 1.5"
end
group :sqlite, optional: true do
gem "sqlite3", "~> 2.7"
end
gem "devise" gem "devise"
gem 'importmap-rails' gem "importmap-rails"
# turborails >= 2.0.0 required with npm v8.0.0 with support for [autofocus] gem "turbo-rails", "~> 2.0"
# attribute in turbo-streams
gem 'turbo-rails', '> 1.5.0'
group :development, :test do group :development, :test do
gem "byebug" gem "byebug"

View File

@ -164,6 +164,7 @@ GEM
nokogiri (1.18.8-x86_64-linux-musl) nokogiri (1.18.8-x86_64-linux-musl)
racc (~> 1.4) racc (~> 1.4)
orm_adapter (0.5.0) orm_adapter (0.5.0)
pg (1.5.9)
pp (0.6.2) pp (0.6.2)
prettyprint prettyprint
prettyprint (0.2.0) prettyprint (0.2.0)
@ -245,6 +246,14 @@ GEM
actionpack (>= 6.1) actionpack (>= 6.1)
activesupport (>= 6.1) activesupport (>= 6.1)
sprockets (>= 3.0.0) sprockets (>= 3.0.0)
sqlite3 (2.7.3-aarch64-linux-gnu)
sqlite3 (2.7.3-aarch64-linux-musl)
sqlite3 (2.7.3-arm-linux-gnu)
sqlite3 (2.7.3-arm-linux-musl)
sqlite3 (2.7.3-arm64-darwin)
sqlite3 (2.7.3-x86_64-darwin)
sqlite3 (2.7.3-x86_64-linux-gnu)
sqlite3 (2.7.3-x86_64-linux-musl)
stringio (3.1.7) stringio (3.1.7)
thor (1.3.2) thor (1.3.2)
tilt (2.6.0) tilt (2.6.0)
@ -287,17 +296,16 @@ DEPENDENCIES
devise devise
importmap-rails importmap-rails
mysql2 (~> 0.5) mysql2 (~> 0.5)
pg (~> 1.5)
puma (~> 6.0) puma (~> 6.0)
rails (~> 7.2.2) rails (~> 7.2.2)
sassc-rails sassc-rails
selenium-webdriver selenium-webdriver
sprockets-rails sprockets-rails
turbo-rails (> 1.5.0) sqlite3 (~> 2.7)
turbo-rails (~> 2.0)
tzinfo-data tzinfo-data
web-console web-console
RUBY VERSION
ruby 3.3.7p123
BUNDLED WITH BUNDLED WITH
2.6.3 2.6.3

View File

@ -4,47 +4,70 @@ README
Quantified self Quantified self
Software requirements Installation
--------------------- ------------
The steps described in this section are for preparing a production installation.
For possible modifications to this procedure to configure the development
environment, see the _Contributing_ section below.
### Requirements
* Server side: * Server side:
* Ruby version: developed on Ruby 3.x * Ruby interpreter, depending on the version of Rails used (see _Gemfile_),
* database with: * https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#ruby-versions
* recursive Common Table Expressions (CTE) support, e.g. * database (e.g. MySQL >= 8.0) supporting:
MySQL >= 8.0, MariaDB >= 10.2.2 * recursive Common Table Expressions (CTE) for SELECT/UPDATE/DELETE,
* decimal type with precision of at least 30 (not sure if SQLite3 * MariaDB does not support CTE for UPDATE/DELETE
supports this) (https://jira.mariadb.org/browse/MDEV-18511)
* decimal datatype with precision of at least 30,
* SQLite3 _flexible typing_ decimal will work, but precision
will be limited to 16, making it practical mostly for testing
purposes
* for testing: browser as specified in _Client side_ requirements * for testing: browser as specified in _Client side_ requirements
* Client side: * Client side:
* browser supporting below requirements (e.g. Firefox >= 121): * browser (e.g. Firefox >= 121) supporting:
* [`import maps`](https://caniuse.com/import-maps) * [`import maps`](https://caniuse.com/import-maps)
(required by `importmap-rails` gem >= 2.0) (required by `importmap-rails` gem >= 2.0)
* CSS [`:has()` pseudo-class](https://caniuse.com/css-has) * CSS [`:has()` pseudo-class](https://caniuse.com/css-has)
### Gems
Installation On systems where development tools and libraries are not installed by default
------------ (such as Ubuntu), you should install them before proceeding with Ruby gems.
Select the database client library according to the database engine you are
planning to use:
sudo apt install build-essential libyaml-dev libmysqlclient-dev
git clone https://gitea.michalczyk.pro/fixin.me/fixin.me.git git clone https://gitea.michalczyk.pro/fixin.me/fixin.me.git
bundle config set --local path '.gem' cd fixin.me
bundle config --local frozen true
bundle config --local path .gem
Select which database engine gem to install (mysql, postgresql, sqlite):
bundle config --local with mysql
bundle install bundle install
### Configuration
Configuration Customize application settings (starting below `SETUP` comment) appropriately:
-------------
cp -a config/application.rb.dist config/application.rb cp -a config/application.rb.dist config/application.rb
Modify configuration settings below `SETUP` comment appropriately. Create `secret_key_base`. It will be automatically generated on first
`credentials:edit`, so it's enough to run command below, save the file and exit
editor:
bundle exec rails credentials:edit
Database ### Database
--------
Grant database user and privileges: Grant database user and privileges:
> mysql -p > mysql -p
mysql> create user fixinme@localhost identified by '<some password>'; mysql> create user fixinme@localhost identified by 'Some-password1%';
mysql> grant all privileges on fixinme.* to fixinme@localhost; mysql> grant all privileges on fixinme.* to fixinme@localhost;
mysql> flush privileges; mysql> flush privileges;
@ -62,7 +85,7 @@ Running
### Standalone Rails server + Apache proxy ### Standalone Rails server + Apache proxy
Copy Puma config template: Customize Puma config template:
cp -a config/puma.rb.dist config/puma.rb cp -a config/puma.rb.dist config/puma.rb
@ -70,10 +93,21 @@ and specify server IP/port, either with `port` or `bind`, e.g.:
bind 'tcp://0.0.0.0:3000' bind 'tcp://0.0.0.0:3000'
Run server #### (option 1) Start server manually
bundle exec rails s -e production bundle exec rails s -e production
#### (option 2) Start server as systemd service
Customize service template, setting at least `User` and `WorkingDirectory`:
sudo cp bin/fixinme.service.dist /etc/systemd/system/fixinme.service
sudo systemctl daemon-reload
sudo systemctl enable fixin.service
sudo systemctl start fixin.service
sudo systemctl status fixin.service
### Apache mod_passenger ### Apache mod_passenger

16
bin/fixinme.service.dist Normal file
View File

@ -0,0 +1,16 @@
[Unit]
Description=fixin.me Rails Application
After=network.target
[Service]
Type=simple
User=USER
WorkingDirectory=PATH_TO_APP_DIRECTORY
Environment="RAILS_ENV=production"
Environment="RAILS_SERVE_STATIC_FILES=true"
ExecStart=/bin/bash -lc 'bundle exec rails s -e production'
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target

View File

@ -47,7 +47,7 @@ module FixinMe
# List of hosts this app is available at. # List of hosts this app is available at.
# https://guides.rubyonrails.org/configuring.html#actiondispatch-hostauthorization # https://guides.rubyonrails.org/configuring.html#actiondispatch-hostauthorization
config.hosts << 'localhost' config.hosts += ['localhost', 'example.com', IPAddr.new('1.2.3.4/32')]
# Email address of admin account # Email address of admin account
config.admin = 'admin@localhost' config.admin = 'admin@localhost'

View File

@ -2,7 +2,7 @@
# in your source code, provide the password or a full connection URL as an # in your source code, provide the password or a full connection URL as an
# environment variable when you boot the app. For example: # environment variable when you boot the app. For example:
# #
# DATABASE_PASSWORD="some-password" # DATABASE_PASSWORD="Some-password1%"
# #
# or # or
# #
@ -29,22 +29,22 @@ default: &default
collation: utf8mb4_0900_as_ci collation: utf8mb4_0900_as_ci
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: fixinme username: fixinme
password: password: Some-password1%
socket: /run/mysqld/mysqld.sock socket: /run/mysqld/mysqld.sock
production: production:
<<: *default <<: *default
database: fixinme_production database: fixinme
# Unless you're planning on developing the application, you can skip/remove # Unless you're planning on developing the application, you can skip
# configurations for development and test databases altogether. # configurations for development and test databases altogether.
development: #development:
<<: *default # <<: *default
database: fixinme_dev # database: fixinme_dev
# Warning: The database defined as "test" will be erased and # Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake". # re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production. # Do not set this db to the same as development or production.
test: #test:
<<: *default # <<: *default
database: fixinme_test # database: fixinme_test

View File

@ -28,7 +28,7 @@ Rails.application.configure do
# config.assets.css_compressor = :sass # config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed. # Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false config.assets.compile = true
# Enable serving of images, stylesheets, and JavaScripts from an asset server. # Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.asset_host = "http://assets.example.com" # config.asset_host = "http://assets.example.com"