Skip to content

Commit

Permalink
feat: github actions CI/CD & slack 이벤트 중복처리
Browse files Browse the repository at this point in the history
  • Loading branch information
junseok44 committed Sep 16, 2024
1 parent 5d6eeaa commit 4d4f4b9
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/deploy-server.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Deploy to EC2

on:
push:
branches:
- master

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Set up SSH key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.EC2_KEY }}

- name: Deploy to EC2
env:
EC2_HOST: ${{ secrets.EC2_HOST }}
EC2_USER: ${{ secrets.EC2_USER }}
run: |
ssh -o StrictHostKeyChecking=no $EC2_USER@$EC2_HOST << 'EOF'
cd /home/ubuntu # 프로젝트 디렉토리로 이동
git pull origin master # 최신 코드 가져오기
npm install # 의존성 설치
pm2 restart all # PM2로 애플리케이션 재실행
EOF
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ import summarizeRoutes from "./routes/summarizeRoutes";
dotenv.config();

const app = express();

app.use(bodyParser.json());

app.use("/slack", slackRoutes);

app.use("/api", summarizeRoutes);

app.get("/", (req, res) => {
res.send("Hello, World!");
});

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`서버가 ${PORT}번 포트에서 실행 중입니다.`);
Expand Down
12 changes: 10 additions & 2 deletions src/routes/slackRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,30 @@ const router = express.Router();

const slackToken = process.env.SLACK_BOT_TOKEN || "";

const processedEvents = new Set(); // 간단한 예로 메모리에 저장

if (!slackToken) {
console.error("SLACK_BOT_TOKEN 환경 변수가 설정되지 않았습니다.");
process.exit(1); // 환경 변수가 설정되지 않았으면 앱을 종료합니다.
}

const slackClient = new WebClient(slackToken);

router.post("/events", async (req, res) => {
const { type, event } = req.body;
const { type, event, event_id } = req.body;

if (type === "url_verification") {
// 슬랙 URL 검증 요청 처리
return res.json({ challenge: req.body.challenge });
}

if (processedEvents.has(event_id)) {
// 이미 처리된 이벤트에 대해 200 응답을 보내고 종료
return res.status(200).send("Event already processed.");
}

if (event && event.type === "app_mention") {
processedEvents.add(event_id);

const { text, channel, ts } = event;
const youtubeUrl = extractYoutubeUrl(text);

Expand Down

0 comments on commit 4d4f4b9

Please sign in to comment.