From a044ad23fd90585db36a0be43ff5ab9d1c0e2c40 Mon Sep 17 00:00:00 2001 From: WhitePiano Date: Sat, 27 Jan 2024 19:41:40 +0900 Subject: [PATCH] =?UTF-8?q?feat(Dockerfile):=20=EB=B0=B0=ED=8F=AC=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20(#45)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/Continuous Delivery.yml | 47 +++++++++++++++++++++++ .github/workflows/Deploy.yml | 33 ++++++++++++++++ Dockerfile | 9 +++++ src/main/resources/application.yml | 4 +- 4 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/Continuous Delivery.yml create mode 100644 .github/workflows/Deploy.yml create mode 100644 Dockerfile diff --git a/.github/workflows/Continuous Delivery.yml b/.github/workflows/Continuous Delivery.yml new file mode 100644 index 0000000..4a0cea0 --- /dev/null +++ b/.github/workflows/Continuous Delivery.yml @@ -0,0 +1,47 @@ +name: Continuous Delivery + +on: + pull_request: + branches: + - 'main' + +jobs: + Delivery: + runs-on: ubuntu-22.04 + + env: + DB_URL: ${{ secrets.DB_URL }} + DB_USER: ${{ secrets.DB_USR }} + DB_PASSWORD: ${{ secrets.DB_PWD }} + + steps: + - name: Set up sources + uses: actions/checkout@v4 + with: + token: ${{ secrets.GH_TOKEN }} + submodules: true + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: 17 + distribution: corretto + cache: gradle + + - name: Setup Gradle + uses: gradle/gradle-build-action@v2 + + - name: Execute Gradle build + run: ./gradlew build + + - name: Login to docker-hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build Docker Image + run: docker build --tag goldentrash/plantory:latest . + + - name: Push docker image + run: docker push goldentrash/plantory:latest diff --git a/.github/workflows/Deploy.yml b/.github/workflows/Deploy.yml new file mode 100644 index 0000000..52a4e29 --- /dev/null +++ b/.github/workflows/Deploy.yml @@ -0,0 +1,33 @@ +name: Deploy + +on: + pull_request: + types: + - closed + branches: + - 'main' + +jobs: + Deploy: + if: github.event.pull_request.merged == true + runs-on: ubuntu-22.04 + + steps: + # Needed for `google-github-actions` + - uses: 'actions/checkout@v4' + + - name: Login to Google + uses: google-github-actions/auth@v2 + with: + credentials_json: ${{ secrets.GCP_CREDENTIALS }} + + - name: Update docker container + uses: google-github-actions/ssh-compute@v1 + with: + instance_name: plantory + zone: asia-northeast3-a + ssh_private_key: ${{ secrets.GCP_SSH_KEY }} + command: | + docker pull goldentrash/plantory:latest + docker stop plantory + docker run -d --rm -p 8080:8080 --mount type=volume,src=resources,dst=/app/resources --name plantory goldentrash/plantory diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ec40d81 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +# syntax=docker/dockerfile:1 + +FROM amazoncorretto:17-alpine + +WORKDIR /app +COPY /build/libs/plantory-*-SNAPSHOT.jar app.jar + +EXPOSE 8080 +ENTRYPOINT ["java", "-jar", "app.jar"] diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 1d46cf0..1a6e4f8 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -3,7 +3,7 @@ spring: database: mysql database-platform: org.hibernate.dialect.MySQLDialect hibernate: - ddl-auto: create + ddl-auto: validate properties: hibernate: format_sql: true @@ -22,7 +22,7 @@ spring: local: image: - root: src/test/resources + root: resources companionPlant: image: