Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: s3 url 경로 변경 #59

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions deploy/deploy-prod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# 스크립트의 실제 위치를 기준으로 경로 설정
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR=$(cd "$SCRIPT_DIR/.."; pwd)
PEM_PATH="$SCRIPT_DIR/../../../keys/blccu-prod.pem"
PEM_PATH="$SCRIPT_DIR/../../../keys/blccu-dev-rsa.pem"

# PEM 파일 경로가 올바른지 확인
if [[ ! -f "$PEM_PATH" ]]; then
Expand All @@ -13,12 +13,12 @@ fi
# PEM 파일 권한 확인 및 수정
chmod 400 "$PEM_PATH"

HOSTS=("13.209.215.21")
HOSTS=("3.34.58.11")
ACCOUNT=ubuntu
SERVICE_NAME=blccu
SERVICE_NAME=blccu-ecr
DOCKER_TAG=latest
ECR_URL="792939917746.dkr.ecr.ap-northeast-2.amazonaws.com"
AWS_PROFILE=production # 배포 프로파일 사용
ECR_URL="637423583546.dkr.ecr.ap-northeast-2.amazonaws.com"
AWS_PROFILE=staging # 배포 프로파일 사용
ENV_FILE="$ROOT_DIR/.env.prod"

NGINX_CONFIG=/etc/nginx/nginx.conf
Expand Down Expand Up @@ -66,7 +66,7 @@ for HOST in "${HOSTS[@]}"; do
echo -e "\n## new docker pull & run on $HOST ##\n"
ssh -i $PEM_PATH $SERVER "aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin $ECR_URL"
ssh -i $PEM_PATH $SERVER "docker pull $ECR_URL/$SERVICE_NAME:$DOCKER_TAG"
ssh -i $PEM_PATH $SERVER "docker run --env-file /home/$ACCOUNT/upload/.env.prod -d -p $NEW_PORT:3000 --name $NEW_SERVICE_NAME -e TZ=Asia/Seoul --network blccu_network $ECR_URL/$SERVICE_NAME"
ssh -i $PEM_PATH $SERVER "docker run --env-file /home/$ACCOUNT/upload/.env.prod -d -p $NEW_PORT:3000 --name $NEW_SERVICE_NAME -e TZ=Asia/Seoul $ECR_URL/$SERVICE_NAME"

# 헬스체크 수행
echo -e "\n## 헬스체크 수행 on $HOST ##\n"
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"license": "UNLICENSED",
"scripts": {
"ssh:staging": "ssh -i ../../keys/blccu-dev-rsa.pem [email protected];",
"ssh:prod": "ssh -i ../../keys/blccu-dev-rsa.pem [email protected]",
"ssh:prod1": "ssh -i ../../keys/blccu-prod.pem [email protected]",
"ssh:prod2": "ssh -i ../../keys/blccu-prod.pem [email protected]",
"typeorm": "node --require ts-node/register ./node_modules/typeorm/cli.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
import { Request } from 'express';
import { AnnouncementCreateRequestDto } from '../dtos/request/announcement-create-request.dto';
import { AnnouncementDto } from '../dtos/common/announcement.dto';
import exp from 'constants';
import { AnnouncementPatchRequestDto } from '../dtos/request/announcement-patch-request.dto';
import {
BlccuExceptionTest,
Expand Down
1 change: 1 addition & 0 deletions src/APIs/articleBackgrounds/articleBackgrounds.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class ArticleBackgroundsService {
file,
resize: 2000,
ext: 'png',
tag: 'articles/images/backgrounds',
});
await this.repo_articleBackgrounds.save({ imageUrl });
return { imageUrl };
Expand Down
1 change: 1 addition & 0 deletions src/APIs/articles/services/articles-create.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export class ArticlesCreateService {
file,
ext: 'png',
resize: 1280,
tag: 'articles/images/views',
});

return { imageUrl };
Expand Down
1 change: 1 addition & 0 deletions src/APIs/stickers/stickers.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class StickersService {
file,
resize: 1600,
ext: 'png',
tag: 'stickers/images',
});
const insertData = await this.repo_stickers
.createQueryBuilder()
Expand Down
2 changes: 2 additions & 0 deletions src/APIs/users/services/users-update.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export class UsersUpdateService {
ext: 'jpg',
file,
resize: 800,
tag: 'users/images/profiles',
});
await this.svc_images.deleteImage({ url: user.profileImage });

Expand All @@ -99,6 +100,7 @@ export class UsersUpdateService {
ext: 'jpg',
file,
resize: 1600,
tag: 'users/images/backgrounds',
});
await this.svc_images.deleteImage({ url: user.backgroundImage });

Expand Down
5 changes: 3 additions & 2 deletions src/modules/aws/aws.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ export class AwsService {
) {
try {
const resizedImageBuffer = await this.resizeImage(file.buffer, resize);
const key = `${this.configService.get('S3_KEY')}/${fileName}`;
// AWS S3에 이미지 업로드 명령을 생성합니다. 파일 이름, 파일 버퍼, 파일 접근 권한, 파일 타입 등을 설정합니다.
const command = new PutObjectCommand({
Bucket: this.configService.get('AWS_S3_BUCKET_NAME'), // S3 버킷 이름
Key: fileName, // 업로드될 파일의 이름
Key: key, // 업로드될 파일의 이름
Body: resizedImageBuffer, // 업로드할 파일
ContentType: `image/${ext}`, // 파일 타입
});
Expand All @@ -84,7 +85,7 @@ export class AwsService {
await this.s3Client.send(command);

// 업로드된 이미지의 URL을 반환합니다.
return `https://${this.configService.get('CLOUDFRONT_DOMAIN_NAME')}/${fileName}`;
return `https://${this.configService.get('CLOUDFRONT_DOMAIN_NAME')}/${key}`;
} catch (error) {
this.logger.error('Error uploading image to S3', error.stack);
throw new BlccuException('IMAGE_UPLOAD_TO_S3_ERROR');
Expand Down
3 changes: 2 additions & 1 deletion src/modules/images/images.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ export class ImagesService {
file,
resize,
ext,
tag,
}: IImagesServiceUploadImage): Promise<ImageUploadResponseDto> {
const imageName = getUUID();
const imageUrl = await this.svc_aws.imageUploadToS3(
`${imageName}.${ext}`,
`${tag}/${imageName}.${ext}`,
file,
ext,
resize,
Expand Down
1 change: 1 addition & 0 deletions src/modules/images/interfaces/images.service.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export interface IImagesServiceUploadImage {
file: Express.Multer.File;
resize: number;
ext: 'jpg' | 'png';
tag?: string;
}

export interface IImagesServiceDeleteImage {
Expand Down
Loading