Skip to content

Commit

Permalink
Merge pull request #3 from swisscom/feature/release-pipeline
Browse files Browse the repository at this point in the history
publish release and develop changes. Updates logback configuration
  • Loading branch information
Lesrac authored Jul 1, 2024
2 parents c772d46 + 40ff50f commit 25e2a98
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 73 deletions.
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Only the specified owner can approve changes to workflow files
/.github/workflows/ @swisscom/swisscom-health
35 changes: 35 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Publish release

on:
push:
branches:
- develop
release:
types: [created]

jobs:
publish-release:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout latest code
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17

# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies.
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
- name: Setup Gradle
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0

- name: Build and publish with Gradle Wrapper
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew clean build publishVersion
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,17 @@ client:
source-folder: /tmp/source/8000000000000
mode: test
```

## Running the Jar
If the provided jar should be run directly, the following command can be used:
```java -jar cdr-client.jar```
The jar can be found in build/libs.

Following environment variables need to be present (and correctly configured) so that the application can start successfully:
```
SPRING_CONFIG_ADDITIONAL_LOCATION={{ cdr_client_dir }}/config/application-customer.yaml"
LOGGING_FILE_NAME={{ cdr_client_dir }}/logs/cdr-client.log"
```
The LOGGING_FILE_NAME is just so that the log file is not auto created where the jar is run from.

See [Application Plugin](#application-plugin) regarding the content of the application-customer.yaml
30 changes: 29 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import io.gitlab.arturbosch.detekt.Detekt
import org.springframework.boot.gradle.tasks.bundling.BootJar
import java.net.URI

group = "com.swisscom.health.des.cdr"
version = "2.1.2-SNAPSHOT"
version = "3.0.0-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_17

val jvmVersion: String by project
Expand Down Expand Up @@ -184,3 +185,30 @@ project.afterEvaluate {
}
}
}

tasks.register("publishVersion") {
group = "publishing"
description = "Publishes boot jar"
dependsOn(tasks.withType<PublishToMavenRepository>().matching {
it.repository == publishing.repositories["GitHubPackages"] && it.publication == publishing.publications["bootJava"]
})
}


publishing {
publications {
create<MavenPublication>("bootJava") {
artifact(tasks.named("bootJar"))
}
}
repositories {
maven {
name = "GitHubPackages"
url = URI("https://maven.pkg.github.com/swisscom/cdr-client")
credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
}
}
}
}
129 changes: 57 additions & 72 deletions src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -1,81 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true">

<logger name="org.springframework" level="INFO" />
<logger name="org.springframework" level="INFO"/>

<property name="LOG_LEVEL_PATTERN" value="%highlight(%level)" />
<property name="LOG_EXCEPTION_CONVERSION_WORD" value="%rEx" />
<property name="LOG_LEVEL_PATTERN" value="%highlight(%level)"/>
<property name="LOG_EXCEPTION_CONVERSION_WORD" value="%rEx"/>

<springProfile name="!any">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%highlight(%d{"yyyy-MM-dd'T'HH:mm:ss.SSSXXX", UTC}) | %highlight(${LOG_LEVEL_PATTERN:-%5p}) | %highlight(%magenta(${PID:- })) | %highlight(%yellow(%X{traceId:-None})) | %highlight([%15.15t]) | %highlight(%cyan(%-40.40logger{39})) | %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%ex}
</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</springProfile>
<appender name="ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOGGING_FILE_NAME:-./cdr-client.log}</file>
<append>true</append>

<springProfile name="customer">
<appender name="ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOGGING_FILE_NAME:-./cdr-client.log}</file>
<append>true</append>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOGGING_FILE_NAME:-./cdr-client.log}.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxFileSize>${LOGGING_LOGBACK_ROLLINGPOLICY_MAX_FILE_SIZE:-100MB}</maxFileSize>
<maxHistory>${LOGGING_LOGBACK_ROLLINGPOLICY_MAX_HISTORY:-2}</maxHistory>
</rollingPolicy>

<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOGGING_FILE_NAME:-./cdr-client.log}.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxFileSize>${LOGGING_LOGBACK_ROLLINGPOLICY_MAX_FILE_SIZE:-100MB}</maxFileSize>
<maxHistory>${LOGGING_LOGBACK_ROLLINGPOLICY_MAX_HISTORY:-2}</maxHistory>
</rollingPolicy>

<encoder>
<pattern>%d{"yyyy-MM-dd'T'HH:mm:ss.SSSXXX", UTC} | ${%level:-%5p} | ${PID:- } | %X{traceId:-None} | [%15.15t] | %-40.40logger{39} | %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%ex}
</pattern>
</encoder>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers>
<timestamp>
<fieldName>timestamp</fieldName>
<timeZone>UTC</timeZone>
</timestamp>
<loggerName>
<fieldName>logger</fieldName>
</loggerName>
<logLevel>
<fieldName>level</fieldName>
</logLevel>
<threadName>
<fieldName>thread</fieldName>
</threadName>
<nestedField>
<fieldName>mdc</fieldName>
<providers>
<mdc />
</providers>
</nestedField>
<stackTrace>
<fieldName>stackTrace</fieldName>
<!-- maxLength - limit the length of the stack trace -->
<throwableConverter class="net.logstash.logback.stacktrace.ShortenedThrowableConverter">
<maxDepthPerThrowable>200</maxDepthPerThrowable>
<maxLength>14000</maxLength>
<rootCauseFirst>true</rootCauseFirst>
</throwableConverter>
</stackTrace>
<message />
<throwableClassName>
<fieldName>exceptionClass</fieldName>
</throwableClassName>
</providers>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="ROLLING" />
<appender-ref ref="STDOUT" />
</root>
</springProfile>
<encoder>
<pattern>%d{"yyyy-MM-dd'T'HH:mm:ss.SSSXXX", UTC} | ${%level:-%5p} | ${PID:- } | %X{traceId:-None} | [%15.15t] | %-40.40logger{39} | %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%ex}</pattern>
</encoder>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers>
<timestamp>
<fieldName>timestamp</fieldName>
<timeZone>UTC</timeZone>
</timestamp>
<loggerName>
<fieldName>logger</fieldName>
</loggerName>
<logLevel>
<fieldName>level</fieldName>
</logLevel>
<threadName>
<fieldName>thread</fieldName>
</threadName>
<nestedField>
<fieldName>mdc</fieldName>
<providers>
<mdc/>
</providers>
</nestedField>
<stackTrace>
<fieldName>stackTrace</fieldName>
<!-- maxLength - limit the length of the stack trace -->
<throwableConverter class="net.logstash.logback.stacktrace.ShortenedThrowableConverter">
<maxDepthPerThrowable>200</maxDepthPerThrowable>
<maxLength>14000</maxLength>
<rootCauseFirst>true</rootCauseFirst>
</throwableConverter>
</stackTrace>
<message/>
<throwableClassName>
<fieldName>exceptionClass</fieldName>
</throwableClassName>
</providers>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="ROLLING"/>
<appender-ref ref="STDOUT"/>
</root>

</configuration>

0 comments on commit 25e2a98

Please sign in to comment.