diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..95099ee --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +/node_modules +/dist +.env +.env.test +.env.production +.env.development +.DS_store +*.code-workspace +*.swp +/logs/*.log diff --git a/.env.example b/.env.example index 70bf6dd..bda1812 100644 --- a/.env.example +++ b/.env.example @@ -1 +1,5 @@ -MONGO_CONNECTION_URI=mongodb://localhost:27017 \ No newline at end of file +# required environment variables +MONGO_CONNECTION_URI=mongodb://localhost:27017/council + +# optional environment variables +PORT=2300 \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..2101d39 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,39 @@ +--- +name: Bug report +about: 버그 세부 사항을 입력해 주세요. +title: '' +labels: '' +assignees: '' + +--- + +## 버그 설명 +버그가 무엇인지 명확하고 간결하게 설명합니다. + +## 재현 방법 +버그를 재현하는 단계를 설명해 주세요: +1. '...'로 이동 +2. '....'를 클릭 +3. '....'까지 아래로 스크롤 +4. 오류 발생 + +## 예상된 결과 +정상적인 경우 예상되는 상황에 대해 명확하고 간결하게 설명합니다. + +## 스크린샷 +해당되는 경우 문제를 설명하는 데 도움이 되는 스크린샷을 추가하세요. + +## 문제 발생 환경 +**데스크탑 (다음 정보를 입력해 주세요):** + - OS: [e.g. iOS] + - 브라우저 [e.g. chrome, safari] + - 버전 [e.g. 22] + +**모바일 (다음 정보를 입력해 주세요):** + - 기기명: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - 브라우저 [e.g. chrome, safari] + - 버전 [e.g. 22] + +## 추가 정보 +문제에 대한 추가적인 정보가 있다면 입력해 주세요. diff --git a/.github/ISSUE_TEMPLATE/custom.md b/.github/ISSUE_TEMPLATE/custom.md new file mode 100644 index 0000000..48d5f81 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/custom.md @@ -0,0 +1,10 @@ +--- +name: Custom issue template +about: Describe this issue template's purpose here. +title: '' +labels: '' +assignees: '' + +--- + + diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..349c2c2 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Feature 작업 사항을 입력해 주세요. +title: '' +labels: '' +assignees: '' + +--- + +## 문제 상황 +해결하려는 문제가 있다면 무엇인지 명확하고 간결하게 설명합니다. (ex. [...] 가 안 돼서 짜증나요!) + +## 해결 방안 제안 +해결하려는 방법을 명확하고 간결하게 설명합니다. + +## 고려한 다른 대안들 +고려해 본 다른 대안이나 기능에 대해 명확하고 간결하게 설명합니다. + +## 추가 정보 +여기에 기능 요청에 대한 다른 상황이나 스크린샷을 추가하세요. diff --git a/.github/workflows/build-dev-image.yaml b/.github/workflows/build-dev-image.yaml new file mode 100644 index 0000000..c6fdf45 --- /dev/null +++ b/.github/workflows/build-dev-image.yaml @@ -0,0 +1,52 @@ +name: Push Dev Image to GitHub Packages on Pushes to Main + +# when tagging action success +on: + pull_request: + types: + - closed + branches: + - main + +jobs: + if_merged: + if: github.event.pull_request.merged == true + name: Build and Push + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Cache Docker layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Log in to GitHub Packages + run: echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u USERNAME --password-stdin + + - name: Build Image and Push to GitHub Packages + id: build_image_and_push + uses: docker/build-push-action@v5 + env: + IMAGE_TAG: dev + with: + push: true + tags: | + "ghcr.io/NewWays-TechForImpactKAIST/backend:${{ env.IMAGE_TAG }}" + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new + + - name: Remove old cache + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e2a1cb1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +FROM node:18-alpine + +WORKDIR /usr/src/app + +# Install curl(for debugging purpose) and pnpm +RUN apk update && apk add curl && npm install --global pnpm@8.8.0 + +# pnpm fetch does require only lockfile +COPY pnpm-lock.yaml . + +# Note: devDependencies are fetched +RUN pnpm fetch + +# Copy repository and install dependencies +ADD . ./ +RUN pnpm install --offline + +# Build +RUN pnpm build + +# Run container +EXPOSE 80 +ENV PORT 80 +CMD ["pnpm", "prod"] diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 0000000..2ee962f --- /dev/null +++ b/docker-compose.dev.yml @@ -0,0 +1,15 @@ +version: "3.8" +services: + newways-backend: + container_name: newways-backend + image: "ghcr.io/NewWays-TechForImpactKAIST/backend:dev" + ports: + - "${PORT:?}:80" + environment: + - MONGO_CONNECTION_URI=${MONGO_CONNECTION_URI:?} + watchtower: + container_name: newways-watchtower + image: "containrrr/watchtower:latest" + volumes: + - "/var/run/docker.sock:/var/run/docker.sock" + command: --interval 60 --cleanup newways-backend diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..b776f66 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,15 @@ +version: "3.8" +services: + newways-backend: + container_name: newways-backend + image: "ghcr.io/NewWays-TechForImpactKAIST/backend:latest" + ports: + - "${PORT:?}:80" + environment: + - MONGO_CONNECTION_URI=${MONGO_CONNECTION_URI:?} + watchtower: + container_name: newways-watchtower + image: "containrrr/watchtower:latest" + volumes: + - "/var/run/docker.sock:/var/run/docker.sock" + command: --interval 60 --cleanup newways-backend diff --git a/nodemon.json b/nodemon.json new file mode 100644 index 0000000..9e1219a --- /dev/null +++ b/nodemon.json @@ -0,0 +1,7 @@ +{ + "ignore": ["node_modules/*"], + "env": { + "TZ": "Asia/Seoul", + "NODE_ENV": "development" + } +} diff --git a/package.json b/package.json index 0be095a..1c25b46 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "scripts": { "start": "concurrently \"npx tsc -w\" \"tsc-alias -w \" \"nodemon ./dist/index.js\"", "build": "tsc && tsc-alias", - "prod": "cross-env NODE_ENV=production node dist/index.js" + "clean": "rm -rf dist/", + "prod": "cross-env TZ=Asia/Seoul NODE_ENV=production node dist/index.js" }, "keywords": [], "author": "", diff --git a/src/config.ts b/src/config.ts index 72e020d..0c1df9e 100644 --- a/src/config.ts +++ b/src/config.ts @@ -2,7 +2,7 @@ import fs from "fs"; import path from "path"; import dotenv from "dotenv"; -const NODE_ENV = process.env.NODE_ENV || "development"; +const NODE_ENV = process.env.NODE_ENV; if (!NODE_ENV) { throw new Error("NODE_ENV not specified"); diff --git a/src/index.ts b/src/index.ts index 338bda2..4441a95 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,8 +2,10 @@ import express, { Request, Response, NextFunction } from "express"; import cors from "cors"; import { testRouter, scrapResultRouter } from "@/routes"; +import "@/config"; + const app = express(); -const port = 2300; +const port = parseInt(process.env.PORT || "2300"); app.use(express.json());