Skip to content
This repository was archived by the owner on Apr 1, 2021. It is now read-only.

Commit 25d99c8

Browse files
authored
Merge pull request #70 from NKUST-ITC/develop
v3.0.0
2 parents 98bb42f + 694bb10 commit 25d99c8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+8971
-872
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,12 @@ leave_test.py
225225
test_page.html
226226
html/
227227
src/config.py
228-
src/gunicorn_cfg.py
229228

230229
\.vscode/
231230

232231
\.idea/
233232
caddy/Caddyfile
234233
\.env
235-
venv/
234+
venv/
235+
data/certbot/
236+
nginx_nkust_api.conf

Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM python:3.6
2+
# Create app directory
3+
RUN mkdir -p /usr/src/app
4+
WORKDIR /usr/src/app
5+
6+
COPY . /usr/src/app
7+
8+
RUN pip3 install -r ./requirements.txt
9+
10+
RUN apt-get update && \
11+
apt-get install -y nodejs
12+
13+
WORKDIR src
14+
15+
# RUN ["gunicorn","web-server:app"]

README.md

Lines changed: 158 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,175 @@
11
[![Python 3.6](https://img.shields.io/badge/python-3.6-blue.svg)](https://www.python.org/downloads/release/python-360/)
22

3-
NKUST-AP-API
3+
4+
NKUST API Server(高雄科技大學 API Server)
45
==========
6+
* [Requirement](#requirement)
7+
* [API Docs](#api-docs)
8+
* [Quick start](#quick-start)
9+
* [Using Python virtual enviroment & Gunicorn](#using-python-virtual-enviroment-&-gunicorn)
10+
* [Using Docker-compose](#using-docker-compose)
11+
512

6-
高雄科技大學 API Server NKUST API Server
7-
---------------------------
813
Requirement
914
---
1015
- Ubuntu (18.04 or previous version)
1116
- Python 3.6
1217
- Redis server
1318
- NodeJS (if host by python venv)
1419

15-
API Docs
20+
### [API Docs](https://github.com/NKUST-ITC/NKUST-AP-API/tree/gh-pages/docs)
21+
22+
23+
24+
Quick start
1625
---
17-
[API PAGE](https://nkust-itc.github.io/NKUST-AP-API/docs/api-page.html)
26+
### Using Python virtual enviroment & Gunicorn
27+
28+
需要先在本地端設定/安裝好 [Redis server](https://redis.io/)
29+
30+
如果Redis有自行調整Host或Port或是使用外部的Redis,需執行
31+
32+
預設為本地的位置 `redis://127.0.0.1:6379` 執行
33+
34+
```bash
35+
$ export REDIS_URL=redis://127.0.0.1:6666
36+
```
37+
38+
若設定最新消息的管理員,可以透過`;`來新增多位管理員(非必須)
39+
40+
```bash
41+
$ export NEWS_ADMIN="1106111111;1105293392"
42+
```
43+
44+
或是設定一個帳號密碼,來登入管理員。
45+
46+
```bash
47+
$ export NEWS_ADMIN_ACCOUNT="admin"
48+
$ export NEWS_ADMIN_PASSWORD="1234567"
49+
```
50+
51+
創建Python virtual enviroment
1852

19-
[docs](https://github.com/NKUST-ITC/AP-API/tree/develop/docs/v3)
53+
```bash
54+
$ python3 -m venv venv
55+
```
56+
57+
啟動 virtual enviroment
58+
59+
```bash
60+
$ source venv/bin/activate
61+
```
62+
63+
安裝相關packages
64+
65+
```bash
66+
$ pip3 install -r requirement.txt
67+
```
68+
69+
啟動伺服器(Debug 模式)
70+
71+
```bash
72+
$ gunicorn web-server:app
73+
```
74+
75+
啟動伺服器(Release 模式)
76+
77+
```bash
78+
$ gunicorn -c gunicorn_config.py web-server:app
79+
```
2080

21-
Donate
2281
---
23-
[![BitCoin donate
24-
button](http://img.shields.io/bitcoin/donate.png?color=yellow)](https://coinbase.com/checkouts/aa7cf80a2a85b4906cb98fc7b2aad5c5 "Donate
25-
once-off to this project using BitCoin")
2682

2783

84+
85+
### Using Docker-compose (Production Stage)
86+
87+
#### docker-compose中的docker image
88+
89+
* [NKUST-AP-API](https://cloud.docker.com/u/nkustitc/repository/docker/nkustitc/nkust-ap-api/general)
90+
* Redis
91+
* Nginx
92+
* Certbot
93+
94+
95+
96+
```bash
97+
$ cp env.example .env
98+
```
99+
100+
如果有要設定`最新消息`的管理者,可以在`.env`中修改 `NEWS_ADMIN` 參數
101+
102+
```
103+
REDIS_URL=redis://redis:6379
104+
```
105+
106+
如需要更改redis位置,可以在`.env`中修改 `REDIS_URL` 參數,
107+
108+
**這邊redis中的host是套用 `dokcer network` 的設定**
109+
110+
```
111+
REDIS_URL=redis://redis:6379
112+
```
113+
114+
複製 nginx 設定檔(HTTPS)
115+
116+
```bash
117+
$ cp nginx/nginx_nkust_api.conf.Example nginx/nginx_nkust_api.conf
118+
```
119+
120+
若需要單純使用 HTTP 則需複製 `nginx_nkust_api_http.conf.Example`
121+
122+
```bash
123+
$ cp nginx/nginx_nkust_api_http.conf.Example nginx/nginx_nkust_api.conf
124+
```
125+
126+
`nginx_nkust_api_http.conf` 設定檔中 "**所有**"`example.org`取代為要目標的網域
127+
128+
```
129+
2 server_name example.org;
130+
...
131+
17 server_name example.org;
132+
```
133+
更改為
134+
```
135+
2 server_name 目標網域;
136+
...
137+
17 server_name 目標網域;
138+
```
139+
140+
### 註冊SSL憑證
141+
142+
修改`init-letsencrypt.sh` `line 8~9` 中的網域及email
143+
144+
```bash
145+
8 domains=(aaa.example.org aaa.example.org)
146+
147+
```
148+
149+
給予shell sript 權限
150+
151+
```bash
152+
$ sudo chmod +x init-letsencrypt.sh
153+
```
154+
155+
並執行shell sript註冊,此過程會開啟伺服器
156+
157+
```bash
158+
$ sudo ./init-letsencrypt.sh
159+
```
160+
161+
後續再次開啟**不需要**使用`init-letsencrypt.sh`
162+
163+
最後執行docker-compose 開啟伺服器
164+
165+
-d 為背景執行,若不需要可以不用加
166+
167+
```bash
168+
$ docker-compose up -d
169+
```
170+
171+
#### Other port
172+
173+
如有其他port 的需求
174+
175+
修改`nginx/nginx_nkust_api.conf` 像是一般的nginx設定檔案

docker-compose.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
version: "3.6"
2+
services:
3+
web:
4+
container_name: NKUST_AP_API
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
volumes:
9+
- .:/usr/src/app
10+
environment:
11+
- REDIS_URL=${REDIS_URL}
12+
- NEWS_ADMIN=${NEWS_ADMIN}
13+
- NEWS_ADMIN_ACCOUNT=${NEWS_ADMIN_ACCOUNT}
14+
- NEWS_ADMIN_PASSWORD=${NEWS_ADMIN_PASSWORD}
15+
command: ["gunicorn", "-c", "gunicorn_cfg.py", "web-server:app"]
16+
networks:
17+
- redis-net
18+
- open-net
19+
depends_on:
20+
- redis
21+
redis:
22+
image: "redis:alpine"
23+
command: ["redis-server", "--appendonly", "yes"]
24+
networks:
25+
- redis-net
26+
volumes:
27+
- redis-data:/data
28+
29+
nginx:
30+
image: nginx:latest
31+
restart: unless-stopped
32+
volumes:
33+
- ./nginx/nginx_nkust_api.conf:/etc/nginx/conf.d/nginx_nkust_api.conf
34+
- ./data/certbot/conf:/etc/letsencrypt
35+
- ./data/certbot/www:/var/www/certbot
36+
ports:
37+
- "80:80"
38+
- "443:443"
39+
networks:
40+
- open-net
41+
depends_on:
42+
- web
43+
- certbot
44+
command: '/bin/sh -c ''while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g "daemon off;"'''
45+
46+
certbot:
47+
image: certbot/certbot
48+
restart: unless-stopped
49+
container_name: certbot
50+
volumes:
51+
- ./data/certbot/conf:/etc/letsencrypt
52+
- ./data/certbot/www:/var/www/certbot
53+
entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"
54+
networks:
55+
redis-net:
56+
open-net:
57+
volumes:
58+
redis-data:

0 commit comments

Comments
 (0)