# stepbet-deploy
This repository contains various utilities that allow you to deploy, view logs and connect to Stepbet Game Service Servers.
# Installation
1. Place your SSH keys into `secrets/keys` and edit `config/op-servers.rb` to point to those keys.
2. Add `bin` to you homepath by adding this line to your `.bashrc`.
```bash
export PATH=~/dev/stepbet-deploy/bin:$PATH
```
#### Note:
File `config/op-servers.rb` need's to be up to date with the latest infrastructure changes. If say change the amount of Front End Game Service servers from 2 to 3, you will have to add it to this config file.
# Utilities
## 1. sbdeploy
Deploys into Game Service and Imageserver
#### Usage
Use the following options to deploy from `develop` all changes since commit `f94aade44ffa69c7a15e26dd8c8616ab87523f64`
```
sbdeploy -a stepbet-dev-appex -c f94aade44ffa69c7a15e26dd8c8616ab87523f64
```
#### Full list of options
```
-z, --debug Optional: load pry
-h, --help Prints this help
-a, --app=A Required, application name, e.g. stepbet-prod-appex
-c, --commit=C Required, last commit released before
-b, --backup Optional, deploy with backup
```
#### How it works
The script runs the following actions:
1. Fetches stepbet either `develop` or `master` branches from github into a temporary folder `./stepbet-deploy/tmp/repos/stepbet_dev_appex`. Branch is chosen based on config in `config/op-servers.rb`.
2. Optionally diffs all changes since commit SHA (option `-c`).
3. Deletes all files that should are **always edited manually directly on the servers**. These are `data/settings.php` and all the `.htaccess` files.
4. Compresses all `.js` and all `.css` files with `yuicompressor`.
5. Creates a zip and uploads it to directory defined in `config/op-servers.rb`.
6. Unzips the files on the server and deletes the zip.
## 2. sbkonnect
Wrapper around `ssh` that can connect to either one of the Game Service servers or Imageserver
#### Usage
Use the following options to connect to Front End Server #1 for Appex Game Service
```
sbkonnect -s stepbet-prod-appex-1
```
it results in a command
```
ssh -i /home/wbdev/stepbet-deploy/secrets/keys/stepbet-prod-appex.pem centos@ec2-54-234-242-251.compute-1.amazonaws.com -p 22
```
#### Full list of options
```
-z, --debug Optional: load pry
-h, --help Prints this help
-s, --server=S Required, the server instace, e.g. stepbet-prod-appex-1
-c, --command=C Optional, command to run
```
## 3. sblogs
Downloads local text file logs from either Game Service or Imageserver
#### Usage
Use the following command to download database errors from both Fron End Servers for Game Service production
```
sblogs -a stepbet-prod-appex -j -f database/db-errors.txt
```
This results in two downloaded files into:
```
stepbet-deploy/logs/stepbet_prod_appex/stepbet_prod_appex_1-db-errors.txt
/stepbet-deploy/logs/stepbet_prod_appex/stepbet_prod_appex_2-db-errors.t
```
and one file that contains content for both joined
```
stepbet-deploy/logs/stepbet_prod_appex/stepbet_prod_appex-db-errors.txt
```
#### Note:
If you have `gedit` installed locally, you can use option `-o` to automatically open the downloaded files.
#### Full list of options
```
-z, --debug Optional: load pry
-h, --help Prints this help
-a, --app=A Required, application name, e.g. stepbet-prod-appex
-f, --file=F Log file to download
-o, --open Optional, open the downloaded files on exit
-j, --join Optional, join multiple files in one file
```
## 4. sbphplogs
Wrapper around `ssh` that can connect to either one of the Game Service servers or Imageserver and open it's php error log file in `vim`.
#### Usage
Use the following options to see php errors on Fron End Server #1 (and potentially clear them out in `vim`)
```
sbphplogs -s stepbet-prod-appex-1
```
it results in a command
```
'ssh -i /home/wbdev/stepbet-deploy/secrets/keys/stepbet-prod-appex.pem centos@ec2-54-234-242-251.compute-1.amazonaws.com -p 22 -t 'vim "/var/log/php-fpm/www-error.log"''
```
#### Full list of options
```
-z, --debug Optional: load pry
-h, --help Prints this help
-s, --server=S Required, the server instace, e.g. stepbet-prod-appex-1
```