diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..4744b104 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +# Use the official Gradle image with JDK 11 as the base image +FROM gradle:7.6.1-jdk11 + +# Set the working directory inside the container +WORKDIR /desktop_app + +# Copy the Gradle build script into the container +COPY build.gradle ./ + +# Copy the Gradle wrapper scripts into the container +COPY gradlew gradlew.bat ./ + +# Copy the Gradle folder containing wrapper files +COPY gradle ./gradle + +# Copy all other project files into the container +COPY . . + +# Give execution permission to the Gradle wrapper script +RUN chmod +x ./gradlew + +# Expose port 8080 for external access to the application +EXPOSE 8080 + +# Start the application using the Gradle wrapper, +# with "--continuous" to automatically rebuild on file changes +CMD ["./gradlew", "appRun", "--continuous"] +#Fixing appRun because gradle is case sensitive diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..36827c1a --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,105 @@ +// This jenkinsfile is used to run CI/CD on my local (Windows) box, no VM's needed. +pipeline { + agent any + tools { + jdk 'Java 17' + gradle 'Gradle 7.6' + } + + environment { + // This is set so that the Python API tests will recognize it + // and go through the Zap proxy waiting at 9888 + HTTP_PROXY = 'http://127.0.0.1:9888' + // Default Java Home for Jenkins (JDK 17) + JAVA_HOME = '/usr/lib/jvm/java-17-openjdk' + PATH = "${JAVA_HOME}/bin:${PATH}" + } + + stages { + + stage('Docker Access Test') { + steps { + sh 'docker ps' + } + } + // build the war file (the binary). This is the only + // place that happens. + stage('Build') { + environment { + // Override JAVA_HOME to use JDK 11 for this stage + JAVA_HOME = '/usr/lib/jvm/java-11-openjdk' + PATH = "${JAVA_HOME}/bin:${PATH}" + } + steps { + sh 'docker build -t ensf400project1 .' + } + } + // run all the unit tests - these do not require anything else + // to be running and most run very quickly. + stage('Unit Tests') { + environment { + // Override JAVA_HOME to use JDK 11 for this stage + JAVA_HOME = '/usr/lib/jvm/java-11-openjdk' + PATH = "${JAVA_HOME}/bin:${PATH}" + } + steps { + sh './gradlew test' + } + post { + always { + junit 'build/test-results/test/*.xml' + } + } + } + // // run the tests which require connection to a + // // running database. + // stage('Database Tests') { + // environment { + // // Override JAVA_HOME to use JDK 11 for this stage + // JAVA_HOME = '/usr/lib/jvm/java-11-openjdk' + // PATH = "${JAVA_HOME}/bin:${PATH}" + // } + // steps { + // sh './gradlew integrate' + // } + // post { + // always { + // junit 'build/test-results/integrate/*.xml' + // } + // } + // } + // // These are the Behavior Driven Development (BDD) tests + // // See the files in src/bdd_test + // // These tests do not require a running system. + // stage('BDD Tests') { + // environment { + // // Override JAVA_HOME to use JDK 11 for this stage + // JAVA_HOME = '/usr/lib/jvm/java-11-openjdk' + // PATH = "${JAVA_HOME}/bin:${PATH}" + // } + // steps { + // sh './gradlew generateCucumberReports' + // // generate the code coverage report for jacoco + // sh './gradlew jacocoTestReport' + // } + // post { + // always { + // junit 'build/test-results/bdd/*.xml' + // } + // } + // } + // Runs an analysis of the code, looking for any + // patterns that suggest potential bugs. + stage('Static Analysis') { + environment { + // Override JAVA_HOME to use JDK 11 for this stage + JAVA_HOME = '/usr/lib/jvm/java-11-openjdk' + PATH = "${JAVA_HOME}/bin:${PATH}" + } + + steps{ + sh './gradlew sonarqube -Dsonar.host.url=http://localhost:9000 -Dsonar.login=admin -Dsonar.password=ensf400' + } + } + } +} \ No newline at end of file diff --git a/README.md b/README.md index cef0ff62..1d0b618e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +#orginal readme file from existing repo + + ## Demo - demonstrates an application and tests This is an application by [Coveros](https://www.coveros.com/) to demonstrate good diff --git a/Screenshots/Docker_Desktop.png b/Screenshots/Docker_Desktop.png new file mode 100644 index 00000000..1d3cd4b0 Binary files /dev/null and b/Screenshots/Docker_Desktop.png differ diff --git a/Screenshots/Local_Browser.png b/Screenshots/Local_Browser.png new file mode 100644 index 00000000..e072dc5e Binary files /dev/null and b/Screenshots/Local_Browser.png differ diff --git a/Screenshots/Rest_of_Terminal1.png b/Screenshots/Rest_of_Terminal1.png new file mode 100644 index 00000000..30e96e73 Binary files /dev/null and b/Screenshots/Rest_of_Terminal1.png differ diff --git a/Screenshots/Terminal1.png b/Screenshots/Terminal1.png new file mode 100644 index 00000000..5ac1a3c7 Binary files /dev/null and b/Screenshots/Terminal1.png differ diff --git a/build.gradle b/build.gradle index ff7b120e..8b55205b 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ plugins { // gretty is a gradle plugin to make it easy to run a server and hotswap code at runtime. // https://plugins.gradle.org/plugin/org.gretty - id 'org.gretty' version '3.0.4' + id 'org.gretty' version '3.1.5' // provides access to a database versioning tool. id "org.flywaydb.flyway" version "6.0.8" @@ -63,6 +63,8 @@ plugins { java { toolchain { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 languageVersion.set(JavaLanguageVersion.of(11)) } } diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 00000000..9c5bcf3c --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,50 @@ +services: + jenkins: + build: ./jenkins + privileged: true + user: root + ports: + - 8080:8080 + - 50000:50000 + container_name: jenkins + volumes: + - /home/codespace:/var/jenkins_home + - /var/run/docker.sock:/var/run/docker.sock + networks: + - dev-network + depends_on: + - sonarqube + + sonarqube: + image: sonarqube:8.9-community + container_name: sonarqube + environment: + - SONARQUBE_JDBC_URL=jdbc:postgresql://db:5432/sonar + - SONARQUBE_JDBC_USERNAME=sonar + - SONARQUBE_JDBC_PASSWORD=sonar + ports: + - "9000:9000" + volumes: + - sonarqube_data:/opt/sonarqube/data + networks: + - dev-network + + db: + image: postgres:latest + container_name: sonar-db + environment: + - POSTGRES_USER=sonar + - POSTGRES_PASSWORD=sonar + - POSTGRES_DB=sonar + volumes: + - db_data:/var/lib/postgresql/data + networks: + - dev-network + +networks: + dev-network: + +volumes: + jenkins_home: + sonarqube_data: + db_data: \ No newline at end of file diff --git a/docs/BDD_video.mp4 b/docs/BDD_video.mp4 index 27c4646c..571239ed 100644 Binary files a/docs/BDD_video.mp4 and b/docs/BDD_video.mp4 differ diff --git a/gradle.properties b/gradle.properties index 7b3fa8b0..0a5d8b20 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,3 +17,6 @@ org.gradle.workers.max=1 # Setting the memory config explicitly org.gradle.jvmargs=-Xmx1g -XX:MaxMetaspaceSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 + +#Adding compatible java version path +#org.gradle.java.home=C:\\Program Files\\Eclipse Adoptium\\jdk-21.0.6.7-hotspot \ No newline at end of file diff --git a/jenkins/Dockerfile b/jenkins/Dockerfile new file mode 100644 index 00000000..f112afc1 --- /dev/null +++ b/jenkins/Dockerfile @@ -0,0 +1,29 @@ +FROM jenkins/jenkins:alpine +# switch to root user +USER root + +# install docker on top of the base image +RUN apk add --update docker openrc + +# Install Gradle dependencies +RUN apk add --no-cache \ + openjdk11 \ + bash \ + docker \ + curl \ + unzip + +# Set Gradle version +ENV GRADLE_VERSION=7.6 +ENV GRADLE_HOME=/opt/gradle +# Download and install Gradle +RUN mkdir -p ${GRADLE_HOME} && \ + curl -fsSL https://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-bin.zip -o /tmp/gradle.zip && \ + unzip /tmp/gradle.zip -d /opt/gradle && \ + rm /tmp/gradle.zip + +# Add Gradle to PATH +ENV PATH="${GRADLE_HOME}/gradle-${GRADLE_VERSION}/bin:${PATH}" + +# Verify installation +RUN gradle -v \ No newline at end of file diff --git a/jenkins/Jenkinsfile b/jenkins/Jenkinsfile deleted file mode 100644 index d37024fe..00000000 --- a/jenkins/Jenkinsfile +++ /dev/null @@ -1,211 +0,0 @@ -// This jenkinsfile is used to run CI/CD on my local (Windows) box, no VM's needed. - -pipeline { - - agent any - - environment { - // This is set so that the Python API tests will recognize it - // and go through the Zap proxy waiting at 9888 - HTTP_PROXY = 'http://127.0.0.1:9888' - } - - stages { - - // build the war file (the binary). This is the only - // place that happens. - stage('Build') { - steps { - sh './gradlew clean assemble' - } - } - - // run all the unit tests - these do not require anything else - // to be running and most run very quickly. - stage('Unit Tests') { - steps { - sh './gradlew test' - } - post { - always { - junit 'build/test-results/test/*.xml' - } - } - } - - // run the tests which require connection to a - // running database. - stage('Database Tests') { - steps { - sh './gradlew integrate' - } - post { - always { - junit 'build/test-results/integrate/*.xml' - } - } - } - - // These are the Behavior Driven Development (BDD) tests - // See the files in src/bdd_test - // These tests do not require a running system. - stage('BDD Tests') { - steps { - sh './gradlew generateCucumberReports' - // generate the code coverage report for jacoco - sh './gradlew jacocoTestReport' - } - post { - always { - junit 'build/test-results/bdd/*.xml' - } - } - } - - // Runs an analysis of the code, looking for any - // patterns that suggest potential bugs. - stage('Static Analysis') { - steps { - sh './gradlew sonarqube' - // wait for sonarqube to finish its analysis - sleep 5 - sh './gradlew checkQualityGate' - } - } - - - // Move the binary over to the test environment and - // get it running, in preparation for tests that - // require a whole system to be running. - stage('Deploy to Test') { - steps { - sh './gradlew deployToTestWindowsLocal' - // pipenv needs to be installed and on the path for this to work. - sh 'PIPENV_IGNORE_VIRTUALENVS=1 pipenv install' - - // Wait here until the server tells us it's up and listening - sh './gradlew waitForHeartBeat' - - // clear Zap's memory for the incoming tests - sh 'curl http://zap/JSON/core/action/newSession -s --proxy localhost:9888' - } - } - - - // Run the tests which investigate the functioning of the API. - stage('API Tests') { - steps { - sh './gradlew runApiTests' - } - post { - always { - junit 'build/test-results/api_tests/*.xml' - } - } - } - - // We use a BDD framework for some UI tests, Behave, because Python rules - // when it comes to experimentation with UI tests. You can try things and see how they work out. - // this set of BDD tests does require a running system. - // BDD at the UI level is just to ensure that basic capabilities work, - // not that every little detail of UI functionality is correct. For - // that purpose, see the following stage, "UI Tests" - stage('UI BDD Tests') { - steps { - sh './gradlew runBehaveTests' - sh './gradlew generateCucumberReport' - } - post { - always { - junit 'build/test-results/bdd_ui/*.xml' - } - } - } - - // This set of tests investigates the functionality of the UI. - // Note that this is separate fom the UI BDD Tests, which - // only focuses on essential capability and therefore only - // covers a small subset of the possibilities of UI behavior. - stage('UI Tests') { - steps { - sh 'cd src/ui_tests/java && ./gradlew clean test' - } - post { - always { - junit 'src/ui_tests/java/build/test-results/test/*.xml' - } - } - } - - // Run OWASP's "DependencyCheck". https://owasp.org/www-project-dependency-check/ - // You are what you eat - and so it is with software. This - // software consists of a number of software by other authors. - // For example, for this project we use language tools by Apache, - // password complexity analysis, and several others. Each one of - // these might have security bugs - and if they have a security - // bug, so do we! - // - // DependencyCheck looks at the list of known - // security vulnerabilities from the United States National Institute of - // Standards and Technology (NIST), and checks if the software - // we are importing has any major known vulnerabilities. If so, - // the build will halt at this point. - stage('Security: Dependency Analysis') { - steps { - sh './gradlew dependencyCheckAnalyze' - } - } - - // Run Jmeter performance testing https://jmeter.apache.org/ - // This test simulates 50 users concurrently using our software - // for a set of common tasks. - stage('Performance Tests') { - steps { - sh './gradlew runPerfTests' - } - } - - // Runs mutation testing against some subset of our software - // as a spot test. Mutation testing is where bugs are seeded - // into the software and the tests are run, and we see which - // tests fail and which pass, as a result. - // - // what *should* happen is that where code or tests are altered, - // the test should fail, shouldn't it? However, it sometimes - // happens that no matter how code is changed, the tests - // continue to pass, which implies that the test wasn't really - // providing any value for those lines. - stage('Mutation Tests') { - steps { - sh './gradlew pitest' - } - } - - stage('Build Documentation') { - steps { - sh './gradlew javadoc' - } - } - - stage('Collect Zap Security Report') { - steps { - sh 'mkdir -p build/reports/zap' - sh 'curl http://zap/OTHER/core/other/htmlreport --proxy localhost:9888 > build/reports/zap/zap_report.html' - } - } - - - // This is the stage where we deploy to production. If any test - // fails, we won't get here. Note that we aren't really doing anything - this - // is a token step, to indicate whether we would have deployed or not. Nothing actually - // happens, since this is a demo project. - stage('Deploy to Prod') { - steps { - // just a token operation while we pretend to deploy - sh 'sleep 5' - } - } - - } - -} diff --git a/jenkins_home/.lastStarted b/jenkins_home/.lastStarted new file mode 100644 index 00000000..e69de29b diff --git a/jenkins_home/.owner b/jenkins_home/.owner new file mode 100644 index 00000000..62f94575 --- /dev/null +++ b/jenkins_home/.owner @@ -0,0 +1 @@ +6 \ No newline at end of file diff --git a/trigger.txt b/trigger.txt new file mode 100644 index 00000000..3c423c2f Binary files /dev/null and b/trigger.txt differ