issue # gitlab-ci 테스트
This commit is contained in:
@@ -1,17 +1,4 @@
|
|||||||
# PostgreSQL 설정
|
# Nestjs 서버 포트
|
||||||
PGHOST=bkdhome.p-e.kr
|
|
||||||
PGPORT=15454
|
|
||||||
PGDATABASE=scheduler
|
|
||||||
PGUSER=baekyangdan
|
|
||||||
PGPASSWORD=qwas745478!
|
|
||||||
PG_DATABASE_URL=postgres://baekyangdan:qwas745478!@bkdhome.p-e.kr:5454/scheduler
|
|
||||||
|
|
||||||
# Redis 설정
|
|
||||||
RD_HOST=bkdhome.p-e.kr
|
|
||||||
RD_PORT=6779
|
|
||||||
RD_URL=redis://bkdhome.p-e.kr:6779
|
|
||||||
|
|
||||||
# Express 서버 포트
|
|
||||||
PORT=3000
|
PORT=3000
|
||||||
|
|
||||||
# Gmail SMTP 설정
|
# Gmail SMTP 설정
|
||||||
12
.env.dev
Normal file
12
.env.dev
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# PostgreSQL 설정
|
||||||
|
PGHOST=bkdhome.p-e.kr
|
||||||
|
PGPORT=15454
|
||||||
|
PGDATABASE=scheduler
|
||||||
|
PGUSER=baekyangdan
|
||||||
|
PGPASSWORD=qwas745478!
|
||||||
|
PG_DATABASE_URL=postgres://baekyangdan:qwas745478!@bkdhome.p-e.kr:15454/scheduler
|
||||||
|
|
||||||
|
# Redis 설정
|
||||||
|
RD_HOST=bkdhome.p-e.kr
|
||||||
|
RD_PORT=6779
|
||||||
|
RD_URL=redis://bkdhome.p-e.kr:16779
|
||||||
12
.env.local
Normal file
12
.env.local
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# PostgreSQL 설정
|
||||||
|
PGHOST=bkdhome.p-e.kr
|
||||||
|
PGPORT=15454
|
||||||
|
PGDATABASE=scheduler
|
||||||
|
PGUSER=baekyangdan
|
||||||
|
PGPASSWORD=qwas745478!
|
||||||
|
PG_DATABASE_URL=postgres://192.168.219.107:5454/scheduler
|
||||||
|
|
||||||
|
# Redis 설정
|
||||||
|
RD_HOST=bkdhome.p-e.kr
|
||||||
|
RD_PORT=6779
|
||||||
|
RD_URL=redis://192.168.219.107:6779
|
||||||
12
.env.prod
Normal file
12
.env.prod
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# PostgreSQL 설정
|
||||||
|
PGHOST=db
|
||||||
|
PGPORT=5454
|
||||||
|
PGDATABASE=scheduler
|
||||||
|
PGUSER=baekyangdan
|
||||||
|
PGPASSWORD=qwas745478!
|
||||||
|
PG_DATABASE_URL=postgres://baekyangdan:qwas745478!@db:5454/scheduler
|
||||||
|
|
||||||
|
# Redis 설정
|
||||||
|
RD_HOST=redis
|
||||||
|
RD_PORT=6779
|
||||||
|
RD_URL=redis://redis:6779
|
||||||
@@ -19,25 +19,24 @@
|
|||||||
# stages: # List of stages for jobs, and their order of execution
|
# stages: # List of stages for jobs, and their order of execution
|
||||||
# - build
|
# - build
|
||||||
|
|
||||||
# cache:
|
cache:
|
||||||
# key:
|
key: "${CI_COMMIT_REF_SLUG}"
|
||||||
# files:
|
paths:
|
||||||
# - package-lock.json
|
- node_modules/
|
||||||
# paths:
|
- .yarn/cache/
|
||||||
# - node_modules/
|
|
||||||
|
|
||||||
# build: # This job runs in the build stage, which runs first.
|
build: # This job runs in the build stage, which runs first.
|
||||||
# stage: build
|
stage: build
|
||||||
# tags:
|
tags:
|
||||||
# - local-runner
|
- local-runner
|
||||||
# before_script:
|
before_script:
|
||||||
# script:
|
script:
|
||||||
# - echo "Compiling the code..."
|
- echo "Compiling the code..."
|
||||||
# - echo $DOCKER_VOLUME
|
- echo $DOCKER_VOLUME
|
||||||
# - echo $DOCKER_COMPOSE_VOLUME
|
- echo $DOCKER_COMPOSE_VOLUME
|
||||||
# - npm install
|
- yarn install --immutable
|
||||||
# - npm run build
|
- yarn build
|
||||||
# - sudo cp -r $PWD/dist/. $DOCKER_VOLUME/scheduler/back/dist
|
- sudo cp -r $PWD/dist/. $DOCKER_VOLUME/scheduler/back/dist
|
||||||
# - sudo cp $PWD/package.json $DOCKER_VOLUME/scheduler/back/dist
|
- sudo cp $PWD/package.json $DOCKER_VOLUME/scheduler/back/dist
|
||||||
# - docker compose -f $DOCKER_COMPOSE_VOLUME/scheduler/docker-compose.yaml up -d back
|
- docker compose -f $DOCKER_COMPOSE_VOLUME/scheduler/docker-compose.yaml up -d back
|
||||||
# - echo "Compile complete."
|
- echo "Compile complete."
|
||||||
@@ -6,12 +6,13 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"license": "UNLICENSED",
|
"license": "UNLICENSED",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "nest build",
|
"build": "NODE_ENV=prod nest build",
|
||||||
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
||||||
"start": "nest start",
|
"start": "nest start",
|
||||||
"start:dev": "nest start --watch",
|
"start:local": "NODE_ENV=local nest start --watch",
|
||||||
|
"start:dev": "NODE_ENV=dev nest start --watch",
|
||||||
"start:debug": "nest start --debug --watch",
|
"start:debug": "nest start --debug --watch",
|
||||||
"start:prod": "node dist/main",
|
"start:prod": "NODE_ENV=prod node dist/main",
|
||||||
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
"test:watch": "jest --watch",
|
"test:watch": "jest --watch",
|
||||||
@@ -23,6 +24,7 @@
|
|||||||
"@nestjs/class-transformer": "^0.4.0",
|
"@nestjs/class-transformer": "^0.4.0",
|
||||||
"@nestjs/class-validator": "^0.13.4",
|
"@nestjs/class-validator": "^0.13.4",
|
||||||
"@nestjs/common": "^11.0.1",
|
"@nestjs/common": "^11.0.1",
|
||||||
|
"@nestjs/config": "^4.0.2",
|
||||||
"@nestjs/core": "^11.0.1",
|
"@nestjs/core": "^11.0.1",
|
||||||
"@nestjs/platform-express": "^11.0.1",
|
"@nestjs/platform-express": "^11.0.1",
|
||||||
"bcrypt": "^6.0.0",
|
"bcrypt": "^6.0.0",
|
||||||
|
|||||||
@@ -5,9 +5,10 @@ import { DbModule } from './db/db.module';
|
|||||||
import { RedisModule } from './redis/redis.module';
|
import { RedisModule } from './redis/redis.module';
|
||||||
import { AccountModule } from './modules/account/account.module';
|
import { AccountModule } from './modules/account/account.module';
|
||||||
import { MailerModule } from './util/mailer/mailer.module';
|
import { MailerModule } from './util/mailer/mailer.module';
|
||||||
|
import { AppConfigModule } from './config/config.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [DbModule, RedisModule, MailerModule, AccountModule],
|
imports: [AppConfigModule, DbModule, RedisModule, MailerModule, AccountModule],
|
||||||
controllers: [AppController],
|
controllers: [AppController],
|
||||||
providers: [AppService],
|
providers: [AppService],
|
||||||
})
|
})
|
||||||
|
|||||||
15
src/config/config.module.ts
Normal file
15
src/config/config.module.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import { Module } from "@nestjs/common";
|
||||||
|
import { ConfigModule } from '@nestjs/config';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [
|
||||||
|
ConfigModule.forRoot({
|
||||||
|
isGlobal: true,
|
||||||
|
envFilePath: [
|
||||||
|
'.env.common',
|
||||||
|
`.env.${process.env.NODE_ENV}`
|
||||||
|
]
|
||||||
|
})
|
||||||
|
]
|
||||||
|
})
|
||||||
|
export class AppConfigModule{}
|
||||||
@@ -1,20 +1,22 @@
|
|||||||
import { Global, Module } from "@nestjs/common";
|
import { Global, Module } from "@nestjs/common";
|
||||||
import { Pool } from "pg";
|
import { Pool } from "pg";
|
||||||
import { drizzle, NodePgDatabase } from "drizzle-orm/node-postgres";
|
import { drizzle, NodePgDatabase } from "drizzle-orm/node-postgres";
|
||||||
|
import { ConfigModule, ConfigService } from "@nestjs/config";
|
||||||
import * as schema from '../../drizzle/schema';
|
import * as schema from '../../drizzle/schema';
|
||||||
|
|
||||||
@Global()
|
@Global()
|
||||||
@Module({
|
@Module({
|
||||||
|
imports: [ConfigModule],
|
||||||
providers: [
|
providers: [
|
||||||
{
|
{
|
||||||
provide: "DRIZZLE",
|
provide: "DRIZZLE",
|
||||||
useFactory: (): NodePgDatabase<typeof schema> => {
|
useFactory: (configService: ConfigService): NodePgDatabase<typeof schema> => {
|
||||||
const pool = new Pool({
|
const pool = new Pool({
|
||||||
connectionString: process.env.PG_DATABASE_URL
|
connectionString: configService.get<string>('PG_DATABASE_URL')
|
||||||
});
|
});
|
||||||
|
|
||||||
return drizzle(pool, { schema: schema });
|
return drizzle(pool, { schema: schema });
|
||||||
}
|
},
|
||||||
|
inject: [ConfigService]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
exports: ["DRIZZLE"]
|
exports: ["DRIZZLE"]
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Global, Module } from "@nestjs/common";
|
import { Global, Module } from "@nestjs/common";
|
||||||
|
import { ConfigModule, ConfigService } from "@nestjs/config";
|
||||||
import Redis from "ioredis";
|
import Redis from "ioredis";
|
||||||
|
|
||||||
@Global()
|
@Global()
|
||||||
@@ -6,12 +7,13 @@ import Redis from "ioredis";
|
|||||||
providers: [
|
providers: [
|
||||||
{
|
{
|
||||||
provide: "REDIS",
|
provide: "REDIS",
|
||||||
useFactory: (): Redis => {
|
useFactory: (configService: ConfigService): Redis => {
|
||||||
return new Redis({
|
return new Redis({
|
||||||
host: process.env.RD_HOST!,
|
host: configService.get<string>('RD_HOST')!,
|
||||||
port: Number(process.env.RD_PORT || 6779)
|
port: configService.get<number>('RD_PORT')
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
|
inject: [ConfigService]
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
exports: ["REDIS"]
|
exports: ["REDIS"]
|
||||||
|
|||||||
@@ -1,42 +1,54 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import nodemailer from 'nodemailer';
|
import nodemailer from 'nodemailer';
|
||||||
import { google } from 'googleapis';
|
import { google } from 'googleapis';
|
||||||
|
import { OAuth2Client } from 'google-auth-library';
|
||||||
import SMTPTransport from 'nodemailer/lib/smtp-transport';
|
import SMTPTransport from 'nodemailer/lib/smtp-transport';
|
||||||
|
import { ConfigService } from '@nestjs/config';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class MailerService {
|
export class MailerService {
|
||||||
private oauth2Client = new google.auth.OAuth2(
|
private oauth2Client: OAuth2Client;
|
||||||
process.env.GMAIL_CLIENT_ID,
|
private readonly gmailUser: string;
|
||||||
process.env.GMAIL_CLIENT_SECRET,
|
|
||||||
'https://developers.google.com/oauthplayground'
|
constructor(private readonly configService: ConfigService) {
|
||||||
);
|
const clientId = this.configService.get<string>('GMAIL_CLIENT_ID');
|
||||||
|
const clientSecret = this.configService.get<string>('GMAIL_CLIENT_SECRET');
|
||||||
|
const refreshToken = this.configService.get<string>('GMAIL_REFRESH_TOKEN');
|
||||||
|
|
||||||
|
this.gmailUser = this.configService.get<string>('GMAIL_USER')!;
|
||||||
|
|
||||||
|
this.oauth2Client = new google.auth.OAuth2(
|
||||||
|
clientId,
|
||||||
|
clientSecret,
|
||||||
|
'https://developers.google.com/oauthplayground'
|
||||||
|
);
|
||||||
|
|
||||||
constructor() {
|
|
||||||
this.oauth2Client.setCredentials({
|
this.oauth2Client.setCredentials({
|
||||||
refresh_token: process.env.GMAIL_REFRESH_TOKEN
|
refresh_token: refreshToken,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async sendMail(to: string, subject: string, html: string) {
|
async sendMail(to: string, subject: string, html: string) {
|
||||||
const accessToken = await this.oauth2Client.getAccessToken();
|
const accessToken = await this.oauth2Client.getAccessToken();
|
||||||
|
|
||||||
const options: SMTPTransport.Options = {
|
const options: SMTPTransport.Options = {
|
||||||
host: "smtp.gmail.com",
|
host: "smtp.gmail.com",
|
||||||
port: 465,
|
port: 465,
|
||||||
secure: true,
|
secure: true,
|
||||||
auth: {
|
auth: {
|
||||||
type: "OAuth2",
|
type: "OAuth2",
|
||||||
user: process.env.GMAIL_USER,
|
user: this.gmailUser,
|
||||||
clientId: process.env.GMAIL_CLIENT_ID,
|
clientId: this.configService.get<string>('GMAIL_CLIENT_ID'),
|
||||||
clientSecret: process.env.GMAIL_CLIENT_SECRET,
|
clientSecret: this.configService.get<string>('GMAIL_CLIENT_SECRET'),
|
||||||
refreshToken: process.env.GMAIL_REFRESH_TOKEN,
|
refreshToken: this.configService.get<string>('GMAIL_REFRESH_TOKEN'),
|
||||||
accessToken: accessToken?.token || ''
|
accessToken: accessToken?.token || '',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const transporter = nodemailer.createTransport(options);
|
const transporter = nodemailer.createTransport(options);
|
||||||
|
|
||||||
return transporter.sendMail({
|
return transporter.sendMail({
|
||||||
from: `Scheduler ${process.env.GMAIL_USER}>`,
|
from: `Scheduler ${this.gmailUser}>`,
|
||||||
to,
|
to,
|
||||||
subject,
|
subject,
|
||||||
html
|
html
|
||||||
|
|||||||
Reference in New Issue
Block a user