Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy #147

Merged
merged 47 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
4357148
Add: dockerize worker script
Junha-Jang Oct 6, 2023
b51c468
Fix: Dockerfile worker directory
Junha-Jang Oct 6, 2023
f45f175
Fix: zabo-worker environment
Junha-Jang Oct 6, 2023
47e8448
sort by time
Yongworry Oct 25, 2023
db17670
Revert "sort by time"
Yongworry Oct 25, 2023
78ffe93
Merge pull request #138 from sparcs-kaist/feat/sort_by_time
withSang Oct 25, 2023
bcb5739
Merge branch 'develop' of https://github.com/sparcs-kaist/zabo-server…
Junha-Jang Nov 3, 2023
dadd9b8
feat(board): add device schema
Junha-Jang Nov 17, 2023
d6a0976
feat(board): add device to admin
Junha-Jang Nov 17, 2023
9ee6a20
feat(board): add zabo board API
Junha-Jang Nov 17, 2023
0caafa2
env: add device jwt secret
jinho-choi123 Dec 1, 2023
f0b296f
feat: add device add page in admin panel
jinho-choi123 Dec 1, 2023
47ebd6c
feat: add device add page in admin panel
jinho-choi123 Dec 1, 2023
f35c153
k8s migration (#142)
xMHW Jan 17, 2024
73f27f0
feat(secrets): add sealed secrets
withSang Jan 17, 2024
ae742ef
Sealed secret 추가 (#143)
withSang Jan 17, 2024
7e233de
fix(cors): allow credentials
withSang Jan 17, 2024
b1340d8
feat: add image pull policy
Jan 17, 2024
86a5886
feat: change image of deployment
Jan 17, 2024
16ad29e
feat: add group name to ingress for sharing elb across namespaces
Feb 21, 2024
60c60ab
feat: add more fields to device schema
jinho-choi123 Mar 10, 2024
7aa82a5
feat: implement addDevice and removeDevice at admin panel
jinho-choi123 Mar 10, 2024
8726e36
refactor: remove unneeded part
jinho-choi123 Mar 10, 2024
59d3d25
fix: change "const" to "let" for mutable variable
jinho-choi123 Mar 10, 2024
abfc664
misc: yarn-lock update
jinho-choi123 Mar 10, 2024
9054973
feat: implement deleteDevice
jinho-choi123 Mar 10, 2024
4a527b0
feat: implement device login, logout
jinho-choi123 Mar 10, 2024
9544862
fix: change const to let for mutable variable
jinho-choi123 Mar 11, 2024
cad43b9
feat: add device getting zabo api. stores last seen zabo id to db, an…
jinho-choi123 Mar 11, 2024
4f971ac
misc: remove console log
jinho-choi123 Mar 18, 2024
12e0d53
feat: log which zabo was shown by device
jinho-choi123 Mar 22, 2024
bf3810e
feat: add device log to admin panel
jinho-choi123 Mar 22, 2024
ed080aa
fix: remove package-lock.json
jinho-choi123 Mar 22, 2024
c53e617
misc: removed unused env variables for device auth
jinho-choi123 Mar 22, 2024
4dd6a3f
refactor: use js built-in map instead of lodash map
jinho-choi123 Mar 22, 2024
f87176a
docs: add api spec to routes.md
jinho-choi123 Mar 22, 2024
ae02355
remove: remove worker container
jinho-choi123 Mar 22, 2024
7f19965
misc: ignore .uuid files generated from jetbrain
jinho-choi123 Mar 24, 2024
aba91e3
showBoard
Yongworry Apr 26, 2024
9509403
fix: add required dependency to package.json
jinho-choi123 May 5, 2024
ea1867a
migrate: add showBoard field to zabo schema
jinho-choi123 May 5, 2024
db6e744
Merge pull request #145 from sparcs-kaist/feature/showBoard
withSang May 5, 2024
8568ef2
Merge pull request #144 from sparcs-kaist/feature/board
withSang May 5, 2024
40d5436
upgrade node version for dev deploy
jinho-choi123 May 5, 2024
6c5734d
update node version for production
jinho-choi123 May 5, 2024
5f4a890
Delete .uuid
jinho-choi123 May 10, 2024
61ed131
Merge pull request #148 from sparcs-kaist/jinho-choi123-patch-1
withSang May 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:16-alpine
FROM node:18.18.2-alpine


RUN apk add --no-cache git
Expand Down
4 changes: 2 additions & 2 deletions .docker/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:16.19.1
FROM node:18.18.2

RUN apt update

Expand All @@ -10,4 +10,4 @@ EXPOSE 6001

VOLUME [ "/app" ]

CMD ["yarn", "dev"]
CMD ["yarn", "dev"]
16 changes: 16 additions & 0 deletions .docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ services:
- DB_STR=zabo
volumes:
- zabo-scheduler-log:/backup_log:rw

# zabo-worker:
# container_name: zabo-worker
# restart: always
# build:
# context: ..
# dockerfile: .worker/Dockerfile
# environment:
# - NODE_ENV=${NODE_ENV:-production}
# - MINIMUM_LOG_LEVEL=info
# - MONGODB_URL=mongodb://zabo-mongo:27017/zabo
# - DB_STR=zabo
# volumes:
# - zabo-worker-log:/backup_log:rw

volumes:
zabo-server-log:
Expand All @@ -61,3 +75,5 @@ volumes:
external: true
zabo-scheduler-log:
external: true
# zabo-worker-log:
# external: true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

.uuid
# dependencies
/node_modules

Expand All @@ -11,6 +12,7 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*
zabo-server-deployment/base/**/secret.yaml

*.log

Expand Down
14 changes: 14 additions & 0 deletions .worker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM node:16-alpine


RUN apk add --no-cache git

WORKDIR '/app'

COPY ./package.json ./
COPY ./yarn.lock ./
RUN yarn

COPY . .

CMD ["node", "worker.js"]
25 changes: 25 additions & 0 deletions migrations/1714912017538-add_showBoard_field.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require ('@babel/register');
require ('../config/env');

const {Zabo} = require('../src/db');

/**
* Make any changes you need to make to the database here
*/
async function up () {
// Write migration here
// eslint-disable-next-line no-restricted-syntax
for await (const zabo of Zabo.find()) {
zabo.showBoard = false;
await zabo.save ();
}
}

/**
* Make any changes that UNDO the up function side effects here (if possible)
*/
async function down () {
// Write migration here
}

module.exports = { up, down };
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@
"@babel/preset-env": "^7.20.2",
"@babel/preset-react": "^7.18.6",
"@babel/register": "^7.21.0",
"@tiptap/pm": "^2.3.1",
"adminjs": "^6.8.7",
"aws-sdk": "^2.485.0",
"axios": ">=0.18.1",
"bcrypt": "^5.1.1",
"chalk": "^2.4.2",
"connect-redis": "^3.4.1",
"cors": "^2.8.5",
Expand All @@ -56,7 +58,7 @@
"http-errors": "~1.6.2",
"ioredis": "^4.14.1",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.19",
"lodash": "^4.17.21",
"migrate-mongoose": "^4.0.0",
"moment": "^2.24.0",
"mongoose": "^5.7.5",
Expand Down Expand Up @@ -84,7 +86,7 @@
"figlet": "^1.2.4",
"husky": "^4.0.6",
"inquirer": "^7.0.3",
"lint-staged": "^9.5.0",
"lint-staged": "^15.1.0",
"nodemon": "^1.18.11",
"prettier": "^1.17.0"
},
Expand Down
42 changes: 42 additions & 0 deletions routes.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
* [`POST`](routes.md) /zabo/:zaboId/share
* [`DELETE`](routes.md) /zabo/:zaboId/

### Board
* [`POST`](routes.md) /board/device
* [`DELETE`](routes.md) /board/device
* [`POST`](routes.md) /board/login
* [`POST`](routes.md) /board/logout
* [`GET`](routes.md) /board/list


## Authentication

Following **Authorization** field must be set in HTTP request header
Expand Down Expand Up @@ -361,6 +369,40 @@ TODO: 그룹의 정보 \(사진\)을 업데이트할 수 있습니다. 이름도

400 : null id 500

### Board
#### `POST` /board/device { name, description, password } => deviceInfo
자보 보드를 게시할 디바이스를 생성합니다. Admin 패널에서 생성할 수 있습니다.
Admin 권한이 필요합니다. 기존의 디바이스들과 이름이 겹치면 생성되지 않습니다.

유효성 확인
* 관리자이여야 합니다.
* 기존의 디바이스와 겹치지 않는 디바이스 이름이여야 합니다.

#### `DELETE` /board/device { name } => { message }
자보 보드를 게시하는 디바이스를 삭제합니다. Admin 패널에서 삭제할 수 있습니다.

유효성 확인
* 관리자이여야 합니다.
* 유효한 디바이스 이름이여야 합니다.

#### `POST` /board/login { name, password } => { success, message }
자보 보드 디바이스에 로그인합니다. 세션 쿠키를 사용하여 인증합니다.

유효성 확인
* 올바른 디바이스 이름 및 비밀번호인지 확인합니다.

#### `POST` /board/logout => { message }
자보 보드 디바이스에서 로그아웃합니다.

유효성 확인
* 디바이스로 로그인되어있어야 합니다.

#### `GET` /board/list => zaboList
디바이스에서 자보 보드용 자보를 받아옵니다. 디바이스 로깅을 위해 /zabo/list와 분리해서 사용해야 합니다.

유효성 확인
* 디바이스로 로그인되어있어야 합니다.

## English

#### `GET` /auth \(\) ⇒ `user`
Expand Down
6 changes: 6 additions & 0 deletions src/admin/actions/addDevice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Components } from "../components";

