Fakultas Ilmu Komputer UI

Commit 8ee8fe29 authored by Daya Adianto's avatar Daya Adianto 🐈
Browse files

Update README

parent e68f121a
Pipeline #20526 passed with stages
in 21 minutes and 12 seconds
# How To Deploy to Production Server
## Deployment
* Clone this repository
* Install docker, you can do this manually or using command `bash /provision/setup-docker.sh`
* Deploy using command `bash /provision/run-docker.sh DOCKERNAME APP_PORT SSH_PORT` for example `bash /provision/run-docker.sh staging 8000 8022`
* Profit :)
## HTTPS Server and Domain Name
* Add your domain name on the `ALLOWED_HOSTS` field on `kape/settings.py`
* Add these server blocks on yout NGINX setting (change `DOMAIN_NAME` and `APP_PORT`)
```
server {
listen 80;
listen [::]:80;
server_name your.DOMAIN_NAME.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
include snippets/ssl-your.DOMAIN_NAME.sslconfiguration.conf;
server_name your.DOMAIN_NAME.com;
location / {
proxy_pass http://localhost:APP_PORT;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
```
## Git push on the production server
* You can push directly to production git if SSH port is not blocked
* In the repo directory, run `git remote add production ssh://kape@DOMAIN_NAME:SSH_PORT/home/kape.git`
* To push to production server, run `git push production master` (default docker ssh password : yukcarikape)
# How To Build for Development Environment
## Requirements
* NodeJS + Npm Package Manager
* Python + Pip Package Manager
* PostgreSQL
## Installation
* `git clone https://gitlab.com/PPL2017csui/PPLA1.git kape`
* `cd kape`
* `npm install`
* `pip install -r requirements.txt`
* `psql` insert these queries:
* `create user kape password 'kape';` to create user.
* `create database kape;` to create database.
* if you want to create another database user, please update the setting file `kape/settings.py`
* `python manage.py migrate` To migrate all the database
## Run Development Mode App
* `npm run webpack` to run webpack server. (if you don't want live update run `npm run build`, if you want the uglified+zipped+production ready version run `npm run build-production`)
* on a different terminal window, run `python manage.py runserver` to run API server
### Now go to localhost:8000 and you'll see the App running!
## Run Unit Test
* Frontend test, run `npm run webpack`
* Backend test, run `python manage.py test`
# Kanal Akses Pendaftaran KP Elektronik _(kape)_
> Internship matchmaking platform for students and companies.
## Table of Contents
- [Install](#install)
- [Running Development Mode (Classic)](#running-development-mode-classic)
- [Running Development Mode (Containerised)](#running-development-mode-containerised)
- [License](#license)
## Install
This project uses Python 2 and Node.js v4 for building the backend and frontend,
respectively. The backend uses Django Framework and PostgreSQL database, while
the frontend is developed using React. You need to install the required
dependencies prior to building and contributing to the project.
- [Node.js v4.9.1](https://nodejs.org/en/download/releases/) and `npm` package
manager.
> Note: We recommend `nvm` (Node Version Manager) for installing Node.js. You
> can find `nvm` for your OS at the following links:
> - [nvm for macOS or GNU/Linux-based OS](https://github.com/creationix/nvm)
> - [nvm for Windows](https://github.com/coreybutler/nvm-windows)
>
> Once `nvm` has been installed, install Node.js and activate it by executing
> `nvm install 4.9.1` followed by `nvm activate 4.9.1`.
- [Python 2.7.16](https://www.python.org/downloads/release/) and `pip` package
manager.
> Note: We recommend using _virtual environment_ to isolate project-specific
> Python packages from system-level packages. You can install and use
> [`virtualenv`](https://virtualenv.pypa.io/en/stable/) package to create the
> virtual environment for this project.
- [PostgreSQL 9.6](https://www.postgresql.org/download/) and any database
client that can interface with PostgreSQL, e.g. `psql`, pgAdmin.
> Note: We recommend running the database as container or virtual machine to
> avoid cluttering your local development environment. Please consult the
> documentation for your container engine (e.g. Docker) or virtualization
> platform (e.g. VirtualBox or Hyper-V) on how to provision PostgreSQL
> database. If you had to use locally-installed database, make sure your
> own data will not interleave with the data generated by this project.
Verify that Node.js and Python 2 have been successfully installed. Make sure
the interpreter for both platforms can be invoked from the shell. For example,
in `bash` shell (macOS or GNU/Linux-based OS):
```bash
# Assuming there is a Python virtual environment directory named `env` in
# current path
$ source env/bin/activate
$ python --version # or: python2 --version
Python 2.7.16
$ node --version
v4.9.1
```
Now install the packages required by Node.js and Python 2:
```bash
npm install
pip install -r requirements.txt
```
If you are cloning the project for the first time into your local development
environment, you need to create a new database user named `kape` and create a
new database with the same name for this project. Do not forget to set the
ownership of the new database to `kape` user. Once you have finished initalising
the database, perform database migration and seeding:
```bash
python manage.py migrate
python manage.py loaddata seeder.json
```
> Note: Can't connect to the database? Adjust the database connection settings
> at [`settings.py`](kape/settings.py).
Finally, verify that the test suites pass:
```bash
# Run the test suite for backend
python manage.py test
```
To run the test suite for frontend, you need to build the frontend first before
running the test suite:
```bash
npm run build-production
npm run karma
```
## Running Development Mode (Classic)
To run the API (backend) server:
```bash
python manage.py runserver
```
To serve the frontend:
```bash
npm run webpack
# If you don't want live update, run: npm run build
# If you want the uglified, zipped, production-ready version, run: npm run build-production
```
You can see the app running by going to `localhost:8080` via your favourite
Web browser.
## Running Development Mode (Containerised)
If you have installed Docker and Docker Compose, you can build the app
into a container image and run it with container-based database and
Web server:
```bash
docker-compose up --build --detach
docker-compose run --rm app python manage.py migrate
docker-compose run --rm app python manage.py loaddata seeder.json
```
> Explanation:
> 1. Rebuild the application (the frontend + backend), then start it along with
> the database (`postgres`) and Web server (`nginx`).
> 1. Perform database migration
> 1. Perform database seeding
Before you can see the app, you need to know the port in the host that mapped
to the port in the Web server container:
```bash
# The following is just an example. The output may vary in your environment.
$ docker-compose ps
Name Command State Ports
---------------------------------------------------------------------------
kape_app_1 gunicorn --bind 0.0.0.0:80 ... Up 8001/tcp
kape_db_1 docker-entrypoint.sh postgres Up 5432/tcp
kape_web_1 nginx -g daemon off; Up 0.0.0.0:32770->80/tcp
```
In the above example, port 32770 is mapped to port 80 in the Web server
container. Thus, you can see the app via Web browser by opening
`http://localhost:32770`.
> Note: Running the app and its dependencies as containers are convenient, but
> you will not be able to see any changes to the codebase in real-time. If
> you want to see changes in the codebase reflected in real-time, follow the
> classical approach for running the development mode.
## License
......
# How To Deploy to Production Server
## Deployment
* Clone this repository
* Install docker, you can do this manually or using command `bash /provision/setup-docker.sh`
* Deploy using command `bash /provision/run-docker.sh DOCKERNAME APP_PORT SSH_PORT` for example `bash /provision/run-docker.sh staging 8000 8022`
* Profit :)
## HTTPS Server and Domain Name
* Add your domain name on the `ALLOWED_HOSTS` field on `kape/settings.py`
* Add these server blocks on yout NGINX setting (change `DOMAIN_NAME` and `APP_PORT`)
```
server {
listen 80;
listen [::]:80;
server_name your.DOMAIN_NAME.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
include snippets/ssl-your.DOMAIN_NAME.sslconfiguration.conf;
server_name your.DOMAIN_NAME.com;
location / {
proxy_pass http://localhost:APP_PORT;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
```
## Git push on the production server
* You can push directly to production git if SSH port is not blocked
* In the repo directory, run `git remote add production ssh://kape@DOMAIN_NAME:SSH_PORT/home/kape.git`
* To push to production server, run `git push production master` (default docker ssh password : yukcarikape)
# How To Build for Development Environment
## Requirements
* NodeJS + Npm Package Manager
* Python + Pip Package Manager
* PostgreSQL
## Installation
* `git clone https://gitlab.com/PPL2017csui/PPLA1.git kape`
* `cd kape`
* `npm install`
* `pip install -r requirements.txt`
* `psql` insert these queries:
* `create user kape password 'kape';` to create user.
* `create database kape;` to create database.
* if you want to create another database user, please update the setting file `kape/settings.py`
* `python manage.py migrate` To migrate all the database
## Run Development Mode App
* `npm run webpack` to run webpack server. (if you don't want live update run `npm run build`, if you want the uglified+zipped+production ready version run `npm run build-production`)
* on a different terminal window, run `python manage.py runserver` to run API server
### Now go to localhost:8000 and you'll see the App running!
## Run Unit Test
* Frontend test, run `npm run webpack`
* Backend test, run `python manage.py test`
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment