/buyma_insider

Insider

Primary LanguageRuby

# Buyma Insider

## DEPLOYMENT

1. First deploy to environment

be cap staging deploy
ps1. you might need to install rbenv, ruby, and bundler

2. Link + setup with generate erb config files from current_dir
3. Use monit to start and monitor all services
4. Capistrano will symlink shared dir to current
5. `bundle config github.https true` if bundler complains about insecure git
6. Check `buyma_insider_client` for frontend deployment

## SETUP

- Unicorn in development can be run with local launch command
- Nginx has to be setup in production, but locally
  unicorn is directly listening on port 5000 and
  localhost, so nginx don't have to be setup
- - Nginx can be installed with --with-debug (dev, staging)
- - Nginx must be installed with --with-gzip-static
- - Using homebrew `brew tap homebrew/nginx`
- Daemonize command option is not added for unicorn, but
  could be if needed, just modify Procfile
- Make sure to set the ENVIRONMENT variable when running elsewhere
- Make sure that a proper HTTPS certificate is installed (https://gist.github.com/fnichol/867550)
- `foreman export launchd ./tmp/plist --log /usr/local/var/log`
- Install nginx-full, or use Brewfile
```
brew tap homebrew/nginx
brew install nginx-full --with-debug --with-gzip-static
```

### Elasticsearch

- Setup indices
- Setup mappings
- Setup analyzers
```

### Docker / VirtualBox

- Example of creating port forwarding on windows
-- `vboxmanage controlvm default natpf1 rethinkdb,tcp,127.0.0.1,8080,,8080`

- Example of building docker image
-- `docker build -t buyma_insider_sidekiq:latest .`
-- `docker run -it --network buymainsider_default --rm --privileged --name buyma_insider_sidekiq buyma_insider_sidekiq`
-- `compose up sidekiq`
- rethinkdb `docker run --name rethinkdb -p 8080:8080 -p 28015:28015 --rm greyarch/rethinkdb`
- elasticsearch `docker run --name elastic -p 9200:9200 -p 9300:9300 --rm -e ES_JAVA_OPTS='-Xms1g -Xmx1g' elasticsearch:latest`
TODO: Add to Dockerfile?
- sidekiq `bundle exec sidekiq --environment development --require ./config/application.rb --pidfile ./tmp/pids/sidekiq.pid --logfile ./log/sidekiq.log --concurrency 5`
- - sidekiq save a few stroke `bundle exec sidekiq -e development -r ./config/application.rb -P ./tmp/pids/sidekiq_1.pid -L ./log/sidekiq_1.log -c 1`

- Example running alpine for job
-- `docker run -it --rm --network buymainsider_default --privileged --name buyma_insider_sidekiq ruby:2.3-alpine sh`

### Local

- unicorn `ENVIRONMENT=development be unicorn -c config/unicorn.rb -E $ENVIRONMENT -d --host localhost --port 5000`
- pry `be pry -Iapp`