Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
140 lines (84 sloc) 4.99 KB

Pre-Requirements | Running | Testing | Postman | Running outside docker | Tech Stack | Formatting | Deploy | Jobs

Contributing

Contributions are always welcome, no matter how large or small.

Pre-Requirements

You need to have installed:

Running

docker-compose up

It will take a while, about 20 minutes to download an compile all rust dependencies.

But that's it! Now go to http://localhost:8000/admin and it should be running.

The default credentials for logging in the admin area are email: admin@fakenewsdetector.org, password: 123

Testing

To run the tests, with docker-compose up running, fire up another terminal and execute:

docker-compose exec web cargo test

If you want to run it in watch mode, use:

docker-compose exec web cargo watch -x test

Postman

Postman is an app that helps you make requests when developing APIs.

We have a postman collection ready for you to use for debugging the API, just download postman and import the dev/postman_collection.json file.

Postman Collection

Running Outside Docker

If you want to run the app outside docker for faster development flow, you will need to install nightly rust, cargo watch and nodejs.

Also, you will need to have a postgres database running, if you don't, you can run it with docker-compose:

docker-compose up database

Install the rust and js dependencies:

cargo build
cd src/scrapper/
npm install
cd -

Create and migrate the database:

export DATABASE_URL="postgres://postgres:password@localhost:5432/fakenews"
diesel database setup

Then start the app:

cargo watch -w src -x run

For compiling the admin area:

cargo watch -w admin -s "elm-make --yes admin/Main.elm --output target/admin.js"

To run the tests:

cargo watch -x test

Tech Stack

This project is done in Rust, if you don't know Rust yet, the official guide is a good place to start. It shouldn't take very long before you can start contributing, just a few first chapters and you should be good to go, the compiler helps a lot.

For the web framework we use rocket, for starting a web server, routing, json-responses, etc.

We use PostgreSQL for the database, with Diesel as the ORM for connecting with Rust and run the migrations.

Finally, we use docker-compose to launch the database and build an image with everything we need to run the project. By using docker we ensure that what's running locally is as close as possible from production.

Formatting

We use rustfmt to automatically format the source code, please use it as well when developing new features, it integrates with most text editors and IDEs and keep a standard across the codebase.

Also, we add no configuration to it, just use the standard behaviours, this way we eliminate the discussions about formatting on PRs.

Configuring your IDE

To develop with Rust, having a well configured IDE helps A LOT, once you have a well configured one, you won't be able to code Rust without it anymore, so we recomment to spend a few minutes doing it.

Visual Studio Code has a good support for Rust. After installing it add the Rust Lang Extension, it should take you about half an hour to configure it well. Things to check:

  • Autocomplete is working
  • Code autoformats on save (rustfmt)
  • Compilation errors and warnings show up on the IDE
  • Code compiles on save

Deploy

The deploy is automatically done by the CircleCI pipeline after merging to master.

If you want to learn more how it works, read about deploying to heroku with docker on the oficial docs.

Jobs

There are some jobs for helping administrating the app, for creating and running migrations, check out diesel's docummentation. If you are running any diesel's job outside docker, you have to export DATABASE_URL=postgres://postgres:password@localhost:5432/fakenews.

Custom jobs are added on the src/jobs.rs file, and ran like this:

cargo run -- --scrape-missing-data

or, if the app is installed:

fake-news-api --scrape-missing-data
You can’t perform that action at this time.