export const addDeviceAction = {
actionType: "resource",
component: Components.addDeviceComponent,
};
20 changes: 20 additions & 0 deletions src/admin/actions/deleteDevice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import axios from "axios";
export const deleteDeviceAction = {
actionType: "record",
component: false,
guard: "Do you really want to delete this device?",
handler: async (req, res, context) => {
const { record } = context;
const deviceName = record.params.name;
const response = await axios.delete("/api/board/device", {
name: deviceName,
});

response.data.message;

return {
record: {},
msg: "Deleting Device: Success",
};
},
};
51 changes: 51 additions & 0 deletions src/admin/components/addDevice.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React, {useState} from 'react'
import { H3, Input, Button } from '@adminjs/design-system';
import axios from 'axios';

const addDevice = async (name, description, password) => {
const response = await axios.post('/api/board/device',
{
name,
description,
password
}
);
}

const addDeviceComponent = (props) => {
const [name, setName] = useState("");
const [description, setDescription] = useState("");
const [password, setPassword] = useState("");

const handleNameChange = (e) => {
setName(e.target.value);
}

const handleDescriptionChange = (e) => {
setDescription(e.target.value);
}

const handlePasswordChange = (e) => {
setPassword(e.target.value);
}

const handleDeviceSubmit = async() => {
await addDevice(name, description, password);
}

return (
<div>
<H3> Create your zabo boards device</H3>
<br/>
<Input type="text" onChange={handleNameChange} placeholder="name" />
<br/>
<Input type="text" onChange={handleDescriptionChange} placeholder="description" />
<br/>
<Input type="password" onChange={handlePasswordChange} placeholder="password" />
<br/>
<Button size="icon" rounded="True" onClick={handleDeviceSubmit}>Submit</Button>
</div>
)
}

