Skip to content

Commit c45dbdb

Browse files
authored
Merge pull request #3 from Computer-Research-Association/2-feat-fastapi-colyseus-프로젝트-init
2 feat fastapi colyseus 프로젝트 init
2 parents 15050ee + c1a1f31 commit c45dbdb

23 files changed

Lines changed: 5251 additions & 0 deletions

.github/workflows/deploy.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: CI/CD Deployment
2+
3+
# deploy 실행 조건
4+
on:
5+
push:
6+
branches: ["main"] # main 브랜치에 코드가 push 시
7+
workflow_dispatch: # 테스트용 - 수동으로 배포 버튼 클릭시
8+
9+
jobs:
10+
deploy:
11+
# 미니 PC의 Runner 에서 실행
12+
runs-on: self-hosted
13+
14+
steps:
15+
# 최신 코드 가져오기
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
# GitHub Secrets를 사용하여 .env 파일 생성
20+
# 서버의 보안을 위해 실제 비밀번호는 GitHub Settings의 Secrets에 저장해야 함.
21+
- name: Create .env file
22+
run: |
23+
echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> .env
24+
echo "JWT_SECRET=${{ secrets.JWT_SECRET }}" >> .env
25+
echo "NODE_ENV=production" >> .env
26+
# 필요한 다른 환경변수가 있다면 여기에 추가하세요.
27+
28+
# docker compose 실행
29+
- name: Docker Compose Deploy
30+
run: |
31+
# --build: 코드가 바뀌었으므로 새로 이미지를 빌드합니다.
32+
# -d: 백그라운드에서 실행합니다.
33+
docker compose down
34+
docker compose up --build -d
35+
36+
# 도커 용량 최적화 (안 쓰는 오래된 이미지 삭제) -> 빌드 후 찌꺼기 제거
37+
- name: Cleanup unused Docker images
38+
run: docker image prune -f

colyseus-server/.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
node_modules
2+
build
3+
dist/
4+
lib/
5+
out/
6+
.colyseus-cloud.json
7+
.devmode.json
8+
9+
.env
10+
.env.development
11+
.env.production
12+
.env.local
13+

colyseus-server/Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# 1. 빌드 단계
2+
FROM node:20-alpine AS builder
3+
4+
WORKDIR /app
5+
6+
# 의존성 설치
7+
COPY package*.json ./
8+
RUN npm ci
9+
10+
# 소스 복사 및 빌드 (TypeScript -> JavaScript)
11+
COPY . .
12+
RUN npm run build
13+
14+
# 2. 실행 단계 (runtime)
15+
FROM node:20-alpine AS runtime
16+
17+
WORKDIR /app
18+
19+
ENV NODE_ENV=production
20+
21+
# devDependencies 제외한런타임 의존성만 재설치
22+
COPY package*.json ./
23+
RUN npm ci --omit=dev
24+
25+
# 빌드 산출물 복사
26+
COPY --from=builder /app/build ./build
27+
28+
# Colyseus 기본 포트
29+
EXPOSE 2567
30+
31+
# 서버 실행
32+
CMD ["npm", "start"]

colyseus-server/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Welcome to Colyseus!
2+
3+
This project has been created using [⚔️ `create-colyseus-app`](https://github.com/colyseus/create-colyseus-app/) - an npm init template for kick starting a Colyseus project in TypeScript.
4+
5+
[Documentation](http://docs.colyseus.io/)
6+
7+
## :crossed_swords: Usage
8+
9+
```
10+
npm start
11+
```
12+
13+
## Structure
14+
15+
- `index.ts`: main entry point, register an empty room handler and attach [`@colyseus/monitor`](https://github.com/colyseus/colyseus-monitor)
16+
- `src/rooms/MyRoom.ts`: an empty room handler for you to implement your logic
17+
- `src/rooms/schema/MyRoomState.ts`: an empty schema used on your room's state.
18+
- `loadtest/example.ts`: scriptable client for the loadtest tool (see `npm run loadtest`)
19+
- `package.json`:
20+
- `scripts`:
21+
- `npm start`: runs `ts-node-dev index.ts`
22+
- `npm test`: runs mocha test suite
23+
- `npm run loadtest`: runs the [`@colyseus/loadtest`](https://github.com/colyseus/colyseus-loadtest/) tool for testing the connection, using the `loadtest/example.ts` script.
24+
- `tsconfig.json`: TypeScript configuration file
25+
26+
27+
## License
28+
29+
MIT
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const os = require('os');
2+
3+
/**
4+
* COLYSEUS CLOUD WARNING:
5+
* ----------------------
6+
* PLEASE DO NOT UPDATE THIS FILE MANUALLY AS IT MAY CAUSE DEPLOYMENT ISSUES
7+
*/
8+
9+
module.exports = {
10+
apps : [{
11+
name: "colyseus-app",
12+
script: 'build/index.js',
13+
time: true,
14+
watch: false,
15+
instances: os.cpus().length,
16+
exec_mode: 'fork',
17+
wait_ready: true,
18+
env_production: {
19+
NODE_ENV: 'production'
20+
}
21+
}],
22+
};
23+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Client, Room } from "colyseus.js";
2+
import { cli, Options } from "@colyseus/loadtest";
3+
4+
export async function main(options: Options) {
5+
const client = new Client(options.endpoint);
6+
const room: Room = await client.joinOrCreate(options.roomName, {
7+
// your join options here...
8+
});
9+
10+
console.log("joined successfully!");
11+
12+
room.onMessage("message-type", (payload) => {
13+
// logic
14+
});
15+
16+
room.onStateChange((state) => {
17+
console.log("state change:", state);
18+
});
19+
20+
room.onLeave((code) => {
21+
console.log("left");
22+
});
23+
}
24+
25+
cli(main);

0 commit comments

Comments
 (0)