Skip to content

Commit f82938f

Browse files
authored
Initial commit
0 parents  commit f82938f

File tree

15 files changed

+453
-0
lines changed

15 files changed

+453
-0
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
npm-debug.log

.github/workflows/main.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: CI/CD Pipeline
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
build-and-push:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
# 코드 체크아웃
17+
- name: Checkout code
18+
uses: actions/checkout@v3
19+
20+
# Docker 로그인
21+
- name: Log in to Docker Hub
22+
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
23+
24+
# Docker 이미지 빌드 및 푸시
25+
- name: Build and Push Docker image
26+
run: |
27+
IMAGE_NAME=${{ secrets.DOCKER_USERNAME }}/docker-test-app
28+
docker build -t $IMAGE_NAME:latest .
29+
docker push $IMAGE_NAME:latest
30+
31+
deploy:
32+
runs-on: ubuntu-latest
33+
needs: build-and-push
34+
35+
steps:
36+
# SSH를 통해 EC2에 연결하여 배포
37+
- name: Deploy to EC2
38+
uses: appleboy/[email protected]
39+
with:
40+
host: ${{ secrets.EC2_HOST }}
41+
username: ${{ secrets.EC2_USER }}
42+
key: ${{ secrets.EC2_SSH_KEY }}
43+
script: |
44+
# Docker Hub에 로그인
45+
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
46+
47+
# 기존 컨테이너 중지 및 삭제
48+
docker stop my-app || true
49+
docker rm my-app || true
50+
51+
# 최신 Docker 이미지 가져오기
52+
IMAGE_NAME=${{ secrets.DOCKER_USERNAME }}/docker-test-app
53+
docker pull $IMAGE_NAME:latest
54+
55+
# 새로운 컨테이너 실행
56+
docker run -d --name my-app -p 80:3000 $IMAGE_NAME:latest

.gitignore

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Created by https://www.toptal.com/developers/gitignore/api/node,dotenv
2+
# Edit at https://www.toptal.com/developers/gitignore?templates=node,dotenv
3+
### dotenv ###
4+
.env
5+
### Node ###
6+
# Logs
7+
logs
8+
*.log
9+
npm-debug.log*
10+
yarn-debug.log*
11+
yarn-error.log*
12+
lerna-debug.log*
13+
.pnpm-debug.log*
14+
# Diagnostic reports (https://nodejs.org/api/report.html)
15+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
16+
# Runtime data
17+
pids
18+
*.pid
19+
*.seed
20+
*.pid.lock
21+
# Directory for instrumented libs generated by jscoverage/JSCover
22+
lib-cov
23+
# Coverage directory used by tools like istanbul
24+
coverage
25+
*.lcov
26+
# nyc test coverage
27+
.nyc_output
28+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29+
.grunt
30+
# Bower dependency directory (https://bower.io/)
31+
bower_components
32+
# node-waf configuration
33+
.lock-wscript
34+
# Compiled binary addons (https://nodejs.org/api/addons.html)
35+
build/Release
36+
# Dependency directories
37+
node_modules/
38+
jspm_packages/
39+
# Snowpack dependency directory (https://snowpack.dev/)
40+
web_modules/
41+
# TypeScript cache
42+
*.tsbuildinfo
43+
# Optional npm cache directory
44+
.npm
45+
# Optional eslint cache
46+
.eslintcache
47+
# Optional stylelint cache
48+
.stylelintcache
49+
# Microbundle cache
50+
.rpt2_cache/
51+
.rts2_cache_cjs/
52+
.rts2_cache_es/
53+
.rts2_cache_umd/
54+
# Optional REPL history
55+
.node_repl_history
56+
# Output of 'npm pack'
57+
*.tgz
58+
# Yarn Integrity file
59+
.yarn-integrity
60+
# dotenv environment variable files
61+
.env.development.local
62+
.env.test.local
63+
.env.production.local
64+
.env.local
65+
# parcel-bundler cache (https://parceljs.org/)
66+
.cache
67+
.parcel-cache
68+
# Next.js build output
69+
.next
70+
out
71+
# Nuxt.js build / generate output
72+
.nuxt
73+
dist
74+
# Gatsby files
75+
.cache/
76+
# Comment in the public line in if your project uses Gatsby and not Next.js
77+
# https://nextjs.org/blog/next-9-1#public-directory-support
78+
# public
79+
# vuepress build output
80+
.vuepress/dist
81+
# vuepress v2.x temp and cache directory
82+
.temp
83+
# Docusaurus cache and generated files
84+
.docusaurus
85+
# Serverless directories
86+
.serverless/
87+
# FuseBox cache
88+
.fusebox/
89+
# DynamoDB Local files
90+
.dynamodb/
91+
# TernJS port file
92+
.tern-port
93+
# Stores VSCode versions used for testing VSCode extensions
94+
.vscode-test
95+
# yarn v2
96+
.yarn/cache
97+
.yarn/unplugged
98+
.yarn/build-state.yml
99+
.yarn/install-state.gz
100+
.pnp.*
101+
### Node Patch ###
102+
# Serverless Webpack directories
103+
.webpack/
104+
# Optional stylelint cache
105+
# SvelteKit build / generate output
106+
.svelte-kit
107+
# End of https://www.toptal.com/developers/gitignore/api/node,dotenv
108+
#보안관련
109+
package-lock.json

Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# 베이스 이미지 설정
2+
FROM node:16
3+
4+
# 작업 디렉토리 설정
5+
WORKDIR /usr/src/app
6+
7+
# 의존성 파일 복사 및 설치
8+
COPY package*.json ./
9+
RUN npm install
10+
11+
# 소스 코드 복사
12+
COPY . .
13+
14+
# 앱 포트 설정
15+
EXPOSE 3000
16+
17+
# 앱 실행 명령어
18+
CMD ["npm", "start"]

