• Documentation can be found here, it is fairly incomplete but most methods are documented here: VpsCli documentation

Purpose

  • To be able to spin up multiple development environments without having to reconfigure all the time
  • ### Note: This is a fragile process and currently is OS dependent.
  • Supported OS'es:

    • Ubuntu 18.10 - DigitalOcean
    • Ubuntu 18.04 on personal laptop
    • Lubuntu 18.10 on a seperate personal laptop
  • Ideally, you should brush over the contents of each file

  • .rc files located in config_files/dotfiles

  • config_files/misc_files contains non dotfiles such as sshd_config & gnome_terminal_settings

Warnings

  • ### This will update your /etc/ssh/sshd_config file.
  • Your original can be obtained at ~/backup_files/sshd_config.orig

  • This will add source chruby to your .bashrc or .zshrc file

  • This is done during setup.sh

  • This will also update your dotfiles

  • dotfiles should be able to be restored by appending a .orig to the file like so

  • if a dotfile backup already exists, no backup will be created

~/backup_files/vimrc.orig
~/backup_files/tmux.conf.orig
~/backup_files/zshrc.orig

Prerequisites

  • have git installed
sudo apt[-get] install git

How i use this script

  1. Ensure your ssh key is inside of your DigitalOcean droplet under security
  • If you have an existing droplet, consult digitalocean documents on adding an ssh key
  1. Create your droplet

  2. ssh into your server

ssh [email protected]<ip_address>
  1. Create a new user, do not use root as your main user. Ensure to give your user sudo permissions
adduser <username>
adduser <username> sudo
  • Ensure that you have ssh keys added. I have disabled clear text passwords.
  1. Clone the repo & setup for use
git clone https://github.com/ParamagicDev/vps_cli.git ~/vps_cli
cd ~/vps_cli
./setup.bash
  1. Setup pgp keys
  2. If you have not setup PGP / GPG before, you can follow my guide: My Guide to setting up PGP / GPG
  • export your PGP key for use by sops
export SOPS_PGP_FP="$KEY_ID"
  • Your $KEY_ID can be obtained by running:
gpg --list-keys
  1. Next step is to create a .credentials.yaml file in your home directory
sops ~/.credentials.yaml
  • Follow the same layout as provided inside of this repo: example_credentials.yaml

  • ensure your github api token has read:public_key & write_public_key scope as well as in the format "token 123456789"

  • You can either use scp to send the file from your local computer to your server, or you can simply create a new one everytime.

  1. Run a fresh install, this will provide you with all my dotfiles, all the ways I like everything setup etc.
vps-cli fresh_install

Maintenance

  • To pull in any local changes into your repo run:
vps-cli pull -a
  • To copy any changes from your repo to your local files, run:
vps-cli copy -a
  • This will only pull / copy dotfiles already found within config_files/misc_files & config_files/dotfiles

  • To add additional dotfiles, add them to config_files/dotfiles

Dependencies Installed

  • There are many dependencies installed, a large list can be located in:
  • /path/to/vps_cli/setup.bash
  • /path/to/vps_cli/lib/vps_cli/packages.rb

Tools installed

  • Vim / Neovim
  • Zsh / OhMyZsh
  • Tmux w/ tmux plugin manager - Terminal multiplexer
  • Mosh - Mobile Shell
  • Asciinema - records your terminal
  • Docker (Installed but not used currently)
  • Heroku CLI (--classic)
  • Ufw - Allows only certain people to connect
  • Httpie - for playing around with API requests
  • PGP / GPG - Public / Private key authentication
  • gnome-terminal - gnome terminal emulator

Languages / Frameworks installed

  • Nodejs
  • Yarn
  • Npm
  • sqlite3
  • Python3 / pip
  • Golang
  • Ruby 2.6.0
  • Chruby
  • Ruby-Install
  • Rails

Gems

  • pry - Ruby debugger / IRB alternative
  • bundler - package manager
  • neovim - neovim support
  • colorls - colorful file display
  • rake
  • rails

Viewing localhost of the server

  • For viewing apps over ssh, ensure to use
ssh -L <localport>:localhost:<remoteport> [email protected]
  • At full speed it should look like:
ssh -L 9000:localhost:3000 [email protected]
  • Then you can visit localhost:9000 in your browser and view your web app
  • Alternatively, ngrok is installed via linode.bash
ngrok http <localport>
ngrok http 3000 
  • This will bring up a CLI to connect to for example localhost:3000 on the web

Testing

  • Import the gpg dev key, I just took the one from The mozilla SOPS github and added it into this repo for testing purposes.
gpg --import /path/to/vps_cli/sops_testing_key.asc
  • The test suite will fail if the testing key is not present, this is to be expected

    rake test
    
  • if you have not run the setup script you can do the following:

cd exe
./vps-cli [COMMAND] [OPTIONS]

Example commands

  • The following command will copy all files to $HOME directory from . With the --interactive flag, it will prompt the user before overwriting any files.
vps-cli copy --all --interactive
  • The following command will pull files from the local directory ($HOME) to
vps-cli pull --all
  • This is still a work in progress. More commands and flags will be added

Contents of credentials.yaml

Updates for the future?

  • Adding docker support via images

Utilities used

  • RAKE For various command line tasks
  • THOR For command line options via ruby
  • YARD For documentation of code
  • GNUPG2 For GPG keys to be used with sops
  • SOPS For secret management via YAML files

Things learned:

  • Configuration is hard. There is a reason things like chef, puppet, ansible etc exist.
  • How to create a logger. Example is in test/logs after running rake test
  • Rake is a great tool, but is weak with command line arguments, may look into Thor for the future
  • It works, its not pretty, but it gets the job done.
  • Mixing command line and Ruby is not easy
  • Thor does args well
  • Testing apt-get install / apt install etc is nearly impossible unless i were to go through and do a File.exist? for everything which is not feasible
  • My original, non extensible, less easily tested version is available here: Deprecated Bash Scripting Branch
  • NEVER USE A PASSWORD AS A COMMAND LINE ARGUMENT
  • How to remove a file with sensitive information from your commit history via git rebase
  • As this project grows, RDoc / YARD is a great way to have an easy view of what everything does
  • Created calls to the web via Curl / Net:HTTP provided by Ruby
  • Proper storage of secrets such as API keys, SSH keys, etc
  • Wrapping something such as sops with Ruby is not easy.
  • So much testing on things that are not easy to test
  • Scope creep is a real thing and ive experienced it with this project
  • This projected ended up being way bigger than expected, I need to get back to web development

ISSUES

  • You may encounter the following issue if you have oh-my-zsh already on your machine and running the setup.bash script
/home/paramagician/.oh-my-zsh/oh-my-zsh.sh: line 23: autoload: command not found
/home/paramagician/.oh-my-zsh/oh-my-zsh.sh: line 34: syntax error near unexpected token `('
/home/paramagician/.oh-my-zsh/oh-my-zsh.sh: line 34: `for config_file ($ZSH/lib/*.zsh); do'
/home/paramagician/.oh-my-zsh/oh-my-zsh.sh: line 23: autoload: command not found
/home/paramagician/.oh-my-zsh/oh-my-zsh.sh: line 34: syntax error near unexpected token `('
/home/paramagician/.oh-my-zsh/oh-my-zsh.sh: line 34: `for config_file ($ZSH/lib/*.zsh); do'
  • This is because the script is run via bash instead of ZSH, this should not affect anything