From c4d01ffc3c67652c1b953f38fa25591539ee2d17 Mon Sep 17 00:00:00 2001 From: Cosimo Commisso Date: Thu, 9 Jun 2022 16:03:56 -0400 Subject: [PATCH 1/8] optimizing dockerfiles --- dockerfile-db | 2 +- dockerfile-tt | 35 +++++++++++++++-------------------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/dockerfile-db b/dockerfile-db index 757aa0b30..4ad663068 100644 --- a/dockerfile-db +++ b/dockerfile-db @@ -1,5 +1,5 @@ # This file is for development work. Not suitable for production. -FROM mariadb:latest +FROM mariadb:10.8 # Copy database creation script. COPY mysql.sql /docker-entrypoint-initdb.d/ diff --git a/dockerfile-tt b/dockerfile-tt index 9c79f4786..c8edc6019 100644 --- a/dockerfile-tt +++ b/dockerfile-tt @@ -7,30 +7,25 @@ RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" # Override with custom settings. # COPY config/php_tt.ini $PHP_INI_DIR/conf.d/ -# Install mysqli extension. -RUN docker-php-ext-install mysqli - -# Install gd extension. -RUN apt-get update && apt-get install libpng-dev libfreetype6-dev -y \ - && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ \ - && docker-php-ext-install gd - -# Install ldap extension. -RUN apt-get install libldap2-dev -y \ - && docker-php-ext-install ldap -# TODO: check if ldap works, as the above is missing this step: -# && docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ && \ - -# Cleanup. The intention was to keep image size down. -# RUN rm -rf /var/lib/apt/lists/* -# -# The above does not work. Files are removed, but -# image files (zipped or not) are not getting smaller. Why? - +# Install php extensions. +RUN apt-get update && apt-get install --no-install-recommends -y \ + libpng-dev \ + libfreetype6-dev \ + libldap2-dev && \ + rm -rf /var/lib/apt/lists/* + +# Configure php extensions +RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ \ + && docker-php-ext-install gd \ + ldap \ + mysqli + # Copy application source code to /var/www/html/. COPY . /var/www/html/ + # Create configuration file. RUN cp /var/www/html/WEB-INF/config.php.dist /var/www/html/WEB-INF/config.php + # Replace DSN value to something connectable to a Docker container running mariadb. RUN sed -i "s|mysqli://root:no@localhost/dbname|mysqli://anuko_user:anuko_pw@anuko_db/timetracker|g" /var/www/html/WEB-INF/config.php # Note that db is defined as anuko_db/timetracker where anuko_db is service name and timetracker is db name. From 9218acf715035d574f4c6b2cf6df7b84d15cd92e Mon Sep 17 00:00:00 2001 From: Fabian Heinrich <127763209+ram-fabian-heinrich@users.noreply.github.com> Date: Mon, 4 Sep 2023 17:28:37 +0200 Subject: [PATCH 2/8] Updated docker configuration --- docker-compose.yml | 4 +++ dockerfile-tt | 63 ++++++++++++++++++++++------------------------ xdebug.ini | 6 +++++ 3 files changed, 40 insertions(+), 33 deletions(-) create mode 100644 xdebug.ini diff --git a/docker-compose.yml b/docker-compose.yml index e621c4105..fa8de9162 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,6 +12,10 @@ services: # Use localhost:8080 to connect to timetracker via browser. ports: - "8080:80" + volumes: + - .:/var/www/html + extra_hosts: + - "host.docker.internal:host-gateway" # anuko_db is a mariadb instance to which timetracker connects. # Connect parameters are also specified in timetracker dockerfile after diff --git a/dockerfile-tt b/dockerfile-tt index 9c79f4786..8d073f3a2 100644 --- a/dockerfile-tt +++ b/dockerfile-tt @@ -1,39 +1,36 @@ # This file is for development work. Not suitable for production. -FROM php:7.2-apache +FROM php:8.1-apache + +ARG USER_NAME=www-data +ARG USER_GROUP=www-data +ARG USER_ID=1000 +ARG GROUP_ID=1000 # Use the default production configuration. RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" -# Override with custom settings. -# COPY config/php_tt.ini $PHP_INI_DIR/conf.d/ - -# Install mysqli extension. -RUN docker-php-ext-install mysqli - # Install gd extension. -RUN apt-get update && apt-get install libpng-dev libfreetype6-dev -y \ - && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ \ - && docker-php-ext-install gd - -# Install ldap extension. -RUN apt-get install libldap2-dev -y \ - && docker-php-ext-install ldap -# TODO: check if ldap works, as the above is missing this step: -# && docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ && \ - -# Cleanup. The intention was to keep image size down. -# RUN rm -rf /var/lib/apt/lists/* -# -# The above does not work. Files are removed, but -# image files (zipped or not) are not getting smaller. Why? - -# Copy application source code to /var/www/html/. -COPY . /var/www/html/ -# Create configuration file. -RUN cp /var/www/html/WEB-INF/config.php.dist /var/www/html/WEB-INF/config.php -# Replace DSN value to something connectable to a Docker container running mariadb. -RUN sed -i "s|mysqli://root:no@localhost/dbname|mysqli://anuko_user:anuko_pw@anuko_db/timetracker|g" /var/www/html/WEB-INF/config.php -# Note that db is defined as anuko_db/timetracker where anuko_db is service name and timetracker is db name. -# See docker-compose.yml for details. - -RUN chown -R www-data /var/www/html/ +RUN apt-get update && apt-get install --no-install-recommends -y \ + libldap2-dev \ + libpng-dev \ + libfreetype6-dev \ + && rm -rf /var/lib/apt/lists/* + + +RUN docker-php-ext-configure gd --with-freetype \ + && docker-php-ext-install \ + gd \ + ldap \ + mysqli \ + && pecl install xdebug \ + && docker-php-ext-enable xdebug + +# Copy xdebug and php config. +COPY xdebug.ini /usr/local/etc/php/conf.d/ + +# Change www-data users uid and www-data groups gid +RUN usermod --uid $USER_ID $USER_NAME && groupmod --gid $GROUP_ID $USER_GROUP + +# set default user and working directory +USER www-data +WORKDIR /var/www/project \ No newline at end of file diff --git a/xdebug.ini b/xdebug.ini new file mode 100644 index 000000000..b155414b4 --- /dev/null +++ b/xdebug.ini @@ -0,0 +1,6 @@ +[XDebug] +xdebug.mode=debug +xdebug.client_host = host.docker.internal + +# Enable for automatic connection. This is useful for CLI debugging. +#xdebug.start_with_request=yes \ No newline at end of file From 4454d2800301d3931232916fb5640cfd5bd300bf Mon Sep 17 00:00:00 2001 From: Fabian Heinrich <127763209+ram-fabian-heinrich@users.noreply.github.com> Date: Mon, 4 Sep 2023 17:28:46 +0200 Subject: [PATCH 3/8] Updated docker configuration --- dockerfile-db | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dockerfile-db b/dockerfile-db index 757aa0b30..4ad663068 100644 --- a/dockerfile-db +++ b/dockerfile-db @@ -1,5 +1,5 @@ # This file is for development work. Not suitable for production. -FROM mariadb:latest +FROM mariadb:10.8 # Copy database creation script. COPY mysql.sql /docker-entrypoint-initdb.d/ From 3259823d0d1395d97fb321e0d8058ce237f77a71 Mon Sep 17 00:00:00 2001 From: Fabian Heinrich <127763209+ram-fabian-heinrich@users.noreply.github.com> Date: Mon, 4 Sep 2023 17:43:08 +0200 Subject: [PATCH 4/8] Added a comment --- dockerfile-tt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dockerfile-tt b/dockerfile-tt index ac545120e..38e0421a0 100644 --- a/dockerfile-tt +++ b/dockerfile-tt @@ -19,7 +19,7 @@ RUN apt-get update && apt-get install --no-install-recommends -y \ libldap2-dev && \ rm -rf /var/lib/apt/lists/* - +# Configure and install php extensions. RUN docker-php-ext-configure gd --with-freetype \ && docker-php-ext-install gd \ ldap \ From 28714c2e317b869746019958ac7241e50b859aa9 Mon Sep 17 00:00:00 2001 From: Fabian Heinrich <127763209+ram-fabian-heinrich@users.noreply.github.com> Date: Mon, 4 Sep 2023 17:44:08 +0200 Subject: [PATCH 5/8] Updated comments --- dockerfile-tt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dockerfile-tt b/dockerfile-tt index 38e0421a0..de3c58392 100644 --- a/dockerfile-tt +++ b/dockerfile-tt @@ -1,6 +1,7 @@ # This file is for development work. Not suitable for production. FROM php:8.1-apache +# Arguments for user and group modification. Needed for file permissions. ARG USER_NAME=www-data ARG USER_GROUP=www-data ARG USER_ID=1000 @@ -32,9 +33,9 @@ RUN pecl install xdebug \ # Copy xdebug config. COPY xdebug.ini /usr/local/etc/php/conf.d/ -# Change www-data users uid and www-data groups gid +# Change www-data users uid and www-data groups gid. RUN usermod --uid $USER_ID $USER_NAME && groupmod --gid $GROUP_ID $USER_GROUP -# set default user and working directory +# Set default user and working directory. USER www-data WORKDIR /var/www/project \ No newline at end of file From 2c4ec2628c24966276e38a88d21400bf08cfca6f Mon Sep 17 00:00:00 2001 From: Fabian Heinrich <127763209+ram-fabian-heinrich@users.noreply.github.com> Date: Mon, 4 Sep 2023 18:11:01 +0200 Subject: [PATCH 6/8] Added step on how to set up dev environment --- CONTRIBUTING.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 58c971801..be6935f87 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -23,6 +23,10 @@ Docker users: install both docker and docker-compose, then run a dev instance: ```bash docker-compose up ``` +Create configuration file and replace DSN string: +```bash +cp ./WEB-INF/config.php.dist ./WEB-INF/config.php && RUN sed -i "s|mysqli://root:no@localhost/dbname|mysqli://anuko_user:anuko_pw@anuko_db/timetracker|g" ./WEB-INF/config.php +``` Navigate to: http://localhost:8080 to use Time Tracker. Default credentials for initial login are: ``` usr: admin From 942c64acadf901642b3e37b83b21417d79ad4696 Mon Sep 17 00:00:00 2001 From: Fabian Heinrich <127763209+ram-fabian-heinrich@users.noreply.github.com> Date: Mon, 4 Sep 2023 18:13:06 +0200 Subject: [PATCH 7/8] Removed wrongly copied RUN --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index be6935f87..e40cef568 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -25,7 +25,7 @@ docker-compose up ``` Create configuration file and replace DSN string: ```bash -cp ./WEB-INF/config.php.dist ./WEB-INF/config.php && RUN sed -i "s|mysqli://root:no@localhost/dbname|mysqli://anuko_user:anuko_pw@anuko_db/timetracker|g" ./WEB-INF/config.php +cp ./WEB-INF/config.php.dist ./WEB-INF/config.php && sed -i "s|mysqli://root:no@localhost/dbname|mysqli://anuko_user:anuko_pw@anuko_db/timetracker|g" ./WEB-INF/config.php ``` Navigate to: http://localhost:8080 to use Time Tracker. Default credentials for initial login are: ``` From 393cc44cf5887b7830c06cedc28ae971dcf511dc Mon Sep 17 00:00:00 2001 From: Fabian Heinrich <127763209+ram-fabian-heinrich@users.noreply.github.com> Date: Thu, 14 Sep 2023 12:55:17 +0200 Subject: [PATCH 8/8] Update dockerfile-tt --- dockerfile-tt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dockerfile-tt b/dockerfile-tt index de3c58392..a47ba3a62 100644 --- a/dockerfile-tt +++ b/dockerfile-tt @@ -38,4 +38,4 @@ RUN usermod --uid $USER_ID $USER_NAME && groupmod --gid $GROUP_ID $USER_GROUP # Set default user and working directory. USER www-data -WORKDIR /var/www/project \ No newline at end of file +WORKDIR /var/www/html