From e0c0a20519426ab9f103bb14885ff773905f4a25 Mon Sep 17 00:00:00 2001 From: derklaro Date: Tue, 26 Nov 2024 22:26:02 +0100 Subject: [PATCH] add deployment config for info collector --- .github/workflows/deploy.yml | 52 +++++++++++++++++++ info-collector/.deploy/Dockerfile | 11 ++++ info-collector/.deploy/app.json | 37 +++++++++++++ info-collector/build.gradle.kts | 9 ++++ ....properties => application-dev.properties} | 0 .../main/resources/application-prd.properties | 47 +++++++++++++++++ 6 files changed, 156 insertions(+) create mode 100644 .github/workflows/deploy.yml create mode 100644 info-collector/.deploy/Dockerfile create mode 100644 info-collector/.deploy/app.json rename info-collector/src/main/resources/{application.properties => application-dev.properties} (100%) create mode 100644 info-collector/src/main/resources/application-prd.properties diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..136b18a --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,52 @@ +name: Deploy Release +on: + workflow_dispatch: + inputs: + api: + type: boolean + description: API + collector: + type: boolean + description: Data-Collector + +concurrency: + cancel-in-progress: true + group: deploy-${{ github.ref }} + +permissions: + contents: read + +jobs: + deploy_api: + runs-on: ubuntu-latest + name: Deploy Rest API + if: ${{ github.event.inputs.api == 'true' }} + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Push to Dokku + uses: dokku/github-action@master + with: + branch: main + git_push_flags: --force + ssh_private_key: ${{ secrets.DOKKU_PRIVATE_KEY }} + git_remote_url: 'ssh://dokku@${{ secrets.DOKKU_HOST }}:22/sit-api' + + deploy_datacollect: + runs-on: ubuntu-latest + name: Deploy Data Collector + if: ${{ github.event.inputs.collector == 'true' }} + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Push to Dokku + uses: dokku/github-action@master + with: + branch: main + git_push_flags: --force + ssh_private_key: ${{ secrets.DOKKU_PRIVATE_KEY }} + git_remote_url: 'ssh://dokku@${{ secrets.DOKKU_HOST }}:22/sit-collector' diff --git a/info-collector/.deploy/Dockerfile b/info-collector/.deploy/Dockerfile new file mode 100644 index 0000000..7997d05 --- /dev/null +++ b/info-collector/.deploy/Dockerfile @@ -0,0 +1,11 @@ +FROM --platform=$BUILDPLATFORM azul/zulu-openjdk:23 AS builder +WORKDIR /build + +COPY ./ ./ +RUN ./gradlew clean buildForDocker -x test -x checkstyleMain -x checkstyleTest --no-daemon + +FROM azul/zulu-openjdk-alpine:23-jre-headless +WORKDIR /app + +COPY --from=builder /build/info-collector/build/libs/docker/info-collector.jar ./ +CMD ["java", "-Duser.timezone=Europe/Berlin", "-Dspring.profiles.active=prd", "-jar", "--enable-preview", "/app/info-collector.jar"] diff --git a/info-collector/.deploy/app.json b/info-collector/.deploy/app.json new file mode 100644 index 0000000..0b08e7d --- /dev/null +++ b/info-collector/.deploy/app.json @@ -0,0 +1,37 @@ +{ + "name": "info-collector", + "description": "Info Collector for SIT", + "repository": "https://github.com/simrailtools/backend", + "addons": [], + "healthchecks": { + "web": [ + { + "wait": 5, + "initialDelay": 3, + "type": "readiness", + "path": "/admin/health", + "name": "container readiness check" + }, + { + "wait": 5, + "type": "liveness", + "path": "/admin/health", + "name": "container liveness check" + } + ] + }, + "env": { + "SPRING_DATASOURCE_URL": { + "required": true, + "description": "The datasource url" + }, + "SPRING_DATASOURCE_USERNAME": { + "required": true, + "description": "The datasource username" + }, + "SPRING_DATASOURCE_PASSWORD": { + "required": true, + "description": "The datasource password" + } + } +} diff --git a/info-collector/build.gradle.kts b/info-collector/build.gradle.kts index 2bee494..c28d38e 100644 --- a/info-collector/build.gradle.kts +++ b/info-collector/build.gradle.kts @@ -74,3 +74,12 @@ protobuf { } } } + +// From StackOverflow: https://stackoverflow.com/a/53087407 +tasks.register("buildForDocker") { + from(tasks.getByName("bootJar")) + into("build/libs/docker") + rename { fileName -> + fileName.replace("-$version", "") + } +} diff --git a/info-collector/src/main/resources/application.properties b/info-collector/src/main/resources/application-dev.properties similarity index 100% rename from info-collector/src/main/resources/application.properties rename to info-collector/src/main/resources/application-dev.properties diff --git a/info-collector/src/main/resources/application-prd.properties b/info-collector/src/main/resources/application-prd.properties new file mode 100644 index 0000000..d6506f3 --- /dev/null +++ b/info-collector/src/main/resources/application-prd.properties @@ -0,0 +1,47 @@ +# +# This file is part of simrail-tools-backend, licensed under the MIT License (MIT). +# +# Copyright (c) 2024 Pasqual Koschmieder and contributors +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +spring.jpa.open-in-view=false +spring.jpa.database=postgresql +spring.jpa.hibernate.ddl-auto=update +spring.jpa.properties.hibernate.order_inserts=true +spring.jpa.properties.hibernate.order_updates=true +spring.jpa.properties.hibernate.jdbc.batch_size=250 + +logging.pattern.console=%yellow(%date{dd.MM.yy HH:mm:ss}) [%highlight(%5p)] %cyan(%-40.40logger{0})[%magenta(%4.4line)]: %msg %ex%n + +server.error.path=/error +server.http2.enabled=true +server.error.whitelabel.enabled=false + +management.endpoint.health.enabled=true +management.endpoint.health.show-details=never +management.endpoint.health.probes.enabled=true +management.endpoint.health.show-components=never +management.endpoint.health.cache.time-to-live=10s + +management.endpoints.web.base-path=/admin +management.endpoints.enabled-by-default=false +management.endpoints.web.exposure.include=health +management.endpoints.web.discovery.enabled=false