Skip to content

Commit

Permalink
rollback wp 6 entrypoint and test
Browse files Browse the repository at this point in the history
  • Loading branch information
Buburoi committed Mar 14, 2023
1 parent c789a14 commit 3eedc8b
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
3 changes: 2 additions & 1 deletion wordpress/6-apache/Dockerfile
Expand Up @@ -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"]
Expand Down
25 changes: 25 additions & 0 deletions wordpress/6-apache/docker-entrypoint.sh
Expand Up @@ -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 "$@"
Expand Down
20 changes: 20 additions & 0 deletions 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 "<?php " > /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
12 changes: 12 additions & 0 deletions wordpress/6-apache/test.yaml
Expand Up @@ -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
Expand All @@ -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"
Expand Down

0 comments on commit 3eedc8b

Please sign in to comment.