Русская версия ниже. For russian version see below.
Octoshell - access management system for HPC centers. This project is based on Ruby on Rails framework(5.2) Working production: https://users.parallel.ru/
Requires: Docker and Docker Composer
- copy repo
git clone https://github.com/octoshell/octoshell-v2.git
- execute
cd docker
- build and run containers
docker-compose up
. Add-d
flag for detached mode: run containers in background. Now your containers are launched, you can press ctrl + c to turn them off. - check status of containers
docker-compose ps
- install database and run seeds.rb while your containers are running:
docker-compose exec app bundle exec rake db:setup
- visit
http://localhost:3000/
(login:admin@octoshell.ru
, password:123456
)
Here Octoshell is run inside isolated container. This introduces difficulties, espcially for inexperienced developers, and can overwhelm advantages of fast and easy installation compared to direct installation. When you run rails server in development environment, you expect some code changes to take effect after next request is sent (F5 driven development). It works here too, thanks to bind mounts: octoshell-v2 directory on the host machine is mounted into a container. Postgres database is saved inside volume, so you can stop and start containers as much as you like without data loss.
But still sometimes you have to run commands inside container. These commands have to be started with docker-compose exec app
or you can run bash
docker-compose exec app bash
when the containers are running. But it can not help when you have to bundle and the app container is turned off. Just write bundle install
in docker/entrypoints/docker-entrypoint.sh
instead of rails server
command.
The Letter-opener gem opens for you sent emails via browser. It is not possible for docker, but you can read all sent emails here http://localhost:3000/admin/letter_opener
- Start the containers:
docker-compose up
- Stop the containers:
docker-compose down
- Read stdout of containers, when in detached mode:
docker-compose logs
- Reinstall container:
docker-compose build
(you might need to remove volumes sometimes)
We assume, that all below is doing as user octo
(or root, if it is said 'as root'). You can use another user. Please, note, that linux account octo
and database role octo
are not connected, but we prefer to use the same name for both cases. You can create user by command like adduser octo
-
install packages as root (under debian/ubuntu:
sudo apt-get install -y git curl wget build-essential libssl-dev libreadline-dev zlib1g-dev sudo yarnpkg pg-dev
) -
install as root redis (under debian/ubuntu:
sudo apt-get install -y redis-server redis-tools
) -
install postgresql (under debian/ubuntu:
sudo apt-get install -y postgresql postgresql-server-dev-all
) -
as root add database user octo:
sudo -u postgres bash -c "psql -c \"CREATE USER octo WITH PASSWORD 'HERE_COMES_YOUR_DESIRED_PASSWORD';\""
-
as root allow user octo to create databases:
sudo -u postgres bash -c "psql -c \"ALTER USER octo CREATEDB;\""
-
enable and start redis and postgresql (e.g.
systemctl enable redis; systemctl enable postgresql; systemctl start redis; systemctl start postgresql
) -
check if your postgresql is listening 127.0.0.1 port 5432 (e.g.
ss -lpn |grep 5432
). If it is not, check postgresql config files (in debian/ubuntu - /etc/postgresql/VERSION/main/postgresql.conf, 'port' parameter) -
as user install rbenv (e.g.
curl https://raw.githubusercontent.com/rbenv/rbenv-installer/master/bin/rbenv-installer | bash
) -
make sure rbenv is loaded automatically, by adding to ~/.bashrc these lines:
export PATH=~/.rbenv/bin:$PATH eval "$(rbenv init -)"
-
reopen your terminal session or execute lines from point above in console
-
install ruby:
rbenv install 2.7.6 rbenv global 2.7.6
-
execute
gem install bundler --version '< 2.0'
-
execute
git clone https://github.com/octoshell/octoshell-v2.git
-
go into cloned directory
cd octoshell-v2
-
execute
./rebuild_bundles full
-
copy
config/database.yml.example
intoconfig/database.yml
-
fill database parameters and password in
config/database.yml
-
execute
bundle exec rake db:setup
-
execute
bundle exec rake assets:precompile
(Downloading pages without precompilation and config.assets.debug = true can take significant amount of time)
Now you can test all in development mode, just execute ./dev
and wait for 'Use Ctrl-C to stop'. Open 'http://localhost:5000/' to access application.
To test delayed actions, such as email send, cluster sync, start sidekiq in development mode: dev-sidekiq
.
Enter as admin with login admin@octoshell.ru
and password 123456
To run in production mode:
- as root install nginx (
sudo apt-get install nginx
) - as root copy nginx config file (
cp nginx-octo.conf /etc/nginx/sites-enabled/
), restart nginx (systemctl restart nginx
) - as root move your app into /var/www:
mkdir /var/www/octoshell2; mv ~octo/octoshell-v2 /var/www/octoshell2/current
) - Start production sidekiq:
./run-sidekiq
- Start production server:
./run
- To add cluster sync you should login to your cluster as root, create new user 'octo'. Login as
admin@octoshell.ru
in web-application. Go to "Admin/Cluster control" and edit "Test cluster". Copyocto
public key from web to /home/octo/.ssh/authorized_keys.
Best way is to test in development mode and then do deploy on production (or stage) server. See Deploy section for more details.
If you want add errors report via Airbrake or Honeybadger protocols, export any nonempty content in environment
variable AIRBRAKE or HONEYBADGER respectively. For Airbrake use first tune config/initializers/airbrake.rb file as you want.
For Honeybadger after bundle install
execute bundle exec honeybadger install YOUR_API_KEY
and optionally tune
config/honeybadger.yaml.
For correct work of images and video uploading you'll need to install imagemagick and ffmpegthumbnailer packages.
Currently Octoshell supports 2 locales: ru (Russian) and en (English). Other locales can be added, but your code should support at least these 2 locales. "Static" content must be used with I18n.t
method. Database data is translated using Traco gem. Validation is designed with validates_translated
method (lib/model_translation/active_record.rb
), perfoming validation of data stored in current locale columns.
Users table has the 'language' column. User's working language is stored here. lib/localized_emails
contains code for emails localization. Email locale depends on user language. If you want to send an email to unregistered user, 'en' locale will be chosen. You can preview your emails with Rails Email Preview gem.
I18n-tasks gem is used to manage locales in the project. But native gem is not designed to work with Rails engines. See this fork.
javascript libraries: jquery, handlebars, select2 and alpaca.js(for building forms).
We use bootstrap-forms gem to create static forms. Select2 can build lists using remote data. You can use autocomplete_field
method (engines/face/lib/face/custom_autocomplete_field.rb
) to prepopulate select2 field(if you use remote data).
Example:
= bootstrap_form_for @search, method: :get, url: admin_users_path, layout: :horizontal do |f|
= f.autocomplete_field :id_in,{ label: User.model_name.human, source: main_app.users_path, include_blank: true} do |val|
-User.find(val).full_name_with_email ## if id_in is not blank, Selected value will contain all users' full names.
You may need to notify administrators using support tickets (requests). Special class was designed to do it. Its functionality is very similar to ActionMailer::Base class (engines/support/lib/support/notificator.rb
). Example: engines/core/app/notificators/core/notificator.rb engines/core/lib/core/checkable.rb
. Be careful with the topic_name
method. It must be used only inside "action" method like Notificator.check
. Pay special attention that the new
method is not used here explicitly and method_missing is used to set correct options.
Use "options" to extend desription of any model.
- In model (see app/models/application_record.rb for details): class YourModel < ApplicationRecord extend_with_options end
- In your form use #form_for_options and bootstrap_nested_form_for (nested_form_for) methods: = bootstrap_nested_form_for :@instance do |f| # your fields = form_for_options(f)
- show_options helper: = show_options(@instance) do - can? :manage, :packages #user will see only options with admin boolean attribute set to false if he can't manage packages = show_options(@instance) # user will see all options for this instance
- in your controller params: def your_model_params params.require(:your_model) .permit(:your_attrs, options_attributes: options_attributes) end
You can autocomplete name and value fields. Edit all name and values available for autocomplete here: /admin/options_categories
- Prepare deploy server (1-10 from above)
- Make sure you can ssh to deploy server without password
git clone
- Rename
deploy_env.sample
todeploy_env
and fill right environment ./do_deploy_setup
./do_deploy
./deploy_copy_files
./do_after_1_deploy
- ssh to deploy server and start all by
systemctl start octoshell
All deploys after this can be done by git fetch; ./do_deploy
, and then on deploy server systemctl restart octoshell
.
You can help us and other users of Octoshell by writting usefull cool features etc. Please, note, that from 2019 we are using Conventional Commits standart for commits: each commit comment should have this form:
<type>(scope): description
Full description. If it has two or more points, each point should start with '* '.
Types:
Type | Description |
---|---|
docs | Documantation update |
uix | User interface changes |
feat | New functions and features |
fix | Bug fixes |
perf | Performance improvement |
refactor | Just refactoring |
revert | Back to old code! |
style | Code style fixes |
test | Adding and improving tests |
Scope: one of engines or 'base' for main app or other files (README, deployment, etc).
Базовое приложение для модульной версии octoshell.
Важно: после удаление контейнера все данные пропадут. Требования: Docker и Docker Composer
- выполните
git clone https://github.com/octoshell/octoshell-v2.git
- выполните
cd octoshell-v2/docker
- выполните
docker-compose up -d --build
- откройте в браузере
127.0.0.1:35000
(логин:admin@octoshell.ru
, пароль:123456
)
Далее считаем, что установка производится под пользователем octo
(или root
, если сказано под рутом
). Можно использовать другое имя пользователя. Отметим, что имя пользователя и имя роли базы данных не обязаны совпадать, но мы используем одинаковые. Пользователя можно создать, например, командой adduser octo
-
под рутом ставим пакеты (debian/ubuntu:
sudo apt-get install -y git curl wget build-essential libssl-dev libreadline-dev zlib1g-dev sudo yarnpkg libsqlite3-dev sqlite3
) -
под рутом ставим redis (debian/ubuntu:
sudo apt-get install -y redis-server redis-tools
) -
под рутом ставим postgresql (debian/ubuntu:
sudo apt-get install -y postgresql postgresql-server-dev-all
) -
под рутом добавим роль для БД octo:
sudo -u postgres bash -c "psql -c \"CREATE USER octo WITH PASSWORD 'ТУТ_ПАРОЛЬ_ПОЛЬЗОВАТЕЛЯ_БД';\""
-
под рутом добавим права octo:
sudo -u postgres bash -c "psql -c \"ALTER USER octo CREATEDB;\""
-
под рутом включаем и запускаем redis и postgresql (например
systemctl enable redis; systemctl enable postgresql; systemctl start redis; systemctl start postgresql
) -
проверяем, что postgresql слушает на 127.0.0.1 порт 5432 (например
ss -lpn |grep 5432
). Если нет, проверяем настройки postgresql (в debian/ubuntu - /etc/postgresql/VERSION/main/postgresql.conf, строчка 'port') -
под пользователем ставим rbenv (проще всего так:
curl https://raw.githubusercontent.com/rbenv/rbenv-installer/master/bin/rbenv-installer | bash
) -
в ~/.bashrc пользователя должны быть добавлены эти строки, чтобы работал rbenv:
export PATH=~/.rbenv/bin:$PATH eval "$(rbenv init -)"
-
запускаем новое окно терминала или терминальную сессию или просто выполняем в консоли строки из предыдущего пункта.
-
ставим ruby:
rbenv install 2.5.1 rbenv global 2.5.1
-
выполняем
gem install bundler --version '< 2.0'
-
выполняем
git clone https://github.com/octoshell/octoshell-v2.git
-
переходим в созданный каталог
cd octoshell-v2
-
выполняем
./rebuild_bundles
-
копируем
config/database.yml.example
вconfig/database.yml
-
вписываем параметры БД и пароль в
config/database.yml
-
выполняем
bundle exec rake db:setup
-
выполняем
bundle exec rake assets:precompile
Теперь можно запустить всё в development режиме, просто выполнив ./dev
и подождав строчки 'Use Ctrl-C to stop'. В браузере открываем 'http://localhost:5000/'.
Чтобы протестировать отложенные операции, такие как рассылка email, синхронизация с кластером и т.п., запускаем sidekiq в development режиме: dev-sidekiq
.
В браузере вводим логин admin@octoshell.ru
и пароль 123456
Для запуска в production режиме:
- под рутом ставим nginx (
sudo apt-get install nginx
) - под рутом копируем конфиг nginx-а (
cp nginx-octo.conf /etc/nginx/sites-enabled/
), перезапускаем nginx (systemctl restart nginx
) - под рутом перемещаем каталог приложения в /var/www:
mkdir /var/www/octoshell2; mv ~octo/octoshell-v2 /var/www/octoshell2/current
) - запускаем production sidekiq:
./run-sidekiq
- запускаем production server:
./run
- для синхронизации с кластером, заходим как root на кластер, создаём пользователя 'octo'. Входим как
admin@octoshell.ru
в приложение. Идём в "Admin/Cluster control" редактируем "Test cluster" (или новый). Копируем открытый ключocto
из web-странички в /home/octo/.ssh/authorized_keys.
Лучше всего потестировать приложение в development режиме, а потом выполнить деплой на рабочий (или тестовый) сервер, см. раздел Деплой.
- Подготовьте сервер деплоя (пп. 1-10 из раздела "Установка...")
- Убедитесь, что вы можете входить на сервер деплоя по ssh без пароля
git clone
- Переименовать
deploy_env.sample
вdeploy_env
и внесите нужные правки ./do_deploy_setup
./do_deploy
./deploy_copy_files
./do_after_1_deploy
- Войдите на сервер деплоя и запустите сервисы
systemctl start octoshell
Последующие деплои можно выполнять командой git fetch; ./do_deploy
и последующим перезапуском сервиса на сервере systemctl restart octoshell
.
Для корректной работы с картинками и видео необходимо установить пакеты imagemagick и ffmpegthumbnailer.
Вы можете помочь нам и другим пользователям улучшить Октошелл, создав новые крутые фишки и прочее, мы всегда рады новой функциональности. Пожалуйста, помните, что с 2019 года мы используем стандарт Conventional Commits: каждый комментарий к коммиту должен иметь вид:
<тип>(область): описание
Полное описание. Если в описании более одного пункта, каждый долен начинаться с '* '.
Типы:
Type | Description |
---|---|
docs | Обновление документации |
uix | Исправления в интерфейсе пользователя |
feat | Добавление нового функционала |
fix | Исправление ошибок |
perf | Изменения направленные на улучшение производительности |
refactor | Правки кода без исправления ошибок или добавления новых функций |
revert | Откат на предыдущие коммиты |
style | Правки по кодстайлу (табы, отступы, точки, запятые и т.д.) |
test | Добавление тестов |
Область - один из engines или 'base' для основного приложения или других файлов (типа README, деплоя, и т.п.)