From 2af44001602b79098af117863a3ede2ee57aa2c4 Mon Sep 17 00:00:00 2001 From: Niels H Date: Sat, 20 Apr 2024 19:02:23 +0200 Subject: [PATCH 01/10] move installtion to installation file to reduce layers --- Dockerfile | 18 ++++-------------- install.sh | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 install.sh diff --git a/Dockerfile b/Dockerfile index 202cac0..c837f80 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,10 @@ #FROM wordpress:fpm FROM wordpress:fpm-alpine -# Pm ondemand to save RAM -RUN sed -i 's/pm = dynamic/pm = ondemand/g' /usr/local/etc/php-fpm.d/www.conf - -#RUN apt-get update && apt-get -y install curl unzip -RUN apk add --update curl unzip && rm -Rf /var/cache/apk/* +COPY . /tmp +WORKDIR /tmp +RUN sh /tmp/install.sh -# Sqlite integration plugin -RUN curl -o /tmp/wpplugin.zip https://downloads.wordpress.org/plugin/sqlite-integration.1.8.1.zip -RUN unzip /tmp/wpplugin.zip -d /usr/src/wordpress/wp-content/plugins/ -RUN rm /tmp/wpplugin.zip -# Setup -RUN cp /usr/src/wordpress/wp-content/plugins/sqlite-integration/db.php /usr/src/wordpress/wp-content - -COPY config/wp-config.php /var/www/wp-config.php -RUN chown www-data:www-data /var/www/wp-config.php +# Pm ondemand to save RAM VOLUME ["/var/www/db"] diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..162a842 --- /dev/null +++ b/install.sh @@ -0,0 +1,29 @@ +#!/bin/bash +echo "sed'ing www.conf to use ondemand pm" +sed -i 's/pm = dynamic/pm = ondemand/g' /usr/local/etc/php-fpm.d/www.conf + +echo "installing curl and unzip" +apk add --update curl unzip + +echo "clear cache" +rm -Rf /var/cache/apk/* + + +echo "download Sqlite integration plugin" +curl -o /tmp/wpplugin.zip https://downloads.wordpress.org/plugin/sqlite-database-integration.zip + +echo "unzip Sqlite integration plugin" +unzip /tmp/wpplugin.zip -d /usr/src/wordpress/wp-content/plugins/ + +echo "removing zip file" +rm /tmp/wpplugin.zip + +echo "setting up wp-config.php" +cp /usr/src/wordpress/wp-content/plugins/sqlite-integration/db.php /usr/src/wordpress/wp-content + + +echo "copying wp-config.php" +cp config/wp-config.php /var/www/wp-config.php + +echo "chown wp-config.php" +chown www-data:www-data /var/www/wp-config.php From dba696519b6ab4ceb528e15f3263c5089528f4bd Mon Sep 17 00:00:00 2001 From: Niels H Date: Sun, 21 Apr 2024 15:42:57 +0200 Subject: [PATCH 02/10] using alpine image --- Dockerfile | 9 ++------ config/default.conf | 55 +++++++++++++++++++++++++++++++++++++++++++++ install.sh | 10 ++++++--- 3 files changed, 64 insertions(+), 10 deletions(-) create mode 100644 config/default.conf diff --git a/Dockerfile b/Dockerfile index c837f80..5f6fea0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,5 @@ -#FROM wordpress:fpm -FROM wordpress:fpm-alpine +FROM wordpress:6.5.2-php8.1-fpm-alpine COPY . /tmp -WORKDIR /tmp -RUN sh /tmp/install.sh +RUN chmod 777 /tmp/install.sh && /bin/bash /tmp/install.sh -# Pm ondemand to save RAM - -VOLUME ["/var/www/db"] diff --git a/config/default.conf b/config/default.conf new file mode 100644 index 0000000..d487dbb --- /dev/null +++ b/config/default.conf @@ -0,0 +1,55 @@ +server { + listen 80; + listen [::]:80; + server_name $host; + index index.php index.html index.htm; + root /var/www/html; + server_tokens off; + client_max_body_size 75M; + + # logging + access_log /var/log/nginx/wordpress.access.log; + error_log /var/log/nginx/wordpress.error.log; + + # some security headers ( optional ) + add_header X-Frame-Options "SAMEORIGIN" always; + add_header X-XSS-Protection "1; mode=block" always; + add_header X-Content-Type-Options "nosniff" always; + add_header Referrer-Policy "no-referrer-when-downgrade" always; + add_header Content-Security-Policy "default-src * data: 'unsafe-eval' 'unsafe-inline'" always; + + location / { + try_files $uri $uri/ /index.php$is_args$args; + } + + location ~ \.php$ { + try_files $uri = 404; + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_pass 127.0.0.1:9000; + fastcgi_index index.php; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param PATH_INFO $fastcgi_path_info; + } + + location ~ /\.ht { + deny all; + } + + location = /favicon.ico { + log_not_found off; access_log off; + } + + location = /favicon.svg { + log_not_found off; access_log off; + } + + location = /robots.txt { + log_not_found off; access_log off; allow all; + } + + location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ { + expires max; + log_not_found off; + } +} \ No newline at end of file diff --git a/install.sh b/install.sh index 162a842..0b63e04 100644 --- a/install.sh +++ b/install.sh @@ -1,9 +1,13 @@ #!/bin/bash -echo "sed'ing www.conf to use ondemand pm" -sed -i 's/pm = dynamic/pm = ondemand/g' /usr/local/etc/php-fpm.d/www.conf +#echo "sed'ing www.conf to use ondemand pm" +#sed -i 's/pm = dynamic/pm = ondemand/g' /usr/local/etc/php-fpm.d/www.conf + +# insert line "exec nginx" before a line containing 'exec "$@"' in /usr/local/bin/docker-entrypoint.sh using sed +sed -i '/exec "$@"/i exec nginx' /usr/local/bin/docker-entrypoint.sh echo "installing curl and unzip" apk add --update curl unzip +apk add nginx echo "clear cache" rm -Rf /var/cache/apk/* @@ -20,7 +24,7 @@ rm /tmp/wpplugin.zip echo "setting up wp-config.php" cp /usr/src/wordpress/wp-content/plugins/sqlite-integration/db.php /usr/src/wordpress/wp-content - +cp /tmp/default.conf /etc/nginx/http.d/default.conf echo "copying wp-config.php" cp config/wp-config.php /var/www/wp-config.php From 3f96985068d9583a1b9c92fe726c95f660a1249b Mon Sep 17 00:00:00 2001 From: Niels H Date: Sun, 21 Apr 2024 15:59:57 +0200 Subject: [PATCH 03/10] changed to LineFeed Sequenze --- config/wp-config.php | 150 +++++++++++++++++++++---------------------- 1 file changed, 75 insertions(+), 75 deletions(-) diff --git a/config/wp-config.php b/config/wp-config.php index 582d758..60a184e 100755 --- a/config/wp-config.php +++ b/config/wp-config.php @@ -1,75 +1,75 @@ - Date: Sun, 21 Apr 2024 16:09:09 +0200 Subject: [PATCH 04/10] fixing broken paths --- install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 0b63e04..af007bf 100644 --- a/install.sh +++ b/install.sh @@ -23,11 +23,11 @@ echo "removing zip file" rm /tmp/wpplugin.zip echo "setting up wp-config.php" -cp /usr/src/wordpress/wp-content/plugins/sqlite-integration/db.php /usr/src/wordpress/wp-content +cp /usr/src/wordpress/wp-content/plugins/sqlite-database-integration/wp-includes/sqlite/db.php /usr/src/wordpress/wp-content cp /tmp/default.conf /etc/nginx/http.d/default.conf echo "copying wp-config.php" -cp config/wp-config.php /var/www/wp-config.php +cp /tmp/config/wp-config.php /var/www/wp-config.php echo "chown wp-config.php" chown www-data:www-data /var/www/wp-config.php From dd89beba39dfc6b82a5baf07a11d36b4549b2927 Mon Sep 17 00:00:00 2001 From: Niels H Date: Sun, 21 Apr 2024 17:16:54 +0200 Subject: [PATCH 05/10] fixing stuff --- install.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/install.sh b/install.sh index af007bf..0b26ab0 100644 --- a/install.sh +++ b/install.sh @@ -3,7 +3,7 @@ #sed -i 's/pm = dynamic/pm = ondemand/g' /usr/local/etc/php-fpm.d/www.conf # insert line "exec nginx" before a line containing 'exec "$@"' in /usr/local/bin/docker-entrypoint.sh using sed -sed -i '/exec "$@"/i exec nginx' /usr/local/bin/docker-entrypoint.sh +sed -i '/exec "$@"/i nginx' /usr/local/bin/docker-entrypoint.sh echo "installing curl and unzip" apk add --update curl unzip @@ -23,11 +23,11 @@ echo "removing zip file" rm /tmp/wpplugin.zip echo "setting up wp-config.php" -cp /usr/src/wordpress/wp-content/plugins/sqlite-database-integration/wp-includes/sqlite/db.php /usr/src/wordpress/wp-content -cp /tmp/default.conf /etc/nginx/http.d/default.conf +#cp /usr/src/wordpress/wp-content/plugins/sqlite-database-integration/wp-includes/sqlite/db.php /usr/src/wordpress/wp-content +cp /tmp/config/default.conf /etc/nginx/http.d/default.conf -echo "copying wp-config.php" -cp /tmp/config/wp-config.php /var/www/wp-config.php +#echo "copying wp-config.php" +#cp /tmp/config/wp-config.php /usr/src/wordpress/wp-config.php -echo "chown wp-config.php" -chown www-data:www-data /var/www/wp-config.php +#echo "chown wp-config.php" +#chown www-data:www-data /var/www/wp-config.php From b7bfdaa964f9e5173cf7dc10578fc4f42bee462e Mon Sep 17 00:00:00 2001 From: Niels H Date: Sun, 21 Apr 2024 21:42:15 +0200 Subject: [PATCH 06/10] taken install script from soulteary --- .gitattributes | 9 +++++++++ install.sh | 26 ++++++++++++++++++-------- 2 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..0c8074b --- /dev/null +++ b/.gitattributes @@ -0,0 +1,9 @@ +# set default line endings to auto +* text=auto +# files that end with .sh should have lf line endings +*.sh text eol=lf +# files that end with .conf should have lf line endings +*.conf text eol=lf + +# dockerfile should have lf line endings +Dockerfile text eol=lf diff --git a/install.sh b/install.sh index 0b26ab0..c52b25c 100644 --- a/install.sh +++ b/install.sh @@ -6,7 +6,7 @@ sed -i '/exec "$@"/i nginx' /usr/local/bin/docker-entrypoint.sh echo "installing curl and unzip" -apk add --update curl unzip +apk add --update curl apk add nginx echo "clear cache" @@ -14,13 +14,23 @@ rm -Rf /var/cache/apk/* echo "download Sqlite integration plugin" -curl -o /tmp/wpplugin.zip https://downloads.wordpress.org/plugin/sqlite-database-integration.zip - -echo "unzip Sqlite integration plugin" -unzip /tmp/wpplugin.zip -d /usr/src/wordpress/wp-content/plugins/ - -echo "removing zip file" -rm /tmp/wpplugin.zip +curl -L -o /tmp/sqlite-database-integration.tar.gz "https://github.com/WordPress/sqlite-database-integration/archive/refs/tags/v2.1.9.tar.gz" + +echo "untar Sqlite integration plugin" +tar zxvf sqlite-database-integration.tar.gz -c /tmp/ + +#install +mkdir -p /usr/src/wordpress/wp-content/mu-plugins/sqlite-database-integration +cp -r /tmp/sqlite-database-integration/* /usr/src/wordpress/wp-content/mu-plugins/sqlite-database-integration/ +mv "/usr/src/wordpress/wp-content/mu-plugins/sqlite-database-integration/db.copy" "/usr/src/wordpress/wp-content/db.php" +sed -i 's#{SQLITE_IMPLEMENTATION_FOLDER_PATH}#/var/www/html/wp-content/mu-plugins/sqlite-database-integration#' "/usr/src/wordpress/wp-content/db.php" +sed -i 's#{SQLITE_PLUGIN}#sqlite-database-integration/load.php#' "/usr/src/wordpress/wp-content/db.php" +mkdir "/usr/src/wordpress/wp-content/database" +touch "/usr/src/wordpress/wp-content/database/.ht.sqlite" +chmod 640 "/usr/src/wordpress/wp-content/database/.ht.sqlite" + +echo "removing tar file" +rm /tmp/sqlite-database-integration.tar.gz echo "setting up wp-config.php" #cp /usr/src/wordpress/wp-content/plugins/sqlite-database-integration/wp-includes/sqlite/db.php /usr/src/wordpress/wp-content From f4e0a7be014a318f08800457c7f15e7fc7fc481a Mon Sep 17 00:00:00 2001 From: Niels H Date: Sun, 21 Apr 2024 22:06:02 +0200 Subject: [PATCH 07/10] not yet working --- install.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index c52b25c..2fda8de 100644 --- a/install.sh +++ b/install.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e #echo "sed'ing www.conf to use ondemand pm" #sed -i 's/pm = dynamic/pm = ondemand/g' /usr/local/etc/php-fpm.d/www.conf @@ -17,11 +18,11 @@ echo "download Sqlite integration plugin" curl -L -o /tmp/sqlite-database-integration.tar.gz "https://github.com/WordPress/sqlite-database-integration/archive/refs/tags/v2.1.9.tar.gz" echo "untar Sqlite integration plugin" -tar zxvf sqlite-database-integration.tar.gz -c /tmp/ +tar zxvf /tmp/sqlite-database-integration.tar.gz -C /tmp/ #install mkdir -p /usr/src/wordpress/wp-content/mu-plugins/sqlite-database-integration -cp -r /tmp/sqlite-database-integration/* /usr/src/wordpress/wp-content/mu-plugins/sqlite-database-integration/ +cp -r /tmp/sqlite-database-integration-2.1.9/* /usr/src/wordpress/wp-content/mu-plugins/sqlite-database-integration/ mv "/usr/src/wordpress/wp-content/mu-plugins/sqlite-database-integration/db.copy" "/usr/src/wordpress/wp-content/db.php" sed -i 's#{SQLITE_IMPLEMENTATION_FOLDER_PATH}#/var/www/html/wp-content/mu-plugins/sqlite-database-integration#' "/usr/src/wordpress/wp-content/db.php" sed -i 's#{SQLITE_PLUGIN}#sqlite-database-integration/load.php#' "/usr/src/wordpress/wp-content/db.php" From a5885f81b47307432cc629024c684ebe5cb7f923 Mon Sep 17 00:00:00 2001 From: Niels H Date: Sun, 21 Apr 2024 22:22:24 +0200 Subject: [PATCH 08/10] finaly working version --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 5f6fea0..54b2be9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,6 @@ FROM wordpress:6.5.2-php8.1-fpm-alpine COPY . /tmp +ENV WORDPRESS_PREPARE_DIR /usr/src/wordpress RUN chmod 777 /tmp/install.sh && /bin/bash /tmp/install.sh From 5b1656533075bed389b4c905175e3ed3bdaec5ba Mon Sep 17 00:00:00 2001 From: Niels H Date: Sun, 21 Apr 2024 22:24:34 +0200 Subject: [PATCH 09/10] cleanup --- install.sh | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/install.sh b/install.sh index 2fda8de..b8b2a6e 100644 --- a/install.sh +++ b/install.sh @@ -1,12 +1,11 @@ #!/bin/bash +# exit on error set -e -#echo "sed'ing www.conf to use ondemand pm" -#sed -i 's/pm = dynamic/pm = ondemand/g' /usr/local/etc/php-fpm.d/www.conf # insert line "exec nginx" before a line containing 'exec "$@"' in /usr/local/bin/docker-entrypoint.sh using sed sed -i '/exec "$@"/i nginx' /usr/local/bin/docker-entrypoint.sh -echo "installing curl and unzip" +echo "installing curl and nginx" apk add --update curl apk add nginx @@ -33,12 +32,6 @@ chmod 640 "/usr/src/wordpress/wp-content/database/.ht.sqlite" echo "removing tar file" rm /tmp/sqlite-database-integration.tar.gz -echo "setting up wp-config.php" -#cp /usr/src/wordpress/wp-content/plugins/sqlite-database-integration/wp-includes/sqlite/db.php /usr/src/wordpress/wp-content +echo "setting up nginx" cp /tmp/config/default.conf /etc/nginx/http.d/default.conf -#echo "copying wp-config.php" -#cp /tmp/config/wp-config.php /usr/src/wordpress/wp-config.php - -#echo "chown wp-config.php" -#chown www-data:www-data /var/www/wp-config.php From 2653d267aa5eb84545c3392722f006040c9b0bcf Mon Sep 17 00:00:00 2001 From: Niels H Date: Sun, 21 Apr 2024 22:26:29 +0200 Subject: [PATCH 10/10] cleanup2 --- config/wp-config.php | 75 -------------------------------------------- 1 file changed, 75 deletions(-) delete mode 100755 config/wp-config.php diff --git a/config/wp-config.php b/config/wp-config.php deleted file mode 100755 index 60a184e..0000000 --- a/config/wp-config.php +++ /dev/null @@ -1,75 +0,0 @@ -