Skip to content

Commit

Permalink
Merge pull request #81 from paulissoft/development
Browse files Browse the repository at this point in the history
Development merge into master
  • Loading branch information
gpaulissen authored Oct 6, 2022
2 parents 6bdd9f9 + 1b72630 commit da8e0d2
Show file tree
Hide file tree
Showing 10 changed files with 257 additions and 113 deletions.
2 changes: 0 additions & 2 deletions conf/app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
<db.schema>${oracle_tools_schema}</db.schema>
<exec.cleanupDaemonThreads>false</exec.cleanupDaemonThreads>
<conf.test.connection>false</conf.test.connection> <!-- no recursion -->
<conf.test.connection.skip>false</conf.test.connection.skip>
<!-- Pass as environment variables for security reasons (Jenkins) -->
<db.username>${env.DB_USERNAME}</db.username>
<db.password>${env.DB_PASSWORD}</db.password>
Expand All @@ -40,7 +39,6 @@
<goal>java</goal>
</goals>
<configuration>
<skip>${conf.test.connection.skip}</skip>
<mainClass>TestConnection</mainClass>
<arguments>
<argument>${db.url}</argument>
Expand Down
137 changes: 73 additions & 64 deletions conf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -338,80 +338,89 @@
<!-- db.prev.database.link is empty meaning the previous database schema is used -->
<property name="db.prev.database.link"
value="${db.schema}@${db.prev.service}" />
<condition property="conf.test.connection" value="false" else="true">
<or>
<contains string="${db.url}" substring="${" />
<contains string="${db.username}" substring="${" />
</or>
</condition>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>

<execution>
<!-- This must be named -->
<id>conf-test-connection</id>
<phase>${conf.phase.process}</phase>
<configuration>
<exportAntProperties>true</exportAntProperties>
<target if="${conf.test.connection}">
<!-- It must be possible to test the connection with a timeout. -->
<!-- https://github.com/paulissoft/oracle-tools/issues/77 -->
<echo level="${ant.log.level}" message="Testing connection with url '${db.url}' and username '${db.username}'" />
<!-- This build directory will be created due to the invocation of maven below so store the poperties there. -->
<property name="property.file" location="${oracle-tools.dir}/conf/app/target/.connect.properties"/>
<property file="${property.file}"/>
<!-- Test the connection for a database (only once) -->

<tstamp /> <!-- sets ${TODAY} -->
<!-- The exec below will create directory ${oracle-tools.dir}/conf/app/target/ -->
<property name="conf.test.connection.property.file"
location="${oracle-tools.dir}/conf/app/target/conf.test.connection.${TODAY}.properties" />
<property file="${conf.test.connection.property.file}" />

<!-- Ant Contrib new style -->
<ac:propertycopy xmlns:ac="antlib:net.sf.antcontrib"
property="conf.test.connection.skip"
property="conf.test.connection.ok"
override="true"
from="conf.test.connection.skip.${db}"
silent="true"/>
<property name="conf.test.connection.skip" value="false" /> <!-- default -->
<exec executable="perl"
spawn="false"
failonerror="false"
outputproperty="test.connection.output"
errorproperty="test.connection.error"
resultproperty="test.connection.result"
failifexecutionfails="false">
<arg value="${oracle-tools.dir}/src/scripts/timeout.pl"/>
<arg value="mvn"/>
<arg value="-q"/>
<arg value="-f"/>
<arg value="${oracle-tools.dir}/conf/app/pom.xml"/>
<arg value="-Ptest-connection"/>
<arg value="-Ddb.url=${db.url}"/>
<arg value="-Dconf.test.connection.skip=${conf.test.connection.skip}"/>
<env key="DB_USERNAME" value="${db.username}"/>
<env key="DB_PASSWORD" value="${db.password}"/>
<env key="LC_CTYPE" value="en_US.UTF-8"/>
<env key="LC_ALL" value="en_US.UTF-8"/>
</exec>
<fail message="${test.connection.error}">
<condition>
<and>
<isset property="test.connection.result"/>
<not>
<equals arg1="${test.connection.result}" arg2="0"/>
</not>
</and>
</condition>
</fail>
<!-- Store the fact that a database connection has been successful for this database. -->
<propertyfile file="${property.file}">
<entry key="conf.test.connection.skip.${db}" value="true"/>
</propertyfile>
from="conf.test.connection.ok.${db}"
silent="true" />

