# Setting up Hyku Addons from scratch

## Deleting existing system

If already exists and you want to start fresh
DANGER: This will kill it all including data

```sh
docker-compose down
docker-compose system prune
docker rm -f (docker ps -a -q)
docker volume rm (docker volume ls -q)
```

##  Setup

Bundle: 

```sh
bundle install
```

You may see an error with Zookeeper not being installed correctly. On Linux, the fix for this is: 

```sh
CFLAGS=-Wno-error=format-overflow  gem install zookeeper -v ‘1.4.11’ --source ‘https://rubygems.org/’
```

In order to access the super-admin host as well as the normal tenants, you will need to add them to your `/etc/hosts`. This will depend on what your tenants cname's are, however an example host file might look like this: 

```
127.0.0.1       localhost
::1             localhost

# Hyku
127.0.0.1       hyku.docker # Required for the super admin to work
127.0.0.1       repo.hyku.docker # One of the tenants for this instantion
127.0.0.1       anschutz.hyku.docker # Another tenant
```

Please note, you will have to use the `:3000` to access the tenants, as you would for any normal Rails app: http://hyku.docker:3000/


Docker Compose Up and allow debugging (via byebug)

```sh
docker-compose up -d web workers; docker attach hyku_addons_web_1
```

Enter bash inside container

```sh
docker-compose exec web /bin/bash
```

### Create a Super Admin

```sh
bundle exec rails app:hyku_addons:superadmin:create
```

### Create an account

#### Via app interface 

Goto the accounts screen http://hyku.docker:3000/proprietor/accounts?locale=en 

#### Via console

Goto the console

```sh
docker-compose exec web bundle exec rails console
```

Copy the string returned from secure random for use as the account UUID

```ruby
SecureRandom.uuid
```

Run the following: 

```sh
# bundle exec rails "app:hyku:account:create[Name, Copied UUID, CNAME, Email from above]"
 docker-compose exec web bundle exec rails "app:hyku:account:create[test, aa070467-09d7-4b13-bb5a-7192f900e6c3, test.hyku.docker, paul.danelli+admin@ubiquitypress.com]"
```

### Activate user

Your user will need to be activated as invitations are not sent locally

```sh
docker-compose exec web bundle exec rails console
```

```ruby
AccountElevator.switch!(Account.first.cname)

# NOTE: The password is being set again as it doesn't seem to be correct when trying to login
User.first.update(invitation_token: nil, invitation_accepted_at: DateTime.current, password: 'test1234')
```