윤준석

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