Skip to content

PéK like Profiles and Groups. The administration system for Schönherz Student Hostel and SVIE

Notifications You must be signed in to change notification settings

kir-dev/pek-next

Repository files navigation

PéK-Next

The administration system for Schönherz Student Hostel and SVIE

Build Status Code Climate Dependency Status

Requirements

  • Ruby 2.5.7
  • Postgresql 9.6
  • Node (asset compiling)
  • Redis (optional)

or

  • Docker

Installing requirements

Debian derivatives

Packages
# Redis is optional
sudo apt install postgresql-9.6 libpq-dev nodejs redis-server
Ruby 2.5.7

Use asdf with ruby plugin or rbenv. Install Ruby 2.5.7 and set executable version. You can check current ruby version with ruby -v

MacOS

Brew

Easiest way to install brew, then install required packages.

# Redis is optional
brew install asdf postgresql@9.6 redis
brew services start postgresql@9.6
brew services start redis
Ruby 2.5.7 and Node

Add ruby and node plugin to asdf. Install Ruby 2.5.7 and set executable version. You can check current ruby version with ruby -v. Install node too.

Setting up

The source code and dependencies
git clone https://github.com/kir-dev/pek-next.git
cd pek-next
gem install bundler
bundle install
Environment

Create a .env file using .env.example and replace the values with real ones.

The database
sudo su postgres
psql -c 'create user "pek-next" with superuser password '\''pek-next'\'';'
Init database

As your own user

rake db:setup

Running

The server
rails s
Worker (optional, requires redis)
bundle exec sidekiq
The tests (of course)
rake test

Deployment

Easiest way for deployment is docker-compose.

Copy .env from .env.example, add APP_ID and APP_SECRET according to auth.sch and generate a SECRET_KEY_BASE using bundle exec rake secret.

Then run the following commands:

# These volumes are not necessary and could be removed from docker-compose, but a named volume easier to find later on
docker volume create pek_public
docker volume create pek_database
docker-compose up --build

To deploy the application in staging environment use the following command:

docker-compose -f docker-compose.yml -f docker-compose.staging.yml up -d --build

After creating, while the containers are running run the following commands:

# This is only necessary at new setups
docker-compose run web bash -c "bundle exec rake db:setup"

# This is only necessary after pending migrations
docker-compose run web bash -c "bundle exec rake db:migrate"

# This is required at new setups and after changing in assets
docker-compose run web bash -c "bundle exec rake assets:precompile"

Maintenance tasks

Be sure to make regular backups in prod.

To create a database dump, use the following commands:

# open a session to the postgres container
docker-compose exec postgres bash

# create the database dump in the postgres container (use your current date),then exit
pg_dump -U postgres -Fc pek-next > /tmp/pek-next-production-db-2022-12-04.dump
exit

# copy the database dump from the container to the host machine
docker cp pek-next_postgres_1:/tmp/pek-next-production-db-2022-12-04.dump ~/db-dumps

To load a previously created database dump, use the following commands:

# copy the dump from the host to the postgres container
docker cp ~/db-dumps/pek-next-production-db-2022-12-04.dump pek-next_postgres_1:/tmp

# open the postgres container and load the database dump 
docker-compose exec postgres bash
pg_restore -U postgres -d pek-next /tmp/pek-next-production-db-2022-12-04.dump

Problems you may encounter and the solutions

Ruby cannot build the native extensions
sudo apt install ruby-dev
Rbenv install only gives ruby-build usage instructions
rbenv install -v 2.5.7
Rbenv doesn't modify your ruby version
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
source ~/.bashrc
Rails command is not recognized after install

Restart your terminal

by Kir-Dev Team

Special thanks for

Rollbar