Move to different base image for Java

This way we can also support arm/v7
This commit is contained in:
Nanne Baars 2021-10-23 20:57:16 +02:00 committed by Nanne Baars
parent cc0d0fa2a6
commit 981fcb3ebc
5 changed files with 35 additions and 37 deletions

View File

@ -94,7 +94,7 @@ jobs:
context: ./docker context: ./docker
file: docker/Dockerfile file: docker/Dockerfile
push: true push: true
platforms: linux/amd64, linux/arm64 platforms: linux/amd64, linux/arm64, linux/arm/v7
tags: | tags: |
webgoat/goatandwolf:${{ env.WEBGOAT_TAG_VERSION }} webgoat/goatandwolf:${{ env.WEBGOAT_TAG_VERSION }}
webgoat/goatandwolf:latest webgoat/goatandwolf:latest

View File

@ -1,7 +1,4 @@
FROM openjdk:16-slim FROM eclipse-temurin:16.0.2_7-jdk-focal
ARG webgoat_version=8.2.1-SNAPSHOT
ENV webgoat_version_env=${webgoat_version}
RUN apt-get update RUN apt-get update
RUN useradd -ms /bin/bash webgoat RUN useradd -ms /bin/bash webgoat
@ -11,12 +8,12 @@ USER webgoat
COPY --chown=webgoat nginx.conf /etc/nginx/nginx.conf COPY --chown=webgoat nginx.conf /etc/nginx/nginx.conf
COPY --chown=webgoat index.html /usr/share/nginx/html/ COPY --chown=webgoat index.html /usr/share/nginx/html/
COPY --chown=webgoat target/webgoat-server-${webgoat_version}.jar /home/webgoat/webgoat.jar COPY --chown=webgoat target/webgoat-server-*.jar /home/webgoat/webgoat.jar
COPY --chown=webgoat target/webwolf-${webgoat_version}.jar /home/webgoat/webwolf.jar COPY --chown=webgoat target/webwolf-*.jar /home/webgoat/webwolf.jar
COPY --chown=webgoat start.sh /home/webgoat COPY --chown=webgoat start.sh /home/webgoat
EXPOSE 8080 EXPOSE 8080
EXPOSE 9090 EXPOSE 9090
WORKDIR /home/webgoat WORKDIR /home/webgoat
ENTRYPOINT /bin/bash /home/webgoat/start.sh $webgoat_version_env ENTRYPOINT /bin/bash start.sh

6
docker/start.sh Normal file → Executable file
View File

@ -16,11 +16,11 @@ java \
--add-opens java.desktop/java.awt.font=ALL-UNNAMED \ --add-opens java.desktop/java.awt.font=ALL-UNNAMED \
--add-opens java.base/sun.nio.ch=ALL-UNNAMED \ --add-opens java.base/sun.nio.ch=ALL-UNNAMED \
--add-opens java.base/java.io=ALL-UNNAMED \ --add-opens java.base/java.io=ALL-UNNAMED \
-jar webgoat.jar --webgoat.build.version="$1" --server.address=0.0.0.0 > webgoat.log & -jar webgoat.jar --server.address=0.0.0.0 > webgoat.log &
echo "Starting WebWolf..." echo "Starting WebWolf..."
java -Duser.home=/home/webgoat -Dfile.encoding=UTF-8 -jar webwolf.jar --webgoat.build.version=$1 --server.address=0.0.0.0 > webwolf.log & java -Duser.home=/home/webgoat -Dfile.encoding=UTF-8 -jar webwolf.jar --server.address=0.0.0.0 > webwolf.log &
echo "Browse to http://localhost to get started" >> webgoat.log echo "Browse to http://localhost to get started" >> webgoat.log
tail -300f webgoat.log exec tail -300f webgoat.log

View File

