From 1182927d597038c8b2c30318ed74ba275add9cd2 Mon Sep 17 00:00:00 2001
From: Fabrice Gangler <fabrice@asqatasun.org>
Date: Sun, 10 Dec 2017 08:25:17 +0100
Subject: [PATCH] Fixed #112 - Added new docker image: alpine 3.7 (tomcat-7)

---
 CHANGELOG.md                                  |  8 +-
 docker/RELEASE/alpine-3.7_tomcat-7/Dockerfile | 82 ++++++++++++++++++
 docker/RELEASE/alpine-3.7_tomcat-7/README.md  |  1 +
 .../distrib/alpine-3.7_tomcat-7/Dockerfile    | 57 ++++++++++++
 .../Dockerfile                                | 86 +++++++++++++++++++
 5 files changed, 230 insertions(+), 4 deletions(-)
 create mode 100644 docker/RELEASE/alpine-3.7_tomcat-7/Dockerfile
 create mode 120000 docker/RELEASE/alpine-3.7_tomcat-7/README.md
 create mode 100644 docker/SNAPSHOT-local/distrib/alpine-3.7_tomcat-7/Dockerfile
 create mode 100644 docker/pre-requisites/pre-requisites_alpine-3.7_tomcat-7/Dockerfile

diff --git a/CHANGELOG.md b/CHANGELOG.md
index c9193330..5d2623aa 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -18,7 +18,9 @@ none
 none
 
 ### Improvement 