<ac:if xmlns:ac="antlib:net.sf.antcontrib">
<equals arg1="${conf.test.connection.ok}" arg2="true" />
<then>
<echo level="${ant.log.level}" message="Skipping test for connection to database ${db} since it has already been tested today" />
</then>
<elseif>
<equals arg1="${conf.test.connection}" arg2="false" />
<then>
<echo level="${ant.log.level}" message="Skipping test for connection to database ${db} since property conf.test.connection is false" />
</then>
</elseif>
<elseif>
<contains string="${db.url}" substring="${" />
<then>
<echo level="${ant.log.level}" message="Skipping test for connection to database ${db} since property db.url contains '${'" />
</then>
</elseif>
<elseif>
<contains string="${db.username}" substring="${" />
<then>
<echo level="${ant.log.level}" message="Skipping test for connection to database ${db} since property db.username contains '${'" />
</then>
</elseif>
<else>
<echo level="${ant.log.level}" message="Executing test for connection to database ${db}" />
<exec executable="perl"
spawn="false"
failonerror="false"
outputproperty="test.connection.output"
errorproperty="test.connection.error"
resultproperty="test.connection.result"
failifexecutionfails="false">
<arg value="${oracle-tools.dir}/src/scripts/timeout.pl"/>
<arg value="mvn"/>
<arg value="-q"/>
<arg value="-f"/>
<arg value="${oracle-tools.dir}/conf/app/pom.xml"/>
<arg value="-Ptest-connection"/>
<arg value="-Ddb.url=${db.url}"/>
<env key="DB_USERNAME" value="${db.username}"/>
<env key="DB_PASSWORD" value="${db.password}"/>
<env key="LC_CTYPE" value="en_US.UTF-8"/>
<env key="LC_ALL" value="en_US.UTF-8"/>
</exec>
<fail message="${test.connection.error}">
<condition>
<and>
<isset property="test.connection.result"/>
<not>
<equals arg1="${test.connection.result}" arg2="0"/>
</not>
</and>
</condition>
</fail>
<!-- Store the fact that the test for a database connection has been successful for this database. -->
<propertyfile file="${conf.test.connection.property.file}">
<entry key="conf.test.connection.ok.${db}" value="true"/>
</propertyfile>
</else>
</ac:if>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>

<execution>
<id>conf-debug-after</id>
<phase>${conf.phase.process}</phase>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,6 @@ volumes:
name: jenkins-data

services:
# See https://davelms.medium.com/run-jenkins-in-a-docker-container-part-2-socat-d5f18820fe1d
jenkins-docker:
container_name: jenkins_docker
image: alpine/socat
restart: unless-stopped
hostname: jenkins-docker
networks:
- jenkins-network
expose:
- "2375"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
command: tcp-listen:2375,fork,reuseaddr unix-connect:/var/run/docker.sock
jenkins-controller:
container_name: jenkins_controller
build: jenkins-controller
Expand Down
32 changes: 32 additions & 0 deletions jenkins/docker-compose-jenkins-nfs-client.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: '3.8'

networks:
jenkins-network:
name: jenkins

volumes:
jenkins-m2-repository:
name: jenkins-m2-repository
driver_opts:
type: "nfs"
o: "addr=${JENKINS_NFS_SERVER},nfsvers=4,nolock,soft,rw"
device: ":"

services:
jenkins-nfs-client-m2-repository:
container_name: jenkins_nfs_client_m2_repository
image: ghcr.io/paulissoft/pato-jenkins-agent:latest
hostname: jenkins-nfs-client-m2-repository
networks:
- jenkins-network
volumes:
- jenkins-m2-repository:/home/jenkins:rw
jenkins-nfs-client-agent-workspace:
container_name: jenkins_nfs_client_agent_workspace
image: ghcr.io/paulissoft/pato-jenkins-agent:latest
hostname: jenkins-nfs-client-agent-workspace
networks:
- jenkins-network
volumes:
- jenkins-agent-workspace:/home/jenkins:rw