@ -53,18 +53,18 @@ public class StartWebGoat extends SpringBootServletInitializer {
String webgoatPort = System.getenv("WEBGOAT_PORT"); String webgoatPort = System.getenv("WEBGOAT_PORT");
String databasePort = System.getenv("WEBGOAT_HSQLPORT"); String databasePort = System.getenv("WEBGOAT_HSQLPORT");
String webGoatHost = null==System.getenv("WEBGOAT_HOST")?"127.0.0.1":System.getenv("WEBGOAT_HOST"); String webGoatHost = null == System.getenv("WEBGOAT_HOST") ? "127.0.0.1" : System.getenv("WEBGOAT_HOST");
int goatPort = webgoatPort == null?8080:Integer.parseInt(webgoatPort); int goatPort = webgoatPort == null ? 8080 : Integer.parseInt(webgoatPort);
int dbPort = databasePort == null?9001:Integer.parseInt(databasePort); int dbPort = databasePort == null ? 9001 : Integer.parseInt(databasePort);
if (isAlreadyRunning(webGoatHost, goatPort)) { if (isAlreadyRunning(webGoatHost, goatPort)) {
log.error("Port {}:{} is already in use", webGoatHost, goatPort); log.error("Port {}:{} is already in use", webGoatHost, goatPort);
System.out.println("Port "+webGoatHost+":"+goatPort+" is in use. Use environment value WEBGOAT_PORT to set a different value."); System.out.println("Port " + webGoatHost + ":" + goatPort + " is in use. Use environment value WEBGOAT_PORT to set a different value.");
System.exit(-1); System.exit(-1);
} }
if (isAlreadyRunning(webGoatHost, dbPort)) { if (isAlreadyRunning(webGoatHost, dbPort)) {
log.error("Port {}:{} is already in use", webGoatHost, goatPort); log.error("Port {}:{} is already in use", webGoatHost, goatPort);
System.out.println("Port "+webGoatHost+":"+goatPort+" is in use. Use environment value WEBGOAT_HSQLPORT to set a different value."); System.out.println("Port " + webGoatHost + ":" + goatPort + " is in use. Use environment value WEBGOAT_HSQLPORT to set a different value.");
System.exit(-1); System.exit(-1);
} }
SpringApplication.run(StartWebGoat.class, args); SpringApplication.run(StartWebGoat.class, args);

View File

@ -26,10 +26,12 @@ import java.io.IOException;
import java.net.Socket; import java.net.Socket;
import org.owasp.webwolf.requests.WebWolfTraceRepository; import org.owasp.webwolf.requests.WebWolfTraceRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.trace.http.HttpTraceRepository; import org.springframework.boot.actuate.trace.http.HttpTraceRepository;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Profile;
@SpringBootApplication @SpringBootApplication
public class WebWolf { public class WebWolf {
@ -43,20 +45,19 @@ public class WebWolf {
System.setProperty("spring.config.name", "application-webwolf"); System.setProperty("spring.config.name", "application-webwolf");
String webwolfPort = System.getenv("WEBWOLF_PORT"); String webwolfPort = System.getenv("WEBWOLF_PORT");
String webGoatHost = null==System.getenv("WEBGOAT_HOST")?"127.0.0.1":System.getenv("WEBGOAT_HOST"); String webWolfHost = null == System.getenv("WEBWOLF_HOST") ? "127.0.0.1" : System.getenv("WEBWOLF_HOST");
String webWolfHost = null==System.getenv("WEBWOLF_HOST")?"127.0.0.1":System.getenv("WEBWOLF_HOST");
String fileEncoding = System.getProperty("file.encoding"); String fileEncoding = System.getProperty("file.encoding");
int wolfPort = webwolfPort == null?9090:Integer.parseInt(webwolfPort); int wolfPort = webwolfPort == null ? 9090 : Integer.parseInt(webwolfPort);
if (null==fileEncoding || !fileEncoding.equals("UTF-8")) { if (null == fileEncoding || !fileEncoding.equals("UTF-8")) {
System.out.println("It seems the application is startd on a OS with non default UTF-8 encoding:"+fileEncoding); System.out.println("It seems the application is started on a OS with non default UTF-8 encoding:" + fileEncoding);
System.out.println("Please add: -Dfile.encoding=UTF-8"); System.out.println("Please add: -Dfile.encoding=UTF-8");
System.exit(-1); System.exit(-1);
} }
if (isAlreadyRunning(webGoatHost, wolfPort)) { if (isAlreadyRunning(webWolfHost, wolfPort)) {
System.out.println("Port "+webWolfHost+":"+wolfPort+" is in use. Use environment value WEBWOLF_PORT to set a different value."); System.out.println("Port " + webWolfHost + ":" + wolfPort + " is in use. Use environment value WEBWOLF_PORT to set a different value.");
System.exit(-1); System.exit(-1);
} }
SpringApplication.run(WebWolf.class, args); SpringApplication.run(WebWolf.class, args);