diff --git a/.jenkins/Dockerfile b/.jenkins/Dockerfile new file mode 100644 index 00000000..8ab4292c --- /dev/null +++ b/.jenkins/Dockerfile @@ -0,0 +1,104 @@ +# Base image: Ubuntu 20.04 +FROM ubuntu:20.04 +LABEL maintainer="CPSWT Team" + +# Set it to noninteractive mode +ARG DEBIAN_FRONTEND=noninteractive + +# Install necessary packages +RUN apt-get update && \ + apt-get install -y \ + apt-transport-https \ + bison \ + build-essential \ + ca-certificates \ + clang \ + curl \ + doxygen \ + flex \ + gcc \ + gdb \ + git \ + graphviz \ + libboost1.71-all-dev \ + libcppunit-dev \ + libjsoncpp-dev \ + libosgearth-dev \ + libqt5opengl5-dev \ + libwebkit2gtk-4.0-37 \ + libxml2-dev \ + lld \ + make \ + mongodb \ + mpi-default-dev \ + netcat \ + openjdk-8-jdk \ + openjdk-17-jdk \ + openscenegraph-plugin-osgearth \ + perl \ + python2 \ + python3 \ + python3-pip \ + python-is-python2 \ + qt5-qmake \ + qtbase5-dev \ + qtbase5-dev-tools \ + qtchooser \ + software-properties-common \ + wget \ + xterm \ + zlib1g-dev \ + unzip \ + zip + +#install Gradle +ARG GRADLE_VERSION=7.5 +RUN wget -O gradle.zip https://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-bin.zip && \ + mkdir /opt/gradle && \ + unzip -d /opt/gradle gradle.zip && \ + rm gradle.zip +# Set Gradle in the environment variables +ENV GRADLE_HOME="/opt/gradle/gradle-${GRADLE_VERSION}" +ENV PATH="${GRADLE_HOME}/bin:${PATH}" + +# Install Python packages +RUN python3 -m pip install --system --upgrade \ + jinja2 \ + matplotlib \ + numpy \ + pandas \ + posix_ipc \ + scipy \ + seaborn \ + webgme-bindings + +# Download and extract portico +WORKDIR /home +RUN wget -O portico.tar.gz https://master.dl.sourceforge.net/project/portico/Portico/portico-2.1.0/portico-2.1.0-linux64.tar.gz?viasf=1 && \ + tar xf portico.tar.gz && \ + rm portico.tar.gz +ENV RTI_HOME="/home/portico-2.1.0" + +# Download and set up Apache Archiva +WORKDIR /opt +RUN wget -O archiva.tar.gz https://archive.apache.org/dist/archiva/2.2.5/binaries/apache-archiva-2.2.5-bin.tar.gz && \ + tar xf archiva.tar.gz && \ + rm archiva.tar.gz + +# Expose the Archiva port +EXPOSE 8080/tcp + +# Use SIGINT for stopping +STOPSIGNAL SIGINT + +# Set up Gradle properties +COPY gradle.properties /root/.gradle/ +RUN chmod 600 /root/.gradle/gradle.properties + +# Clone and build CPSWT packages +RUN mkdir /home/cpswt +COPY experiment_wrapper.sh /home/cpswt + +WORKDIR /home/cpswt +# Start Archiva +CMD ["/usr/bin/bash", "experiment_wrapper.sh"] diff --git a/.jenkins/Jenkinsfile b/.jenkins/Jenkinsfile new file mode 100644 index 00000000..13547d3e --- /dev/null +++ b/.jenkins/Jenkinsfile @@ -0,0 +1,77 @@ +// Do NOT place within the pipeline block +properties([ [ $class: 'ThrottleJobProperty', + categories: ['ci_cpswt_build'], + limitOneJobWithMatchingParams: false, + maxConcurrentPerNode: 1, + maxConcurrentTotal: 1, + paramsToUseForLimit: '', + throttleEnabled: true, + throttleOption: 'category' ] ]) + +pipeline { + agent any + triggers { + pollSCM('*/1 * * * *') // poll the SCM every 1 minutes + } + + stages { + stage('Clone repository') { + steps { + echo 'Cloning cpswt-cpp...' + deleteDir() // Delete workspace before cloning + sh 'git clone git@github.com:justinyeh1995/CI_with_Jenkins.git' + } + } + stage('Build cpswt-cpp image') { + steps { + echo 'Start a Docker Container for this experiment, which should start the experiment and a archiva server, a inet server, and a omnet++ server..' + // sh 'if docker images | grep -q cpswt-cpp:latest; then docker rmi cpswt-cpp:latest; fi' // Remove the existing image with the name:tag cpswt-cpp:latest + dir("CI_with_Jenkins/cpswt-cpp") { + sh 'docker build -t cpswt-cpp:latest -f Dockerfile --build-arg ssh_prv_key="$(cat ~/.ssh/id_rsa)" --build-arg ssh_pub_key="$(cat ~/.ssh/id_rsa.pub)" .' + } + } + } + stage('Deploy image') { + steps { + echo 'Run the Docker Container inside Jenkins container' + //sh 'if docker ps -a | grep -q cpswt-cpp; then docker stop cpswt-cpp; fi' //Stop the existing container with the name cpswt-cpp + //sh 'if docker ps -a | grep -q cpswt-cpp; then docker rm -f cpswt-cpp; fi' // Remove the existing container with the name cpswt-cpp + sh 'docker run \ + --name cpswt-cpp \ + -p 8082:8080 \ + cpswt-cpp:latest' + } + } + stage('Wait for cpswt-cpp container to stop') { + options { + timeout(time: 30, unit: 'MINUTES') + } + steps { + echo 'Wait for container to stop' + sh 'docker wait cpswt-cpp' + } + } + stage('Archive loggings') { + steps { + echo 'Archiving cpswt-cpp results...' + sh 'docker logs cpswt-cpp > cpswt-cpp.log' + archiveArtifacts artifacts: 'cpswt-cpp.log', fingerprint: true + } + } + } + + post { + always { + echo 'This will always run' + emailext body: "${currentBuild.currentResult}: Job ${env.JOB_NAME} build ${env.BUILD_NUMBER}\n More info at: ${env.BUILD_URL}", + recipientProviders: [[$class: 'DevelopersRecipientProvider'], [$class: 'RequesterRecipientProvider']], + subject: "Jenkins Build ${currentBuild.currentResult}: Job ${env.JOB_NAME}", + attachLog: true, + attachmentsPattern: 'cpswt-cpp.log' + // echo 'Tearing Down the image & container....' + sh 'rm -rf cpswt-cpp' + sh 'docker rm -f cpswt-cpp' + sh 'docker rmi cpswt-cpp:latest' + } + } +} diff --git a/.jenkins/experiment_wrapper.sh b/.jenkins/experiment_wrapper.sh new file mode 100644 index 00000000..fb111e21 --- /dev/null +++ b/.jenkins/experiment_wrapper.sh @@ -0,0 +1,91 @@ +# this script is used to build cpswt-core and its dependencies in the docker container +ORIGINAL_PATH=$PATH +export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64 +export PATH=$JAVA_HOME/bin:$PATH +/opt/apache-archiva-2.2.5/bin/archiva start + +# wait for archiva to start +echo "Waiting archiva to launch on 8080..." + +while ! nc -z localhost 8080; do + sleep 0.1 # wait for 1/10 of the second before check again +done + +echo "archiva launched" + +# create admin user +curl --no-progress-meter -X POST -H "Content-Type: application/json" -H "Origin: http://localhost:8080" -d @- \ + http://localhost:8080/restServices/redbackServices/userService/createAdminUser <<'TERMINUS' +{ + "username": "admin", + "password": "adminpass123", + "email": "admin@archiva-test.org", + "fullName": "Admin", + "locked": false, + "passwordChangeRequired": false, + "permanent": false, + "readOnly": false, + "validated": true, + "confirmPassword": "adminpass123" +} +TERMINUS + +# disable rest.csrffilter.enabled in archiva.xml +sed -i '//,/<\/csrffilter>/s/true/false/' /opt/apache-archiva-2.2.5/conf/archiva.xml +# sed -i 's//http:\/\/129.59.107.97\/archiva-core\/<\/baseUrl>/' /opt/apache-archiva-2.2.5/conf/archiva.xml + +# # restart archiva +/opt/apache-archiva-2.2.5/bin/archiva stop +/opt/apache-archiva-2.2.5/bin/archiva start + +echo "Waiting archiva to launch again on 8080..." + +while ! nc -z localhost 8080; do + sleep 0.1 # wait for 1/10 of the second before check again +done + +echo "archiva launched again" + + +# switch to java 17 +unset JAVA_HOME +export JAVA_HOME=/usr/lib/jvm/java-1.17.0-openjdk-amd64 +export PATH=$JAVA_HOME/bin:$ORIGINAL_PATH + +# clone cpswt-core and build it +cd /home/cpswt +git clone https://github.com/SimIntToolkit/cpswt-core.git +cd cpswt-core/cpswt-core + +gradle wrapper --gradle-version=8.0 + +./gradlew :utils:publish +./gradlew :root:publish +./gradlew :base-events:publish +./gradlew :config:publish +./gradlew :federate-base:publish +./gradlew :coa:publish +./gradlew :federation-manager:publish +./gradlew :fedmanager-host:publish + +# build cpswt-cpp +cd /home/cpswt +git clone https://github.com/SimIntToolkit/cpswt-cpp.git +cd cpswt-cpp + +gradle wrapper --gradle-version=8.0 + +./gradlew :foundation:CppTestHarness:publish +./gradlew :foundation:core-cpp:publish +./gradlew :foundation:C2WConsoleLogger:publish +./gradlew :foundation:rti-base-cpp:publish +./gradlew :foundation:CPSWTConfig:publish +./gradlew :foundation:SynchronizedFederate:publish + +cd /home/cpswt/cpswt-cpp/examples/HelloWorldCpp +touch build.dummy.kts +gradle -b build.dummy.kts wrapper --gradle-version=8.0 +./gradlew :Source:build +./gradlew :Sink:build +./gradlew :PingCounter:build +./gradlew :runFederationBatch diff --git a/.jenkins/gradle.properties b/.jenkins/gradle.properties new file mode 100644 index 00000000..bbace050 --- /dev/null +++ b/.jenkins/gradle.properties @@ -0,0 +1,9 @@ +archivaUser=admin +archivaPassword=adminpass123 +archivaHostId=localhost +archivaPort=8080 +version=0.8.0-SNAPSHOT + +org.gradle.console=plain + +omnetppHome=/opt/omnetpp-5.6.2 diff --git a/gradle.properties b/gradle.properties deleted file mode 100644 index 65a82a47..00000000 --- a/gradle.properties +++ /dev/null @@ -1 +0,0 @@ -version=0.8.0-SNAPSHOT