Dockerfile 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. FROM maven:3.5-jdk-8-alpine as builder
  2. ARG LOCAL_MAVEN_MIRROR=http://maven.aliyun.com/nexus/content/groups/public/
  3. # used to edit maven settings.xml
  4. RUN apk add --no-cache xmlstarlet
  5. # change default local repository location. parent image set ~/.m2 as volume, so data won't be persisted for following build cmds
  6. RUN xmlstarlet ed --inplace -N 's=http://maven.apache.org/SETTINGS/1.0.0' \
  7. --subnode '/s:settings' --type elem -n localRepository -v '${user.home}/m2/repository' \
  8. /usr/share/maven/conf/settings.xml
  9. RUN if test -n "$LOCAL_MAVEN_MIRROR"; then \
  10. xmlstarlet ed --inplace -N 's=http://maven.apache.org/SETTINGS/1.0.0' \
  11. --subnode '/s:settings/s:mirrors' --type elem -n mirror -v '' \
  12. /usr/share/maven/conf/settings.xml \
  13. && xmlstarlet ed --inplace -N 's=http://maven.apache.org/SETTINGS/1.0.0' \
  14. --subnode '/s:settings/s:mirrors/s:mirror' --type elem -n id -v 'custom-mirror' \
  15. /usr/share/maven/conf/settings.xml \
  16. && xmlstarlet ed --inplace -N 's=http://maven.apache.org/SETTINGS/1.0.0' \
  17. --subnode '/s:settings/s:mirrors/s:mirror' --type elem -n name -v 'custom-mirror' \
  18. /usr/share/maven/conf/settings.xml \
  19. && xmlstarlet ed --inplace -N 's=http://maven.apache.org/SETTINGS/1.0.0' \
  20. --subnode '/s:settings/s:mirrors/s:mirror' --type elem -n url -v "$LOCAL_MAVEN_MIRROR" \
  21. /usr/share/maven/conf/settings.xml \
  22. && xmlstarlet ed --inplace -N 's=http://maven.apache.org/SETTINGS/1.0.0' \
  23. --subnode '/s:settings/s:mirrors/s:mirror' --type elem -n mirrorOf -v 'central' \
  24. /usr/share/maven/conf/settings.xml \
  25. ;fi
  26. # copy lib/ and src/ seperately to leverage cache (lib/ rarely changes)
  27. COPY ./lib /DWSurvey/lib
  28. RUN mvn install:install-file -Dfile=/DWSurvey/lib/QRCode.jar -DgroupId=net.qrcode -DartifactId=qrcode -Dversion=1.0 -Dpackaging=jar
  29. RUN mvn install:install-file -Dfile=/DWSurvey/lib/spssw-1.66.jar -DgroupId=net.spssw -DartifactId=spssw -Dversion=1.66 -Dpackaging=jar
  30. RUN mvn install:install-file -Dfile=/DWSurvey/lib/xssProtect-0.1.jar -DgroupId=net.xssprotect -DartifactId=xssprotest -Dversion=1.0 -Dpackaging=jar
  31. # if pom.xml is not updates, m2/ may be cached as well
  32. COPY pom.xml /DWSurvey/pom.xml
  33. RUN cd /DWSurvey && mvn dependency:resolve
  34. # copy src/ and build, src changes constantly
  35. COPY ./src /DWSurvey/src
  36. RUN cd /DWSurvey && mvn install
  37. # ------------------------- 8< -------------------------
  38. # there is a bug with 8.0-jre8-alpine, which was introduced in alpine3.6
  39. # see: https://bugs.alpinelinux.org/issues/7372
  40. # image layers: tomcat:8.0-jre8 -> openjdk:8-jre-alpine -> alpine:3.6
  41. # let's switch to 8.0-jre8-alpine after alpine has fixed the bug (alpine 3.6.3 release)
  42. FROM tomcat:8.0-jre8
  43. ENV MYSQL_HOST= MYSQL_PORT=3306 MYSQL_DATABASE= MYSQL_USER= MYSQL_PASSWORD=
  44. ENV ADMIN_EMAIL= ADMIN_PASSWORD=
  45. ENV CONTEXT_ROOT=/
  46. # install xmlstarlet to edit configurations
  47. #RUN apk add --no-cache xmlstarlet mysql-client bash
  48. RUN apt-get update \
  49. && DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
  50. xmlstarlet \
  51. mysql-client \
  52. && rm -rf /var/lib/apt/lists/* \
  53. && rm -rf /usr/local/tomcat/webapps/ \
  54. && mkdir /usr/local/tomcat/webapps/
  55. COPY --from=builder /DWSurvey/target/diaowen.war /target/diaowen.war
  56. COPY docker-entry.sh /docker-entry.sh
  57. # TODO , specify volumes
  58. EXPOSE 8080
  59. ENTRYPOINT [ "/docker-entry.sh" ]