From 85b5f92fb3b2a7685a940a0e6dc9162295d1aba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9C=A0=EB=8F=84=EC=A7=84?= Date: Sun, 12 Nov 2023 17:00:54 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[etc]=20etc=20tag=20maintanance=EB=A1=9C=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20(#43)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/release-drafter.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index 0ed1e2d..87582c0 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -12,6 +12,7 @@ categories: - 'test' - 'style' - 'refactor' + - 'etc' change-template: '- $TITLE (#$NUMBER) @$AUTHOR ' change-title-escapes: '\<*_&' From 6164b0b7f10eba9c977404cd9bf6becbef7e3e0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9C=A0=EB=8F=84=EC=A7=84?= Date: Sun, 12 Nov 2023 21:04:19 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[etc]=20=EB=B0=B0=ED=8F=AC=20=EC=A4=80?= =?UTF-8?q?=EB=B9=84=20(#42)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 77 +++++++++++++++++++++ Dockerfile | 19 +++++ build.gradle.kts | 10 ++- compose.yaml | 13 ++++ gradle.properties | 2 +- src/main/resources/application.yml | 15 +++- src/main/resources/logback/logback-prod.xml | 46 ++++++++++++ 7 files changed, 178 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/deploy.yml create mode 100644 Dockerfile create mode 100644 src/main/resources/logback/logback-prod.xml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..2ed6be1 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,77 @@ +name: Release Deploy + +on: + push: + branches: [ "release" ] + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'corretto' + cache: "gradle" + + - name: Build with Gradle + run: ./gradlew clean build --no-daemon --exclude-task test + + - name: Login To DockerHub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + push: true + build-args: | + DB_URL=${{ secrets.DB_URL }} + DB_USERNAME=${{ secrets.DB_USERNAME }} + DB_PASSWORD=${{ secrets.DB_PASSWORD }} + tags: | + eatda/api-server:latest + + - name: Get Github IP + id: ip + uses: haythem/public-ip@v1.2 + + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-region: ${{ secrets.AWS_REGION } + role-to-assume: ${{ secrets.AWS_ARN_ROLE_TO_ASSUME } + + - name: Add GitHub IP to AWS + run: | + aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port ${{ secrets.EC2_SSH_PORT }} --cidr ${{ steps.ip.outputs.ipv4 }}/32 + + - name: Deploy + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USERNAME }} + password: ${{ secrets.EC2_PASSWORD }} + port: ${{ secrets.EC2_SSH_PORT }} + timeout: 60s + script: | + cd eatda-api-server/ + sudo docker rm - f $(docker ps -qa) + sudo docker pull eatda/api-server:latest + sudo docker stop $(sudo docker ps -aq) + sudo docker run -d eatda/api-server:latest \ + --name api-server \ + -p 8080:8080 \ + + - name: Remove IP FROM security group + run: | + aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port ${{ secrets.EC2_SSH_PORT }} --cidr ${{ steps.ip.outputs.ipv4 }}/32 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e5bf806 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM amazoncorretto:17-alpine + +CMD ["./gradlew", "clean", "build"] +EXPOSE 8080 + +ARG JAR_FILE=build/libs/*.jar +ARG PROFILE=prod +ARG DB_URL +ARG DB_USERNAME +ARG DB_PASSWORD + +COPY ${JAR_FILE} app.jar + +ENV PROFILE=${PROFILE} +ENV DB_URL=${DB_URL} +ENV DB_USERNAME=${DB_USERNAME} +ENV DB_PASSWORD=${DB_PASSWORD} + +ENTRYPOINT ["java", "-jar", "-Dspring.profiles.active=${PROFILE}", "-Djava.security.egd=file:/dev/./urandom", "/app.jar"] diff --git a/build.gradle.kts b/build.gradle.kts index 26e0399..669611f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,8 +1,8 @@ import com.epages.restdocs.apispec.gradle.OpenApi3Task -import org.gradle.internal.impldep.org.junit.experimental.categories.Categories.CategoryFilter.exclude import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jooq.meta.jaxb.Logging +import org.springframework.boot.gradle.tasks.bundling.BootJar plugins { id("org.springframework.boot") @@ -27,6 +27,14 @@ val autoParamsVersion = "${property("autoParamsVersion")}" val jacocoVersion = "${property("jacocoVersion")}" val jooqVersion = "${property("jooqVersion")}" +tasks.withType { + enabled = false +} + +tasks.withType { + enabled = true +} + java { sourceCompatibility = JavaVersion.valueOf("VERSION_$javaVersion") } diff --git a/compose.yaml b/compose.yaml index d660e90..b9b3f34 100644 --- a/compose.yaml +++ b/compose.yaml @@ -14,5 +14,18 @@ services: - "15432:5432" restart: always + server: + image: eatda-docker-test:0.0.2 + container_name: server + environment: + PROFILE: prod + DB_URL: jdbc:postgresql://db:5432/eatda + DB_USERNAME: local + DB_PASSWORD: local + ports: + - "18080:8080" + depends_on: + - db + volumes: postgres: diff --git a/gradle.properties b/gradle.properties index e9ca100..a3862b4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ ### Application version ### -applicationVersion=0.0.1-SNAPSHOT +applicationVersion=0.1.0-RELEASE ### Project configs ### projectGroup="com.mjucow" diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 244c109..277b32f 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -45,12 +45,23 @@ spring: config: activate: on-profile: prod + jpa: + open-in-view: false + generate-ddl: false + hibernate: + ddl-auto: none datasource: + driver-class-name: org.postgresql.Driver + url: ${DB_URL} + username: ${DB_USERNAME} + password: ${DB_PASSWORD} hikari: - driver-class-name: maximum-pool-size: 25 connection-timeout: 1100 keepalive-time: 30000 validation-timeout: 1000 - max-lifetime: 600000 \ No newline at end of file + max-lifetime: 600000 + + jooq: + sql-dialect: postgres diff --git a/src/main/resources/logback/logback-prod.xml b/src/main/resources/logback/logback-prod.xml new file mode 100644 index 0000000..42c0ed9 --- /dev/null +++ b/src/main/resources/logback/logback-prod.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + ${CONSOLE_LOG_PATTERN} + + + + + + 512 + 0 + false + true + 1000 + + + + + ${LOGS_ABSOLUTE_PATH}/logback.log + + ${FILE_LOG_PATTERN} + + + logFile.%d{yyyy-MM-dd}.log + 30 + 3GB + + + + + + + + +