Skip to content

Commit

Permalink
Merge branch 'develop' into feature/#1/notification-api
Browse files Browse the repository at this point in the history
  • Loading branch information
redblackblossom authored Jul 30, 2024
2 parents d1b37b4 + 33d8ff3 commit 8763816
Show file tree
Hide file tree
Showing 23 changed files with 380 additions and 39 deletions.
5 changes: 4 additions & 1 deletion .github/ISSUE_TEMPLATE/issue_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ assignees: ''
<!-- 이슈 제목 : [Commit Type] [이슈 제목] -->
<!-- ex) [FEAT] 회원 API 구현 -->

<!-- 브랜치 컨벤션: {이슈_타입}/#{이슈_번호}/{작업할_내용_요약} -->
<!-- feature/#21/member-request-validation -->

## 💡 구현할 기능 설명
기능에 대해 설명해주세요
기능에 대해 설명해주세요.

## ❗체크리스트
- [ ] 모든 포지션의 팀원들이 이해할 수 있도록 충분한 설명을 제공하나요?
- [ ] 제목 형식을 지키고 브랜치 및 라벨을 할당했나요?
- [ ] 리뷰어와 Assignee도 할당했나요?
- [ ] 브랜치명 컨벤션을 지켜 브랜치를 생성하였나요?
6 changes: 5 additions & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<!-- PR 제목 : [Commit Type] PR_내용 -->
<!-- PR 내용의 경우, 이슈 제목을 그대로 써도 되고, 이슈에 언급되지 않은 내용까지 써주세용 -->
<!-- ex) [FEAT] 회원 API 구현 -->

## ❗️ 이슈 번호
Closes
Closes

## 📝 작업 내용

Expand Down
84 changes: 84 additions & 0 deletions .github/workflows/cicd-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Docker Hub Dev Deploy

run-name: ${{ github.head_ref }} 브랜치 작업 내용 병합 후 배포

on:
push:
branches:
- develop

jobs:
deploy:
runs-on: ubuntu-latest
steps:
# develop 브랜치 체크아웃
- name: Checkout
uses: actions/checkout@v3

# application.yml 파일 생성
- name: make application.yml
run: |
# create application.yml
cd ./src/main
cd ./resources
touch ./application.yml
echo "${{ secrets.APPLICATION_DEV_YML }}" >> ./application.yml
# 빌드 권한 부여
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew

# docker image 빌드
- name: Build
run: docker build --no-cache -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE_NAME }}:${{ secrets.DOCKERHUB_IMAGE_TAG }} .

# docker hub 로그인
- name: Docker Hub login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN_READ_WRITE }}

# docker hub에 image push
- name: docker image push
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE_NAME}}:${{secrets.DOCKERHUB_IMAGE_TAG }}

# docker compose에 사용될 환경 변수들이 담긴 env 파일 세팅
- name: Set up environment variables
run: |
echo "DOCKER_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}" >> dev.env
echo "DOCKER_IMAGE_NAME=${{ secrets.DOCKERHUB_IMAGE_NAME }}" >> dev.env
echo "DOCKER_IMAGE_TAG=${{ secrets.DOCKERHUB_IMAGE_TAG }}" >> dev.env
echo "SPRING_OUTER_PORT=${{ secrets.SPRING_OUTER_PORT }}" >> dev.env
echo "SPRING_INNER_PORT=${{ secrets.SPRING_INNER_PORT }}" >> dev.env
# compose.yml, dev.env 파일 서버로 복사
- name: Copy compose.yml, dev.env
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SSH_HOST }}
port: ${{ secrets.SSH_PORT }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
source: "compose.yml, dev.env"
target: /home/ubuntu

# EC2에서 docker compose up
- name: Deploy to Server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST }}
port: ${{ secrets.SSH_PORT }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd /home/ubuntu
sudo docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN_READ_ONLY }}
sudo docker container stop naoman-dev
sudo docker container rm naoman-dev
sudo docker image rm ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE_NAME}}:${{secrets.DOCKERHUB_IMAGE_TAG }}
sudo docker compose --env-file dev.env -f compose.yml up -d
sudo docker container prune -f
sudo docker image prune -a -f
32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# base 이미지 가져오기
# 최신 버전의 alpine 사용
# 빌드 스테이지를 builder라고 명명
FROM amazoncorretto:17-alpine-jdk AS builder