export default addDeviceComponent
1 change: 1 addition & 0 deletions src/admin/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const Components = {
"uploadZaboComponent",
"./uploadZabo",
),
addDeviceComponent: componentLoader.add("addDeviceComponent", "./addDevice"),
};

export { componentLoader, Components };
5 changes: 3 additions & 2 deletions src/admin/components/uploadZabo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const uploadZaboComponent = (props) => {
const [description, setDescription] = useState("");
const [category, setCategory] = useState("");
const [schedule, setSchedule] = useState({});
const [showBoard, setShowBoard] = useState(false);

const handleZaboChange = (e) => {
const files = Array.from(e.target.files);
Expand Down Expand Up @@ -119,6 +120,7 @@ const uploadZaboComponent = (props) => {
zaboJSON.append("title", title);
zaboJSON.append("description", description);
zaboJSON.append("category", category);
zaboJSON.append("showBoard", showBoard);
//TODO: handle if schedule exists
// formData.append("schedule", schedule);

Expand All @@ -128,7 +130,7 @@ const uploadZaboComponent = (props) => {
await sortedImageFiles.sort(gridLayoutCompareFunction);

const {width, height} = await imageFileGetWidthHeight(sortedImageFiles[0]);
const ratio = width / height;
let ratio = width / height;
if (ratio > 2) ratio = 2;
else if (ratio < 0.5) ratio = 0.5;
const sources = await Promise.all(sortedImageFiles.map((file) => cropImage(file, ratio)));
Expand All @@ -144,7 +146,6 @@ const uploadZaboComponent = (props) => {
},
});

return
}

return (
Expand Down
4 changes: 4 additions & 0 deletions src/admin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import {
Statistic,
PreRegister,
Meta,
DeviceLog,
} from "../db";

import { GroupResource } from "./resources/Group";
import { ZaboResource } from "./resources/Zabo";
import { AdminUserResource } from "./resources/AdminUser";
import { DeviceResource } from "./resources/Device";

AdminJS.registerAdapter({
Resource: AdminJSMongoose.Resource,
Expand All @@ -34,7 +36,9 @@ const adminOptions = {
Statistic,
PreRegister,
Meta,
DeviceResource,
ZaboResource,
DeviceLog,
],
componentLoader,
};
Expand Down
11 changes: 11 additions & 0 deletions src/admin/resources/Device.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Device } from "../../db/index";
import { addDeviceAction } from "../actions/addDevice";

export const DeviceResource = {
resource: Device,
options: {
actions: {
addDevice: addDeviceAction,
},
},
};
3 changes: 2 additions & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ app.use(
app.use(
cors({
origin: [/sparcs\.org$/, /kaist\.ac\.kr$/],
credentials: true,
}),
);

Expand Down Expand Up @@ -67,7 +68,7 @@ app.use((err, req, res, next) => {
logger.api.error(err?.message || err); // TODO: Log params and body?
res.status(err.status || 500);
res.json({
error: err,
error: err, // 이거 뭐임? 왜 넣었지 ㅋㅋ 이거 없애도 되는거 아님? ㅋㅋ 이거 없애면 에러 안나는데 ㅋㅋ 이거 왜 넣었지 ㅋㅋ
});
});

Expand Down
4 changes: 3 additions & 1 deletion src/controllers/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export const checkAdmin = ash(async (req, res, next) => {
export const postNewZabo = ash(async (req, res) => {
const self = req.adminUser.user;

const { title, description, schedules: jsonSchedules } = req.body;
const { title, description, schedules: jsonSchedules, showBoard } = req.body;
const schedules = parseJSON(jsonSchedules, []);
let { category } = req.body;
logger.zabo.info(
Expand All @@ -111,6 +111,7 @@ export const postNewZabo = ash(async (req, res) => {
description,
category,
schedules,
showBoard,
req.files,
);
category = (category || "")
Expand Down Expand Up @@ -142,6 +143,7 @@ export const postNewZabo = ash(async (req, res) => {
description,
category,
schedules,
showBoard,
});

const calSizes = [];
Expand Down
Loading
Loading