From ec2208cb24a98f9c447c8d775d7c2d73ae93f37b Mon Sep 17 00:00:00 2001 From: EunHyunsu Date: Sun, 22 Sep 2024 00:19:00 +0900 Subject: [PATCH 1/7] =?UTF-8?q?feat:=20#1=20Dockerfile=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f1dcb73 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +# open jdk 17 버전의 환경을 구성 +FROM openjdk:17-alpine + +# build가 되는 시점에 JAR_FILE이라는 변수 명에 build/libs/*.jar 선언 +# build/libs - gradle로 빌드했을 때 jar 파일이 생성되는 경로 +ARG JAR_FILE=build/libs/*.jar + +# JAR_FILE을 app.jar로 복사 +COPY ${JAR_FILE} app.jar + +# 운영 및 개발에서 사용되는 환경 설정을 분리 +ENTRYPOINT ["java", "-jar", "-Dspring.profiles.active=local", "/app.jar"] \ No newline at end of file From 86659faf54974b4db89f8978a45f524b03392f99 Mon Sep 17 00:00:00 2001 From: EunHyunsu Date: Sun, 22 Sep 2024 00:23:54 +0900 Subject: [PATCH 2/7] =?UTF-8?q?chore:=20#1=20gitingnore=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 추후 개발 보안을 위해 ignore에 추가하였습니다 --- .gitignore | 5 +++++ src/main/resources/application-dev.yaml | 24 ----------------------- src/main/resources/application-local.yaml | 24 ----------------------- src/main/resources/application.yaml | 8 -------- 4 files changed, 5 insertions(+), 56 deletions(-) delete mode 100644 src/main/resources/application-dev.yaml delete mode 100644 src/main/resources/application-local.yaml delete mode 100644 src/main/resources/application.yaml diff --git a/.gitignore b/.gitignore index c2065bc..c57af71 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,11 @@ build/ !**/src/main/**/build/ !**/src/test/**/build/ +application.yaml +application-dev.yaml +application-local.yaml + + ### STS ### .apt_generated .classpath diff --git a/src/main/resources/application-dev.yaml b/src/main/resources/application-dev.yaml deleted file mode 100644 index d0875d9..0000000 --- a/src/main/resources/application-dev.yaml +++ /dev/null @@ -1,24 +0,0 @@ -spring: - datasource: - url: ${DB_URL} - username: ${DB_USER} - password: ${DB_PASSWORD} - driver-class-name: com.mysql.cj.jdbc.Driver - jpa: - show-sql: true - properties: - hibernate: - dialect: org.hibernate.dialect.MySQLDialect - hibernate: - ddl-auto: create - -Xcellent: - security: - jwt: - key: ${JWT_KEY} - access: - expiration: ${ACCESS_EXP} - header: ${ACCESS_HEAD} - refresh: - expiration: ${REFRESH_EXP} - header: ${REFRESH_HEAD} diff --git a/src/main/resources/application-local.yaml b/src/main/resources/application-local.yaml deleted file mode 100644 index d0875d9..0000000 --- a/src/main/resources/application-local.yaml +++ /dev/null @@ -1,24 +0,0 @@ -spring: - datasource: - url: ${DB_URL} - username: ${DB_USER} - password: ${DB_PASSWORD} - driver-class-name: com.mysql.cj.jdbc.Driver - jpa: - show-sql: true - properties: - hibernate: - dialect: org.hibernate.dialect.MySQLDialect - hibernate: - ddl-auto: create - -Xcellent: - security: - jwt: - key: ${JWT_KEY} - access: - expiration: ${ACCESS_EXP} - header: ${ACCESS_HEAD} - refresh: - expiration: ${REFRESH_EXP} - header: ${REFRESH_HEAD} diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml deleted file mode 100644 index d9bcc3b..0000000 --- a/src/main/resources/application.yaml +++ /dev/null @@ -1,8 +0,0 @@ -spring: - profiles: - active: local - -springdoc: - swagger-ui: - operations-sorter: method - tags-sorter: alpha From 415323f233823c34e496c67154d5b3541c612f00 Mon Sep 17 00:00:00 2001 From: EunHyunsu Date: Sun, 22 Sep 2024 20:35:38 +0900 Subject: [PATCH 3/7] =?UTF-8?q?chore:=20#1=20github=20actions=20=EC=8A=A4?= =?UTF-8?q?=ED=81=AC=EB=A6=BD=ED=8A=B8=20=EA=B5=AC=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/github-actions.yml | 83 ++++++++++++++++++++++++++++ Dockerfile | 2 +- 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/github-actions.yml diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml new file mode 100644 index 0000000..9b524be --- /dev/null +++ b/.github/workflows/github-actions.yml @@ -0,0 +1,83 @@ +# github repository actions 페이지에 나타날 이름 +name: CI/CD using github actions & docker + +# event trigger +# develop 브랜치에 push가 되었을 때 실행 +on: + push: + branches: [ "develop" ] + +permissions: + contents: read + +jobs: + CI-CD: + runs-on: ubuntu-latest + steps: + + # JDK setting - github actions에서 사용할 JDK 설정 (프로젝트나 AWS의 java 버전과 달라도 무방) + - uses: actions/checkout@v3 + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + + # gradle caching - 빌드 시간 향상 + - name: Gradle Caching + uses: actions/cache@v3 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + + # 환경별 yml 파일 생성(1) - application.yml + - name: make application.yml + if: | + contains(github.ref, 'develop') + run: | + mkdir ./src/main/resources # resources 폴더 생성 + cd ./src/main/resources # resources 폴더로 이동 + touch ./application.yml # application.yml 생성 + echo "${{ secrets.YML }}" > ./application.yml # github actions에서 설정한 값을 application.yml 파일에 쓰기 + shell: bash + + # 환경별 yml 파일 생성(2) - dev + - name: make application-dev.yml + if: contains(github.ref, 'develop') + run: | + cd ./src/main/resources + touch ./application-dev.yml + echo "${{ secrets.YML_DEV }}" > ./application-dev.yml + shell: bash + + # gradle build + - name: Build with Gradle + run: ./gradlew build -x test + + # docker build & push to develop + - name: Docker build & push to dev + if: contains(github.ref, 'develop') + run: | + docker login ghcr.io -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + docker build -t ${{ secrets.DOCKER_USERNAME }}/xcellent-be . + docker push ${{ secrets.DOCKER_USERNAME }}/xcellent-be + + ## deploy to develop + - name: Deploy to dev + uses: appleboy/ssh-action@master + id: deploy-dev + if: contains(github.ref, 'develop') + with: + host: ${{ secrets.HOST }} # EC2 퍼블릭 IPv4 DNS + username: ${{ secrets.USERNAME }} # ec-user + port: 22 + key: ${{ secrets.PRIVATE_KEY }} + script: | + sudo docker ps + sudo docker pull ${{ secrets.DOCKER_USERNAME }}/xcellent-be + sudo docker run -d -p 8081:8081 ${{ secrets.DOCKER_USERNAME }}/xcellent-be + sudo docker image prune -f \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index f1dcb73..c09cf2e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,4 +9,4 @@ ARG JAR_FILE=build/libs/*.jar COPY ${JAR_FILE} app.jar # 운영 및 개발에서 사용되는 환경 설정을 분리 -ENTRYPOINT ["java", "-jar", "-Dspring.profiles.active=local", "/app.jar"] \ No newline at end of file +ENTRYPOINT ["java", "-jar", "-Dspring.profiles.active=dev", "/app.jar"] \ No newline at end of file From 8a859f8ee3ad4f2a7425d2f6faf70011921afc66 Mon Sep 17 00:00:00 2001 From: EunHyunsu Date: Sun, 22 Sep 2024 20:36:37 +0900 Subject: [PATCH 4/7] =?UTF-8?q?chore:=20#1=20plain=20jar=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=83=9D=EC=84=B1=20=EB=B0=A9=EC=A7=80=EB=A5=BC=20?= =?UTF-8?q?=EC=9C=84=ED=95=9C=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/build.gradle b/build.gradle index 8920c4b..dc174e1 100644 --- a/build.gradle +++ b/build.gradle @@ -5,6 +5,11 @@ plugins { id 'org.asciidoctor.jvm.convert' version '3.3.2' } +jar { // plain 파일 생성 방지 + enabled = false +} + + group = 'com.leets' version = '0.0.1-SNAPSHOT' From 03626c4f7f5089993f60d474b1006542b238af73 Mon Sep 17 00:00:00 2001 From: EunHyunsu Date: Sun, 22 Sep 2024 20:39:24 +0900 Subject: [PATCH 5/7] =?UTF-8?q?chore:=20#1=20=ED=8F=AC=ED=8A=B8=20?= =?UTF-8?q?=EB=B2=88=ED=98=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/github-actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index 9b524be..5de5b06 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -79,5 +79,5 @@ jobs: script: | sudo docker ps sudo docker pull ${{ secrets.DOCKER_USERNAME }}/xcellent-be - sudo docker run -d -p 8081:8081 ${{ secrets.DOCKER_USERNAME }}/xcellent-be + sudo docker run -d -p 8080:8080 ${{ secrets.DOCKER_USERNAME }}/xcellent-be sudo docker image prune -f \ No newline at end of file From b7071fd113fe1e54ebe4e4b8045359851d69522d Mon Sep 17 00:00:00 2001 From: EunHyunsu Date: Sun, 22 Sep 2024 21:58:27 +0900 Subject: [PATCH 6/7] =?UTF-8?q?chore:=20#1=20Github=20Actions=20=EC=9E=90?= =?UTF-8?q?=EB=B0=94=20=EB=B2=84=EC=A0=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/github-actions.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index 5de5b06..ca95159 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -17,10 +17,10 @@ jobs: # JDK setting - github actions에서 사용할 JDK 설정 (프로젝트나 AWS의 java 버전과 달라도 무방) - uses: actions/checkout@v3 - - name: Set up JDK 11 + - name: Set up JDK 17 uses: actions/setup-java@v3 with: - java-version: '11' + java-version: '17' distribution: 'temurin' # gradle caching - 빌드 시간 향상 @@ -80,4 +80,4 @@ jobs: sudo docker ps sudo docker pull ${{ secrets.DOCKER_USERNAME }}/xcellent-be sudo docker run -d -p 8080:8080 ${{ secrets.DOCKER_USERNAME }}/xcellent-be - sudo docker image prune -f \ No newline at end of file + sudo docker image prune -f From fb27ddc4bdbe0b5df6e923bf72bfa39c1c91fe43 Mon Sep 17 00:00:00 2001 From: EunHyunsu Date: Sun, 22 Sep 2024 22:00:51 +0900 Subject: [PATCH 7/7] =?UTF-8?q?chore:=20#1=20EOF=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index c09cf2e..2693d12 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,4 +9,4 @@ ARG JAR_FILE=build/libs/*.jar COPY ${JAR_FILE} app.jar # 운영 및 개발에서 사용되는 환경 설정을 분리 -ENTRYPOINT ["java", "-jar", "-Dspring.profiles.active=dev", "/app.jar"] \ No newline at end of file +ENTRYPOINT ["java", "-jar", "-Dspring.profiles.active=dev", "/app.jar"]