# !!! CLEANUP THE README FILES !!!

TODO - many of the README files in this repo are out of date. Clean them up!

# Bigscreen Devops

This repo contains various automation tools and recipes for setting up instances of Bigscreen's server environment.  It includes:
- Server setup recipes and config files.
- Terraform scripts for setting up a complete server environment from pre made images.
- Continuous integration scripts for our server applications.
- Build scripts for the Unity client.

# !!! IMPORTANT NOTE !!!

**This repo should never contain an unencrypted key file or any file containing a secret key! This applies even for a third party systems or APIs.**

In *almost* all cases, the server config files, private and public key files, .env files, and so forth, are generated at build time by jenkins.

Some fixed signing certificates and prebuilt .env files are available in our dropbox account for `dev` and `test` networks.

This repo *may* contain public DNS or IP addresses, but probably shouldn't.


# !!! IMPORTANT NOTE !!!

## SOME INFORMATION IN THIS README FILE MAY BE OBSOLETE.

# TERRAFORM

TBD - see `Jenkins/server_builder_v5.sh` for the latest terraform scripts.

The terraform scripts are designed to run on Jenkins in conjunction with a build pipeline.


# Creating Public/Private key pairs for JWT

## Private Key

```
ssh-keygen -t rsa -b 2048 -f KEY_NAME.key
```

## Public Key
```
openssl rsa -in KEY_NAME.key -pubout -outform PEM -out KEY_NAME.key.pub
```

# Generating API Keys

```
uuidgen.exe | sha256sum.exe
```


# Handling Urgent Rollbacks

Each server build is built to a folder, in the format `$STAGE_$NAME_$BUILDNUMBER` (e.g `staging_accounts_75`). To rollback to a previous build, you'll need to
ssh to the server, change to the desired folder directory, and then use pm2 to execute the target application.

Pre-requisites:
* Access to the `Server_Keys` folder in dropbox (email david@bigscreenvr.com or darshan@bigscreenvr.com for this)
* git bash on Windows.

## Example
Rollback to build #75 of the staging accounts api:
```
#!/bin/bash

DROPBOX_PATH=/c/path/to/dropbox
SERVER_USER=ubuntu
SERVER_DNS="ec2_ip.region.compute.amazonaws.com"

ssh -i "$DROPBOX_PATH/Server_Keys/DevSignal/DevSignal.pem" $SERVER_USER@$SERVER_DNS
cd staging_accounts_75
pm2 start api.js 
```