Kodkollektivet / unitime-api

Unitime Rest API
http://api.kodkollektivet.se/unitime/
8 stars 2 forks source link
lnu timeedit unitime

+TITLE: Unitime API 2.0

+AUTHOR: John Herrlin

[[https://travis-ci.org/Kodkollektivet/unitime-api][https://travis-ci.org/Kodkollektivet/unitime-api.svg?branch=celery-docker]]

This is the new Unitime 2.0 branch.

It is still under development but it's getting stable.

** Start a new server

Start a new Debian (yes it must be Debian) server somewhere. I mostly use [[https://www.digitalocean.com/][digitalocean]]. Log in to the server first via SSH as it will ask you to set a new password for the root user.

** Clone this project

to your local machine.

** Generate SSH key

Navigate to the secrets folder within the project directory. Take a look at the files and what they contains. Generate a new SSH key. Move the public key to ansible users filder. This key will be used for deploy. If it asks you to overwrite the existing file, choose =y=. Dont enter a passphrase.

+BEGIN_SRC

 cd <PROJECTDIR>/secrets
 ssh-keygen -t ed25519 -f unitime-deploy-user -C unitime-deploy-user
 cp unitime-deploy-user.pub ../ansible/roles/users/files/authorized_keys

+END_SRC

** Update inventory

In =secrets/inventory= you shall now update some secrets.

Change the =ansible_ssh_host= variable to your servers IP.

Change the =ansible_ssh_pass= variable to your server root password account.

In =secrets/production.json= change:

=unix->password= to a new random password

=postgres->password= to a new random password

** Configure the server

To configure the server run:

+BEGIN_SRC sh

 docker build -t unians:0.1 -f Dockerfile-ansible .
 docker run -it -v $PWD:/app --rm -w /app/ansible unians:0.1 ansible-playbook -e @../secrets/production.json main.yml

+END_SRC

If all things went fine (no red output).

** Set up unitime application

This will apply the code from the project and start the services.

+BEGIN_SRC sh

 docker build -t unifab:0.1 -f Dockerfile-fabric .
 docker run -it -v $PWD:/app --rm -w /app unifab:0.1 fab bootstrap

+END_SRC

** Update the application

To update the application use the following to update it by specifying a branch.

+BEGIN_SRC sh

 docker build -t unifab:0.1 -f Dockerfile-fabric .
 docker run -it -v $PWD:/app --rm -w /app unifab:0.1 fab deploy:branch=celery-docker

+END_SRC

** Rollback when deploy fails

If a deploy fails you can do a rollback, this will rollback to the codebase that was before the deploy. This wont handle database rollbacks!

+BEGIN_SRC sh

 docker build -t unifab:0.1 -f Dockerfile-fabric .
 docker run -it -v $PWD:/app --rm -w /app unifab:0.1 fab rollback

+END_SRC

** Try to access the API

Now, try to access the API with a course

+BEGIN_SRC shell :results output

 curl -i -X GET --header 'Content-Type: application/json' --data '{"course": "2DV50E"}' http://46.101.162.201/api/course/

+END_SRC

If you are using Emacs orgmode restclient and reading this documentation from orgmode. Here is a src block for you:

+BEGIN_SRC restclient

GET http://46.101.162.201/api/course/
User-Agent: Emacs Restclient
Content-Type: application/json

{
    "course": "2DV50E"
}

+END_SRC

** Manual SSH with deploy user.

This will log you in to the server with the =deploy= user.

+BEGIN_SRC sh

 cd <PROJECT>
 ssh -i secrets/unitime-deploy-user deploy@46.101.162.201

+END_SRC

** Manual SSH with root user.

This will log you in to the server with the =root= user. You find the password in =secrets/inventory=. The default is: =SERVERROOTPASSWORD=

+BEGIN_SRC sh

 ssh root@46.101.162.201

+END_SRC