docker-entrypoint.sh 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/bash
  2. #set -e
  3. LETS_ENCRYPT_ENABLED=${LETS_ENCRYPT_ENABLED:-false}
  4. PUBLIC_DNS=${PUBLIC_DNS:-'draw.example.com'}
  5. ORGANISATION_UNIT=${ORGANIZATION_UNIT:-'Cloud Native Application'}
  6. ORGANISATION=${ORGANISATION:-'example inc'}
  7. CITY=${CITY:-'Paris'}
  8. STATE=${STATE:-'Paris'}
  9. COUNTRY_CODE=${COUNTRY:-'FR'}
  10. KEYSTORE_PASS=${KEYSTORE_PASS:-'V3ry1nS3cur3P4ssw0rd'}
  11. KEY_PASS=${KEY_PASS:-$KEYSTORE_PASS}
  12. if ! [ -f $CATALINA_HOME/.keystore ] && [ "$LETS_ENCRYPT_ENABLED" == "true" ]; then
  13. echo "Generating Let's Encrypt certificate"
  14. keytool -genkey -noprompt -alias tomcat -dname "CN=${PUBLIC_DNS}, OU=${ORGANISATION_UNIT}, O=${ORGANISATION}, L=${CITY}, S=${STATE}, C=${COUNTRY_CODE}" -keystore $CATALINA_HOME/.keystore -storepass "${KEYSTORE_PASS}" -KeySize 2048 -keypass "${KEY_PASS}" -keyalg RSA -storetype pkcs12
  15. keytool -list -keystore $CATALINA_HOME/.keystore -v -storepass "${KEYSTORE_PASS}"
  16. keytool -certreq -alias tomcat -file request.csr -keystore $CATALINA_HOME/.keystore -storepass "${KEYSTORE_PASS}"
  17. certbot certonly --csr $CATALINA_HOME/request.csr --standalone --register-unsafely-without-email --agree-tos
  18. keytool -import -trustcacerts -alias tomcat -file 0001_chain.pem -keystore $CATALINA_HOME/.keystore -storepass "${KEYSTORE_PASS}"
  19. fi
  20. if ! [ -f $CATALINA_HOME/.keystore ] && [ "$LETS_ENCRYPT_ENABLED" == "false" ]; then
  21. echo "Generating Self-Signed certificate"
  22. keytool -genkey -noprompt -alias selfsigned -dname "CN=${PUBLIC_DNS}, OU=${ORGANISATION_UNIT}, O=${ORGANISATION}, L=${CITY}, S=${STATE}, C=${COUNTRY_CODE}" -keystore $CATALINA_HOME/.keystore -storepass "${KEYSTORE_PASS}" -KeySize 2048 -keypass "${KEY_PASS}" -keyalg RSA -validity 3600 -storetype pkcs12
  23. keytool -list -keystore $CATALINA_HOME/.keystore -v -storepass "${KEYSTORE_PASS}"
  24. fi
  25. # Update SSL port configuration if it does'nt exists
  26. #
  27. UUID="$(cat /dev/urandom | tr -dc 'a-zA-Z' | fold -w 1 | head -n 1)$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 7 | head -n 1)"
  28. VAR=$(cat conf/server.xml | grep "$CATALINA_HOME/.keystore")
  29. if [ -f $CATALINA_HOME/.keystore ] && [ -z $VAR ]; then
  30. echo "Append https connector to server.xml"
  31. xmlstarlet ed \
  32. -P -S -L \
  33. -s '/Server/Service' -t 'elem' -n "${UUID}" \
  34. -i "/Server/Service/${UUID}" -t 'attr' -n 'port' -v '8443' \
  35. -i "/Server/Service/${UUID}" -t 'attr' -n 'protocol' -v 'org.apache.coyote.http11.Http11NioProtocol' \
  36. -i "/Server/Service/${UUID}" -t 'attr' -n 'SSLEnabled' -v 'true' \
  37. -i "/Server/Service/${UUID}" -t 'attr' -n 'maxThreads' -v '150' \
  38. -i "/Server/Service/${UUID}" -t 'attr' -n 'scheme' -v 'https' \
  39. -i "/Server/Service/${UUID}" -t 'attr' -n 'secure' -v 'true' \
  40. -i "/Server/Service/${UUID}" -t 'attr' -n 'clientAuth' -v 'false' \
  41. -i "/Server/Service/${UUID}" -t 'attr' -n 'sslProtocol' -v 'TLS' \
  42. -i "/Server/Service/${UUID}" -t 'attr' -n 'KeystoreFile' -v "$CATALINA_HOME/.keystore" \
  43. -i "/Server/Service/${UUID}" -t 'attr' -n 'KeystorePass' -v "${KEY_PASS}" \
  44. -r "/Server/Service/${UUID}" -v 'Connector' \
  45. conf/server.xml
  46. fi
  47. #Run the export server
  48. cd /usr/local/drawio/draw-image-export2
  49. npm start &
  50. cd $CATALINA_HOME
  51. exec "$@"