Skip to content

Commit

Permalink
All in one docker (WebGoat#749)
Browse files Browse the repository at this point in the history
* all-in-one Dockerfile preparations

* some cleanup

* add to main pom and add links in index.html

* updated deploy script from build pipeline

* additional line feed just in case
  • Loading branch information
zubcevic authored Jan 25, 2020
1 parent 4e371b6 commit 9eee726
Show file tree
Hide file tree
Showing 9 changed files with 290 additions and 1 deletion.
1 change: 1 addition & 0 deletions docker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.jar
30 changes: 30 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM openjdk:11.0.1-jre-slim-stretch

ARG webgoat_version=v8.0.0-SNAPSHOT
ENV webgoat_version_env=${webgoat_version}

RUN apt-get update && apt-get install
RUN useradd --home-dir /home/webgoat --create-home -U webgoat
RUN apt-get -y install apt-utils nginx

USER webgoat
RUN cd /home/webgoat/; mkdir -p .webgoat-${webgoat_version}

COPY nginx.conf /etc/nginx/nginx.conf
COPY index.html /usr/share/nginx/html/
COPY webgoat-server-${webgoat_version}.jar /home/webgoat/webgoat.jar
COPY webwolf-${webgoat_version}.jar /home/webgoat/webwolf.jar
COPY start.sh /home/webgoat

EXPOSE 8080
EXPOSE 9090

ENV WEBGOAT_PORT 8080
ENV WEBGOAT_SSLENABLED false

ENV GOATURL https://127.0.0.1:$WEBGOAT_PORT
ENV WOLFURL http://127.0.0.1:9090


WORKDIR /home/webgoat
ENTRYPOINT /bin/bash /home/webgoat/start.sh $webgoat_version_env
9 changes: 9 additions & 0 deletions docker/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Docker all-in-one image

## Docker build

docker build --no-cache --build-arg webgoat_version=v8.0.0-SNAPSHOT -t webgoat/goatandwolf:latest .

## Docker run

docker run -d -p 80:8888 -p 8080:8080 -p 9090:9090 -e TZ=Europe/Amsterdam webgoat/goatandwolf:latest
43 changes: 43 additions & 0 deletions docker/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html>
<body>
<h1>OWASP WebGoat Training tools</h1>
<p>
Use the following links to access the WebGoat and WebWolf applications.
Register a user using WebGoat. The same user can access WebWolf.
</p>

<h2>Use without special host name entries</h2>

<table>
<tr>
<td>WebGoat URL</td>
<td><a href="http://127.0.0.1:8080/WebGoat" target="_blank">http://127.0.0.1:8080/WebGoat</a></td>
</tr>
<tr>
<td>WebWolf URL</td>
<td><a href="http://127.0.0.1:9090/WebWolf" target="_blank">http://127.0.0.1:9090/WebWolf</a></td>
</tr>
<table>

<h2>Use with www.webgoat.local and www.webwolf.local</h2>
<p>
Add the following entries to your local <b><i>hosts</i></b> file on Windows (c:\Windows\System32\drivers\etc\hosts) or Linux (/etc/hosts)

<pre>
127.0.0.1 www.webgoat.local www.webwolf.local
</pre>
Then use the following URL's:
</p>
<table>
<tr>
<td>WebGoat URL</td>
<td><a href="http://www.webgoat.local/WebGoat" target="_blank">http://www.webgoat.local/WebGoat</a></td>
</tr>
<tr>
<td>WebWolf URL</td>
<td><a href="http://www.webwolf.local/WebWolf" target="_blank">http://www.webwolf.local/WebWolf</a></td>
</tr>
<table>
</body>
</html>
140 changes: 140 additions & 0 deletions docker/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
error_log /tmp/error.log;
pid /tmp/nginx.pid;

worker_processes 1;

events { worker_connections 1024; }

http {

client_body_temp_path /tmp/client_body;
fastcgi_temp_path /tmp/fastcgi_temp;
proxy_temp_path /tmp/proxy_temp;
scgi_temp_path /tmp/scgi_temp;
uwsgi_temp_path /tmp/uwsgi_temp;

sendfile on;

upstream docker-webgoat {
server 127.0.0.1:8080;
}

upstream docker-webwolf {
server 127.0.0.1:9090;
}

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;

server {
listen 8888;
server_name www.webgoat.local;

root /var/www;

access_log /tmp/goataccess.log;
error_log /tmp/goaterror.log;

location ~* \.(png|jpg|jpeg|gif|ico|woff|otf|ttf|mvc|svg|txt|pdf|docx?|xlsx?)$ {
access_log off;
proxy_pass http://docker-webgoat;
proxy_redirect off;
}

location / {
root /usr/share/nginx/html;
index index.html;
add_header Cache-Control no-cache;
expires 0;
}

location /WebGoat {
proxy_pass http://docker-webgoat;
proxy_redirect off;
}

}

server {
listen 8888;
server_name www.webwolf.local;

root /var/www;

access_log /tmp/wolfaccess.log;
error_log /tmp/wolferror.log;

location /WebGoat/PasswordReset/ForgotPassword/create-password-reset-link {
proxy_pass http://docker-webgoat;
proxy_redirect off;
}

location /PasswordReset/reset/reset-password {
proxy_pass http://docker-webwolf;
proxy_redirect off;
}

location /files {
proxy_pass http://docker-webwolf;
proxy_redirect off;
}

location /tmpdir {
proxy_pass http://docker-webwolf;
proxy_redirect off;
}

location /webjars {
proxy_pass http://docker-webwolf;
proxy_redirect off;
}

location /css {
proxy_pass http://docker-webwolf;
proxy_redirect off;
}

location /login {
proxy_pass http://docker-webwolf;
proxy_redirect off;
}

location /images {
proxy_pass http://docker-webwolf;
proxy_redirect off;
}

location /mail {
proxy_pass http://docker-webwolf;
proxy_redirect off;
}

location /upload {
proxy_pass http://docker-webwolf;
proxy_redirect off;
}

location /js {
proxy_pass http://docker-webwolf;
proxy_redirect off;
}

location /landing {
proxy_pass http://docker-webwolf;
proxy_redirect off;
}

location /logout {
proxy_pass http://docker-webwolf;
proxy_redirect off;
}

location /WebWolf {
proxy_pass http://docker-webwolf;
proxy_redirect off;
}

}
}
40 changes: 40 additions & 0 deletions docker/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>webgoat-all-in-one-docker</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>org.owasp.webgoat</groupId>
<artifactId>webgoat-parent</artifactId>
<version>v8.0.0-SNAPSHOT</version>
</parent>

<dependencies>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>install</phase>
<configuration>
<target>
<copy file="../webgoat-server/target/webgoat-server-${project.version}.jar" tofile="webgoat-server-${project.version}.jar"/>
<copy file="../webwolf/target/webwolf-${project.version}.jar" tofile="webwolf-${project.version}.jar"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
12 changes: 12 additions & 0 deletions docker/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

cd /home/webgoat
service nginx start
sleep 1
java -Dfile.encoding=UTF-8 -jar webgoat.jar --webgoat.build.version=$1 --server.address=0.0.0.0 > webgoat.log &

sleep 10

java -Dfile.encoding=UTF-8 -jar webwolf.jar --webgoat.build.version=$1 --server.address=0.0.0.0 > webwolf.log &

tail -300f webgoat.log
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
<module>webgoat-server</module>
<module>webwolf</module>
<module>webgoat-integration-tests</module>
<module>docker</module><!-- copy required jars in preparation of docker all-in-one build -->
</modules>

<dependencies>
Expand Down
15 changes: 14 additions & 1 deletion scripts/deploy-webgoat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,17 @@ if [ ! -z "${TRAVIS_TAG}" ]; then
docker push $REPO
else
echo "Skipping releasing to DockerHub because it is a build of branch ${BRANCH}"
fi
fi

export REPO=webgoat/goatandwolf
cd ..
cd docker
ls target/

if [ ! -z "${TRAVIS_TAG}" ]; then
# If we push a tag to master this will update the LATEST Docker image and tag with the version number
docker build --build-arg webgoat_version=${TRAVIS_TAG:1} -f Dockerfile -t $REPO:latest -t $REPO:${TRAVIS_TAG} .
docker push $REPO
else
echo "Skipping releasing to DockerHub because it is a build of branch ${BRANCH}"
fi

0 comments on commit 9eee726

Please sign in to comment.