# 작업 디렉토리 /app 으로 설정
WORKDIR /app

# gradlew, build.gradle, settings.gradle, gradle, src 복사
COPY gradlew build.gradle settings.gradle ./
COPY gradle ./gradle
COPY src ./src

# jar 파일 생성을 위한 bootJar 실행
RUN ./gradlew bootJar

# 2번째 빌드 스테이지
# base 이미지 가져오기
FROM amazoncorretto:17-alpine-jdk

# 작업 디렉토리 설정
WORKDIR /app

# jar 파일 가져오기
# 이전 빌드 스테이지 'builder'에서 생성된 jar 파일을 복사
COPY --from=builder /app/build/libs/*.jar /app/naoman.jar

# 8080 포트를 사용함을 명시
EXPOSE 8080

# 컨테이너 실행 시 naoman.jar 파일 실행
ENTRYPOINT java -jar /app/naoman.jar
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ dependencies {
implementation 'com.github.josa-moa:josa-moa:1.0.3'

// AWS
// AWS, AWS S3
implementation platform("io.awspring.cloud:spring-cloud-aws-dependencies:3.0.0")
implementation 'io.awspring.cloud:spring-cloud-aws-starter-s3'
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'
Expand Down
29 changes: 29 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
services:
spring-application:
container_name: naoman-dev
image: ${DOCKER_USERNAME}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG}
ports:
- ${SPRING_OUTER_PORT}:${SPRING_INNER_PORT}

nginx:
container_name: nginx-dev
image: nginx:latest
volumes:
- ./naoman/default.conf:/etc/nginx/conf.d/default/conf
restart: always
ports:
- 80:80

# 설정을 6시간마다 다시 로드하여 최신 상태를 유지한다.
# 포그라운드 실행을 통해 Nginx 서버를 계속 실행시킨다.
command: [
"/bin/sh",
"-c",
"while :; do sleep 6h && wait $${!}; nginx -s reload; done & nginx -g 'daemon off;'"
]

redis:
container_name: redis-dev
image: redis:7.2.5
ports:
- 6379:6379
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.umc.naoman.domain.photo.dto.PhotoRequest;
import com.umc.naoman.domain.photo.dto.PhotoResponse;
import com.umc.naoman.domain.photo.service.PhotoService;
import com.umc.naoman.domain.photo.service.PhotoServiceImpl;
import com.umc.naoman.global.result.ResultResponse;
import com.umc.naoman.global.result.code.PhotoResultCode;
import jakarta.validation.Valid;
Expand All @@ -26,7 +25,13 @@ public class PhotoController {

@PostMapping("/preSignedUrl")
public ResultResponse<PhotoResponse.PreSignedUrlListInfo> getPreSignedUrlList(@Valid @RequestBody PhotoRequest.PreSignedUrlRequest request) {
List<PhotoResponse.PreSignedUrlInfo> preSignedUrlList = photoService.getPreSignedUrlList(request.getImageNameList());
return ResultResponse.of(PhotoResultCode.CREATE_SHARE_GROUP, photoConverter.toPreSignedUrlListInfo(preSignedUrlList));
List<PhotoResponse.PreSignedUrlInfo> preSignedUrlList = photoService.getPreSignedUrlList(request);
return ResultResponse.of(PhotoResultCode.CREATE_PRESIGNED_URL, photoConverter.toPreSignedUrlListInfo(preSignedUrlList));
}

@PostMapping("/upload")
public ResultResponse<PhotoResponse.PhotoUploadInfo> upload(@Valid @RequestBody PhotoRequest.PhotoUploadRequest request) {
PhotoResponse.PhotoUploadInfo photoUploadInfo = photoService.uploadPhotoList(request);
return ResultResponse.of(PhotoResultCode.UPLOAD_PHOTO, photoUploadInfo);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.umc.naoman.domain.photo.converter;

import com.umc.naoman.domain.photo.dto.PhotoResponse;
import com.umc.naoman.domain.photo.entity.Photo;
import com.umc.naoman.domain.shareGroup.entity.ShareGroup;
import org.springframework.stereotype.Component;

import java.util.List;
Expand All @@ -13,8 +15,8 @@ public PhotoResponse.PreSignedUrlListInfo toPreSignedUrlListInfo(List<PhotoRespo
List<PhotoResponse.PreSignedUrlInfo> preSignedUrlInfoList = preSignedUrlList.stream()
.map(preSignedUrlInfo -> toPreSignedUrlInfo(
preSignedUrlInfo.getPreSignedUrl(),
preSignedUrlInfo.getImageUrl(),
preSignedUrlInfo.getImageName()
preSignedUrlInfo.getPhotoUrl(),
preSignedUrlInfo.getPhotoName()
))
.collect(Collectors.toList());

Expand All @@ -23,12 +25,19 @@ public PhotoResponse.PreSignedUrlListInfo toPreSignedUrlListInfo(List<PhotoRespo
.build();
}

public PhotoResponse.PreSignedUrlInfo toPreSignedUrlInfo(String preSignedUrl, String imageUrl, String imageName) {
public PhotoResponse.PreSignedUrlInfo toPreSignedUrlInfo(String preSignedUrl, String photoUrl, String photoName) {
return PhotoResponse.PreSignedUrlInfo.builder()
.preSignedUrl(preSignedUrl)
.imageUrl(imageUrl)
.imageName(imageName)
.photoUrl(photoUrl)
.photoName(photoName)
.build();
}

public Photo toEntity(String photoUrl, String photoName, ShareGroup shareGroup) {
return Photo.builder()
.url(photoUrl)
.name(photoName)
.shareGroup(shareGroup)
.build();
}
}
17 changes: 15 additions & 2 deletions src/main/java/com/umc/naoman/domain/photo/dto/PhotoRequest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.umc.naoman.domain.photo.dto;

import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -16,9 +17,21 @@ public abstract class PhotoRequest {
@AllArgsConstructor
public static class PreSignedUrlRequest {

@NotEmpty(message = "이미지의 이름은 하나 이상이어야 합니다.")
private List<String> imageNameList;
@NotEmpty(message = "사진의 이름은 하나 이상이어야 합니다.")
private List<String> photoNameList;

}

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class PhotoUploadRequest {

@NotNull(message = "공유 그룹의 아이디 값을 입력해야 합니다.")
private Long shareGroupId;
@NotEmpty(message = "사진의 주소는 하나 이상이어야 합니다.")
private List<String> photoUrlList;
}

}
13 changes: 11 additions & 2 deletions src/main/java/com/umc/naoman/domain/photo/dto/PhotoResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@ public static class PreSignedUrlListInfo {
@NoArgsConstructor
public static class PreSignedUrlInfo {
private String preSignedUrl;
private String imageUrl;
private String imageName;
private String photoUrl;
private String photoName;
}

@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public static class PhotoUploadInfo {
private Long shareGroupId;
private int uploadCount;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.umc.naoman.domain.photo.service;

import com.umc.naoman.domain.photo.dto.PhotoRequest;
import com.umc.naoman.domain.photo.dto.PhotoResponse;

import java.util.List;

public interface PhotoService {

List<PhotoResponse.PreSignedUrlInfo> getPreSignedUrlList(List<String> imageNameList);
List<PhotoResponse.PreSignedUrlInfo> getPreSignedUrlList(PhotoRequest.PreSignedUrlRequest request);

PhotoResponse.PhotoUploadInfo uploadPhotoList(PhotoRequest.PhotoUploadRequest request);
}
Loading

0 comments on commit 8763816

Please sign in to comment.