diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml new file mode 100644 index 0000000..c63586c --- /dev/null +++ b/.github/workflows/deploy-dev.yml @@ -0,0 +1,74 @@ +name: Spring Boot CD to EC2 + +on: + push: + branches: + - develop + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + + steps: + # 1. 코드 체크아웃 + - name: Checkout code + uses: actions/checkout@v3 + + # 2. JDK 설정 + - name: Set up JDK 21 + uses: actions/setup-java@v3 + with: + java-version: '21' + distribution: 'temurin' + cache: 'gradle' + + # 3. Gradle 실행 권한 부여 + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + # 4. 빌드 (테스트 포함) + - name: Build with Gradle + run: ./gradlew clean build + + # 5. JAR 파일명 확인 및 환경변수 설정 + - name: Get JAR file name + id: jar_name + run: | + JAR_FILE=$(ls build/libs/*.jar | grep -v plain | head -n 1) + echo "jar_path=$JAR_FILE" >> $GITHUB_OUTPUT + echo "jar_name=$(basename $JAR_FILE)" >> $GITHUB_OUTPUT + + # 6. EC2로 JAR 파일 전송 + - name: Copy JAR to EC2 + uses: appleboy/scp-action@master + with: + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USERNAME }} + key: ${{ secrets.EC2_SSH_KEY }} + port: ${{ secrets.EC2_SSH_PORT }} + source: ${{ steps.jar_name.outputs.jar_path }} + target: "/home/${{ secrets.EC2_USERNAME }}/app" + strip_components: 2 + + # 7. 배포 스크립트 실행 + - name: Execute deployment script on EC2 + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USERNAME }} + key: ${{ secrets.EC2_SSH_KEY }} + port: ${{ secrets.EC2_SSH_PORT }} + script: | + cd /home/${{ secrets.EC2_USERNAME }}/app + chmod +x deploy.sh + ./deploy.sh ${{ steps.jar_name.outputs.jar_name }} + + # 8. 배포 결과 알림 + - name: Notify deployment status + if: always() + run: | + if [ ${{ job.status }} == 'success' ]; then + echo "✅ 배포 성공!" + else + echo "❌ 배포 실패!" + fi diff --git a/.gitignore b/.gitignore index 88938d8..94d228a 100644 --- a/.gitignore +++ b/.gitignore @@ -37,7 +37,7 @@ out/ ### VS Code ### .vscode/ -**/application.yml +**/application-local.yml **/application.properties /lib/ diff --git a/build.gradle b/build.gradle index 6635b0e..73ee8fe 100644 --- a/build.gradle +++ b/build.gradle @@ -37,13 +37,22 @@ dependencies { implementation 'org.locationtech.jts:jts-core:1.19.0' // Swagger-ui - implementation "org.springdoc:springdoc-openapi-starter-webmvc-ui:2.5.0" + implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.5.0' // EXIF metadata extraction implementation 'com.drewnoakes:metadata-extractor:2.19.0' // File type validation implementation 'org.apache.tika:tika-core:2.9.1' + + // BOM + implementation platform('io.awspring.cloud:spring-cloud-aws-dependencies:3.2.1') + + // 사용하려는 프레임워크 모듈 + implementation 'io.awspring.cloud:spring-cloud-aws-starter-parameter-store' + + // AWS 자격 증명 + implementation 'io.awspring.cloud:spring-cloud-aws-starter' } tasks.named('test') { diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml new file mode 100644 index 0000000..26f867e --- /dev/null +++ b/src/main/resources/application-dev.yml @@ -0,0 +1,19 @@ +spring: + config: + import: + - "aws-parameterstore:/PHOTO_LINER_API/rds/dev/" + - "aws-parameterstore:/PHOTO_LINER_API/ec2/dev/" + + cloud: + aws: + region: + static: ap-northeast-2 + + datasource: + url: ${MYSQL_URL} + username: ${MYSQL_USER_NAME} + password: ${MYSQL_PASSWORD} + +photo: + upload: + base-dir: ${PHOTOS_UPLOAD_URL} diff --git a/src/main/resources/application-local-example.yml b/src/main/resources/application-local-example.yml new file mode 100644 index 0000000..02a44f7 --- /dev/null +++ b/src/main/resources/application-local-example.yml @@ -0,0 +1,10 @@ +spring: + + datasource: + url: url + username: username + password: password + +photo: + upload: + base-dir: url diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..af82374 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,27 @@ +spring: + profiles: + active: local + + application: + name: PhotoLiner + + servlet: + multipart: + enabled: true + max-file-size: 10MB + max-request-size: 100MB + + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + + jpa: + hibernate: + ddl-auto: validate + show-sql: true + properties: + hibernate: + format_sql: true + + flyway: + enabled: true + baseline-on-migrate: true