diff --git a/wordpress/6-apache/Dockerfile b/wordpress/6-apache/Dockerfile index f1078d3c..f553311e 100644 --- a/wordpress/6-apache/Dockerfile +++ b/wordpress/6-apache/Dockerfile @@ -186,7 +186,8 @@ RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli # hadolint ignore=DL3045 # Add default configuration files COPY --chown=www-data:www-data etc/wp-config.php /var/www/html/ -RUN mkdir /.artifakt +COPY etc/entrypoint.sh /.artifakt/ + COPY docker-entrypoint.sh /usr/local/bin/ ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] diff --git a/wordpress/6-apache/docker-entrypoint.sh b/wordpress/6-apache/docker-entrypoint.sh index 06bf7ad5..fbe9c5d9 100755 --- a/wordpress/6-apache/docker-entrypoint.sh +++ b/wordpress/6-apache/docker-entrypoint.sh @@ -11,6 +11,31 @@ for persistent_folder in "${PERSISTENT_FOLDER_LIST[@]}"; do chown -h www-data:www-data "/var/www/html/$persistent_folder" "/data/$persistent_folder" done +if [[ -x "/.artifakt/entrypoint.sh" ]]; then + + # source: https://gist.github.com/karlrwjohnson/1921b05c290edb665c238676ef847f3c + function lock_cmd { + LOCK_FILE="$1"; shift + LOCK_TIMEOUT="$1"; shift; + + ( + trap "rm -f $LOCK_FILE" 0 + flock -x -w $LOCK_TIMEOUT 200 + RETVAL=$? + if [ $RETVAL -ne 0 ]; then + echo -e "Failed to aquire lock on $LOCK_FILE within $LOCK_TIMEOUT seconds. Is a similar script hung?" + exit $RETVAL + fi + echo -e "Running command: $@" + $@ + ) 200>"$LOCK_FILE" + } + + lock_file=${ARTIFAKT_ENTRYPOINT_LOCK:-/data/artifakt-entrypoint-lock} + lock_timeout=${ARTIFAKT_TIMEOUT_LOCK:-600} + lock_cmd $lock_file $lock_timeout /.artifakt/entrypoint.sh +fi + # first arg is `-f` or `--some-option` if [ "${1#-}" != "$1" ]; then set -- apache2-foreground "$@" diff --git a/wordpress/6-apache/etc/entrypoint.sh b/wordpress/6-apache/etc/entrypoint.sh new file mode 100755 index 00000000..c9ad0ca8 --- /dev/null +++ b/wordpress/6-apache/etc/entrypoint.sh @@ -0,0 +1,20 @@ +#!/bin/bash +set -e + +# Generate file holding custom keys +[[ ! -f /data/secret-key.php ]] && \ + echo " /data/secret-key.php && \ + curl https://api.wordpress.org/secret-key/1.1/salt >> /data/secret-key.php && \ + chown www-data:www-data /data/secret-key.php + +# Uncomment to mount plugins directory if you don't version them +#rm -rf /var/www/html/wp-content/plugins && \ +# mkdir -p /data/wp-content/plugins && \ +# ln -sfn /data/wp-content/plugins /var/www/html/wp-content/plugins && \ +# chown -h www-data:www-data /var/www/html/wp-content/plugins /data/wp-content/plugins + +# Uncomment to mount themes directory if you don't version them +#rm -rf /var/www/html/wp-content/themes && \ +# mkdir -p /data/wp-content/themes && \ +# ln -sfn /data/wp-content/themes /var/www/html/wp-content/themes && \ +# chown www-data:www-data /var/www/html/wp-content/themes /data/wp-content/themes diff --git a/wordpress/6-apache/test.yaml b/wordpress/6-apache/test.yaml index 8a002cfe..f84d534b 100644 --- a/wordpress/6-apache/test.yaml +++ b/wordpress/6-apache/test.yaml @@ -25,6 +25,13 @@ fileExistenceTests: uid: 0 gid: 0 isExecutableBy: 'any' +- name: 'default entrypoint' + path: '/.artifakt/entrypoint.sh' + shouldExist: true + permissions: '-rwxr-xr-x' + uid: 0 + gid: 0 + isExecutableBy: 'any' - name: 'default wp-config' path: '/var/www/html/wp-config.php' shouldExist: true @@ -34,6 +41,11 @@ fileExistenceTests: commandTests: + - name: "check default salt file" + setup: [["/usr/local/bin/docker-entrypoint.sh"]] + command: "ls" + args: [ "-la", "/data/secret-key.php"] + expectedOutput: [ '-rw-r--r-- 1 www-data www-data .+ /data/secret-key.php' ] - name: "check mounted folder content cache" setup: [["/usr/local/bin/docker-entrypoint.sh"]] command: "ls"