Skip to content

Commit bdb0751

Browse files
committed
Merge remote-tracking branch 'origin/main' into sprint
# Conflicts: # .github/workflows/release-build.yaml # README.md # RELEASENOTES.md # checkstyle.xml # pom.xml # runLocal.bat # runLocal.sh # src/main/java/de/muenchen/mobidam/Application.java # src/main/resources/application.yml # src/test/resources/application.yml
2 parents 85b4158 + 5c2ca58 commit bdb0751

6 files changed

Lines changed: 286 additions & 0 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Build and publish to demo
2+
3+
on:
4+
workflow_dispatch: # execute manually
5+
schedule: # it's important that the hour in the cron-job is after the hour of project_start_date in step calculate-time-passed
6+
- cron: '0 13 * * 6' # execute automatically every Saturday at 13:00, change!! day of week if needed
7+
8+
env:
9+
SPRINT_LENGTH_IN_WEEKS: 3
10+
11+
jobs:
12+
build-and-docker-push:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Get seconds passed since project start # project_start_date needs to be changed!! if different dispatch day is preferred
18+
id: calculate-time-passed
19+
run: | # 2023-10-28 is a Saturday and is used as the base for calculating the weeks passed
20+
project_start_date=$(echo -n "2023-10-28 10:00") # it's important that the hour in this step is before the hour given in the cron-job
21+
project_start_epoch_seconds=$(date -d "$project_start_date" +%s)
22+
time_passed=$(($(date +"%s")-$project_start_epoch_seconds))
23+
echo "::set-output name=time_passed::$time_passed"
24+
25+
- name: Get number of weeks passed
26+
id: get-number-of-weeks
27+
run: | # 604800 is 1 week in seconds
28+
num_weeks_mod_sprint=$(((${{ steps.calculate-time-passed.outputs.time_passed }}/604800)%${{ env.SPRINT_LENGTH_IN_WEEKS }}))
29+
echo "::set-output name=num_weeks_mod_sprint::$num_weeks_mod_sprint"
30+
31+
- name: Check if job should be run # the automatically triggered actions should only be executed at the end of a sprint
32+
if: github.event_name != 'workflow_dispatch' && steps.get-number-of-weeks.outputs.num_weeks_mod_sprint != 0
33+
run: | # canceling the job if the conditions weren't met, https://stackoverflow.com/a/75809743
34+
gh run cancel ${{ github.run_id }}
35+
gh run watch ${{ github.run_id }}
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
39+
- name: Git checkout to main branch # the workflow is triggered in the default branch, which doesn't have to be MAIN
40+
uses: actions/checkout@v4
41+
with: { ref: main } # this also serves as a safeguard for workflows triggered manually
42+
43+
- name: Set up JDK 17
44+
uses: actions/setup-java@v3
45+
with:
46+
java-version: '17'
47+
distribution: 'temurin'
48+
49+
- name: Build with Maven
50+
run: mvn --update-snapshots -f pom.xml verify
51+
52+
- name: Set up QEMU
53+
uses: docker/setup-qemu-action@v2
54+
55+
- name: Set up Docker Buildx
56+
uses: docker/setup-buildx-action@v2
57+
58+
- name: Login to Registry
59+
uses: docker/login-action@v3
60+
with:
61+
registry: ghcr.io
62+
username: ${{ github.actor }}
63+
password: ${{ secrets.GITHUB_TOKEN }}
64+
65+
- name: Build and push image
66+
uses: docker/build-push-action@v4
67+
with:
68+
context: .
69+
push: true
70+
tags: ghcr.io/it-at-m/mobidam-mobilithek-eai:demo

