Includes:
- A simple admin interface
- Bootstrap
- Capybara
- Devise
- Kaminari
- Lograge
- RSpec
sudo apt-get install -y build-essential postgresql libpq-dev nodejsTo start a new project, clone the repository:
git clone --depth 1 git@github.com:hackberryco/rails-starter.git <NEW_PROJECT_NAME>cd into the new directory:
cd <NEW_PROJECT_NAME>Remove the git repository:
rm -rf .gitRename the application in config/application.rb, config/deploy.rb and
config/database.yml.
Set the application repository in config/application.rb.
Initialize the new git repository and you're good to go!
To make a user admin, start the Rails console (bin/rails console) and execute:
user = User.find(<USER_ID>)
user.make_adminCreate user on the server:
adduser developerAdd the user to sudoers:
usermod -aG sudo developerUpdate the system:
sudo apt-get update && sudo apt-get -y upgradeInstall dependencies (git, ruby, nginx, passenger, etc.):
sudo apt-get install -y build-essential git nginx postgresql postgresql-contrib libpq-dev nodejs htopInstall bundler:
gem install bundlerCreate PostgreSQL user:
sudo -u postgres createuser -s developerSet the PostgreSQL user password:
sudo -u postgres psql
\password developer
\qPut database password in application_name.env:
APPLICATION_NAME_DATABASE_PASSWORD="..."Load the new environment variables:
source ~/.bashrcCopy secrets.yml.key to the server:
mkdir -p database/shared/config
scp config/secrets.yml.key server_name:database/shared/configPut the new production server IP to config/deploy/production.rb.
Deploy, from the development machine (it will fail):
bundle exec cap production deployCreate database (on the server):
bundle exec rake db:createConfigure passwordless sudo - put following line to /etc/sudoers:
developer ALL=(ALL) NOPASSWD: ALLConfigure Nginx and Puma:
bundle exec cap production puma:config
bundle exec cap production puma:nginx_configDisable paswordless sudo!
Remove default Nginx site:
sudo rm /etc/nginx/sites-enabled/default
sudo service nginx restartTo restore a database dump, execute:
scp application_name.dump server_name:~
pg_restore --no-privileges --no-owner -d application_name_production application_name.dumpDeploy again:
bundle exec cap production deployCopy the following configuration to /etc/systemd/system/application_name.service:
[Unit]
Description=Application Name Server
[Service]
Type=simple
User=developer
Group=developer
WorkingDirectory=/home/developer/application_name/current
EnvironmentFile=/home/developer/application_name.env
ExecStart=/bin/bash -lc 'bundle exec puma -C /home/developer/application_name/shared/puma.rb'
Restart=always
[Install]
WantedBy=multi-user.targetCopy the following logrotate configuration to /etc/logrotate.d/application_name:
/home/developer/application_name/shared/log/*.log { daily rotate 7 create size 10M compress delaycompress }
Disable password authentication by adding PasswordAuthentication no to
/etc/ssh/sshd_config.
Then, reload SSH daemon - sudo systemctl reload sshd.
Setup firewall:
sudo ufw allow OpenSSH
sudo ufw allow https
sudo ufw enable