diff --git a/.github/workflows/dev_deploy.yml b/.github/workflows/dev_deploy.yml index 5e75b52..0ae0340 100644 --- a/.github/workflows/dev_deploy.yml +++ b/.github/workflows/dev_deploy.yml @@ -1,63 +1,135 @@ +#name: Maeummal CI/CD +# +#on: +# pull_request: +# types: [closed] # pull request 가 닫히면 즉, 머지가 됐을 때 돌아라! +# workflow_dispatch: # (2).수동 실행도 가능하도록 +# +#jobs: +# build: +# runs-on: ubuntu-latest # (3).OS환경 / 우분투 기반 +# if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'develop' +# # 머지가 되었는데, 머지가 된 대상이 'develop' 브랜치이면 돌아라! +# +# steps: +# - name: Checkout # 코드를 가져오는 것. 빌드를 할 코드를 가져오는 것. ( 이름은 본인이 지정 ) +# uses: actions/checkout@v2 # (4).코드 check out +# # 리포지터리 최상단부터 체크 아웃 함 +# +# - name: Set up JDK 17 +# uses: actions/setup-java@v3 +# with: +# java-version: 17 # (5).자바 설치 +# distribution: 'adopt' +# +# - name: Grant execute permission for gradlew +# run: chmod +x ./gradlew +# shell: bash # (6).권한 부여 +# +# - name: Build with Gradle +# run: ./gradlew clean build -x test # gradlew에 권한 줌 +# shell: bash # (7).build 시작 +# +# - name: Get current time +# uses: 1466587594/get-current-time@v2 +# id: current-time +# with: +# format: YYYY-MM-DDTHH-mm-ss +# utcOffset: "+09:00" # (8).build 시점의 시간확보 +# +# - name: Show Current Time +# run: echo "CurrentTime=$" +# shell: bash # (9).확보한 시간 보여주기 +# +# - name: Generate deployment package # 빌드하는 과정 +# run: | +# mkdir -p deploy +# cp build/libs/*.jar deploy/application.jar +# cp Procfile deploy/Procfile +# cp -r .ebextensions_dev deploy/.ebextensions +# cp -r .platform deploy/.platform +# cd deploy && zip -r deploy.zip . +# +# - name: Beanstalk Deploy +# uses: einaregilsson/beanstalk-deploy@v20 +# with: +# aws_access_key: ${{ secrets.AWS_ACTION_ACCESS_KEY_ID }} +# aws_secret_key: ${{ secrets.AWS_ACTION_SECRET_ACCESS_KEY }} +# application_name: maeummal-dev # 프로젝트명 +# environment_name: Maeummal-dev-env # 프로젝트명 +# version_label: github-action-${{ steps.current-time.outputs.formattedTime }} +# region: ap-northeast-2 +# deployment_package: deploy/deploy.zip +# wait_for_deployment: false + +#name: Java CI with Gradle +# +#on: +# push: +# branches: develop +# pull_request: +# branches: develop +# +#jobs: +# build: +# +# runs-on: ubuntu-latest +# +# steps: +# - uses: actions/checkout@v2 +# - name: Set up JDK 11 +# uses: actions/setup-java@v2 +# with: +# java-version: '11' +# distribution: 'adopt' +# - name: Grant execute permission for gradlew +# run: chmod +x gradlew +# - name: Build with Gradle +# run: ./gradlew build +# - name: Docker build +# run: | +# docker login -u ${{ secrets.USERNAME }} -p ${{ secrets.PASSWORD }} +# docker build -t maeummal-cicd . +# docker tag maeummal-cicd maeummal/maeummal-cicd:${GITHUB_SHA::7} +# docker push maeummal/maeummal-cicd:${GITHUB_SHA::7} + name: Maeummal CI/CD on: + push: + branches: [ "develop" ] pull_request: - types: [closed] # pull request 가 닫히면 즉, 머지가 됐을 때 돌아라! - workflow_dispatch: # (2).수동 실행도 가능하도록 + branches: [ "develop" ] jobs: - build: - runs-on: ubuntu-latest # (3).OS환경 / 우분투 기반 - if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'develop' - # 머지가 되었는데, 머지가 된 대상이 'develop' 브랜치이면 돌아라! + deploy: + runs-on: ubuntu-latest steps: - - name: Checkout # 코드를 가져오는 것. 빌드를 할 코드를 가져오는 것. ( 이름은 본인이 지정 ) - uses: actions/checkout@v2 # (4).코드 check out - # 리포지터리 최상단부터 체크 아웃 함 + - name: Checkout + uses: actions/checkout@v2 - name: Set up JDK 17 - uses: actions/setup-java@v3 + uses: actions/setup-java@v2 with: - java-version: 17 # (5).자바 설치 - distribution: 'adopt' + java-version: '17' + distribution: 'temurin' - - name: Grant execute permission for gradlew - run: chmod +x ./gradlew - shell: bash # (6).권한 부여 + # Spring Boot 어플리케이션 Build (1) + - name: Spring Boot Build + run: ./gradlew clean build --exclude-task test - - name: Build with Gradle - run: ./gradlew clean build -x test # gradlew에 권한 줌 - shell: bash # (7).build 시작 + # Docker 이미지 Build (2) + - name: docker image build + run: docker build -t maeummal/maeummal-cicd . - - name: Get current time - uses: 1466587594/get-current-time@v2 - id: current-time + # DockerHub Login (3) + - name: docker login + uses: docker/login-action@v2 with: - format: YYYY-MM-DDTHH-mm-ss - utcOffset: "+09:00" # (8).build 시점의 시간확보 - - - name: Show Current Time - run: echo "CurrentTime=$" - shell: bash # (9).확보한 시간 보여주기 - - - name: Generate deployment package # 빌드하는 과정 - run: | - mkdir -p deploy - cp build/libs/*.jar deploy/application.jar - cp Procfile deploy/Procfile - cp -r .ebextensions_dev deploy/.ebextensions - cp -r .platform deploy/.platform - cd deploy && zip -r deploy.zip . - - - name: Beanstalk Deploy - uses: einaregilsson/beanstalk-deploy@v20 - with: - aws_access_key: ${{ secrets.AWS_ACTION_ACCESS_KEY_ID }} - aws_secret_key: ${{ secrets.AWS_ACTION_SECRET_ACCESS_KEY }} - application_name: maeummal-dev # 프로젝트명 - environment_name: Maeummal-dev-env # 프로젝트명 - version_label: github-action-${{ steps.current-time.outputs.formattedTime }} - region: ap-northeast-2 - deployment_package: deploy/deploy.zip - wait_for_deployment: false \ No newline at end of file + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + # Docker Hub push (4) + - name: docker Hub push + run: docker push maeummal/maeummal-cicd diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..975f5f9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +#FROM ubuntu:latest +#LABEL authors="solor" +# +#ENTRYPOINT ["top", "-b"] + +FROM openjdk:17-slim +ARG JAR_FILE=build/libs/*.jar +COPY ${JAR_FILE} app.jar +ENTRYPOINT ["java","-jar","/app.jar"] \ No newline at end of file diff --git a/build.gradle b/build.gradle index 48577e5..4e2779e 100644 --- a/build.gradle +++ b/build.gradle @@ -100,4 +100,10 @@ tasks.named('test') { } jar { // ci set enabled = false +} + +bootJar{ // 프로젝트 빌드 파일명 설정 + archivesBaseName = 'maeummal' + archiveFileName = 'maeummal.jar' + archiveVersion = "0.0.0" } \ No newline at end of file diff --git a/src/main/java/com/vlc/maeummal/domain/prep/prep1/config/ChatGPTConfig.java b/src/main/java/com/vlc/maeummal/domain/prep/prep1/config/ChatGPTConfig.java deleted file mode 100644 index 2d390bb..0000000 --- a/src/main/java/com/vlc/maeummal/domain/prep/prep1/config/ChatGPTConfig.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.vlc.maeummal.domain.prep.prep1.config; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; -import org.springframework.web.client.RestTemplate; - -/** - * ChatGPT에서 사용하는 환경 구성 - * - * @author : yu - * @fileName : RestTemplate - * @since : 07/17/24 - */ -@Configuration -public class ChatGPTConfig { - - @Value("${openai.api.key}") - private String secretKey; - - @Bean - public RestTemplate restTemplate() { - RestTemplate template = new RestTemplate(); - template.getInterceptors().add((request, body, execution) -> { - request.getHeaders().add( - "Authorization" - ,"Bearer "+secretKey); - return execution.execute(request,body); - }); - return template; - } - -// @Bean -// public HttpHeaders httpHeaders() { -// HttpHeaders headers = new HttpHeaders(); -// headers.set("Authorization", "Bearer " + secretKey); -// headers.setContentType(MediaType.APPLICATION_JSON); -// return headers; -// } -} \ No newline at end of file diff --git a/src/main/java/com/vlc/maeummal/domain/word/service/WordService.java b/src/main/java/com/vlc/maeummal/domain/word/service/WordService.java index e86e403..4fb8d7b 100644 --- a/src/main/java/com/vlc/maeummal/domain/word/service/WordService.java +++ b/src/main/java/com/vlc/maeummal/domain/word/service/WordService.java @@ -38,7 +38,6 @@ public class WordService { private final UuidRepository uuidRepository; - private final WordRepository wordRepository; private final UserAuthorizationConverter userAuthorizationConverter; private final ChallengeService challengeService; diff --git a/src/main/java/com/vlc/maeummal/global/config/AmazonConfig.java b/src/main/java/com/vlc/maeummal/global/config/AmazonConfig.java index 1439224..1a47ad9 100644 --- a/src/main/java/com/vlc/maeummal/global/config/AmazonConfig.java +++ b/src/main/java/com/vlc/maeummal/global/config/AmazonConfig.java @@ -1,5 +1,5 @@ package com.vlc.maeummal.global.config; - +/* import com.amazonaws.auth.AWSCredentials; import com.amazonaws.auth.AWSCredentialsProvider; import com.amazonaws.auth.AWSStaticCredentialsProvider; @@ -18,24 +18,26 @@ public class AmazonConfig { private AWSCredentials awsCredentials; - @Value(("${cloud.aws.credentials.accessKey}")) + @Value("${cloud.aws.credentials.accessKey}") private String accessKey; - @Value(("${cloud.aws.credentials.secretKey}")) + @Value("${cloud.aws.credentials.secretKey}") private String secretKey; - @Value(("${cloud.aws.region.static}")) + @Value("${cloud.aws.region.static}") private String region; - @Value(("${cloud.aws.s3.bucket}")) + @Value("${cloud.aws.s3.bucket}") private String bucket; @Value("${cloud.aws.s3.path.words}") private String wordPath; - @PostConstruct + */ +/* @PostConstruct public void init() { - this.awsCredentials = new BasicAWSCredentials(accessKey, secretKey); } + this.awsCredentials = new BasicAWSCredentials(accessKey, secretKey); }*//* + @Bean public AmazonS3 amazonS3() { AWSCredentials credentials @@ -51,3 +53,44 @@ public AWSCredentialsProvider awsCredentialsProvider() { return new AWSStaticCredentialsProvider(awsCredentials); } } +*/ + +import com.amazonaws.auth.AWSCredentials; +import com.amazonaws.auth.AWSStaticCredentialsProvider; +import com.amazonaws.auth.BasicAWSCredentials; +import com.amazonaws.services.s3.AmazonS3; +import com.amazonaws.services.s3.AmazonS3Client; +import com.amazonaws.services.s3.AmazonS3ClientBuilder; +import lombok.Getter; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +@Getter +public class AmazonConfig { + + @Value("${cloud.aws.credentials.accessKey}") + private String accessKey; + + @Value("${cloud.aws.credentials.secretKey}") + private String secretKey; + + @Value("${cloud.aws.region.static}") + private String region; + + @Value("${cloud.aws.s3.bucket}") + private String bucket; + + @Value("${cloud.aws.s3.path.words}") + private String wordPath; + + @Bean + public AmazonS3 amazonS3() { + AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); + return AmazonS3ClientBuilder.standard() + .withRegion(region) + .withCredentials(new AWSStaticCredentialsProvider(credentials)) + .build(); + } +}