Skip to content

Commit

Permalink
Simple build (#18)
Browse files Browse the repository at this point in the history
* Removed old vagrant build system, still need to update the README.md file to reflect the change

* Updated README.md to remove vagrant install, and updated the example environment file to use the ribot database user, rather than the vagrant one.

* Added an additional test user, and updated the git ignore to ignore some MacOS files

* Updated node version to 9.11.1

* Rebuilt npm modules for new version of node

* Removed authentication from nfc-scans

* Update the blueprint doc to reflect that the authorization has been removed from the nfc-scans endpoint
  • Loading branch information
wmwragg authored Apr 27, 2018
1 parent af4723a commit ff4dd20
Show file tree
Hide file tree
Showing 46 changed files with 7,245 additions and 1,638 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PORT=4568
BASE_URL=http://localhost:4568
LOG_LEVEL=debug
JWT_SECRET=ribot
DATABASE_URL=postgresql://vagrant@localhost/ribot-api
DATABASE_URL=postgresql://ribot@localhost/ribot-api
DATABASE_DEBUG=true
GOOGLE_API_BASE_URL=https://www.googleapis.com
GOOGLE_CLIENT_ID=<replace>
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@ cookbooks

# App
data/jobs/*

# OS files to ignore
.DS_Store
9 changes: 0 additions & 9 deletions Cheffile

This file was deleted.

45 changes: 0 additions & 45 deletions Cheffile.lock

This file was deleted.

79 changes: 9 additions & 70 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,9 @@
This API allows you to access information about each ribot, as well as perform actions on your own profile such as update your location, status and availability. It will also allow access to health information such as water consumption.

## Setting up your development environment
We are using [Vagrant](https://www.vagrantup.com/) to manage the development environment. This ensure that all developers can be set up very quickly and in the same configuration. This in turn avoids issues where "it works on my machine".
Make sure you have [node](https://nodejs.org/en/), if not it's probably simplest to install them through [brew](https://brew.sh).

To get started you must [install Vagrant](https://www.vagrantup.com/downloads.html) and [install Virtualbox](https://www.virtualbox.org/wiki/Downloads). If you are using [Homebrew](http://brew.sh) you can install box from the command line by running:

```sh
brew install caskroom/cask/brew-cask
brew cask install virtualbox
brew cask install vagrant
```

Once both of these tools are installed, you need to make sure vagrant has the [Chef](http://chef.io) cookbooks needed to start the VM. Install [Librarian-chef](https://github.com/applicationsonline/librarian-chef) and then install the cookbooks:

```sh
gem install librarian-chef
librarian-chef install
```

Once the download is complete, you can start the development environment by running this command from the root of the project:

```sh
vagrant up
```

This will download the required virtual machine, install all the project dependancies and start the virtual machine. The virtual machine will then be used to run the project code, in an enviroment that is the same on every developers machine.

While this is happening, set up the development environment variables by duplicating the `.env.example` file to one called `.env`. Inside that file replace any example values (denoted by `<replace>`) with real values. Take a look at the table below if you are unsure what any of the enviornment variables do.
Set up the development environment variables by duplicating the `.env.example` file to one called `.env`. Inside that file replace any example values (denoted by `<replace>`) with real values. Take a look at the table below if you are unsure what any of the environment variables do.

| Variable Name | Description |
|------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
Expand All @@ -43,11 +20,11 @@ While this is happening, set up the development environment variables by duplica
| `GOOGLE_CLIENT_ID` | The server's client ID from the [Google Developer Console](https://console.developers.google.com) |
| `GOOGLE_CLIENT_SECRET` | The server's client secret from the [Google Developer Console](https://console.developers.google.com) |

To start the node project on the VM you now need to SSH into it, change into the `app` directory, install node dependancies and start the node server:
You need to install [postgresSQL](https://www.postgresql.org/download/macosx/), create a `ribot` user, and create two databases `ribot-api` and `ribot-api-test`, making sure to assign the `ribot` user as owner of these databases.

```sh
vagrant ssh
cd app
To start the node project you now need to install node dependancies and start the node server:

```
npm install
npm start
```
Expand All @@ -59,10 +36,9 @@ node data/scripts/setup.js --seed
```

## Running the tests
The best way to run tests is from inside the Vagrant VM:
The best way to run tests is:

```sh
vagrant ssh
```
npm test
```

Expand All @@ -89,47 +65,10 @@ You then need to write a migration script that makes all the changes needed to m
3. Add a new line to the `exports` of the `data/migrations/index.js` file with the new schema number and a `require` to your migration script. There is an example at the top of the file
4. Test your migration works on your local machine!

## Adding a new dependency to the VM
Sometimes you may want to add a new dependency to the VM, for example MongoDB, Redis or Postgres. These sort of dependencies are installed on the VM using [Chef](https://www.chef.io/).

Chef installs dependancies using [Cookbooks](https://supermarket.chef.io/) (sigh... developer puns...). Cookbooks are simply a file which tells chef how to install a specific piece of software. All cookbooks for this project (along with dependancies) are stored in the `cookbooks` folder. This project is written using nodejs, so we have a cookbook for that, along with ones for all the dependancies it needs.

Managing these cookbooks is not complex, however it is boring, so we have chosen to use [Librarian](https://github.com/applicationsonline/librarian-chef) to manage them. To install this tool you can run:

```sh
gem install librarian-chef
```

Dependancies are managed using the `Cheffile`. To add a new dependency, add a new line to the file, for example:

```ruby
cookbook 'mongodb', '~> 0.16.2'
```

And then run:

```sh
librarian-chef install
```

This will download all the cookbooks needed for MongoDB and place them in the `cookbooks` folder.

You now need to tell Vagrant to install this recipe when provisoning. Add a new line to the `Vagrantfile` with the name of the new cookbook:

```sh
chef.add_recipe "mongodb"
```

The last step is to "provision" your VM again. This means that the VM will be restarted with all the new dependancies by running Chef again. This also needs to be done by every other developer who created the VM before the changes to the `cookbooks` folder were made. Thankfully it's a simple command!

```sh
vagrant provision
```

## Deploying the app
Changes to master will automatically cause the app to be deployed to [Dokku](https://api.ribot.io). You should not need to deploy manually. If you do however you can set up your machine by adding a new git remote and then push to it:

```sh
```
git remote add deploy [email protected]:api
git push deploy master
```
Expand Down
48 changes: 0 additions & 48 deletions Vagrantfile

This file was deleted.

4 changes: 3 additions & 1 deletion app/controllers/nfc-scan.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ var logger = require( '../lib/logger' ),
*/
var init = function init() {

// router.post( '/nfc-scans',
// middleware.validateBody,
// requestPostNfcScan );
router.post( '/nfc-scans',
middleware.validateBody,
requestPostNfcScan );

};
Expand Down
78 changes: 0 additions & 78 deletions cookbooks/dmg/CHANGELOG.md

This file was deleted.

Loading

0 comments on commit ff4dd20

Please sign in to comment.