From bb84a4dcc43f3d7ab7aa5eb868184760140da900 Mon Sep 17 00:00:00 2001 From: matbgn Date: Wed, 18 May 2022 21:01:19 +0200 Subject: [PATCH] Docker first non-working attempt --- .dockerignore | 21 +++++++++++ .gitignore | 4 +- Dockerfile | 70 +++++++++++++++++++++++++++++++++++ docker-utils/adjust-rights | 17 +++++++++ docker-utils/init-server | 16 ++++++++ docker-utils/install-composer | 17 +++++++++ readme.md | 6 ++- system/system.php | 2 +- 8 files changed, 150 insertions(+), 3 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-utils/adjust-rights create mode 100644 docker-utils/init-server create mode 100644 docker-utils/install-composer diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..238da74 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,21 @@ +# Ignore everything +** + +# Allow system files and directories +!docker-utils/ +!system/ +!.htaccess +!composer* +!index.php + +# Allow example files and directories +!cache/ +!content/ +!data/ +!media/ +!settings/ +!themes/ + +# Ignore unnecessary files inside allowed directories below +# This should go after the allowed directories +# e.g. docker-utils/test.php diff --git a/.gitignore b/.gitignore index 902f6fe..eb781af 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,6 @@ system/vendor plugins/demo zips build.php -node_modules \ No newline at end of file +node_modules +.idea +dist \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ef1bcf4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,70 @@ +FROM php:8-apache + +# Install OS dependencies required +RUN apt-get update && apt-get upgrade -y && apt-get install git unzip zlib1g-dev libpng-dev -y + +# Adapt apache config +RUN a2enmod rewrite \ + && echo "ServerName 127.0.0.1" >> /etc/apache2/apache2.conf + +# Install PHP ext-gd +RUN docker-php-ext-install gd + +COPY docker-utils /usr/local/bin + +WORKDIR /src + +COPY system ./system +COPY .htaccess \ + composer* \ + index.php \ + /src/ +COPY cache ./cache +COPY data ./data +COPY media ./media +COPY settings ./settings +COPY themes ./themes + +RUN chmod +x /usr/local/bin/install-composer && \ + /usr/local/bin/install-composer && \ + ./composer.phar update && \ + chmod +x /usr/local/bin/init-server && \ + chmod +x /usr/local/bin/adjust-rights + +WORKDIR /tmp + +COPY content ./content + +# Create a non-root user to own the files and run our server +WORKDIR /var/www/html + +# Expose single volume of data to simplify maintenance +VOLUME /var/www/html + +#RUN cp -R /src/* /var/www/html/ +#RUN cp -R /tmp/* /var/www/html/ +#ARG UNAME=www-data +#ARG UGROUP=www-data +#ENV UID=1000 +#ENV GID=1000 +#RUN usermod --uid $UID $UNAME && \ +# groupmod --gid $GID $UGROUP + +# Install PHP dependencies +#RUN /usr/local/bin/install-composer && \ +# ./composer.phar update && \ +# rm -rf composer* Dockerfile docker-utils/install-composer +# +## Adjust rights for www-data, a non-root user, to own the files and run our server +#RUN /usr/local/bin/adjust-rights && \ +# rm -rf Dockerfile + + +#RUN sed -i 's/^exec /chown www-data:www-data \/var\/www\/html/\n\nexec /' /usr/local/bin/apache2-foreground +# +### Use our non-root user +#RUN chown -R www-data:www-data /var/www/html/ +#USER www-data + +# Run the server +CMD ["/usr/local/bin/init-server"] \ No newline at end of file diff --git a/docker-utils/adjust-rights b/docker-utils/adjust-rights new file mode 100644 index 0000000..a05cf08 --- /dev/null +++ b/docker-utils/adjust-rights @@ -0,0 +1,17 @@ +#!/bin/sh + +chown -R www-data:www-data /var/www/html +find /var/www/html -type d -exec chmod 570 {} \; +find /var/www/html -type f -exec chmod 460 {} \; +chown -R www-data:www-data /var/www/html/cache +find /var/www/html/cache -type d -exec chmod 770 {} \; +find /var/www/html/cache -type f -exec chmod 660 {} \; +chown -R www-data:www-data /var/www/html/content +find /var/www/html/content -type d -exec chmod 770 {} \; +find /var/www/html/content -type f -exec chmod 660 {} \; +chown -R www-data:www-data /var/www/html/media +find /var/www/html/media -type d -exec chmod 770 {} \; +find /var/www/html/media -type f -exec chmod 660 {} \; +chown -R www-data:www-data /var/www/html/settings +find /var/www/html/settings -type d -exec chmod 770 {} \; +find /var/www/html/settings -type f -exec chmod 660 {} \; \ No newline at end of file diff --git a/docker-utils/init-server b/docker-utils/init-server new file mode 100644 index 0000000..2933aad --- /dev/null +++ b/docker-utils/init-server @@ -0,0 +1,16 @@ +#!/bin/sh + +find /var/www/html -type d -empty -exec cp -R /tmp/* /var/www/html/ \; + +cp -R /src/* /var/www/html/ +cp -R /tmp/* /var/www/html/ + +/usr/local/bin/install-composer && \ +./composer.phar update + +usermod -u $PUID www-data +groupmod -g $PGID www-data + +/usr/local/bin/adjust-rights + +apache2-foreground \ No newline at end of file diff --git a/docker-utils/install-composer b/docker-utils/install-composer new file mode 100644 index 0000000..585031d --- /dev/null +++ b/docker-utils/install-composer @@ -0,0 +1,17 @@ +#!/bin/sh + +EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')" +php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" +ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")" + +if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ] +then + >&2 echo 'ERROR: Invalid installer checksum' + rm composer-setup.php + exit 1 +fi + +php composer-setup.php --quiet +RESULT=$? +rm composer-setup.php +exit $RESULT \ No newline at end of file diff --git a/readme.md b/readme.md index 0fbd9ce..ca016fa 100644 --- a/readme.md +++ b/readme.md @@ -41,6 +41,7 @@ Some plugin highlights are: If you run a linux system, then please double check that mod_rewrite and htaccess are active!!! ## Installation +### Bare-metal installation Download TYPEMILL from the [TYPEMILL website](http://typemill.net), unzip the files and you are done. @@ -56,7 +57,7 @@ If you did not use composer before, please go to the [composer website](http://g To run TYPEMILL on a **live** system, simply upload the files to your server -## Make Folders Writable. +#### Make Folders Writable. Make sure that the following folders and all their files are writable (permission 774 recursively): @@ -67,6 +68,9 @@ Make sure that the following folders and all their files are writable (permissio You can use your ftp-software for that. +### Docker installation + + ## Setup If you visit your website first, then you will be redirected to the `/setup` page. Please create an initial user and configure your system in the author panel. diff --git a/system/system.php b/system/system.php index 62829c7..e02c00d 100644 --- a/system/system.php +++ b/system/system.php @@ -29,7 +29,7 @@ $settings = Typemill\Settings::loadSettings(); /**************************** * HANDLE DISPLAY ERRORS * ****************************/ - +$settings['settings']['displayErrorDetails'] = true; if(isset($settings['settings']['displayErrorDetails']) && $settings['settings']['displayErrorDetails']) { ini_set('display_errors', 1);