윤준석

Merge branch 'release/220527_deployment_alpha' into 'main'

Release/220527 deployment alpha

# 매무리 봇 알파 버전 배포

- node.js express 서버 docker-compose에 추가
- ngrok를 통한 ssl tunneling
- ngrok conatainter 생성 및 docker-compose에 추가
- 어플리케이션 빌드 스크립트 추가

See merge request !21
...@@ -437,5 +437,6 @@ cython_debug/ ...@@ -437,5 +437,6 @@ cython_debug/
437 437
438 # Ignore .env file 438 # Ignore .env file
439 .env 439 .env
440 +ngrok.yml
440 441
441 # End of https://www.toptal.com/developers/gitignore/api/jetbrains,visualstudiocode,python,node 442 # End of https://www.toptal.com/developers/gitignore/api/jetbrains,visualstudiocode,python,node
...\ No newline at end of file ...\ No newline at end of file
......
1 +# Database Configuration
1 TZ=Asia/Seoul 2 TZ=Asia/Seoul
2 MYSQL_HOST={YOUR_MYSQL_HOST} 3 MYSQL_HOST={YOUR_MYSQL_HOST}
3 MYSQL_PORT={YOUR_MYSQL_PORT} 4 MYSQL_PORT={YOUR_MYSQL_PORT}
......
1 CREATE DATABASE mamuri_db; 1 CREATE DATABASE mamuri_db;
2 -
3 -USE mamuri_db;
4 -
5 -CREATE TABLE user
6 -(
7 - id INT AUTO_INCREMENT PRIMARY KEY,
8 - user_id INT NOT NULL
9 -);
10 -
11 -CREATE TABLE keyword
12 -(
13 - id INT AUTO_INCREMENT PRIMARY KEY,
14 - keyword VARCHAR(150) NULL
15 -);
16 -
17 -CREATE TABLE user_keyword
18 -(
19 - id INT AUTO_INCREMENT PRIMARY KEY,
20 - user_id INT NOT NULL,
21 - keyword_id INT NOT NULL,
22 - FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE,
23 - FOREIGN KEY (keyword_id) REFERENCES keyword (id) ON DELETE CASCADE
24 -);
25 -
26 -CREATE TABLE item
27 -(
28 - id INT AUTO_INCREMENT PRIMARY KEY,
29 - keyword_id INT NOT NULL,
30 - platform VARCHAR(50) NOT NULL,
31 - name VARCHAR(100) NOT NULL,
32 - price INT NOT NULL,
33 - thumbnail_url VARCHAR(255) NULL,
34 - item_url VARCHAR(255) NOT NULL,
35 - extra_info TEXT NULL,
36 - created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
37 -);
38 -
39 -CREATE TABLE item_check
40 -(
41 - id INT AUTO_INCREMENT PRIMARY KEY,
42 - item_id INT NULL,
43 - user_id INT NULL,
44 - FOREIGN KEY (item_id) REFERENCES item (id) ON DELETE CASCADE,
45 - FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE
46 -);
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -4,5 +4,7 @@ docker build -t daangn-api-server ./daangn/ ...@@ -4,5 +4,7 @@ docker build -t daangn-api-server ./daangn/
4 docker build -t joongna-api-server ./joongna/ 4 docker build -t joongna-api-server ./joongna/
5 docker build -t bunjang-api-server ./bunjang/ 5 docker build -t bunjang-api-server ./bunjang/
6 docker build -t mamuri-db ./database/ 6 docker build -t mamuri-db ./database/
7 +docker build -t mamuri-server ./server/
8 +docker build -t mamuri-ngrok ./ngrok/
7 9
8 docker-compose up -d 10 docker-compose up -d
...\ No newline at end of file ...\ No newline at end of file
......
1 version: '3' 1 version: '3'
2 2
3 services: 3 services:
4 + db:
5 + image: mamuri-db
6 + restart: always
7 + container_name: mamuri-db
8 + ports:
9 + - '13060:3306'
10 + env_file:
11 + - "./database/mysql_init/.env"
12 + volumes:
13 + - "/usr/mysql/data:/var/lib/mysql"
14 +
15 + server:
16 + image: mamuri-server
17 + restart: always
18 + container_name: mamuri-server
19 + ports:
20 + - '8080:8080'
21 +
4 daangn_api: 22 daangn_api:
5 image: daangn-api-server 23 image: daangn-api-server
6 restart: always 24 restart: always
7 - container_name: daangn-api-server-container 25 + container_name: daangn-api-server
8 ports: 26 ports:
9 - '18080:8080' 27 - '18080:8080'
10 28
11 joongna_api: 29 joongna_api:
12 image: joongna-api-server 30 image: joongna-api-server
13 restart: always 31 restart: always
14 - container_name: joongna-api-server-container 32 + container_name: joongna-api-server
15 ports: 33 ports:
16 - '18081:8080' 34 - '18081:8080'
17 35
18 bunjang_api: 36 bunjang_api:
19 image: bunjang-api-server 37 image: bunjang-api-server
20 restart: always 38 restart: always
21 - container_name: bunjang-api-server-container 39 + container_name: bunjang-api-server
22 ports: 40 ports:
23 - '18082:8080' 41 - '18082:8080'
24 42
25 - db: 43 + ngrok:
26 - image: mamuri-db 44 + image: mamuri-ngrok
27 - restart: always 45 + container_name: mamuri-ngrok
28 - container_name: mamuri-db-container
29 - ports:
30 - - '13060:3306'
31 env_file: 46 env_file:
32 - - "./database/mysql_init/.env"
...\ No newline at end of file ...\ No newline at end of file
47 + - "ngrok/ngrok.yml"
48 + ports:
49 + - '4040:4040'
...\ No newline at end of file ...\ No newline at end of file
......
1 # Secret Configuration 1 # Secret Configuration
2 -SECRET.CLIENTID=
3 -SECRET.CLIENTSECRET=
...\ No newline at end of file ...\ No newline at end of file
2 +SECRET.CLIENTID={NAVER_API_CLIENT_ID}
3 +SECRET.CLIENTSECRET={NAVER_API_CLIENT_SECRET}
4 +
5 +# Header Configuration
6 +HEADER.COOKIE={NID_SES=YOUR_COOKIE}
7 +HEADER.USERAGENT={YOUR_SYSTEM_USER_AGENT}
...\ No newline at end of file ...\ No newline at end of file
......
1 +FROM ubuntu:latest as builder
2 +
3 +WORKDIR /src
4 +
5 +RUN apt-get update \
6 + && apt-get install -y wget
7 +
8 +RUN wget https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-linux-amd64.tgz
9 +RUN tar -xvzf ./ngrok-v3-stable-linux-amd64.tgz
10 +
11 +FROM alpine
12 +
13 +WORKDIR /src
14 +
15 +COPY ngrok.yml /src
16 +COPY start.sh /src
17 +RUN chmod +x /src/start.sh
18 +
19 +COPY --from=builder /src/ngrok /src/ngrok
20 +
21 +RUN apk --no-cache add curl
22 +RUN apk --no-cache add jq
23 +
24 +EXPOSE 4040
25 +
26 +CMD ["sh", "start.sh"]
...\ No newline at end of file ...\ No newline at end of file
1 +authtoken: {YOUR_NGROK_AUTO_TOKEN}
2 +version: 2
3 +tunnels:
4 + mamuri:
5 + proto: http
6 + addr: mamuri-server:8080
...\ No newline at end of file ...\ No newline at end of file
1 +#!/bin/sh
2 +
3 +echo "> Ngrok start in mamuri-server:8080"
4 +/src/ngrok start --config=./ngrok.yml --all &
5 +
6 +sleep 1s
7 +
8 +public_url=$(curl -s localhost:4040/api/tunnels | jq -r .tunnels[0].public_url)
9 +echo "> public_url: $public_url"
10 +
11 +tail -f /dev/null
...\ No newline at end of file ...\ No newline at end of file
1 +node_modules
2 +npm-debug.log
...\ No newline at end of file ...\ No newline at end of file
1 +FROM node:17.9.0-alpine
2 +
3 +WORKDIR /src
4 +COPY . /src
5 +
6 +RUN npm install
7 +
8 +EXPOSE 8080
9 +CMD ["node", "app.js"]
...\ No newline at end of file ...\ No newline at end of file
...@@ -12,7 +12,8 @@ sequelize ...@@ -12,7 +12,8 @@ sequelize
12 console.log("database connection complete"); 12 console.log("database connection complete");
13 }) 13 })
14 .catch((err) => { 14 .catch((err) => {
15 - console.log("database connection failed"); 15 + console.log("database connection failed. restart the server");
16 + process.exit(-1)
16 }); 17 });
17 18
18 // Load .env configuration 19 // Load .env configuration
...@@ -32,6 +33,6 @@ app.post("/webhook", line.middleware(config), (req, res) => { ...@@ -32,6 +33,6 @@ app.post("/webhook", line.middleware(config), (req, res) => {
32 }); 33 });
33 }); 34 });
34 35
35 -const port = 1231; 36 +const port = 8080;
36 app.listen(port); 37 app.listen(port);
37 console.log(`listening...\nport : ${port}`); 38 console.log(`listening...\nport : ${port}`);
......
...@@ -33,7 +33,7 @@ const db = require("../apis/database"); ...@@ -33,7 +33,7 @@ const db = require("../apis/database");
33 // database.getAllKeywords = async function() 33 // database.getAllKeywords = async function()
34 34
35 // Import credentials for Line chatbot 35 // Import credentials for Line chatbot
36 -require("dotenv").config({ path: __dirname + "/../.env" }); 36 +require("dotenv").config({ path: __dirname + "/../config/.env" });
37 const config = { 37 const config = {
38 channelAccessToken: process.env.channelAccessToken, 38 channelAccessToken: process.env.channelAccessToken,
39 channelSecret: process.env.channelSecret, 39 channelSecret: process.env.channelSecret,
......
...@@ -4,7 +4,7 @@ const bunjangSingleSearch = (keyword) => { ...@@ -4,7 +4,7 @@ const bunjangSingleSearch = (keyword) => {
4 return Promise.resolve( 4 return Promise.resolve(
5 axios 5 axios
6 .get( 6 .get(
7 - `http://43.200.35.46:18082/api/v2/bunjang/${encodeURIComponent( 7 + `http://bunjang-api-server:8080/api/v2/bunjang/${encodeURIComponent(
8 keyword 8 keyword
9 )}` 9 )}`
10 ) 10 )
...@@ -17,7 +17,7 @@ const bunjangMultiSearch = (keyword) => { ...@@ -17,7 +17,7 @@ const bunjangMultiSearch = (keyword) => {
17 return Promise.resolve( 17 return Promise.resolve(
18 axios 18 axios
19 .get( 19 .get(
20 - `http://43.200.35.46:18082/api/v2/bunjang/${encodeURIComponent( 20 + `http://bunjang-api-server:8080/api/v2/bunjang/${encodeURIComponent(
21 keyword 21 keyword
22 )}` 22 )}`
23 ) 23 )
......
...@@ -4,7 +4,7 @@ const daangnSingleSearch = (keyword) => { ...@@ -4,7 +4,7 @@ const daangnSingleSearch = (keyword) => {
4 return Promise.resolve( 4 return Promise.resolve(
5 axios 5 axios
6 .get( 6 .get(
7 - `http://43.200.35.46:18080/api/v2/daangn/${encodeURIComponent(keyword)}` 7 + `http://daangn-api-server:8080/api/v2/daangn/${encodeURIComponent(keyword)}`
8 ) 8 )
9 .then((res) => res.data["items"][0]) 9 .then((res) => res.data["items"][0])
10 .catch((e) => undefined) 10 .catch((e) => undefined)
...@@ -15,7 +15,7 @@ const daangnMultiSearch = (keyword) => { ...@@ -15,7 +15,7 @@ const daangnMultiSearch = (keyword) => {
15 return Promise.resolve( 15 return Promise.resolve(
16 axios 16 axios
17 .get( 17 .get(
18 - `http://43.200.35.46:18080/api/v2/daangn/${encodeURIComponent(keyword)}` 18 + `http://daangn-api-server:8080/api/v2/daangn/${encodeURIComponent(keyword)}`
19 ) 19 )
20 .then((res) => res.data["items"]) 20 .then((res) => res.data["items"])
21 .catch((e) => undefined) 21 .catch((e) => undefined)
......
...@@ -4,7 +4,7 @@ const joongnaSingleSearch = (keyword) => { ...@@ -4,7 +4,7 @@ const joongnaSingleSearch = (keyword) => {
4 return Promise.resolve( 4 return Promise.resolve(
5 axios 5 axios
6 .get( 6 .get(
7 - `http://43.200.35.46:18081/api/v2/joongna/${encodeURIComponent( 7 + `http://joongna-api-server:8080/api/v2/joongna/${encodeURIComponent(
8 keyword 8 keyword
9 )}` 9 )}`
10 ) 10 )
...@@ -17,7 +17,7 @@ const joongnaMultiSearch = (keyword) => { ...@@ -17,7 +17,7 @@ const joongnaMultiSearch = (keyword) => {
17 return Promise.resolve( 17 return Promise.resolve(
18 axios 18 axios
19 .get( 19 .get(
20 - `http://43.200.35.46:18081/api/v2/joongna/${encodeURIComponent( 20 + `http://joongna-api-server:8080/api/v2/joongna/${encodeURIComponent(
21 keyword 21 keyword
22 )}` 22 )}`
23 ) 23 )
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
3 "username": "root", 3 "username": "root",
4 "password": "mamuri", 4 "password": "mamuri",
5 "database": "mamuri_db", 5 "database": "mamuri_db",
6 - "host": "127.0.0.1", 6 + "host": "mamuri-db",
7 + "port": "3306",
7 "dialect": "mysql" 8 "dialect": "mysql"
8 }, 9 },
9 "test": { 10 "test": {
......
1 +#!/usr/bin/env bash
2 +
3 +docker build -t mamuri-db ../database/
4 +docker build -t mamuri-server .
5 +
6 +docker-compose up -d
...\ No newline at end of file ...\ No newline at end of file
1 +version: '3'
2 +
3 +services:
4 + db:
5 + image: mamuri-db
6 + restart: always
7 + container_name: mamuri-db
8 + ports:
9 + - '13060:3306'
10 + env_file:
11 + - "../database/mysql_init/.env"
12 + volumes:
13 + - "/usr/mysql/data:/var/lib/mysql"
14 +
15 + server:
16 + image: mamuri-server
17 + restart: always
18 + container_name: mamuri-server
19 + ports:
20 + - '8080:8080'
21 +
22 + daangn_api:
23 + image: daangn-api-server
24 + restart: always
25 + container_name: daangn-api-server
26 + ports:
27 + - '18080:8080'
28 +
29 + joongna_api:
30 + image: joongna-api-server
31 + restart: always
32 + container_name: joongna-api-server
33 + ports:
34 + - '18081:8080'
35 +
36 + bunjang_api:
37 + image: bunjang-api-server
38 + restart: always
39 + container_name: bunjang-api-server
40 + ports:
41 + - '18082:8080'
...\ No newline at end of file ...\ No newline at end of file
1 +#!/usr/bin/env bash
2 +
3 +docker-compose down
4 +
5 +docker image rm mamuri-server
6 +docker image rm mamuri-db
...\ No newline at end of file ...\ No newline at end of file
...@@ -6,3 +6,5 @@ docker image rm daangn-api-server ...@@ -6,3 +6,5 @@ docker image rm daangn-api-server
6 docker image rm joongna-api-server 6 docker image rm joongna-api-server
7 docker image rm bunjang-api-server 7 docker image rm bunjang-api-server
8 docker image rm mamuri-db 8 docker image rm mamuri-db
9 +docker image rm mamuri-server
10 +docker image rm mamuri-ngrok
...\ No newline at end of file ...\ No newline at end of file
......