Skip to content

Commit

Permalink
github action을 통핸 CI/CD 구축
Browse files Browse the repository at this point in the history
github action을 통핸 CI/CD 구축
  • Loading branch information
seoko97 committed Sep 27, 2023
2 parents c842f6d + 823a9c3 commit 1bf639e
Show file tree
Hide file tree
Showing 288 changed files with 9,505 additions and 224 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
test
.vscode
.git
.github
.yarn/sdks
node_modules
4 changes: 3 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.exports = {
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_" }],
"import/order": [
"error",
{
Expand All @@ -37,7 +38,7 @@ module.exports = {
{
pattern: "@nestjs/**",
group: "internal",
position: "after",
position: "before",
},
{
pattern: "@/**",
Expand All @@ -51,5 +52,6 @@ module.exports = {
},
},
],
"@typescript-eslint/no-unused-vars": ["error", { varsIgnorePattern: "_" }],
},
};
60 changes: 60 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: SEOKO Server Deploy

on:
push:
branches: ["main"]

jobs:
build:
name: Build and Push Project
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node.js environment
uses: actions/[email protected]
with:
node-version: 16

- name: Install the project dependencies
run: yarn install

- name: Create .env file
run: |
jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' <<< "$SECRETS_CONTEXT" > .env
cat .env
env:
SECRETS_CONTEXT: ${{ toJson(secrets) }}

- name: Login to Docker Registry
uses: docker/login-action@v2
with:
registry: ${{secrets.DOCKER_REGISTRY_URL}}
username: ${{secrets.DOCKER_REGISTRY_ACCESS_KEY}}
password: ${{secrets.DOCKER_REGISTRY_SECRET_KEY}}

- name: Docker build & push to push
run: docker buildx build -t ${{secrets.DOCKER_REGISTRY_URL}}/${{secrets.BACK_DOCKER_IMAGE_NAME}}:${{ github.sha }} -t ${{secrets.DOCKER_REGISTRY_URL}}/${{secrets.BACK_DOCKER_IMAGE_NAME}}:latest --push .
working-directory: ${{ env.working-directory }}

deploy:
needs: build
name: Deploy
runs-on: [seoko-server]
steps:
- name: Login to Docker Registry
uses: docker/login-action@v2
with:
registry: ${{secrets.DOCKER_REGISTRY_URL}}
username: ${{secrets.DOCKER_REGISTRY_ACCESS_KEY}}
password: ${{secrets.DOCKER_REGISTRY_SECRET_KEY}}

- name: Docker run
run: |
if [ `docker ps -f "name=back" -q` ]
then
docker rm -f $(docker ps -f "name=back" -q)
fi
docker pull ${{secrets.DOCKER_REGISTRY_URL}}/${{secrets.BACK_DOCKER_IMAGE_NAME}}:${{ github.sha }}
docker run -dit -p 3065:3065 --name back ${{secrets.DOCKER_REGISTRY_URL}}/${{secrets.BACK_DOCKER_IMAGE_NAME}}:${{ github.sha }}
2,163 changes: 2,050 additions & 113 deletions .pnp.cjs

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
13 changes: 13 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
yarnPath: .yarn/releases/yarn-3.6.1.cjs

packageExtensions:
ts-loader@*:
dependencies:
webpack: "*"

"@nestjs/passport@*":
dependencies:
passport: "*"

"@nestjs/axios@*":
dependencies:
axios: "*"
41 changes: 41 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
FROM node:16-alpine as base

FROM base as builder

WORKDIR /app

COPY package.json .
COPY yarn.lock .
COPY .yarnrc.yml .
COPY .pnp.cjs .
COPY .pnp.loader.mjs .
COPY .yarn ./.yarn

RUN yarn install

COPY . .

RUN yarn build

FROM base AS runner

WORKDIR /app

COPY --from=builder /app/.yarn/releases ./.yarn/releases
COPY --from=builder /app/.yarn/cache ./.yarn/cache
COPY --from=builder /app/.yarn/unplugged ./.yarn/unplugged
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/.env ./.env

COPY --from=builder /app/.pnp.cjs ./.pnp.cjs
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/yarn.lock ./yarn.lock
COPY --from=builder /app/.yarnrc.yml ./.yarnrc.yml

ENV NODE_ENV production
ENV PORT 4000
ENV HOSTNAME 0.0.0.0

EXPOSE 4000

CMD ["node", "-r", "./.pnp.cjs", "dist/main.js"]
37 changes: 30 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"main": "index.js",
"repository": "https://github.com/seoko97/SEOKO-server.git",
"author": "seokho10007 <[email protected]>",
"author": "seoko97 <[email protected]>",
"license": "MIT",
"scripts": {
"build": "nest build",
Expand All @@ -12,26 +12,44 @@
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\"",
"lint:fix": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest --runInBand",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@nestjs/axios": "^3.0.0",
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.0.0",
"@nestjs/core": "^10.0.0",
"@nestjs/jwt": "^10.1.0",
"@nestjs/mapped-types": "^2.0.2",
"@nestjs/mongoose": "^10.0.0",
"@nestjs/passport": "^10.0.0",
"@nestjs/platform-express": "^10.0.0",
"bcryptjs": "^2.4.3",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"cookie-parser": "^1.4.6",
"crypto-js": "^4.1.1",
"mongoose": "^7.3.4",
"multer": "^1.4.5-lts.1",
"passport-jwt": "^4.0.1",
"passport-local": "^1.0.0",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1"
},
"devDependencies": {
"@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.0.0",
"@types/cookie-parser": "^1.4.3",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.2",
"@types/multer": "^1.4.7",
"@types/node": "^20.3.1",
"@types/supertest": "^2.0.12",
"@typescript-eslint/eslint-plugin": "^5.59.11",
Expand All @@ -42,6 +60,7 @@
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-prettier": "^4.2.1",
"jest": "^29.5.0",
"mongodb-memory-server": "^8.13.0",
"prettier": "^2.8.8",
"source-map-support": "^0.5.21",
"supertest": "^6.3.3",
Expand All @@ -57,16 +76,20 @@
"json",
"ts"
],
"rootDir": "src",
"rootDir": ".",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
"src/**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
"coverageDirectory": "./coverage",
"testEnvironment": "node",
"moduleNameMapper": {
"^@/(.*)$": "<rootDir>/src/$1",
"^test/(.*)$": "<rootDir>/test/$1"
}
},
"packageManager": "[email protected]"
}
23 changes: 0 additions & 23 deletions src/app.controller.spec.ts

