Skip to content

Instantly share code, notes, and snippets.

@hmasila
Last active September 12, 2024 19:15
Show Gist options
  • Save hmasila/d42a6fbcc60eb82d64592e8a0640af10 to your computer and use it in GitHub Desktop.
Save hmasila/d42a6fbcc60eb82d64592e8a0640af10 to your computer and use it in GitHub Desktop.

Create deploy user

$ sudo adduser deploy

Privileges

Sudoer

add "deploy" user to sudo group if you want deploy to be a sudoer

$ sudo usermod -aG sudo deploy

verify if the user has been added to the sudo group result should include "sudo" for the deploy user $ groups deploy

Non-sudoer

If you don't want deploy to be a sudoer, you can add the privileges independently

$ visudo

Add your new user privileges under root & ctrl+x then y to save

deploy ALL=(ALL:ALL) ALL

Login as deploy

$ su deploy

Add your ssh keys

Si unajua kufanya hiyo

Install dependencies

sudo apt install build-essential libpq-dev libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm-dev autoconf bison postgresql postgresql-contrib

Install Rbenv

$ git clone https://github.com/rbenv/rbenv.git ~/.rbenv

$ echo 'eval "$(~/.rbenv/bin/rbenv init - bash)"' >> ~/.bashrc

$ source ~/.bashrc

Install Ruby Build

git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build

Install your Ruby version

$ rbenv install 3.1.2

install Nvm

$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

$ source ~/.bashrc

Install your node version

$ nvm install 16.10.0

Install Yarn

Via Curl

$ sudo curl --compressed -o- -L https://yarnpkg.com/install.sh | bash

$ source ~/.bashrc

Via npm

$ npm install -g yarn

Install redis

$ curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg

$ echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list

$ sudo apt-get update

$ sudo apt-get install redis redis-server

$ sudo vi /etc/redis/redis.conf

change supervised from auto to systemd

$ sudo systemctl restart redis-server

Setup the database

Login as postgres user

$ su - postgres

Connect to postgres

$ psql

Create deploy user and production database

CREATE USER deploy WITH PASSWORD 'S3Cur3Pa$&W0rD' CREATEDB;

CREATE DATABASE myapp_production;

GRANT ALL PRIVILEGES ON DATABASE spectralhub_production TO deploy;

\q to exit postgres

ctrl+D to exit out of postgres user

Start Postgres

$ sudo systemctl restart postgresql

@imuchene
Copy link

imuchene commented Sep 12, 2024

There are some issues here:

  • With Rails 7, the sections on Node, Yarn and Nvm are unnecessary if you're using the default configuration (importmaps)
  • The section on postgresql is unnecessary if you're using a different RDBMS such as a MariaDB or a NoSQL DB such as MongoDB, or if you're using a managed solution such as CloudSQL/Amazon RDS
  • You've left out the section of generating public/private keys and copying across your public key to the server
  • You've left out a section on configuring capistrano for rails deployment
  • As I said here, it's better if all the above is in a central place, rather than a bunch of gists

@hmasila
Copy link
Author

hmasila commented Sep 12, 2024

Again, thanks for the suggestions. However, these gists are for a specific reason and they serve their purpose as intended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment