Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimized dockerfiles - PHP 8.1, volume and xdebug #136

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 && 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
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion dockerfile-db
Original file line number Diff line number Diff line change
@@ -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/
64 changes: 33 additions & 31 deletions dockerfile-tt
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
# This file is for development work. Not suitable for production.
FROM php:7.2-apache
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
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/
# 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 and install php extensions.
RUN docker-php-ext-configure gd --with-freetype \
&& docker-php-ext-install gd \
ldap \
mysqli

# Install xdebug.
RUN pecl install xdebug \
&& docker-php-ext-enable xdebug

# Copy xdebug 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/html
6 changes: 6 additions & 0 deletions xdebug.ini
Original file line number Diff line number Diff line change
@@ -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