This file was deleted.

13 changes: 0 additions & 13 deletions src/app.controller.ts

This file was deleted.

32 changes: 27 additions & 5 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
import { Module } from "@nestjs/common";
import { APP_GUARD } from "@nestjs/core";

import { AppController } from "./app.controller";
import { AppService } from "./app.service";
import { AccessJwtAuthGuard } from "@/common/guards";
import { CommonModule } from "@/common/modules";
import { SequenceModule } from "@/common/sequence/sequence.module";
import { AuthModule } from "@/routes/auth/auth.module";
import { ExperienceModule } from "@/routes/experience/experience.module";
import { ImageModule } from "@/routes/image/image.module";
import { PostModule } from "@/routes/post/post.module";
import { ProjectModule } from "@/routes/project/project.module";
import { SeriesModule } from "@/routes/series/series.module";
import { SkillModule } from "@/routes/skill/skill.module";
import { TagModule } from "@/routes/tag/tag.module";
import { UserModule } from "@/routes/user/user.module";

@Module({
imports: [],
controllers: [AppController],
providers: [AppService],
imports: [
CommonModule,
SequenceModule,
UserModule,
AuthModule,
PostModule,
SeriesModule,
TagModule,
ProjectModule,
ExperienceModule,
SkillModule,
ImageModule,
],
providers: [{ provide: APP_GUARD, useClass: AccessJwtAuthGuard }],
})
export class AppModule {}
8 changes: 0 additions & 8 deletions src/app.service.ts

This file was deleted.

10 changes: 10 additions & 0 deletions src/common/decorators/RealIp.decorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { createParamDecorator } from "@nestjs/common";

const RealIp = createParamDecorator((data, ctx) => {
const req = ctx.switchToHttp().getRequest();
const ip = req.headers["x-forwarded-for"] || req.headers["x-real-ip"] || "0.0.0.0";

return ip;
});

export { RealIp };
2 changes: 2 additions & 0 deletions src/common/decorators/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./skip-auth.decorator";
export * from "./user.decorator";
9 changes: 9 additions & 0 deletions src/common/decorators/is-optional.decorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { applyDecorators } from "@nestjs/common";

import { IsNotEmpty, IsOptional } from "class-validator";

const IsOptionalCustom = (..._decorators: PropertyDecorator[]) => {
return applyDecorators(IsOptional(), IsNotEmpty(), ..._decorators);
};

export { IsOptionalCustom };
7 changes: 7 additions & 0 deletions src/common/decorators/skip-auth.decorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { SetMetadata } from "@nestjs/common";

import { IS_PUBLIC_KEY } from "@/utils/constants";

const Public = () => SetMetadata(IS_PUBLIC_KEY, true);

export { Public };
Loading

0 comments on commit 1bf639e

Please sign in to comment.