Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vagrant #73

Merged
merged 2 commits into from Jul 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -2,3 +2,5 @@ target
*.bk
.env
*.deb
.vagrant
*.log
53 changes: 53 additions & 0 deletions README.md
Expand Up @@ -2,6 +2,59 @@

Deployed to http://rusty-dash.com right now. Some basic metrics about Rust development.

## Development

A development environment is available using Vagrant. [Install Vagrant](https://www.vagrantup.com/docs/installation/) along with a VM provider (tested with VirtualBox). It's a good idea to install the [vagrant-vbguest](https://github.com/dotless-de/vagrant-vbguest) plugin, as well. Once Vagrant and a VM provider are installed, you'll need to configure a couple of environment variables, (potentially) run DB migrations, and start the server processes. If you run into any issues provisioning the development environment, please file an issue!

### Configuring environment variables

Most of the configuration has some default set (see [vagrant_env.sh](https://github.com/dikaiosune/rust-dashboard/blob/master/vagrant_env.sh)), but you'll need to configure access to the GitHub API for testing the scraper. Something like this in the root project directory should suffice:

```
$ touch .env
$ echo "GITHUB_ACCESS_TOKEN=your_github_access_token_see_config_section_for_details" >> .env
$ echo "GITHUB_USER_AGENT=your_github_username" >> .env
```

**NOTE:** While the dashboard doesn't require any permissions boxes to be checked in access token creation, and the code makes every effort to avoid modifying any state through GitHub's API, there's always a risk with handing 3rd-party code your API credentials.

### Running server processes in Vagrant

There are three daemons to run, one each for the front-end development server, the back-end API server, and the scraper. It's recommended to run these in three separate terminal windows/tabs/sessions. Assuming the VM is already running (`vagrant up`), you'll need to run `vagrant ssh` in each terminal session to access the VM.

You may need to run database migrations if the bootstrap SQL file is stale:

```
$ cd /vagrant && diesel migration run
```

To run the back-end API server:

```
$ cd /vagrant && cargo run -- serve
```

To run the scraper daemon:

```
$ cd /vagrant && cargo run -- scrape
```

**NOTE:** The API server and scraper processes need to be manually restarted whenever you want to see code changes reflected in their behavior, or whenever you run migrations on the test database. A `Ctrl+C` followed by `Up` and `Enter` usually works if running them through cargo.

To install dependencies for the front-end development server and run it:

```
$ cd /vagrant/front && npm install && bower install
$ ember server --proxy=http://localhost:8080
```

You can then browse (on your host machine) to `http://localhost:4040` to view the development server output.

### Database Connection

Assuming that the VM provisions correctly (a little bit of an "if"), you should be able to connect to the PostgreSQL database on the host machine's port `4050`, using user: `vagrant` and password: `foobar`.

## Configuration

### Rust Version
Expand Down
28 changes: 28 additions & 0 deletions Vagrantfile
@@ -0,0 +1,28 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
config.vm.box = "bento/ubuntu-16.04"

config.vm.provision("apt",
type: "shell",
path: "vagrant/native_deps.sh",
keep_color: true)

config.vm.provision("postgres",
type: "shell",
path: "vagrant/postgres.sh",
keep_color: true,
privileged: false,
env: { 'PGVERSION' => '9.5', })

config.vm.provision("rust",
type: "shell",
path: "vagrant/rust.sh",
keep_color: true,
privileged: false,
env: { 'RUST_NIGHTLY_VERSION' => 'nightly-2016-06-15', },)

config.vm.network :forwarded_port, guest: 4200, host: 4040
config.vm.network :forwarded_port, guest: 5432, host: 4050
end
40,350 changes: 22,194 additions & 18,156 deletions bootstrap.sql

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions vagrant/native_deps.sh
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

set -e

# environment variables
cp /vagrant/vagrant/vagrant_env.sh /etc/profile.d/

# build folder
# cargo shouldn't share items b/t VM and host (using editor build-on-save, for example)
mkdir -p /rust-dashboard/target
chown -R vagrant:vagrant /rust-dashboard/

# dependencies
update-locale LANGE=en_US.UTF-8
locale-gen en_US.UTF-8
apt-get update
apt-get install -y postgresql libpq-dev npm nodejs curl
ln -s /usr/bin/nodejs /usr/bin/node

# frontend deps
npm install -g ember-cli
npm install -g bower
2 changes: 2 additions & 0 deletions vagrant/pg_hba.conf
@@ -0,0 +1,2 @@
local all all trust
host all all 0.0.0.0/0 md5
16 changes: 16 additions & 0 deletions vagrant/postgres.sh
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

set -e

# setup postgres
sudo -u postgres pg_dropcluster --stop $PGVERSION main
sudo -u postgres pg_createcluster --locale en_US.UTF-8 -e UTF8 --start $PGVERSION main

sudo -u postgres createuser -s --createdb vagrant
createdb -E UTF8 -l en_US.UTF8 -T template0 -O vagrant dashboard
sudo -u postgres echo "ALTER ROLE vagrant WITH PASSWORD 'foobar'" | psql -d dashboard
psql -d dashboard -f /vagrant/bootstrap.sql

sudo cp /vagrant/vagrant/pg_hba.conf /etc/postgresql/9.5/main/
echo "listen_addresses = '*'" | sudo tee --append /etc/postgresql/$PGVERSION/main/postgresql.conf
sudo systemctl restart postgresql
12 changes: 12 additions & 0 deletions vagrant/rust.sh
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

set -e

# install rust
curl https://sh.rustup.rs -sSf | sh -s -- -y
source $HOME/.cargo/env
rustup default $RUST_NIGHTLY_VERSION
rustup update

# for DB migrations
cargo install diesel_cli --no-default-features --features "postgres"
21 changes: 21 additions & 0 deletions vagrant/vagrant_env.sh
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

# default dashboard config
export DATABASE_URL=postgres://vagrant:foobar@localhost/dashboard
export DATABASE_POOL_SIZE=10
export RUST_LOG=debug,hyper=info,rustc=error,cargo=error
export GITHUB_SCRAPE_INTERVAL=10
export RELEASES_SCRAPE_INTERVAL=720
export BUILDBOT_SCRAPE_INTERVAL=80
export SERVER_PORT=8080

# VM config for cargo
export CARGO_TARGET_DIR=/rust-dashboard/target

export RUST_BACKTRACE=1
export RUST_NEW_ERROR_FORMAT=1

export PATH=$PATH:$HOME/.cargo/bin
export PS1="\[\033[01;37m\]\$? \$(if [[ \$? == 0 ]]; then echo \"\[\033[01;32m\]\342\234\223\"; else echo \"\[\033[01;31m\]\342\234\227\"; fi) $(if [[ ${EUID} == 0 ]]; then echo '\[\033[01;31m\]\h'; else echo '\[\033[01;32m\]\u@\h'; fi)\[\033[01;34m\] \w \$\[\033[00m\] "

echo "Environment variables set!"