Improve Docker start up script
- Make sure the last line contains the information - Split in separate functions - Add option to skip starting nginx (by default it is started)
This commit is contained in:
		| @@ -1,5 +1,11 @@ | ||||
| # WebGoat release notes  | ||||
|  | ||||
| ## Unreleased | ||||
|  | ||||
| ### New functionality | ||||
|  | ||||
| - Update the Docker startup script, it is now possible to pass `skip-nginx` or set `SKIP_NGINX` as environment variable. | ||||
|  | ||||
| ## Version 8.2.2 | ||||
|  | ||||
| ### New functionality | ||||
|   | ||||
| @@ -11,9 +11,10 @@ COPY --chown=webgoat index.html /usr/share/nginx/html/ | ||||
| COPY --chown=webgoat target/webgoat-server-*.jar /home/webgoat/webgoat.jar | ||||
| COPY --chown=webgoat target/webwolf-*.jar /home/webgoat/webwolf.jar | ||||
| COPY --chown=webgoat start.sh /home/webgoat | ||||
| RUN chmod +x /home/webgoat/start.sh | ||||
|  | ||||
| EXPOSE 8080 | ||||
| EXPOSE 9090 | ||||
|  | ||||
| WORKDIR /home/webgoat | ||||
| ENTRYPOINT /bin/bash start.sh | ||||
| ENTRYPOINT ["./start.sh"] | ||||
|   | ||||
| @@ -1,26 +1,72 @@ | ||||
| #!/bin/bash | ||||
|  | ||||
| cd /home/webgoat  | ||||
| service nginx start | ||||
| sleep 1 | ||||
| echo "Starting WebGoat...." | ||||
|  | ||||
| java \ | ||||
|  -Duser.home=/home/webgoat \ | ||||
|  -Dfile.encoding=UTF-8 \ | ||||
|  --add-opens java.base/java.lang=ALL-UNNAMED \ | ||||
|  --add-opens java.base/java.util=ALL-UNNAMED \ | ||||
|  --add-opens java.base/java.lang.reflect=ALL-UNNAMED \ | ||||
|  --add-opens java.base/java.text=ALL-UNNAMED \ | ||||
|  --add-opens java.desktop/java.beans=ALL-UNNAMED \ | ||||
|  --add-opens java.desktop/java.awt.font=ALL-UNNAMED \ | ||||
|  --add-opens java.base/sun.nio.ch=ALL-UNNAMED \ | ||||
|  --add-opens java.base/java.io=ALL-UNNAMED \ | ||||
|  -jar webgoat.jar --server.address=0.0.0.0 > webgoat.log & | ||||
| function should_start_nginx() { | ||||
|   if [[ -v "${SKIP_NGINX}" ]]; then | ||||
|     return 1 | ||||
|   else | ||||
|     for i in "${commandline_args[@]}" ; do [[ $i == "skip-nginx" ]] && return 1 ; done | ||||
|   fi | ||||
|   return 0 | ||||
| } | ||||
|  | ||||
| function nginx() { | ||||
|   if should_start_nginx; then | ||||
|     echo "Starting nginx..." | ||||
|     service nginx start | ||||
|   fi | ||||
| } | ||||
|  | ||||
| function webgoat() { | ||||
|   echo "Starting WebGoat...." | ||||
|   java \ | ||||
|    -Duser.home=/home/webgoat \ | ||||
|    -Dfile.encoding=UTF-8 \ | ||||
|    --add-opens java.base/java.lang=ALL-UNNAMED \ | ||||
|    --add-opens java.base/java.util=ALL-UNNAMED \ | ||||
|    --add-opens java.base/java.lang.reflect=ALL-UNNAMED \ | ||||
|    --add-opens java.base/java.text=ALL-UNNAMED \ | ||||
|    --add-opens java.desktop/java.beans=ALL-UNNAMED \ | ||||
|    --add-opens java.desktop/java.awt.font=ALL-UNNAMED \ | ||||
|    --add-opens java.base/sun.nio.ch=ALL-UNNAMED \ | ||||
|    --add-opens java.base/java.io=ALL-UNNAMED \ | ||||
|    -jar webgoat.jar --server.address=0.0.0.0 > webgoat.log | ||||
| } | ||||
|  | ||||
| function webwolf() { | ||||
|   echo "Starting WebWolf..." | ||||
|   java -Duser.home=/home/webgoat -Dfile.encoding=UTF-8 -jar webwolf.jar --server.address=0.0.0.0 > webwolf.log | ||||
| } | ||||
|  | ||||
| function write_start_message() { | ||||
|   until $(curl --output /dev/null --silent --head --fail http://0.0.0.0:8080/WebGoat/health); do | ||||
|     sleep 2 | ||||
|   done | ||||
|   echo " | ||||
|     __          __       _        _____                   _ | ||||
|     \ \        / /      | |      / ____|                 | | | ||||
|      \ \  /\  / /  ___  | |__   | |  __    ___     __ _  | |_ | ||||
|       \ \/  \/ /  / _ \ | '_ \  | | |_ |  / _ \   / _' | | __| | ||||
|        \  /\  /  |  __/ | |_) | | |__| | | (_) | | (_| | | |_ | ||||
|         \/  \/    \___| |_.__/   \_____|  \___/   \__,_|  \__| | ||||
|   " >> webgoat.log | ||||
|   echo "WebGoat and WebWolf successfully started..." >> webgoat.log | ||||
|   pidof nginx >/dev/null && echo "Browse to http://localhost to get started" >> webgoat.log ||  echo "Browse to http://localhost:8080/WebGoat or http://localhost:9090/WebWolf to get started" >> webgoat.log | ||||
| } | ||||
|  | ||||
| function tail_log_file() { | ||||
|   touch webgoat.log | ||||
|   tail -300f webgoat.log | ||||
| } | ||||
|  | ||||
| commandline_args=("$@") | ||||
|  | ||||
| nginx | ||||
| webgoat & | ||||
| webwolf & | ||||
| write_start_message & | ||||
| tail_log_file | ||||
|  | ||||
| echo "Starting WebWolf..." | ||||
| 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 | ||||
|  | ||||
| exec tail -300f webgoat.log | ||||
|   | ||||
		Reference in New Issue
	
	Block a user