Skip to content

Commit

Permalink
Merge pull request #14 from NewWays-TechForImpactKAIST/feat/deploy-do…
Browse files Browse the repository at this point in the history
…cker
  • Loading branch information
withSang authored Nov 13, 2023
2 parents 22e5d88 + 1ac9f6a commit d50e805
Show file tree
Hide file tree
Showing 13 changed files with 203 additions and 4 deletions.
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/node_modules
/dist
.env
.env.test
.env.production
.env.development
.DS_store
*.code-workspace
*.swp
/logs/*.log
6 changes: 5 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
MONGO_CONNECTION_URI=mongodb://localhost:27017
# required environment variables
MONGO_CONNECTION_URI=mongodb://localhost:27017/council

# optional environment variables
PORT=2300
39 changes: 39 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -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]

## 추가 정보
문제에 대한 추가적인 정보가 있다면 입력해 주세요.
10 changes: 10 additions & 0 deletions .github/ISSUE_TEMPLATE/custom.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
name: Custom issue template
about: Describe this issue template's purpose here.
title: ''
labels: ''
assignees: ''

---


20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Feature 작업 사항을 입력해 주세요.
title: ''
labels: ''
assignees: ''

---

## 문제 상황
해결하려는 문제가 있다면 무엇인지 명확하고 간결하게 설명합니다. (ex. [...] 가 안 돼서 짜증나요!)

## 해결 방안 제안
해결하려는 방법을 명확하고 간결하게 설명합니다.

## 고려한 다른 대안들
고려해 본 다른 대안이나 기능에 대해 명확하고 간결하게 설명합니다.

## 추가 정보
여기에 기능 요청에 대한 다른 상황이나 스크린샷을 추가하세요.
52 changes: 52 additions & 0 deletions .github/workflows/build-dev-image.yaml
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 [email protected]

# 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"]
15 changes: 15 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"ignore": ["node_modules/*"],
"env": {
"TZ": "Asia/Seoul",
"NODE_ENV": "development"
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down

0 comments on commit d50e805

Please sign in to comment.