From c181500a1d3055f162857c86b74c1f81130f9b7d Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Mon, 14 Oct 2024 10:36:50 +0200 Subject: [PATCH] feature/add-jenkinsfile (#114) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michael Hoennig Co-authored-by: Michael Hönnig Reviewed-on: https://dev.hostsharing.net/hostsharing/hs.hsadmin.ng/pulls/114 Reviewed-by: Timotheus Pokorra --- Jenkinsfile | 52 +++++++++++++++++++ etc/jenkinsAgent.Dockerfile | 10 ++++ .../HsOfficeRelationRbacRepository.java | 8 +-- ...DnsSetupHostingAssetValidatorUnitTest.java | 3 ++ src/test/resources/application.yml | 8 +++ 5 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 Jenkinsfile create mode 100644 etc/jenkinsAgent.Dockerfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..5c1722d6 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,52 @@ +pipeline { + agent { + dockerfile { + filename 'etc/jenkinsAgent.Dockerfile' + // additionalBuildArgs ... + args '--network=bridge --user root -v $PWD:$PWD -v /var/run/docker.sock:/var/run/docker.sock --group-add 984' + reuseNode true + } + } + + environment { + DOCKER_HOST = 'unix:///var/run/docker.sock' + HSADMINNG_POSTGRES_ADMIN_USERNAME = 'admin' + HSADMINNG_POSTGRES_RESTRICTED_USERNAME = 'restricted' + HSADMINNG_MIGRATION_DATA_PATH = 'migration' + } + + triggers { + pollSCM('H/1 * * * *') + } + + stages { + stage('Checkout') { + steps { + checkout scm + } + } + + stage ('Compile & Test') { + steps { + sh './gradlew clean check --no-daemon -x pitest -x dependencyCheckAnalyze' + } + } + } + + post { + always { + // archive test results + junit 'build/test-results/test/*.xml' + + // archive the JaCoCo coverage report in XML and HTML format + jacoco( + execPattern: 'build/jacoco/*.exec', + classPattern: 'build/classes/java/main', + sourcePattern: 'src/main/java' + ) + + // cleanup workspace + cleanWs() + } + } +} diff --git a/etc/jenkinsAgent.Dockerfile b/etc/jenkinsAgent.Dockerfile new file mode 100644 index 00000000..648e2f8e --- /dev/null +++ b/etc/jenkinsAgent.Dockerfile @@ -0,0 +1,10 @@ +FROM eclipse-temurin:21-jdk +RUN apt-get update && \ + apt-get install -y bind9-utils && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + + +# RUN mkdir /opt/app +# COPY japp.jar /opt +# CMD ["java", "-jar", "/opt/app/japp.jar"] diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRbacRepository.java b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRbacRepository.java index e5761a5c..96d4b8d5 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRbacRepository.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRbacRepository.java @@ -28,10 +28,10 @@ public interface HsOfficeRelationRbacRepository extends Repository findRelationRelatedToPersonUuidRelationTypePersonAndContactData( - UUID personUuid, - HsOfficeRelationType relationType, - String personData, - String contactData) { + final UUID personUuid, + final HsOfficeRelationType relationType, + final String personData, + final String contactData) { return findRelationRelatedToPersonUuidRelationTypePersonAndContactDataImpl( personUuid, toStringOrNull(relationType), toSqlLikeOperand(personData), toSqlLikeOperand(contactData)); } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainDnsSetupHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainDnsSetupHostingAssetValidatorUnitTest.java index 41684c3b..607485bf 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainDnsSetupHostingAssetValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainDnsSetupHostingAssetValidatorUnitTest.java @@ -176,6 +176,7 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest { // given final var givenEntity = validEntityBuilder().build(); final var validator = HostingAssetEntityValidatorRegistry.forType(givenEntity.getType()); + Dns.fakeResultForDomain(givenEntity.getIdentifier(), Dns.Result.fromRecords()); // when final var errors = validator.validateContext(givenEntity); @@ -317,6 +318,7 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest { )) .build(); final var validator = HostingAssetEntityValidatorRegistry.forType(givenEntity.getType()); + Dns.fakeResultForDomain("example.org", Dns.Result.fromRecords()); // when final var errors = validator.validateContext(givenEntity); @@ -340,6 +342,7 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest { )) .build(); final var validator = HostingAssetEntityValidatorRegistry.forType(givenEntity.getType()); + Dns.fakeResultForDomain("example.org", Dns.Result.fromRecords()); // when final var zonefileErrors = new ArrayList(); diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index 923c62e9..54141c3e 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -33,3 +33,11 @@ logging: level: liquibase: WARN net.ttddyy.dsproxy.listener: DEBUG # HOWTO: log meaningful SQL statements + # just for the case there are problems with Testcontainers/Docker integration + # org.testcontainers: DEBUG + # com.github.dockerjava: DEBUG + +testcontainers: + network: + mode: host +