36 changes: 36 additions & 0 deletions jenkins/docker-compose-jenkins-nfs-server.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: '3.8'

networks:
jenkins-network:
name: jenkins

services:
jenkins-nfs-server-m2-repository:
container_name: jenkins_nfs_server_m2_repository
image: itsthenetwork/nfs-server-alpine
restart: unless-stopped
hostname: jenkins-nfs-server-m2-repository
networks:
- jenkins-network
# ports:
# - "2049:2049"
privileged: true
volumes:
- ${SHARED_DIRECTORY_M2_REPOSITORY}:/nfsshare
environment:
- SHARED_DIRECTORY=/nfsshare
jenkins-nfs-server-agent-workspace:
container_name: jenkins_nfs_server_agent_workspace
image: itsthenetwork/nfs-server-alpine
restart: unless-stopped
hostname: jenkins-nfs-server-agent-workspace
networks:
- jenkins-network
# ports:
# - "3049:2049"
privileged: true
volumes:
- ${SHARED_DIRECTORY_AGENT_WORKSPACE}:/nfsshare
environment:
- SHARED_DIRECTORY=/nfsshare
- SYNC=true
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ services:
dns-proxy-server:
container_name: dns_proxy_server
image: defreitas/dns-proxy-server
restart: unless-stopped
networks:
- jenkins-network
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /etc/resolv.conf:/etc/resolv.conf
hostname: dns.mageddo
depends_on:
- jenkins-docker
12 changes: 6 additions & 6 deletions jenkins/jenkins-agent/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ ENV TNS_ADMIN /opt/oracle/network/admin
# If you use Oracle Wallet
RUN mkdir -m 755 -p /opt/oracle/wallet

# Let github.com be a known host for user jenkins
USER jenkins
RUN mkdir -m 700 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts

# As stated in the documentation, a inherits the directory content and permissions existing in the container.
# So when volume maven-local-repository attaches to /home/jenkins/.m2/repository,
# that directory must already exist and have the correct ownership
# otherwise it will be root giving Maven download permission problems.
# See also https://github.com/paulissoft/oracle-tools/issues/66.
RUN mkdir -m 755 -p /home/jenkins/.m2/repository && chown jenkins:jenkins /home/jenkins/.m2/repository
RUN mkdir -m 755 -p /home/jenkins/.m2/repository
# Also create a workspace directory owned by jenkins
RUN mkdir -m 755 -p /home/jenkins/agent/workspace && chown jenkins:jenkins /home/jenkins/agent/workspace

# Let github.com be a known host for user jenkins
USER jenkins
RUN mkdir -m 700 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts
RUN mkdir -m 755 -p /home/jenkins/agent/workspace
7 changes: 5 additions & 2 deletions jenkins/jenkins-controller/jenkins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ jenkins:
image: "ghcr.io/paulissoft/pato-jenkins-agent:latest"
mounts:
- "type=volume,src=maven-local-repository,dst=/home/jenkins/.m2/repository"
mountsString: "type=volume,src=maven-local-repository,dst=/home/jenkins/.m2/repository"
- "type=volume,src=jenkins-agent-workspace,dst=/home/jenkins/agent/workspace"
mountsString: |-
type=volume,src=maven-local-repository,dst=/home/jenkins/.m2/repository
type=volume,src=jenkins-agent-workspace,dst=/home/jenkins/agent/workspace
network: "jenkins"
labelString: "maven jdk oracle"
labelString: "maven sql jdk oracle"
name: "pato"
pullStrategy: PULL_ALWAYS
pullTimeout: 300
Expand Down
3 changes: 2 additions & 1 deletion jenkins/libraries/maven/steps/process.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ void call(app_env_name, app_env){

withMaven(options: [artifactsPublisher(disabled: true),
findbugsPublisher(disabled: true),
openTasksPublisher(disabled: true)]) {
openTasksPublisher(disabled: true),
junitPublisher(disabled: true)]) {
sh('chmod +x $WORKSPACE/oracle-tools/jenkins/process.sh')
if (!is_empty(env.SCM_CREDENTIALS)) {
sshagent([env.SCM_CREDENTIALS]) {
Expand Down
Loading

0 comments on commit da8e0d2

Please sign in to comment.