nodemon.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"watch": ["src"],
3+
"exec": "node src/server.js"
4+
}

package.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "project-setup-template",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"keywords": [],
6+
"author": "",
7+
"license": "ISC",
8+
"description": "",
9+
"dependencies": {
10+
"cors": "^2.8.5",
11+
"dotenv": "^16.4.5",
12+
"express": "^4.21.1",
13+
"morgan": "^1.10.0",
14+
"swagger-jsdoc": "^6.2.8",
15+
"swagger-ui-express": "^5.0.1"
16+
},
17+
"devDependencies": {
18+
"nodemon": "^3.1.7"
19+
},
20+
"scripts": {
21+
"start": "node src/server.js",
22+
"dev": "nodemon src/server.js",
23+
"test": "echo 'Running tests...' && exit 0"
24+
}
25+
}

src/app.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const express = require('express');
2+
const morgan = require('morgan');
3+
const cors = require('cors');
4+
const api = require("./routers/index");
5+
const setupSwagger = require('./config/swagger');
6+
const { errorHandler } = require("./middlewares/errorHandler");
7+
8+
const app = express();
9+
10+
// 미들웨어 설정
11+
app.use(morgan('dev'));
12+
app.use(cors());
13+
app.use(express.json());
14+
15+
// 라우트 연결
16+
app.use("/api", api);
17+
18+
// Swagger 설정
19+
setupSwagger(app);
20+
21+
// 에러 핸들러 등록
22+
app.use(errorHandler);
23+
24+
module.exports = app;

src/config/swagger.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const swaggerJSDoc = require('swagger-jsdoc');
2+
const swaggerUi = require('swagger-ui-express');
3+
4+
const options = {
5+
definition: {
6+
openapi: '3.0.0',
7+
info: {
8+
title: 'Project Setup Template API',
9+
version: '1.0.0',
10+
description: 'API documentation for Project Setup Template',
11+
},
12+
servers: [
13+
{
14+
url: "/",
15+
description: "API server",
16+
},
17+
],
18+
},
19+
apis: ['./src/routers/*.js'], // 라우트 파일에서 Swagger 주석을 가져옴
20+
};
21+
22+
const swaggerSpec = swaggerJSDoc(options);
23+
24+
const setupSwagger = (app) => {
25+
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
26+
};
27+
28+
module.exports = setupSwagger;

src/controllers/.gitkeep

Whitespace-only changes.

src/middlewares/asyncHandler.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// asyncHandler.js
2+
function asyncHandler(handler) {
3+
return async function (req, res, next) {
4+
try {
5+
await handler(req, res);
6+
} catch (error) {
7+
next(error);
8+
}
9+
};
10+
}
11+
12+
module.exports = asyncHandler;

0 commit comments

Comments
 (0)