From 8b074859018e97521e84a0859bf5e074e5c21b64 Mon Sep 17 00:00:00 2001 From: LeeShinHaeng Date: Sat, 16 Nov 2024 13:59:12 +0900 Subject: [PATCH 1/6] =?UTF-8?q?chore:=20Dockerfile=20=EB=B0=8F=20CD=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/dev-build-deploy.yml | 62 ++++++++++++++++++++++++++ Dockerfile | 12 +++++ 2 files changed, 74 insertions(+) create mode 100644 .github/workflows/dev-build-deploy.yml create mode 100644 Dockerfile diff --git a/.github/workflows/dev-build-deploy.yml b/.github/workflows/dev-build-deploy.yml new file mode 100644 index 00000000..30d7caf8 --- /dev/null +++ b/.github/workflows/dev-build-deploy.yml @@ -0,0 +1,62 @@ +name: CD using github actions & docker + +on: + pull_request: + branches: [ "main", "develop" ] + +permissions: + contents: read + +jobs: + build-docker-image: + runs-on: ubuntu-latest + steps: + - name: get repo from github + uses: actions/checkout@v3 + + # JDK setting + - uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + + # gradle 빌드 + - name: Setup Gradle + run: chmod +x gradlew + + - name: Build with Gradle Wrapper + run: ./gradlew build -p aics-api -x test + + # DockerHub 로그인 + - name: Docker login + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + # Docker 이미지 빌드 + - name: Docker image build + run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/aics-api:latest . + + # Docker Hub 이미지 푸시 + - name: docker Hub push + run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/aics-api:latest + + deploy-to-dev: + runs-on: ubuntu-latest + needs: build-docker-image + steps: + - name: Deploy to dev + uses: appleboy/ssh-action@v1.1.0 + id: deploy-dev + if: contains(github.ref, 'develop') + with: + host: ${{ secrets.HOST_DEV }} + username: ${{ secrets.USERNAME }} + password: ${{ secrets.PASSWORD }} + port: ${{ secrets.PORT }} + script: | + sudo docker-compose pull ${{ secrets.DOCKERHUB_USERNAME }}/aics-api:latest + sudo docker-compose up -d \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..5dd3f335 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +# Dockerfile +# Java 17 사용 +FROM openjdk:17-jdk-slim + +# 작업 디렉토리 설정 +WORKDIR /app + +# 빌드된 JAR 파일을 이미지에 복사 +COPY aics-api/build/libs/*.jar app.jar + +# 실행 +ENTRYPOINT ["java", "-jar", "app.jar"] From 27b852726898b016748f67be205722bbb7518000 Mon Sep 17 00:00:00 2001 From: LeeShinHaeng Date: Sat, 16 Nov 2024 14:01:28 +0900 Subject: [PATCH 2/6] =?UTF-8?q?chore:=20gitignore=EC=97=90=20docker-compos?= =?UTF-8?q?e=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index c2065bc2..4012a0aa 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,6 @@ out/ ### VS Code ### .vscode/ + +### Docker ### +docker-compose.yml \ No newline at end of file From cddffc598618368fd9b8327ae1a27101f2082b52 Mon Sep 17 00:00:00 2001 From: LeeShinHaeng Date: Sat, 16 Nov 2024 14:28:28 +0900 Subject: [PATCH 3/6] =?UTF-8?q?fix:=20actions=20=EC=A4=91=EB=B3=B5=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/dev-build-deploy.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/dev-build-deploy.yml b/.github/workflows/dev-build-deploy.yml index 30d7caf8..b4b69565 100644 --- a/.github/workflows/dev-build-deploy.yml +++ b/.github/workflows/dev-build-deploy.yml @@ -15,7 +15,6 @@ jobs: uses: actions/checkout@v3 # JDK setting - - uses: actions/checkout@v4 - name: Set up JDK 17 uses: actions/setup-java@v4 with: From 05a79aa6030fbc2ee14ea3ffc4f085bbe2c727fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=ED=95=9C=EC=9D=8C?= Date: Sat, 16 Nov 2024 23:14:05 +0900 Subject: [PATCH 4/6] =?UTF-8?q?refactor:=20=EB=8F=84=EC=BB=A4=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=EC=A7=80=20=ED=83=9C=EA=B9=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .github/workflows/dev-build-deploy.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dev-build-deploy.yml b/.github/workflows/dev-build-deploy.yml index b4b69565..1cb923c9 100644 --- a/.github/workflows/dev-build-deploy.yml +++ b/.github/workflows/dev-build-deploy.yml @@ -37,11 +37,17 @@ jobs: # Docker 이미지 빌드 - name: Docker image build - run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/aics-api:latest . + env: + IMAGE_TAG: ${{ github.sha }} + run: | + docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/aics-api:$IMAGE_TAG . + docker tag ${{ secrets.DOCKERHUB_USERNAME }}/aics-api:$IMAGE_TAG ${{ secrets.DOCKERHUB_USERNAME }}/aics-api:latest # Docker Hub 이미지 푸시 - name: docker Hub push - run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/aics-api:latest + run: | + docker push ${{ secrets.DOCKERHUB_USERNAME }}/aics-api:$IMAGE_TAG + docker push ${{ secrets.DOCKERHUB_USERNAME }}/aics-api:latest deploy-to-dev: runs-on: ubuntu-latest From d596a0e063c2eb4b0d4a8d8f4b2495f7d1023fb2 Mon Sep 17 00:00:00 2001 From: LeeHanEum Date: Mon, 18 Nov 2024 21:56:28 +0900 Subject: [PATCH 5/6] =?UTF-8?q?refactor:=20=EC=88=98=EB=8F=99=20=ED=8A=B8?= =?UTF-8?q?=EB=A6=AC=EA=B1=B0=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/dev-build-deploy.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/dev-build-deploy.yml b/.github/workflows/dev-build-deploy.yml index 1cb923c9..46f51c7c 100644 --- a/.github/workflows/dev-build-deploy.yml +++ b/.github/workflows/dev-build-deploy.yml @@ -1,11 +1,7 @@ name: CD using github actions & docker on: - pull_request: - branches: [ "main", "develop" ] - -permissions: - contents: read + workflow_dispatch: jobs: build-docker-image: From 7cd9400e53f00c9bde96818656c3921ebc735a0d Mon Sep 17 00:00:00 2001 From: LeeHanEum Date: Mon, 18 Nov 2024 22:04:56 +0900 Subject: [PATCH 6/6] =?UTF-8?q?refactor:=20=EC=9D=BC=EB=B6=80=20=EB=84=A4?= =?UTF-8?q?=EC=9D=B4=EB=B0=8D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/dev-build-deploy.yml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/.github/workflows/dev-build-deploy.yml b/.github/workflows/dev-build-deploy.yml index 46f51c7c..43a64065 100644 --- a/.github/workflows/dev-build-deploy.yml +++ b/.github/workflows/dev-build-deploy.yml @@ -1,4 +1,4 @@ -name: CD using github actions & docker +name: Build and Deploy to Dev Server on: workflow_dispatch: @@ -22,7 +22,7 @@ jobs: run: chmod +x gradlew - name: Build with Gradle Wrapper - run: ./gradlew build -p aics-api -x test + run: ./gradlew clean build -p aics-api -x test # DockerHub 로그인 - name: Docker login @@ -51,13 +51,11 @@ jobs: steps: - name: Deploy to dev uses: appleboy/ssh-action@v1.1.0 - id: deploy-dev - if: contains(github.ref, 'develop') with: - host: ${{ secrets.HOST_DEV }} - username: ${{ secrets.USERNAME }} - password: ${{ secrets.PASSWORD }} - port: ${{ secrets.PORT }} + host: ${{ secrets.SERVER_HOST }} + username: ${{ secrets.SERVER_USERNAME }} + password: ${{ secrets.SERVER_PASSWORD }} + port: ${{ secrets.SERVER_PORT }} script: | sudo docker-compose pull ${{ secrets.DOCKERHUB_USERNAME }}/aics-api:latest sudo docker-compose up -d \ No newline at end of file