Skip to content

Commit

Permalink
Feature/app beautification (#12)
Browse files Browse the repository at this point in the history
* Webapp version 0.7.7

* injects secrets from 1Password CLI

* removed some secrets from the text java files

* Adds HTTPS to URLS

* enables injection of 1Password secrets by using .tpl file method

* adds stub of LDAP property file

* adds stub.env for docker-compose

* gradle task to get WAR version

* achieves gradle stable build execution

* updates to the README file to match new steps

* streamline 2 views XHTML

* simplified login screen

* moved and renamed XHTML panels to 404 error view

* Upgrades of primefaces to 14-RC1

* clean up and dependencencies

* clean up web.xml to bare minimum

* print project URLS local testing

* removed forms old PrimeFaces5

* design update processes trainer student

* student wireframe mock in draw.io

* simplified beans

* upgrading to use Java17 Amazon distro

* Adds Jakarta EE

* Adds Jakarta EE support jakarta namespace instead of javax

* Primefaces bumped to Release Candidate PF14-RC1

---------

Signed-off-by: Andres LeonRangel <[email protected]>
  • Loading branch information
aleon1220 authored Feb 22, 2024
1 parent 22dc07f commit 657500b
Show file tree
Hide file tree
Showing 46 changed files with 1,371 additions and 961 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ gradle-app.setting
/.project

# Maven build files
/target
target/

# Compiled class file
*.class
Expand Down
26 changes: 23 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
FROM tomcat:8-jdk8-corretto
# install Linux https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository
# Docker desktop https://docs.docker.com/desktop/install/ubuntu/
# https://hub.docker.com/_/tomcat/tags
FROM tomcat:9.0-jdk11-corretto-al2
# FROM tomcat:8.5.97-jdk17-corretto-al2
# FROM tomcat:8.5.97-jdk11-corretto-al2
# FROM tomcat:8.5.97-jdk8-corretto-al2
# FROM tomcat:8-jdk8-corretto

# https://hub.docker.com/layers/library/tomcat/7.0.109-jdk8-openjdk/images/sha256-489823486120d076cb576640c5819c6fa54948f470b46c54f02b48f462eb2c23

ARG APP_WAR_FILE_VERSION
ENV APP_WAR_FILE_VERSION=$APP_WAR_FILE_VERSION
ENV APP_WAR_FILE="Attendance"
ENV APP_WAR_FILE_PATH="build/libs/$APP_WAR_FILE-${APP_WAR_FILE_VERSION}"
LABEL org.nz.itlatinos.image.authors="[email protected]"
LABEL maintainer="andres.nz"
ENV APP_WAR_FILE="AttendanceApp-0.0.1.war"
LABEL war.version="$APP_WAR_FILE_VERSION"
LABEL docker.image.build.command="docker build --build-arg APP_WAR_FILE_VERSION=$APP_WAR_FILE_VERSION --tag aleon1220/soa:latest ."

RUN printf "WAR version is $APP_WAR_FILE-$APP_WAR_FILE_VERSION"
RUN printf "Path to war file $APP_WAR_FILE_PATH"
# Tomcat Custom settings
COPY "build/libs/$APP_WAR_FILE" /usr/local/tomcat/webapps/
# RUN echo ${PWD} && ls -lR # Debugging
# USER 1000 # considered permissions issue
COPY ${APP_WAR_FILE_PATH}.war /usr/local/tomcat/webapps
# COPY build/libs/AttendanceApp-0.7.2 /usr/local/tomcat/webapps/
# https://forums.docker.com/t/docker-build-multistage-failed-to-compute-cache-key/134316/20
76 changes: 49 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
- [Attendance WebApp](#attendance-webapp)
- [Introduction](#introduction)
- [GitHub Reports](#github-reports)
- [GitHub Reports](#github-reports)
- [Security warnings](#security-warnings)
- [GitHub Vulnerability report](#github-vulnerability-report)
- [GitHub Vulnerability report](#github-vulnerability-report)
- [Attendance WebApp Architecture (re-architected)](#attendance-webapp-architecture-re-architected)
- [2018-Attendance WebApp high level Architecture](#2018-attendance-webapp-high-level-architecture)
- [Attendance WebApp UI](#attendance-webapp-ui)
- [Refer to the Wiki for details on the project](#refer-to-the-wiki-for-details-on-the-project)
- [Project general guidelines](#project-general-guidelines)
- [Setup](#setup)
- [Build WebApp](#build-webapp)
- [Gradle Build Web Package](#gradle-build-web-package)
- [Quickstart](#quickstart)
- [Local Setup](#local-setup)
- [Project general guidelines](#project-general-guidelines)
- [Maven Build](#maven-build)
- [Gradle Test suite](#gradle-test-suite)
- [Use 1Password CLI to inject the secrets](#use-1password-cli-to-inject-the-secrets)
Expand All @@ -22,6 +23,7 @@
- [Docker execution](#docker-execution)
- [Docker-compose](#docker-compose)
- [Editing project diagrams](#editing-project-diagrams)
- [References](#references)

# Attendance WebApp

Expand All @@ -40,13 +42,16 @@ The idea is that you have a short timeframe to submit a random generated code by
The application is a proof of concept for Service orientation and Service interoperability in the cloud

## GitHub Reports
### GitHub Reports
### Security warnings
> Security Warnings to check
GitHub found 2 vulnerabilities on aleon1220/multi-cloud-WebApp-Attendance's default branch (2 moderate).
To find out more, visit:
[This project security report](https://github.com/aleon1220/multi-cloud-WebApp-Attendance/security)
### GitHub Vulnerability report
https://github.com/aleon1220/multi-cloud-WebApp-Attendance/security/dependabot
### GitHub Vulnerability report
https://github.com/aleon1220/multi-cloud-WebApp-Attendance/security/dependabot

## Attendance WebApp Architecture (re-architected)

Expand All @@ -73,16 +78,39 @@ https://github.com/aleon1220/multi-cloud-WebApp-Attendance/security/dependabot

[95f44386]: https://github.com/aleon1220/multi-cloud-AttendWebApp/wiki/4-Architecture-and-Technical-Design "Project Wiki"

# Project general guidelines
# Quickstart
- A Bash script has `runme.sh` been created to automate the local development.
Cleans, builds and executes the docker-compose stack locally. Provides a version number for the app found in the build.gradle file

```bash
./runme.sh clean ; ./runme.sh build ; ./runme.sh run
```

- Gradle Build Web Package
build and test the WebArchive file. Generates the .WAR file in `build/libs/*.war`
``` bash
gradle clean build --console plain --warning-mode all
```
- Gradle Check the generated version from the build.gradle.kts
```bash
gradle getAppversion
```
- Run WebApp
Run the tomcat server with the latest pre-built WAR web Archive file
Run from [Docker Hub](https://hub.docker.com/repository/docker/aleon1220/soa/general)
```bash
docker run --interactive --tty --detach --publish 8080:8080 --name attendance_webapp_container aleon1220/soa:latest
```

# Local Setup
> Tested in Win11 with WSL, Github codespaces and Linux Ubuntu 22
## Project general guidelines

1. Installation process: project a Java project JEE. Import in any IDE and build with gradle or maven. Build docker image and run
2. Software dependencies: dependencies are described in pom.xml file
3. Latest releases by using git tags
4. API references. API docs

# Setup
> Tested in Win11 with WSL, Github codespaces and Linux Ubuntu 22
- Clone repo HTTPS
```bash
git clone https://github.com/aleon1220/multi-cloud-WebApp-Attendance.git
Expand All @@ -94,13 +122,6 @@ git clone [email protected]:aleon1220/multi-cloud-WebApp-Attendance.git
- open repo in chosen IDE
IDEs can be Eclipse, IntelliJ (suggested) or use online IDE (Github codespaces)

## Build WebApp
### Gradle Build Web Package
- Pack the WebArchive file. Generate the .WAR file
``` bash
gradle clean build --console plain --warning-mode all
```

### Maven Build
> maven has been deprecated and moved to [maven](./maven)
Expand Down Expand Up @@ -132,34 +153,31 @@ op inject -i .env.tpl -o .env
- Build the app image with Docker. Deploy .WAR file in Tomcat
refer to https://hub.docker.com/_/tomcat
```bash
docker build --tag aleon1220/soa:latest .
docker build --build-arg APP_WAR_FILE_VERSION=$APP_WAR_FILE_VERSION --tag aleon1220/soa:$APP_WAR_FILE_VERSION .
```

#### Available Tomcat versions
Use the tag latest or a particular version e.g. aleon1220/soa:v2 or aleon1220/soa:latest
if you need to edit the Dockerfile and upgrade the servlet container Tomcat version
- 7.0.109 = `TOMCAT_VERSION_DOCKER_TAG="7.0.109-jdk8-openjdk"`
- 9.0.78 = `TOMCAT_VERSION_DOCKER_TAG="9.0.78-jre8"`

## Execute WebApp
### Container Execution
#### Docker execution

##### Run from [Docker Hub](https://hub.docker.com/repository/docker/aleon1220/soa/general)
### Execute WebApp Container Execution
#### Docker execution by image version
Test the immutable webapp from Docker
```bash
docker run -itd --publish 8080:8080 --name attendance_webapp_container aleon1220/soa:latest
docker run --interactive --tty --detach --publish 8080:8080 --name $APP_WAR_FILE_VERSION aleon1220/soa:$APP_WAR_FILE_VERSION
```

##### local build & Run
##### local development & executions
Test the container webapp after building the image locally
```bash
docker build --tag aleon1220/soa:latest .
docker run -itd --publish 8080:8080 --name attendance_webapp_container aleon1220/soa:latest
```
Run the tomcat server with the pre-built WAR web Archive file
```bash
docker run -itd --publish 8080:8080 aleon1220/soa:latest
docker run --interactive --tty --detach --publish 8080:8080 --name attendance_webapp_container aleon1220/soa:$APP_WAR_FILE_VERSION
```
- Get the name of the running container
- get the name of the running container
``` bash
CONTAINER_NAME=$(docker container ls --all --filter publish=8080 --format "{{.Names}}")
Expand All @@ -180,6 +198,10 @@ docker rm $(docker container ls --all --quiet)
```bash
op inject -i .env.tpl -o .env
```
- single variable- inject the secrets for Testing docker-compose
```bash
op inject -i .env.tpl -o .env
```
- single variable
```bash
export LDAP_ADMIN_PASS=$(op read "op://uqbpxejq7gifvi6mg3c7xxokre/jvuj7juvlxlg7delckucvidqhi/password")
Expand Down
140 changes: 103 additions & 37 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import org.gradle.api.tasks.testing.logging.TestLogEvent
/*
* file generated by Gradle 'init' task. @Incubating APIs subject to change
*/
import java.net.InetAddress

plugins {
java
Expand All @@ -19,46 +17,117 @@ repositories {
}

dependencies {
implementation("org.primefaces.extensions:primefaces-extensions:6.0.0")
implementation("org.primefaces:primefaces:6.0")
implementation("com.sun.faces:jsf-api:2.2.12")
implementation("com.sun.faces:jsf-impl:2.2.12")
implementation("javax.json:javax.json-api:1.1")
implementation("javax.ws.rs:javax.ws.rs-api:2.1")
implementation("com.sun.jersey:jersey-client:1.19.4")
implementation("com.google.code.gson:gson:2.8.9")
implementation("org.apache.httpcomponents:httpclient:4.5.3")
implementation("org.glassfish.jersey.core:jersey-common:2.22.2")
implementation("javax.servlet:javax.servlet-api:3.1.0")
// https://mvnrepository.com/artifact/com.google.zxing/javase
// https://www.primefaces.org
// https://primefaces.github.io/primefaces
// https://mvnrepository.com/artifact/org.primefaces/primefaces
implementation("org.primefaces:primefaces:14.0.0-RC1")
// https://mvnrepository.com/artifact/org.primefaces.extensions/primefaces-extensions
implementation("org.primefaces.extensions:primefaces-extensions:14.0.0-RC1")

// JSF runtime
// https://mvnrepository.com/artifact/org.apache.myfaces.core/myfaces-api
// implementation("org.apache.myfaces.core:myfaces-api:4.0.1") // API https://myfaces.apache.org
// implementation("org.apache.myfaces.core:myfaces-impl:4.0.1") // Faces Implementation
// implementation("org.apache.poi:poi:3.17") // apache POI DataExporter (Excel or XML)
// implementation("com.rometools:rome:1.9.0") // FeedReader
// implementation("net.sf.barcode4j:barcode4j-light:2.3.0") // barcode4j-light
// implementation("net.glxn.qrgen:qrgen:1.4") // qrgen QR Code support for Barcode
// implementation("com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:20220608.1")

// Jakarta EE
// https://mvnrepository.com/artifact/jakarta.enterprise/jakarta.enterprise.cdi-api
// implementation("jakarta.enterprise:jakarta.enterprise.cdi-api:4.0.1")
// implementation("jakarta.ws.rs:jakarta.ws.rs-api:3.1.0")
implementation("org.apache.httpcomponents:httpclient:4.5.13")
// https://mvnrepository.com/artifact/jakarta.ws.rs/jakarta.ws.rs-api
// https://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-client
implementation("org.glassfish.jersey.core:jersey-client:3.1.5")
// implementation("org.glassfish.jersey.core:jersey-common:2.22.2")
// https://github.com/google/gson library JSON serialization/deserialization
implementation("com.google.code.gson:gson:2.10.1")
// https://mvnrepository.com/artifact/jakarta.json/jakarta.json-api
implementation("jakarta.json:jakarta.json-api:2.1.3")
// https://bitbucket.org/snakeyaml/snakeyaml/wiki/Documentation
// https://mavenlibs.com/maven/dependency/org.yaml/snakeyaml
implementation("org.yaml:snakeyaml:2.1")
// QRFunctions
implementation("com.google.zxing:javase:3.5.1")
implementation("com.google.zxing:core:3.5.1")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.2")
testImplementation("io.jsonwebtoken:jjwt:0.9.1")
// dependency below only needed if using the Java 8 version of @Generated (through "jdk8") on Java 9 or later
implementation("javax.annotation:javax.annotation-api:1.3.2")
implementation("io.github.threeten-jaxb:threeten-jaxb-core:2.1.0") // Use Java Date/Time API instead of clunky GregorianCalendar class
implementation("com.graphql-java-kickstart:graphql-webclient-spring-boot-starter:2.0.1")
implementation("com.graphql-java:graphql-java:20.7")
implementation("com.graphql-java-generator:graphql-java-runtime:1.18")
// JUnit 4 framework for unit testing
testImplementation("junit:junit:4.13.2")
// implementation("io.github.threeten-jaxb:threeten-jaxb-core:2.1.0") // Use Java Date/Time API. Clunky GregorianCalendar class
// TESTING
// JUnit Jupiter API and Engine for unit testing
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.2")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.0")
// Mockito for mocking in tests
// Mocking in tests
testImplementation("org.mockito:mockito-core:4.5.1")
// JWT Authentication
testImplementation("io.jsonwebtoken:jjwt:0.9.1")
// https://central.sonatype.com/artifact/com.unboundid/unboundid-ldapsdk
implementation("com.unboundid:unboundid-ldapsdk:6.0.11")
// https://github.com/google/gson library JSON serialization/deserialization
implementation("com.google.code.gson:gson:2.10.1")
implementation("com.kstruct:gethostname4j:1.0.0")
}

group = "soa.nz.aut"
version = "0.0.1"
version = "0.7.7"
description = "Student Attendance WebApp"
java.sourceCompatibility = JavaVersion.VERSION_17
// java.sourceCompatibility = JavaVersion.VERSION_17

fun setWarVersion() {
// function body
project.version?.let { version ->
println("WAR Version is $version")
System.setProperty("APP_WAR_FILE_VERSION", version.toString())
println("For local testing do \n APP_WAR_FILE_VERSION=" + version)
println("Append to the .env file with \n")
println("printf \"\$APP_WAR_FILE_VERSION \\n\" >> .env")
}
}

fun getAppVersion() {
println(version)
}

fun getWarpackageVersion() {
val hostname_local = System.getenv("HOSTNAME") ?: "localhost"
val hostname = InetAddress.getLocalHost().getHostName()

// Define the page names
val pages = listOf(
"01-login.xhtml",
"02-attendance.xhtml",
"03-attendanceOK.xhtml",
"04-lecturerHome.xhtml",
"05-adminStaff.xhtml",
"06-Reports.xhtml",
"07-StudentManagement.xhtml",
"08-ClassManagement.xhtml",
"09-UserManagement.xhtml",
"home.xhtml",
"404-attendanceError.xhtml",
"404-loginError.xhtml",
"home.xhtml",
"index.xhtml"
)
// function body
project.version?.let { version ->
println("WAR Version is $version")
println("Set env variable with")
println("export APP_WAR_FILE_VERSION=" + version.toString())
println("http://" + hostname + ":8080/Attendance-"+ version.toString())
}
// Print URLs for each page
pages.forEach { page ->
println("http://$hostname:8080/Attendance-$version/$page")
}
}

tasks.register<DefaultTask>("getProjectInfo") {
description = "Obtains detailed info about the java web project"
getWarpackageVersion()
}

tasks.war {
archiveBaseName.set("Attendance")
Expand All @@ -68,6 +137,9 @@ tasks.war {
// classpath(fileTree("additionalLibs")) // adds a file-set to the WEB-INF/lib dir.
// classpath(moreLibs) // adds a configuration to the WEB-INF/lib dir.
// webXml = file("src/someWeb.xml") // copies a file to WEB-INF/web.xml
doLast{
setWarVersion()
}
}

tasks {
Expand Down Expand Up @@ -107,18 +179,12 @@ tasks.register<Test>("searchOpenLDAP") {
// https://plugins.gradle.org/plugin/com.github.bjornvester.wsdl2java
// https://www.w3schools.com/xml/tempconvert.asmx?WSDL
wsdl2java {
// wsdlDir.set(layout.projectDirectory.dir("src/main/resources/wsdl"))
// https://plugins.gradle.org/plugin/com.github.bjornvester.wsdl2java
bindingFile.set(layout.projectDirectory.file("src/main/bindings/bindings.xjb"))

includes.set(
listOf(
"src/main/resources/wsdl/NumberConversion.wsdl"
)
)
// includesWithOptions.set(
// mapOf(
// "**/ServiceTemp.wsdl" to listOf("-wsdlLocation", "https://www.w3schools.com/xml/tempconvert.asmx?WSDL")
// )
// )
// default output directory $buildDir/generated/sources/wsdl2java/java
}
Loading

0 comments on commit 657500b

Please sign in to comment.