-none
+- [#110 - Added new docker image: ubuntu 16.04 (tomcat-7)](https://github.com/Asqatasun/Contrast-Finder/issues/110) 
+- [#112 - Added new docker image: alpine 3.7 (tomcat-7)](https://github.com/Asqatasun/Contrast-Finder/issues/112) 
+- [#109 - Docker/pre-requisites/ - Added /etc/contrast-finder/softwares-version.txt](https://github.com/Asqatasun/Contrast-Finder/issues/109) 
 
 ### Refactoring
 none
@@ -30,9 +32,7 @@ none
 none
 
 ### Task
-- [#111 -.travis.yml - Add openjdk8 in addition to openjdk7](https://github.com/Asqatasun/Contrast-Finder/issues/111)
-- [#110 - Added new docker image: ubuntu 16.04 (tomcat-7)](https://github.com/Asqatasun/Contrast-Finder/issues/110) 
-- [#109 - Docker/pre-requisites/ - Added /etc/contrast-finder/softwares-version.txt](https://github.com/Asqatasun/Contrast-Finder/issues/109) 
+- [#111 -.travis.yml - Added openjdk8 in addition to openjdk7](https://github.com/Asqatasun/Contrast-Finder/issues/111)
 - [#106 - Added unit tests coverage report (cobertura-maven-plugin)](https://github.com/Asqatasun/Contrast-Finder/issues/106) 
 
 
diff --git a/docker/RELEASE/alpine-3.7_tomcat-7/Dockerfile b/docker/RELEASE/alpine-3.7_tomcat-7/Dockerfile
new file mode 100644
index 00000000..7432a581
--- /dev/null
+++ b/docker/RELEASE/alpine-3.7_tomcat-7/Dockerfile
@@ -0,0 +1,82 @@
+FROM asqatasun/contrast-finder:pre-requisites_alpine-3.7_tomcat-7
+LABEL org.label-schema.schema-version = "1.0.0-rc.1"                                                                \
+      org.label-schema.name           = "Contrast-Finder - WebApp (tomcat7 < jdk7 < alpine 3.7)"                    \
+      org.label-schema.version        = "0.8.4-SNAPSHOT"                                                            \
+      org.label-schema.url            = "https://contrast-finder.org"                                               \
+      org.label-schema.vcs-url        = "https://github.com/Asqatasun/Contrast-Finder"                              \
+      org.label-schema.docker.cmd     = "docker run -p 8087:8080 -d asqatasun/contrast-finder:alpine"               \
+      org.label-schema.usage          = "https://github.com/Asqatasun/Contrast-Finder/tree/develop/documentation/"  \
+      org.label-schema.description    = "Contrast-Finder finds correct color contrasts for web accessibility."
+          # ----> documentation  http://label-schema.org/
+
+# #### usage ######################################################
+#
+#   --- Building this docker image
+#   docker build -t asqatasun/contrast-finder  .
+#   docker build -t asqatasun/contrast-finder  --build-arg CONTRAST_FINDER_RELEASE=0.8.4-SNAPSHOT  .
+#   docker build -t asqatasun/contrast-finder  --build-arg SRC_URL_PREFIX=https://github.com/Asqatasun/Contrast-Finder/releases/download/v0.8.4-SNAPSHOT/   .
+#   docker build -t asqatasun/contrast-finder  --build-arg SRC_URL=https://github.com/Asqatasun/Contrast-Finder/releases/download/v0.8.4-SNAPSHOT/contrast-finder_0.8.4-SNAPSHOT.i386.tar.gz   .
+#
+#   --- Launch a container
+#   docker run -p 127.0.0.1:8087:8080 --name contrast.finder -d asqatasun/contrast-finder
+#
+#   --- Playing with this docker image
+#   docker exec -ti contrast.finder /bin/cat  /softwares-version.txt
+#   docker exec -ti contrast.finder /bin/bash
+#   docker logs -f contrast.finder
+#
+# #### source code  ###############################################
+#   https://github.com/Asqatasun/Contrast-Finder/releases/download/v${CONTRAST_FINDER_RELEASE}/contrast-finder_${CONTRAST_FINDER_RELEASE}.i386.tar.gz
+#     could be overridden with  --build-arg CONTRAST_FINDER_RELEASE=<release>
+#     could be overridden with  --build-arg SRC_URL_PREFIX=<url_prefix>
+#     could be overridden with  --build-arg SRC_URL=<url>
+#
+# #### FROM  ######################################################
+#   asqatasun/contrast-finder:pre-requisites_alpine-3.7_tomcat-7  https://github.com/Asqatasun/Contrast-Finder/blob/master/docker/pre-requisites/contrast-finder:pre-requisites_alpine-3.7_tomcat-7/Dockerfile
+#   |-- tomcat:7-jre7-alpine                                      https://github.com/docker-library/tomcat/blob/master/7/jre7-alpine/Dockerfile
+#       |-- openjdk:7-jre-alpine                                  https://github.com/docker-library/openjdk/blob/master/7-jre/alpine/Dockerfile
+#           |-- alpine:3.7                                        https://github.com/gliderlabs/docker-alpine/blob/master/versions/library-3.7/x86_64/Dockerfile
+###################################################################
+
+# build variables
+ARG CONTRAST_FINDER_RELEASE="0.8.4-SNAPSHOT"
+ARG SRC_URL_PREFIX="https://github.com/Asqatasun/Contrast-Finder/releases/download/v${CONTRAST_FINDER_RELEASE}"
+ARG SRC_URL="${SRC_URL_PREFIX}/contrast-finder_${CONTRAST_FINDER_RELEASE}.i386.tar.gz"
+
+# Install contrast-finder
+RUN  cd         /root/                                              && \
+     wget       ${SRC_URL}                                          && \
+     tar  -xzvf contrast-*.tar.gz                                   && \
+     cd         /root/contrast-*/install/                           && \
+     mv   -v    contrast-*.war    contrast-finder.war               && \
+     mv   -v    contrast-*.war    ${TOMCAT_DIR}webapps              && \
+     rm   -rf  /root/contrast-*                                     && \
+     echo ${CONTRAST_FINDER_RELEASE}               >> ${INFO_FILE}  && \
+     echo ""                                       >> ${INFO_FILE}  && \
+     echo "--- ${CONF_FILE} ---"                   >> ${INFO_FILE}  && \
+     cat  ${CONF_FILE}                             >> ${INFO_FILE}  && \
+     echo ""                                       >> ${INFO_FILE}  && \
+     echo "--- Logs -----------"                   >> ${INFO_FILE}  && \
+     echo "${TOMCAT_DIR}logs/catalina.*.log"       >> ${INFO_FILE}  && \
+     echo "${LOG_FILE}"                            >> ${INFO_FILE}  && \
+     echo "--------------------"                   >> ${INFO_FILE}  && \
+     cat  ${INFO_FILE} > ${LOG_FILE} && echo "-- Install: Ok"
+
+# environment variables
+ENV CONTRAST_FINDER=${CONTRAST_FINDER_RELEASE}
+ENV SRC=${SRC_URL}
+
+
+# Health Check of the Docker Container
+# ----> see asqatasun/contrast-finder:pre-requisites_(...)
+
+
+###### don't work ############################
+# CMD  catalina.sh run ;                                \
+#      tail -f -n 200 ${TOMCAT_DIR}logs/catalina.*.log  \
+#                    ${LOG_FILE}
+###################################################
+
+    # in "tomcat:7.0-jre7" DockerFile
+    #     CMD ["catalina.sh", "run"]
+
diff --git a/docker/RELEASE/alpine-3.7_tomcat-7/README.md b/docker/RELEASE/alpine-3.7_tomcat-7/README.md
new file mode 120000
index 00000000..32d46ee8
--- /dev/null
+++ b/docker/RELEASE/alpine-3.7_tomcat-7/README.md
@@ -0,0 +1 @@
+../README.md
\ No newline at end of file
diff --git a/docker/SNAPSHOT-local/distrib/alpine-3.7_tomcat-7/Dockerfile b/docker/SNAPSHOT-local/distrib/alpine-3.7_tomcat-7/Dockerfile
new file mode 100644
index 00000000..1e31ac95
--- /dev/null
+++ b/docker/SNAPSHOT-local/distrib/alpine-3.7_tomcat-7/Dockerfile
@@ -0,0 +1,57 @@
+FROM asqatasun/contrast-finder:pre-requisites_alpine-3.7_tomcat-7
+
+# #### usage ######################################################
+#
+#   --- Building this docker image
+#   docker build -t asqatasun/contrast-finder:SNAPSHOT_local  .
+#
+#   --- Launch a container
+#   docker run -p 127.0.0.1:8087:8080 --name contrast.finder -d asqatasun/contrast-finder:SNAPSHOT_local
+#
+#   --- Playing with this docker image
+#   docker exec -ti contrast.finder /bin/cat  /softwares-version.txt
+#   docker exec -ti contrast.finder /bin/bash
+#   docker logs -f contrast.finder
+#
+# #### FROM  ######################################################
+#   asqatasun/contrast-finder:pre-requisites_alpine-3.7_tomcat-7  https://github.com/Asqatasun/Contrast-Finder/blob/master/docker/pre-requisites/contrast-finder:pre-requisites_alpine-3.7_tomcat-7/Dockerfile
+#   |-- tomcat:7-jre7-alpine                                      https://github.com/docker-library/tomcat/blob/master/7/jre7-alpine/Dockerfile
+#       |-- openjdk:7-jre-alpine                                  https://github.com/docker-library/openjdk/blob/master/7-jre/alpine/Dockerfile
+#           |-- alpine:3.7                                        https://github.com/gliderlabs/docker-alpine/blob/master/versions/library-3.7/x86_64/Dockerfile
+###################################################################
+
+# environment variables
+ENV CONTRAST_FINDER_RELEASE="0.8.4-SNAPSHOT"
+
+# Add contrast-finder .war
+ADD contrast-finder_${CONTRAST_FINDER_RELEASE}.i386.tar.gz  /root
+
+# Install contrast-finder
+RUN  cd      /root/contrast-*/install/                              && \
+     mv -v   contrast-*.war contrast-finder.war                     && \
+     mv -v   contrast-*.war ${TOMCAT_DIR}webapps                    && \
+     rm -rf  /root/contrast-*                                       && \
+     echo ${CONTRAST_FINDER_RELEASE}               >> ${INFO_FILE}  && \
+     echo ""                                       >> ${INFO_FILE}  && \
+     echo "--- ${CONF_FILE} ---"                   >> ${INFO_FILE}  && \
+     cat  ${CONF_FILE}                             >> ${INFO_FILE}  && \
+     echo ""                                       >> ${INFO_FILE}  && \
+     echo "--- Logs -----------"                   >> ${INFO_FILE}  && \
+     echo "${TOMCAT_DIR}logs/catalina.*.log"       >> ${INFO_FILE}  && \
+     echo "${LOG_FILE}"                            >> ${INFO_FILE}  && \
+     echo "--------------------"                   >> ${INFO_FILE}  && \
+     cat  ${INFO_FILE} > ${LOG_FILE} && echo "-- Install: Ok"
+
+
+# Health Check of the Docker Container
+# ----> see asqatasun/contrast-finder:pre-requisites_(...)
+
+
+###### don't work ############################
+# CMD  catalina.sh run ;                                \
+#      tail -f -n 200 ${TOMCAT_DIR}logs/catalina.*.log  \
+#                    ${LOG_FILE}
+###################################################
+
+    # in "tomcat:7.0-jre7" DockerFile
+    #     CMD ["catalina.sh", "run"]
diff --git a/docker/pre-requisites/pre-requisites_alpine-3.7_tomcat-7/Dockerfile b/docker/pre-requisites/pre-requisites_alpine-3.7_tomcat-7/Dockerfile
new file mode 100644
index 00000000..14fc813b
--- /dev/null
+++ b/docker/pre-requisites/pre-requisites_alpine-3.7_tomcat-7/Dockerfile
@@ -0,0 +1,86 @@
+FROM tomcat:7-jre7-alpine
+LABEL org.label-schema.schema-version = "1.0.0-rc.1"                                                             \
+      org.label-schema.name           = "Contrast-Finder - WebApp pre-requisites (tomcat7 < jdk7 < alpine 3.7)"  \
+      org.label-schema.url            = "https://contrast-finder.org"                                            \
+      org.label-schema.vcs-url        = "https://github.com/Asqatasun/Contrast-Finder"                           \
+      org.label-schema.version        = "0.8.4-SNAPSHOT"
+          # ----> documentation  http://label-schema.org/
+
+# #### usage ######################################################
+#
+#   --- Building this docker image
+#   docker build -t contrast-finder:pre-requisites_Alpine-3.7_Tomcat-7 .
+#
+# #### FROM  ######################################################
+#   tomcat:7-jre7-alpine       https://github.com/docker-library/tomcat/blob/master/7/jre7-alpine/Dockerfile
+#   |-- openjdk:7-jre-alpine   https://github.com/docker-library/openjdk/blob/master/7-jre/alpine/Dockerfile
+#       |-- alpine:3.7         https://github.com/gliderlabs/docker-alpine/blob/master/versions/library-3.7/x86_64/Dockerfile
+###################################################################
+
+######  PRE-REQUISITES ##########################################################
+
+# build variables
+ARG LOG_DIR="/var/log/contrast-finder/"
+ARG CONF_DIR="/etc/contrast-finder/"
+ARG URL_FOR_SPRING_INSTRUMENT_JAR="https://repo.spring.io/release/org/springframework/spring-instrument-tomcat/4.3.13.RELEASE/spring-instrument-tomcat-4.3.13.RELEASE.jar"
+
+    ##################################################################################################
+    # https://repo.spring.io/release/org/springframework/spring-instrument-tomcat/
+    # LAST  https://repo.spring.io/release/org/springframework/spring-instrument-tomcat/4.3.13.RELEASE/
+    #       JAR   spring-instrument-tomcat-4.3.13.RELEASE.jar
+    #       SHA1  spring-instrument-tomcat-4.3.13.RELEASE.jar.sha1
+    ##################################################################################################
+
+# environment variables
+ENV     SPRING_INSTRUMENT_SRC="${URL_FOR_SPRING_INSTRUMENT_JAR}"     \
+        TOMCAT_DIR="/usr/local/tomcat/"                              \
+        LOG_FILE="${LOG_DIR}contrast-finder.log"                     \
+        CONF_FILE="${CONF_DIR}contrast-finder.conf"                  \
+        INFO_FILE="/softwares-version.txt"                           \
+        WWWPORT="8080"
+EXPOSE  $WWWPORT
+
+# build
+RUN  cd      ${TOMCAT_DIR}lib/                              && \
+     wget    ${SPRING_INSTRUMENT_SRC}                       && \
+     apk add --no-cache curl                                && \
+     mkdir   -p  ${LOG_DIR}                                 && \
+     mkdir   -p  ${CONF_DIR}                                && \
+     touch   ${LOG_FILE}                                    && \
+     touch   ${CONF_FILE}                                   && \
+     echo "--- OS -------------"       >> ${INFO_FILE}      && \
+     cat /etc/os-release               >> ${INFO_FILE}      && \
+     echo ""                           >> ${INFO_FILE}      && \
+     echo "--- Java -----------"       >> ${INFO_FILE}      && \
+     echo ${JAVA_HOME}                 >> ${INFO_FILE}      && \
+     java -version                    2>> ${INFO_FILE}      && \
+     echo ""                           >> ${INFO_FILE}      && \
+     echo "--- Tomcat ---------"       >> ${INFO_FILE}      && \
+     ${TOMCAT_DIR}bin/version.sh       >> ${INFO_FILE}      && \
+     echo ""                           >> ${INFO_FILE}      && \
+     echo "--- Contrast-Finder ---"    >> ${INFO_FILE}
+
+
+        #######################################################################################
+        # The command line "java -version" returns the output data
+        # at the STDERR stream (2 : error messages) rather than STDOUT (1).
+        # -----> java -version 2> tmp.txt
+        #
+        # https://stackoverflow.com/questions/21453774/redirect-java-version-to-file-or-variable
+        # https://stackoverflow.com/questions/39619087/how-to-write-output-of-java-version-to-a-text-file
+        #######################################################################################
+
+
+# Health Check of the Docker Container
+HEALTHCHECK --timeout=3s    \
+            CMD curl --fail http://localhost:8080/contrast-finder/ || exit 1
+            ######################################################################
+            # doc: https://docs.docker.com/engine/reference/builder/#healthcheck
+            # options:  --interval=DURATION (default: 30s)
+            #           --timeout=DURATION (default: 30s)
+            #           --retries=N (default: 3)
+            # can be overridden at the command line 'docker run --health-cmd (...)'
+            ######################################################################
+
+# in "tomcat:7-jre7-alpine" DockerFile
+#     CMD ["catalina.sh", "run"]