.gitlab-ci.yml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Reihenfolge für die Ausführung der Schritte
2+
# Bitte keine Stages entfernen, da sonst die Syntax u.U. ungültig wird!
3+
stages:
4+
- codecheck
5+
- build
6+
- test
7+
- dependency-check
8+
- sonar
9+
- deploy
10+
- release
11+
- build-image
12+
- review
13+
- cleanup
14+
- deploy-dev
15+
- integration-test
16+
- deploy-test
17+
- system-test
18+
- deploy-production
19+
20+
# Auswahl der Runner
21+
default:
22+
tags:
23+
- openshift
24+
25+
variables:
26+
# Hinweis: Variable APP_JAR_FILE wird in build.mvn ermittelt, als Umgebungsvariable hinzugefügt und in den mvn-Jobs genutzt
27+
# Basispfad der Anwendung. Wird für den Dateipfad zur JAR-Datei benötigt.
28+
APP_PATH: .
29+
# wenn ein Artifact Deployment stattfinden soll, dann ausklammern.
30+
DISABLE_DEPLOYMENT_ARTIFACTORY: "true"
31+
# Leerzeichen-separierte Liste von SAST Analyzers, welche nicht ausgeführt werden sollen
32+
# Siehe https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Jobs/SAST.gitlab-ci.yml
33+
SAST_EXCLUDED_ANALYZERS: "eslint nodejs-scan semgrep spotbugs"
34+
# Name für Openshift Objekte DeploymentConfig, BuildConfig, ConfigMap, ImageStream
35+
OPENSHIFT_APP_NAME:
36+
# Openshift Namespace der DEV-Umgebung.
37+
OPENSHIFT_DEV_NAMESPACE:
38+
# Umgebungsname für die DEV-Umgebung (wird an DC, BC, CM an den Namen angehängt).
39+
OPENSHIFT_DEV_ENV: dev
40+
# Openshift Namespace der TEST-Umgebung.
41+
OPENSHIFT_TEST_NAMESPACE:
42+
# Umgebungsname für die TEST-Umgebung (wird an DC, BC, CM an den Namen angehängt).
43+
OPENSHIFT_TEST_ENV: test
44+
# Openshift Namespace der PROD-Umgebung.
45+
OPENSHIFT_PROD_NAMESPACE:
46+
# Umgebungsname für die PROD-Umgebung (wird an DC, BC, CM an den Namen angehängt).
47+
OPENSHIFT_PROD_ENV: prod
48+
49+
# Legt das Verhalten in Pipeline in verschiedenen Fällen fest:
50+
# 1. Der Auslöser ist ein Bot und es ist keine Tag-Pipeline:
51+
# Die Pipeline wird nicht gestartet, da es sich hierbei um eine Versionsänderung duch das Maven Release Plugin handelt
52+
# 2. DO_RELEASE ist nicht auf "true" und der Commit kommt von einem Branch oder Tag:
53+
# Das ist der "Normalfall" und die Pipeline wird mit allen notwendigen Variablen gestartet
54+
# 3. DO_RELEASE ist auf "true" und der Commit kommt von einem Branch oder Tag:
55+
# Die Pipeline wird ohne Variablen gestartet, da sie lediglich einen Release durchführen soll
56+
workflow:
57+
rules:
58+
- if: $CI_PIPELINE_SOURCE == "schedule"
59+
variables:
60+
DISABLE_SELENIUM: "true"
61+
DISABLE_OPENSHIFT: "true"
62+
DISABLE_DEPLOYMENT_ARTIFACTORY: "true"
63+
- if: $GITLAB_USER_LOGIN =~ /^project_/ && $CI_COMMIT_TAG == null
64+
when: never
65+
- if: $DO_RELEASE != "true" && ($CI_COMMIT_TAG || $CI_COMMIT_BRANCH)
66+
67+
- if: $DO_RELEASE == "true" && ($CI_COMMIT_TAG || $CI_COMMIT_BRANCH)
68+
variables:
69+
DISABLE_OPENSHIFT: "true"
70+
DISABLE_SONAR: "true"
71+
DISABLE_OWASP: "true"
72+
DISABLE_DEPLOYMENT_ARTIFACTORY: "true"
73+
74+
include:
75+
# Für Branch Pipelines
76+
- template: "Workflows/Branch-Pipelines.gitlab-ci.yml"
77+
78+
- project: "ccse/cicd/gitlab-runner-templates"
79+
ref: "main-2.x"
80+
file:
81+
# Gitlab AutoDevOps Secret Detection (siehe: https://docs.gitlab.com/ee/topics/autodevops/stages.html#auto-secret-detection)
82+
- "SecretDetection.gitlab-ci.yml"
83+
# Gitlab AutoDevOps SAST (siehe: https://docs.gitlab.com/ee/topics/autodevops/stages.html#auto-sast)
84+
- "SAST.gitlab-ci.yml"
85+
# Maven Build (stage: build), Unit-Tests (stage: test) und Artifactory Deployment (stage: deploy-dev)
86+
- "Maven.gitlab-ci.yml"
87+
# Maven Release Plugin
88+
- "MavenRelease.gitlab-ci.yml"
89+
# Codecheck Analyse
90+
- "Codecheck.gitlab-ci.yml"
91+
# Include Sonarqube Step
92+
- "SonarQube.gitlab-ci.yml"
93+
# OWASP Dependency Check
94+
- OWASP-Dependency-Check.gitlab-ci.yml
95+
# Openshift Image Build über S2I und Deployment in Dev (stage: deploy-dev)
96+
- "Openshift-CI.gitlab-ci.yml"
97+
# Deployment (Rollout) in Test (stage: deploy-test) und in Prod (stage: deploy-prod)
98+
- "Openshift-CD.gitlab-ci.yml"
99+
100+
# Der Dependency-Check analysiert verwendete Libraries auf bekannte Schwachstellen.
101+
# SUPPRESSION_FILE kann erweitert werden um eine eigene Custom-Suppressions-Datei,
102+
# indem diese mit Leerzeichen getrennt dahinter geschrieben werden.
103+
dependency-check:
104+
variables:
105+
SUPPRESSION_FILE: "--suppression https://ccse.pages.muenchen.de/refarch-security/backend/suppression-cves.xml"
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c): it@M - Dienstleister für Informations- und Telekommunikationstechnik
3+
* der Landeshauptstadt München, 2023
4+
*/
5+
package de.muenchen.mobidam;
6+
7+
import lombok.RequiredArgsConstructor;
8+
import org.apache.camel.LoggingLevel;
9+
import org.apache.camel.builder.RouteBuilder;
10+
import org.springframework.beans.factory.annotation.Value;
11+
import org.springframework.stereotype.Component;
12+
13+
@Component
14+
@RequiredArgsConstructor
15+
public class MobilithekEaiRouteBuilder extends RouteBuilder {
16+
17+
@Value("${output}")
18+
private String outputRoute;
19+
20+
public static final String DIRECT_ROUTE = "direct:eai-route";
21+
public static final String DIRECT_EXCEPTION = "direct:exception-handler";
22+
23+
@Override
24+
public void configure() {
25+
onException(Exception.class).handled(true).log(LoggingLevel.ERROR, "${exception}");
26+
27+
from(DIRECT_ROUTE)
28+
.routeId("eai-route")
29+
.log(LoggingLevel.DEBUG, "de.muenchen",
30+
"Projekt Camel Routing ergaenzen ... (https://camel.apache.org/components/latest/eips/enterprise-integration-patterns.html).")
31+
.to(outputRoute);
32+
}
33+
34+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
server:
2+
port: 8083
3+
4+
camel:
5+
springboot:
6+
# Sollte sich der Camel Main Thread nach dem Start wieder beenden, folgende Property aktivieren (http://camel.apache.org/spring-boot.html).
7+
main-run-controller: true
8+
tracing: false
9+
10+
info:
11+
application:
12+
version: @project.version@-local

src/main/resources/logback.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration>
3+
4+
<appender name="ConsoleAppender" class="ch.qos.logback.core.ConsoleAppender">
5+
<layout class="ch.qos.logback.classic.PatternLayout">
6+
<Pattern>
7+
%d [%t] %-5level %logger{36} - %msg%n <!-- http://logback.qos.ch/manual/layouts.html -->
8+
</Pattern>
9+
</layout>
10+
</appender>
11+
12+
<root level="info">
13+
<appender-ref ref="ConsoleAppender" />
14+
</root>
15+
<logger name="de.muenchen" level="all" additivity="false">
16+
<appender-ref ref="ConsoleAppender" />
17+
</logger>
18+
19+
</configuration>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c): it@M - Dienstleister für Informations- und Telekommunikationstechnik
3+
* der Landeshauptstadt München, 2021
4+
*/
5+
package de.muenchen.mobidam;
6+
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
9+
import org.apache.camel.EndpointInject;
10+
import org.apache.camel.Produce;
11+
import org.apache.camel.ProducerTemplate;
12+
import org.apache.camel.component.mock.MockEndpoint;
13+
import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
14+
import org.junit.jupiter.api.Test;
15+
import org.springframework.boot.test.context.SpringBootTest;
16+
17+
/**
18+
* Der Test dient der Demonstration wie mit einer beliebigen Testkonfiguration
19+
* (test/application.yml) die
20+
* gesamte EAI vom Start bis zum Shutdown mit einem Testaufruf getestet werden kann.
21+
*/
22+
@SpringBootTest
23+
@CamelSpringBootTest
24+
class MobilithekEaiTest {
25+
26+
@Produce(MobilithekEaiRouteBuilder.DIRECT_ROUTE)
27+
private ProducerTemplate producer;
28+
29+
@EndpointInject("mock:output")
30+
private MockEndpoint output;
31+
32+
@Test
33+
void sendToMockTest() throws InterruptedException {
34+
35+
var message = "Hello Test !";
36+
37+
output.expectedMessageCount(1);
38+
39+
producer.sendBody(message);
40+
41+
output.assertIsSatisfied();
42+
assertEquals(message, output.getExchanges().get(0).getMessage().getBody(String.class));
43+
44+
}
45+
46+
}

0 commit comments

Comments
 (0)