From 7d68a4d522f17953684a66cd8c1ad9d686756d5c Mon Sep 17 00:00:00 2001 From: david-parkk Date: Sat, 4 May 2024 00:04:11 +0900 Subject: [PATCH 1/6] fix : gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index ef72a68..c2065bc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -*.yml HELP.md .gradle build/ From e63618815eb8725f2c8c2701a58a2dbc2d801c8d Mon Sep 17 00:00:00 2001 From: david-parkk Date: Sat, 4 May 2024 00:05:06 +0900 Subject: [PATCH 2/6] feat application.yml --- src/main/resources/application.yml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/main/resources/application.yml diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..0037d48 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,7 @@ +spring: + data: + redis: + host: redis + port: 6379 + password: + timeout: 5000 \ No newline at end of file From 557a91c909c54f6531df543c49b0f7eb407a7ca7 Mon Sep 17 00:00:00 2001 From: david-parkk Date: Sat, 4 May 2024 00:05:21 +0900 Subject: [PATCH 3/6] fix dockerfile --- Dockerfile | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2ac400d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM openjdk:17-jdk + +# 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=prod", "/app.jar"] \ No newline at end of file From d91100b5fb2cb259548609342fe16397a511f7c7 Mon Sep 17 00:00:00 2001 From: david-parkk Date: Sat, 4 May 2024 00:05:34 +0900 Subject: [PATCH 4/6] feat : docker compose --- docker-compose.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..230d8ee --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,16 @@ +version: '3' +services: + redis: + image: redis + ports: + - 6379:6379 + springbootapp: + image: ji0513ji/sample-repository:v1.0.0 +# build: +# context: . +# dockerfile: Dockerfile + ports: + - 8080:8080 + depends_on: + - redis + From 7826fe32f4cec77083aa9b4e60324840158fc6fc Mon Sep 17 00:00:00 2001 From: david-parkk Date: Sat, 4 May 2024 00:14:25 +0900 Subject: [PATCH 5/6] =?UTF-8?q?fix=20:=20=EC=9D=B4=EB=A6=84=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/pr-test.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/pr-test.yml b/.github/workflows/pr-test.yml index 94b7637..618cf24 100644 --- a/.github/workflows/pr-test.yml +++ b/.github/workflows/pr-test.yml @@ -5,12 +5,11 @@ # This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle -name: Java CI CD with Gradle +name: Java CI with Gradle on: pull_request: branches: [ "main" ] - workflow_dispatch: jobs: build: From b6295ac528fa1e109fb398beb1ff8e87ead14db8 Mon Sep 17 00:00:00 2001 From: david-parkk Date: Sat, 4 May 2024 00:15:01 +0900 Subject: [PATCH 6/6] =?UTF-8?q?feat=20:=20deploy=20=EC=8A=A4=ED=81=AC?= =?UTF-8?q?=EB=A6=BD=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 71 ++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..6e5d56c --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,71 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. +# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle + +name: Java CD with Gradle + +on: + merge_group: + types: [ checks_requested ] + +jobs: + deploy: + runs-on: ubuntu-latest + permissions: + write-all + #contents: read + + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + + # Configure Gradle for optimal use in GiHub Actions, including caching of downloaded dependencies. + # See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0 + + - name: Build with Gradle Wrapper + run: ./gradlew build + + # dockerfile을 통해 이미지를 빌드하고, 이를 docker repo로 push + - name: Docker build & push to docker repo + run: | + docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + docker build -f Dockerfile -t ${{ secrets.DOCKER_REPO }} . + docker push ${{ secrets.DOCKER_REPO }} + + # appleboy/ssh-action@master 액션을 사용하여 지정한 서버에 ssh로 접속하고, script를 실행합니다. + # script의 내용은 도커의 기존 프로세스들을 제거하고, docker repo로부터 방금 위에서 push한 내용을 pull 받아 실행하는 것입니다. + # 실행 시, docker-compose를 사용합니다. + - name: Deploy to server + uses: appleboy/ssh-action@master + env: + COMPOSE: ${{ secrets.DOCKER_PATH }} + id: deploy + with: + host: ${{ secrets.HOST }} + username: ubuntu + port: 22 + key: ${{ secrets.KEY }} + envs: GITHUB_SHA + script: | + sudo docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + echo ${{secrets.PROJECT_PATH}} + cd ${{secrets.PROJECT_PATH}} + sudo docker-compose stop + + sudo docker rm $(docker ps -a -q) + sudo docker rmi ${{ secrets.DOCKER_USERNAME }}/sample-repository + sudo docker pull ${{ secrets.DOCKER_USERNAME }}/sample-repository + + sudo docker-compose up --build -d