liferay / liferay-docker

Other
59 stars 145 forks source link

File copy in Kubernetes #65

Open lorenzozimolo opened 3 years ago

lorenzozimolo commented 3 years ago

Hello.

in Kubernetes I can mount a ConfigMap under /mnt/liferay/files (and subfolders) instead of mounting a volume. These files are exposed as symbolic links to hidden folders, to manage updates on ConfigMaps.

As a result the automatic copy in configure_liferay.sh, creates links and not regular files in the destination folders, and this fact denies modifications of the files (for example to inject credentials or other env variables), because ConfigMaps are immutable inside the container.

At the moment I execute a script before starting the server with the following code:

cd ${LIFERAY_MOUNT_DIR}/files/
find . -not -path '*/\.*' -type d -exec mkdir -v -p ${LIFERAY_HOME}/{} \;
find . -not -path '*/\.*' -not -type d -exec cp -v -H {} ${LIFERAY_HOME}/{} \;

but it's only a workaround.

Is it possible to better support this situation?

thanks Lorenzo

arbetts commented 3 years ago

@zsoltbalogh @lorenzozimolo from my understanding of the files mount point it is intended to be a LIFERAY_HOME override, which houses the tomcat app server and liferay web app. Based on my understanding of this extension point I would not suggest implementing the configure_liferay.sh script to read through symlinks and copy the underlying files.

in fact we use symlinks on the tomcat folder so that we can target it correctly even though its a link to the tomcat-version folder.

@lorenzozimolo you might be able to use the pre-configure lifecycle phase to read the configMap/secret file and then put it into the right location.

I've used inotifywait to accomplish a dynamic copy of files from the configMap directory into the liferay deploy folder like this:

inotifywait -m -q -e create --exclude data /mnt/my/config/map/ |
    while read watched_filename EVENT_NAMES event_filename; do
      if [[ -d "${watched_filename}${event_filename}" ]]; then
        echo "Notifying on directory creation event: ${watched_filename}${event_filename}"

        for file in ${watched_filename}${event_filename}/*; do
          if [[ -f ${file} ]]; then
            echo -e "Copying $(basename ${file}) to /opt/liferay/deploy"
            cp -p ${file} /opt/liferay/deploy 2>/dev/null
          fi
        done
      fi
    done
mr-ssd commented 2 years ago

@lorenzozimolo in configure_liferay.sh just update cp -r "${LIFERAY_MOUNT_DIR}"/files/* "${LIFERAY_HOME}" to cp -rL "${LIFERAY_MOUNT_DIR}"/files/* "${LIFERAY_HOME}" will fix the issue