From 8790d988d22eb03532539351892a0f156114e472 Mon Sep 17 00:00:00 2001 From: kangjunhyuk Date: Tue, 31 Dec 2024 00:42:42 +0900 Subject: [PATCH 01/15] =?UTF-8?q?Feat=20:=20docker=20=EC=85=8B=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 7 +++ .../workflows/docker-multi-stage-build.yml | 57 +++++++++++++++++++ Docker-compose.yml | 38 +++++++++++++ Dockerfile | 7 +++ .../trello/TrelloApplicationTests.java | 13 ----- 5 files changed, 109 insertions(+), 13 deletions(-) create mode 100644 .env create mode 100644 .github/workflows/docker-multi-stage-build.yml create mode 100644 Docker-compose.yml create mode 100644 Dockerfile delete mode 100644 src/test/java/com/example/trello/TrelloApplicationTests.java diff --git a/.env b/.env new file mode 100644 index 0000000..06449ad --- /dev/null +++ b/.env @@ -0,0 +1,7 @@ +DB_NAME=${{ secrets.DB_NAME }} +DB_USERNAME=${{ secrets.DB_PASSWORD }} +DB_PASSWORD=${{ secrets.DB_USERNAME }} + +BUCKET_ACCESSKEY=${{ secrets.BUCKET_ACCESSORY }} +BUCKET_SECRETKEY=${{ secrets.BUCKET_SECRETARY }} +BUCKET_NAME=${{ secrets.BUCKET_NAME }} \ No newline at end of file diff --git a/.github/workflows/docker-multi-stage-build.yml b/.github/workflows/docker-multi-stage-build.yml new file mode 100644 index 0000000..275918f --- /dev/null +++ b/.github/workflows/docker-multi-stage-build.yml @@ -0,0 +1,57 @@ +name: docker-multi-stage-build.yml + +on: + push: + branches: [ main ] # 해당 branch에 push 되었을 경우 + + # https://github.com/marketplace/actions/build-and-push-docker-images +jobs: + docker-build-and-push: + runs-on: ubuntu-latest + steps: + - + name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ vars.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - + name: Set up Docker Builds + uses: docker/setup-buildx-action@v3 + - + name: Build and push + uses: docker/build-push-action@v6 + with: + file: ./docker/Dockerfile + push: true + tags: ${{ vars.DOCKERHUB_USERNAME }}/${{ vars.DOCKER_IMAGE_TAG_NAME }}:latest + # Ec2 에 배포 + deploy-to-ec2: + needs: docker-build-and-push + runs-on: ubuntu-latest + # https://github.com/marketplace/actions/ssh-remote-commands + steps: + - name: Deploy to EC2 + uses: appleboy/ssh-action@v1.2.0 + with: + host: ${{ vars.EC2_HOST }} + username: ${{ vars.EC2_USER }} + key: ${{ vars.EC2_KEY }} + script: | + # 기존 컨테이너 중지 및 제거 + CONTAINER_ID=$(sudo docker ps -q --filter "publish=8080-8080") + if [ ! -z "$CONTAINER_ID" ]; then + sudo docker stop $CONTAINER_ID + sudo docker rm $CONTAINER_ID + fi + + # 새 이미지 Pull 및 실행 + sudo docker pull ${{ vars.DOCKERHUB_USERNAME }}/${{ vars.DOCKER_IMAGE_TAG_NAME }}:latest + sudo docker run -d -p 8080:8080 \ + -e DB_USERNAME=${{vars.DB_USERNAME}} \ + -e DB_PASSWORD=${{vars.DB_PASSWORD}} \ + -e DB_URL=${{vars.DB_URL}} \ + ${{ vars.DOCKERHUB_USERNAME }}/${{ vars.DOCKER_IMAGE_TAG_NAME }}:latest diff --git a/Docker-compose.yml b/Docker-compose.yml new file mode 100644 index 0000000..279e68d --- /dev/null +++ b/Docker-compose.yml @@ -0,0 +1,38 @@ +version: '3' +services: + app: + image: trello:latest + build: + context: . + dockerfile: Dockerfile + ports: + - "8080:8080" + environment: + BUCKET_ACCESSKEY: ${BUCKET_ACCESSKEY} + BUCKET_SECRETKEY: ${BUCKET_SECRETKEY} + BUCKET_NAME: ${BUCKET_NAME} + SPRING_DATASOURCE_URL: jdbc:mysql://db:3306/trello?serverTimezone=Asia/Seoul&useSSL=false&allowPublicKeyRetrieval=true + SPRING_DATASOURCE_USERNAME: root + SPRING_DATASOURCE_PASSWORD: 1111 + depends_on: + - db + + db: + image: mysql:8.0 + container_name: my-mysql + environment: + MYSQL_ROOT_PASSWORD: 1111 + MYSQL_DATABASE: trello + MYSQL_USER: demo + MYSQL_PASSWORD: demo + ports: + - "3307:3306" + volumes: + - db_data:/var/lib/mysql + command: + - --character-set-server=utf8mb4 + - --collation-server=utf8mb4_unicode_ci + - --default-authentication-plugin=mysql_native_password + +volumes: + db_data: \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ee0d4eb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM eclipse-temurin:17-jdk-alpine + +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/src/test/java/com/example/trello/TrelloApplicationTests.java b/src/test/java/com/example/trello/TrelloApplicationTests.java deleted file mode 100644 index 6281f09..0000000 --- a/src/test/java/com/example/trello/TrelloApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.example.trello; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class TrelloApplicationTests { - - @Test - void contextLoads() { - } - -} From 9282c91e2037491a7ac71f515093cb2349dcf931 Mon Sep 17 00:00:00 2001 From: kangjunhyuk1 Date: Tue, 31 Dec 2024 00:48:45 +0900 Subject: [PATCH 02/15] Update gradle-publish.yml --- .github/workflows/gradle-publish.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/gradle-publish.yml b/.github/workflows/gradle-publish.yml index aafd8b3..4b6a94a 100644 --- a/.github/workflows/gradle-publish.yml +++ b/.github/workflows/gradle-publish.yml @@ -1,9 +1,3 @@ -# 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 package using Gradle and then publish it to GitHub packages when a release is created -# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Publishing-using-gradle name: Gradle Package From 60d7843300662604690a69e0a93f910689947b0a Mon Sep 17 00:00:00 2001 From: kangjunhyuk Date: Tue, 31 Dec 2024 00:50:56 +0900 Subject: [PATCH 03/15] Feat : --- .../workflows/docker-multi-stage-build.yml | 57 ------------------- .github/workflows/gradle-publish.yml | 6 -- 2 files changed, 63 deletions(-) delete mode 100644 .github/workflows/docker-multi-stage-build.yml diff --git a/.github/workflows/docker-multi-stage-build.yml b/.github/workflows/docker-multi-stage-build.yml deleted file mode 100644 index 275918f..0000000 --- a/.github/workflows/docker-multi-stage-build.yml +++ /dev/null @@ -1,57 +0,0 @@ -name: docker-multi-stage-build.yml - -on: - push: - branches: [ main ] # 해당 branch에 push 되었을 경우 - - # https://github.com/marketplace/actions/build-and-push-docker-images -jobs: - docker-build-and-push: - runs-on: ubuntu-latest - steps: - - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ vars.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Builds - uses: docker/setup-buildx-action@v3 - - - name: Build and push - uses: docker/build-push-action@v6 - with: - file: ./docker/Dockerfile - push: true - tags: ${{ vars.DOCKERHUB_USERNAME }}/${{ vars.DOCKER_IMAGE_TAG_NAME }}:latest - # Ec2 에 배포 - deploy-to-ec2: - needs: docker-build-and-push - runs-on: ubuntu-latest - # https://github.com/marketplace/actions/ssh-remote-commands - steps: - - name: Deploy to EC2 - uses: appleboy/ssh-action@v1.2.0 - with: - host: ${{ vars.EC2_HOST }} - username: ${{ vars.EC2_USER }} - key: ${{ vars.EC2_KEY }} - script: | - # 기존 컨테이너 중지 및 제거 - CONTAINER_ID=$(sudo docker ps -q --filter "publish=8080-8080") - if [ ! -z "$CONTAINER_ID" ]; then - sudo docker stop $CONTAINER_ID - sudo docker rm $CONTAINER_ID - fi - - # 새 이미지 Pull 및 실행 - sudo docker pull ${{ vars.DOCKERHUB_USERNAME }}/${{ vars.DOCKER_IMAGE_TAG_NAME }}:latest - sudo docker run -d -p 8080:8080 \ - -e DB_USERNAME=${{vars.DB_USERNAME}} \ - -e DB_PASSWORD=${{vars.DB_PASSWORD}} \ - -e DB_URL=${{vars.DB_URL}} \ - ${{ vars.DOCKERHUB_USERNAME }}/${{ vars.DOCKER_IMAGE_TAG_NAME }}:latest diff --git a/.github/workflows/gradle-publish.yml b/.github/workflows/gradle-publish.yml index aafd8b3..4b6a94a 100644 --- a/.github/workflows/gradle-publish.yml +++ b/.github/workflows/gradle-publish.yml @@ -1,9 +1,3 @@ -# 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 package using Gradle and then publish it to GitHub packages when a release is created -# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Publishing-using-gradle name: Gradle Package From 5af98d90000f7ba6ac5dbb501f78d9648e35416e Mon Sep 17 00:00:00 2001 From: kangjunhyuk1 Date: Tue, 31 Dec 2024 00:58:58 +0900 Subject: [PATCH 04/15] Update gradle-publish.yml From c80c6171da3837365eda2f61732d3d872adb4f11 Mon Sep 17 00:00:00 2001 From: kangjunhyuk Date: Tue, 31 Dec 2024 01:04:06 +0900 Subject: [PATCH 05/15] =?UTF-8?q?Feat=20:=201=EC=B0=A8=20=EC=8B=9C?= =?UTF-8?q?=EB=8F=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 1 + 1 file changed, 1 insertion(+) diff --git a/.env b/.env index 06449ad..db4d196 100644 --- a/.env +++ b/.env @@ -2,6 +2,7 @@ DB_NAME=${{ secrets.DB_NAME }} DB_USERNAME=${{ secrets.DB_PASSWORD }} DB_PASSWORD=${{ secrets.DB_USERNAME }} + BUCKET_ACCESSKEY=${{ secrets.BUCKET_ACCESSORY }} BUCKET_SECRETKEY=${{ secrets.BUCKET_SECRETARY }} BUCKET_NAME=${{ secrets.BUCKET_NAME }} \ No newline at end of file From 911d30b32819d5dd6ef1d6f83ca956bc08429bda Mon Sep 17 00:00:00 2001 From: kangjunhyuk1 Date: Tue, 31 Dec 2024 01:04:59 +0900 Subject: [PATCH 06/15] Update gradle-publish.yml --- .github/workflows/gradle-publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gradle-publish.yml b/.github/workflows/gradle-publish.yml index 4b6a94a..570ae16 100644 --- a/.github/workflows/gradle-publish.yml +++ b/.github/workflows/gradle-publish.yml @@ -45,7 +45,7 @@ jobs: if [ ! -z "$CONTAINER_ID" ]; then sudo docker stop $CONTAINER_ID sudo docker rm $CONTAINER_ID - fi + # 새 이미지 Pull 및 실행 sudo docker pull ${{ vars.DOCKERHUB_USERNAME }}/${{ vars.DOCKER_IMAGE_TAG_NAME }}:latest From 5d8f2c0a055b70ff16e134c3ad782596287b75e5 Mon Sep 17 00:00:00 2001 From: kangjunhyuk Date: Tue, 31 Dec 2024 01:05:37 +0900 Subject: [PATCH 07/15] =?UTF-8?q?Feat=20:=202=EC=B0=A8=20=EC=8B=9C?= =?UTF-8?q?=EB=8F=84?= 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 ee0d4eb..a4a1865 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,4 +4,4 @@ ARG JAR_FILE=build/libs/*.jar COPY ${JAR_FILE} app.jar -ENTRYPOINT ["java", "-jar", "/app.jar"] \ No newline at end of file +ENTRYPOINT ["java", "-jar", "/app.jar"] From 86cce1d02f4f03b1c9cca7bd5b403f24b6f058de Mon Sep 17 00:00:00 2001 From: kangjunhyuk1 Date: Tue, 31 Dec 2024 01:06:42 +0900 Subject: [PATCH 08/15] Update gradle-publish.yml --- .github/workflows/gradle-publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gradle-publish.yml b/.github/workflows/gradle-publish.yml index 570ae16..4b6a94a 100644 --- a/.github/workflows/gradle-publish.yml +++ b/.github/workflows/gradle-publish.yml @@ -45,7 +45,7 @@ jobs: if [ ! -z "$CONTAINER_ID" ]; then sudo docker stop $CONTAINER_ID sudo docker rm $CONTAINER_ID - + fi # 새 이미지 Pull 및 실행 sudo docker pull ${{ vars.DOCKERHUB_USERNAME }}/${{ vars.DOCKER_IMAGE_TAG_NAME }}:latest From 88ff1db1f8361c2970b3ef7a5c01271e88385307 Mon Sep 17 00:00:00 2001 From: kangjunhyuk1 Date: Tue, 31 Dec 2024 01:56:46 +0900 Subject: [PATCH 09/15] Update gradle-publish.yml --- .github/workflows/gradle-publish.yml | 40 +++++++++++++--------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/.github/workflows/gradle-publish.yml b/.github/workflows/gradle-publish.yml index 4b6a94a..5d912d2 100644 --- a/.github/workflows/gradle-publish.yml +++ b/.github/workflows/gradle-publish.yml @@ -1,9 +1,9 @@ +name: docker multi-stage build -name: Gradle Package - -on: [push] +on: [ push ] # 해당 branch에 push 되었을 경우 # https://github.com/marketplace/actions/build-and-push-docker-images + jobs: docker-build-and-push: runs-on: ubuntu-latest @@ -13,12 +13,12 @@ jobs: uses: docker/login-action@v3 with: username: ${{ vars.DOCKERHUB_USERNAME }} - password: ${{ vars.DOCKERHUB_TOKEN }} + password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Set up QEMU uses: docker/setup-qemu-action@v3 - - name: Set up Docker Builds + name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Build and push @@ -36,21 +36,17 @@ jobs: - name: Deploy to EC2 uses: appleboy/ssh-action@v1.2.0 with: - host: ${{ vars.EC2_HOST }} - username: ${{ vars.EC2_USER }} - key: ${{ vars.EC2_KEY }} + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USER }} + key: ${{ secrets.EC2_KEY }} script: | - # 기존 컨테이너 중지 및 제거 - CONTAINER_ID=$(sudo docker ps -q --filter "publish=8080-8080") - if [ ! -z "$CONTAINER_ID" ]; then - sudo docker stop $CONTAINER_ID - sudo docker rm $CONTAINER_ID - fi - - # 새 이미지 Pull 및 실행 - sudo docker pull ${{ vars.DOCKERHUB_USERNAME }}/${{ vars.DOCKER_IMAGE_TAG_NAME }}:latest - sudo docker run -d -p 8080:8080 \ - -e DB_USERNAME=${{vars.DB_USERNAME}} \ - -e DB_PASSWORD=${{vars.DB_PASSWORD}} \ - -e DB_URL=${{vars.DB_URL}} \ - ${{ vars.DOCKERHUB_USERNAME }}/${{ vars.DOCKER_IMAGE_TAG_NAME }}:latest + CONTAINER_ID=$(sudo docker ps -q --filter "publish=8080-8080") + + if [ ! -z "$CONTAINER_ID" ]; then + sudo docker stop $CONTAINER_ID + sudo docker rm $CONTAINER_ID + fi + + sudo docker pull ${{ vars.DOCKERHUB_USERNAME }}/${{ vars.DOCKER_IMAGE_TAG_NAME }}:latest + sudo docker run -d -p 8080:8080 \ + ${{ vars.DOCKERHUB_USERNAME }}/${{ vars.DOCKER_IMAGE_TAG_NAME }}:latest From 62e6d23453aa2f187c628d23d2a01fc400e96d1d Mon Sep 17 00:00:00 2001 From: kangjunhyuk Date: Tue, 31 Dec 2024 01:56:57 +0900 Subject: [PATCH 10/15] =?UTF-8?q?Feat=20:=204=EC=B0=A8=20=EC=8B=9C?= =?UTF-8?q?=EB=8F=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index a4a1865..c23c73c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,3 +5,5 @@ ARG JAR_FILE=build/libs/*.jar COPY ${JAR_FILE} app.jar ENTRYPOINT ["java", "-jar", "/app.jar"] + + From 5ef68ca1b17e5a4785e28aa055e272c5e8d94542 Mon Sep 17 00:00:00 2001 From: kangjunhyuk Date: Tue, 31 Dec 2024 02:03:12 +0900 Subject: [PATCH 11/15] =?UTF-8?q?Feat=20:=205=EC=B0=A8=20=EC=8B=9C?= =?UTF-8?q?=EB=8F=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index c23c73c..fd2b73e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,3 +7,4 @@ COPY ${JAR_FILE} app.jar ENTRYPOINT ["java", "-jar", "/app.jar"] + From 79d6612bed58be52fa70bb2ca517cd4a45053f64 Mon Sep 17 00:00:00 2001 From: kangjunhyuk Date: Tue, 31 Dec 2024 02:08:49 +0900 Subject: [PATCH 12/15] =?UTF-8?q?Feat=20:=206=EC=B0=A8=20=EC=8B=9C?= =?UTF-8?q?=EB=8F=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index fd2b73e..144ae86 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,3 +8,4 @@ ENTRYPOINT ["java", "-jar", "/app.jar"] + From 9531a515616f2b0758e89ca6736e7a63ea6bfdc3 Mon Sep 17 00:00:00 2001 From: kangjunhyuk Date: Tue, 31 Dec 2024 02:30:30 +0900 Subject: [PATCH 13/15] =?UTF-8?q?Feat=20:=207=EC=B0=A8=20=EC=8B=9C?= =?UTF-8?q?=EB=8F=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 144ae86..12fc962 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,3 +9,4 @@ ENTRYPOINT ["java", "-jar", "/app.jar"] + From 1d418c4038ce878f8ba497fc95739c888af34d2f Mon Sep 17 00:00:00 2001 From: kangjunhyuk Date: Tue, 31 Dec 2024 02:33:49 +0900 Subject: [PATCH 14/15] =?UTF-8?q?Feat=20:=208=EC=B0=A8=20=EC=8B=9C?= =?UTF-8?q?=EB=8F=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 12fc962..9aa7c6b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,3 +10,4 @@ ENTRYPOINT ["java", "-jar", "/app.jar"] + From 3a4faf101ebe0a07835a83824ee51bff6d432070 Mon Sep 17 00:00:00 2001 From: kangjunhyuk Date: Tue, 31 Dec 2024 02:40:42 +0900 Subject: [PATCH 15/15] =?UTF-8?q?Feat=20:=209=EC=B0=A8=20=EC=8B=9C?= =?UTF-8?q?=EB=8F=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 9aa7c6b..5f24a4c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,3 +11,4 @@ ENTRYPOINT ["java", "-jar", "/app.jar"] +