Skip to content

Commit

Permalink
Update setup instructions to work with Linux/NixOS (#1105)
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperSandro2000 authored Jul 14, 2022
1 parent 021e4d1 commit 38e4dea
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ yarn-debug.log*
/yarn-error.log
yarn-debug.log*
.yarn-integrity
/testing/postgresql-data

/app/assets/builds/*
!/app/assets/builds/.keep
39 changes: 37 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ In Greek mythology Elektra, the bright or brilliant one, is the Goddess of Cloud

# Installing and Running Elektra

## Steps for locally development on mac
## Steps to setup a local development environemnt

### MacOS

1. Install **postgres** database (actual version is 12).

Expand Down Expand Up @@ -83,7 +85,7 @@ In Greek mythology Elektra, the bright or brilliant one, is the Goddess of Cloud
6. Clone this repository to your machine.

```bash
git clone git@github.com:sapcc/elektra.git
git clone https://github.com/sapcc/elektra.git
```

7. Install **bundler**
Expand Down Expand Up @@ -134,6 +136,39 @@ In Greek mythology Elektra, the bright or brilliant one, is the Goddess of Cloud

Browser access for Elektra: http://localhost:3000

### Linux

1. Clone the repository with `git clone https://github.com/sapcc/elektra.git`
2. Install Yarn and PostgreSQL via package manager
3. Check if the ruby version in your package manager matches the version number in `.ruby-version`.
If yes then install ruby via your package manager. If no then follow the extra steps:
1. Set up [rbenv](https://github.com/rbenv/rbenv) and [ruby-build](https://github.com/rbenv/ruby-build) according to their documentation.
2. Install Ruby with `rbenv install 2.7.6` (substitute the Ruby version with the one from the aforementioned file).
4. Install Ruby gems with `bundle install`.
5. Install JavaScript packages with `yarn`.
6. Create database if not already done `./testing/with-postgres-db.sh bin/rails db:prepare`
7. In one terminal or tmux, run `yarn build --watch` to compile the JavaScript assets. Leave this running until you're done with development.
8. In a second terminal or tmux, run `./testing/with-postgres-db.sh bin/rails server -p 3000` to run the Ruby application. Leave this running, too.
9. Now you can access the GUI at `http://localhost:3000`. When coming in from a different machine, you need to set up forwarding for ports 3000, e.g. `ssh -L 3000:127.0.0.1:8180 -L 8081:127.0.0.1:8081`.
After each pull, you may have to repeat steps 4-5 if the Ruby version or any package versions were changed.
#### NixOS notes
Step 2 and 3 should be replaced with the following commands and the nix-shell must be kept open for the steps afterwards.
```bash
nix-shell
bundle config build.sqlite3 --with-sqlite3-include="$(nix-store -r "$(nix-instantiate '<nixpkgs>' -A sqlite.dev)")/include" --with-sqlite3-lib="$(nix-store -r "$(nix-instantiate '<nixpkgs>' -A sqlite.out)"'!out')/lib"
```
or with nix-command enabled:
```bash
nix shell -f shell.nix
bundle config build.sqlite3 --with-sqlite3-include="$(nix eval nixpkgs#sqlite.dev)/include" --with-sqlite3-lib="$(nix eval nixpkgs#sqlite.out)/lib"
```
## Use Elektra Request Management
1. Create another administrator user for the Default domain with email address in Horizon or with CLI
Expand Down
27 changes: 19 additions & 8 deletions env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,48 @@ POSTGRES_SERVICE_PORT=5432

# Rails development port
PORT=3000
RAILS_ENV=development

MONSOON_DB_USER=postgres
# MONSOON_DB_PASSWORD=<very-secure-passw0rd>

>>>>>>> b95f152de (Update setup instructions to work with Linux/NixOS)
# Devstack standard admin user/pw settings used for elektra service user
MONSOON_OPENSTACK_AUTH_API_ENDPOINT=http://localhost:5000/v3/auth/tokens
MONSOON_OPENSTACK_AUTH_API_USERID=admin
MONSOON_OPENSTACK_AUTH_API_PASSWORD=devstack
MONSOON_OPENSTACK_AUTH_API_DOMAIN=Default
# settings for test system service user. Replace domain for keystone and password with real values.
#MONSOON_OPENSTACK_AUTH_API_DOMAIN=Default
#MONSOON_OPENSTACK_AUTH_API_ENDPOINT=https://keystone.example.com/v3/auth/tokens
#MONSOON_OPENSTACK_AUTH_API_PASSWORD=<very-secure-passw0rd>
#MONSOON_OPENSTACK_AUTH_API_USERID=dashboard
# openstack service endpoint interface, default internal (for local development you most likely need to set this to public)
DEFAULT_SERVICE_INTERFACE=public

MONSOON_DASHBOARD_REGION=eu-de-1
MONSOON_DASHBOARD_MAIL_SERVER=<your-server>
MONSOON_DASHBOARD_REGION=qa-de-1
# MONSOON_DASHBOARD_MAIL_SERVER=<your-server>
# Retrieve avatar from Gravatar.com based on hashed user emails
MONSOON_DASHBOARD_AVATAR_URL='https://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(current_user.email)}?d=mm&size=24x24'
# CAM base URL
MONSOON_DASHBOARD_CAM_URL=<cam-url>
# MONSOON_DASHBOARD_CAM_URL=<cam-url>

# to access better errors and web console
# should be changed if you accessing the dashboard not from localhost
# TRUSTED_IP=localhost

# reduce logging
# ELEKTRON_QUIET=true
# ACTIVE_RECORD_QUIET=true
ELEKTRON_QUIET=true
ACTIVE_RECORD_QUIET=true

# SAP Arc Automation settings
#ARC_UPDATES_URL=<your-arc-update-server-url>
#ARC_PKI_URL=<your-arc-pki-server-url>
#ARC_BROKER_URL=<your-arc-broker-server-url>

# default true.
# ELEKTRA_SSL_VERIFY_PEER=false
# defaults to true, should not be disabled in production
ELEKTRA_SSL_VERIFY_PEER=false
ELEKTRA_EXTENSION=true

# debug excon api communication, default false.
# EXCON_DEBUG = true
Expand All @@ -58,4 +69,4 @@ DOMAIN_MASTERDATA_INHERITANCE_BLACKLIST=hcp03,monsoon3
# TEST_MEMBER_USER="TEST_D021500_TM"
# TEST_MEMBER_PASSWORD="xxx"
# TEST_ADMIN_USER="TEST_D021500_TA"
# TEST_ADMIN_PASSWORD="xxx"
# TEST_ADMIN_PASSWORD="xxx"
14 changes: 14 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{ pkgs ? import <nixpkgs> { } }:

with pkgs;

mkShellNoCC {
buildInputs = [
bintools
gcc
libffi.dev
nodejs
ruby
yarn
];
}
49 changes: 49 additions & 0 deletions testing/with-postgres-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/sh
# shellcheck shell=ash
set -euo pipefail

# Darwin compatibility
if hash greadlink >/dev/null 2>/dev/null; then
readlink() { greadlink "$@"; }
fi

# set working directory to repo root
cd "$(dirname "$(dirname "$(readlink -f "$0")")")"

step() {
printf '\x1B[1;36m>>\x1B[0;36m %s...\x1B[0m\n' "$1"
}

if [ ! -d testing/postgresql-data/ ]; then
step "First-time setup: Creating PostgreSQL database for testing"
initdb -A trust -U postgres testing/postgresql-data/
fi
mkdir -p testing/postgresql-run/

step "Configuring PostgreSQL"
sed -ie '/^#\?\(external_pid_file\|unix_socket_directories\|port\)\b/d' testing/postgresql-data/postgresql.conf
(
echo "external_pid_file = '${PWD}/testing/postgresql-run/pid'"
echo "unix_socket_directories = '${PWD}/testing/postgresql-run'"
echo "port = 5432"
) >> testing/postgresql-data/postgresql.conf

stop_postgres() {
EXIT_CODE=$?
step "Stopping PostgreSQL"
pg_ctl stop -D testing/postgresql-data/ -w -s
exit "${EXIT_CODE}"
}

step "Starting PostgreSQL"
rm -f -- testing/postgresql.log
trap stop_postgres EXIT INT TERM
pg_ctl start -D testing/postgresql-data/ -l testing/postgresql.log -w -s

step "Running command: $*"
set +e
"$@"
EXIT_CODE=$?
set -e

exit "${EXIT_CODE}"

0 comments on commit 38e4dea

Please sign in to comment.