mdgspace / codephile-backend

Back-end for Official Codephile App
https://codephile.mdg.iitr.ac.in/
16 stars 6 forks source link
elasticsearch mongodb odyssey rest-api

Codephile | CircleCI

Services

We use the following services in our server,

Environment Variables

Environment variable is a way to store/pass some sensitive/config information that is required by the software. This can include passwords, secret keys, config variables.

To setup environment variables, create a .env file at conf directory of project containing following information:

ENVIRONMENT=<dev/prod>
PORT=<The port to be used: optional>
DBPath=<Connection string of local database>
HMACKEY=<HMAC Encryption key>
REDISURL=<connection string of redis server>
FIREBASE_CONFIG=<Firebase config including bucket name(json)>
FIREBASE_CREDENTIALS=<Firebase admin SDK credentials(json)>
SENTRY_DSN=<Data source name of sentry server: optional>
EMAIL_CLIENT_SECRET=<Client secret of google client>
EMAIL_CLIENT_ID=<Client ID of google client>
EMAIL_REFRESH_TOKEN=<Refresh token of above client have these scopes: send, compose, mail.google.com>

NOTE: Before proceeding further, ensure that your local .env file is present with above configuration variables.

Ask for codechef creds from the maintainer

CLIENT_ID=<codechef id>
CLIENT_SECRET=<codechef secret>

Setup Instructions

Download golang from here and setup GOPATH

In order to ensure the GOPATH environment variable is setup run:

$ echo $GOPATH

This should give non empty output

Now clone the repo in the appropriate directory.

$ mkdir -p $GOPATH/src/github.com/mdg-iitr/Codephile && cd $_ 
$ git clone https://github.com/mdg-iitr/Codephile.git

Now install the following services - redis and mongodb to run the project locally. Use these env variables in the .env file:

REDISURL=redis://redis:6379
DBPath=mongodb://mongoadmin:secret@mongo:27017/admin

We used beego framework to bootstrap the project. Download and setup bee command line program from here.

In order to generate documentation from comments, run:

$ bee run -downdoc=true -gendoc=true

If you didn't make any changes in documentation comment, simply run:

$ bee run

Custom programs could be run using

$ go run cmd/<path to main package go file>

E.g.

 $ go run cmd/blacklist-user/blacklist_user.go

Note: During commiting changes, always run go mod vendor if there are any changes in 3rd party dependency.

Setup using docker

You can use the dev_docker-compose.yml file to spin up containers with Mongo & Redis services easily. Use these env variables

REDISURL=redis://redis:6379
DBPath=mongodb://mongoadmin:secret@mongo:27017/admin

And run this command

$ docker-compose -f dev_docker-compose.yml up

Accessing the APIs

Note: If the DBPath in the .env file is of a local database, the API /user/search will not work, as it uses MongoDB Atlas Search which needs a MongoDB Atlas cloud Database.

Tests

Change the DBPath in .env file

Run the tests

$ go test -mod=vendor -v ./tests

Components

Beginners are advised to begin with writing some tests.

CI

When a pull request is submitted, continuous integration jobs are run automatically to ensure the code builds and is relatively well-written. The jobs are run on circleci. At present, the build, tests and linters are run on CI.

We use golang-ci lint for linting jobs. Download and run the linter locally before submitting a PR.

💬 For commit messages

Please start your commits with these prefixes for better understanding among collaborators, based on the type of commit:

feat: (addition of a new feature)
rfac: (refactoring the code: optimization/ different logic of existing code - output doesn't change, just the way of execution changes)
docs: (documenting the code, be it readme, or extra comments)
bfix: (bug fixing)
chor: (chore - beautifying code, indents, spaces, camelcasing, changing variable names to have an appropriate meaning)
ptch: (patches - small changes in code, mainly UI, for example color of a button, increasing size of tet, etc etc)
conf: (configurational settings - changing directory structure, updating gitignore, add libraries, changing manifest etc)