Skip to content

Commit

Permalink
Improve Docker image and scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
mescalantea committed Dec 31, 2024
1 parent 08cd77c commit 2037415
Show file tree
Hide file tree
Showing 17 changed files with 51 additions and 102 deletions.
37 changes: 25 additions & 12 deletions .docker/magento/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FROM php:${PHP_VERSION}-apache

SHELL ["/bin/bash", "-c"]

RUN apt-get update && apt-get install -y \
RUN apt-get update && apt-get install -y --no-install-recommends \
mariadb-client \
libfreetype6-dev \
libjpeg62-turbo-dev \
Expand Down Expand Up @@ -44,33 +44,46 @@ RUN apt-get update && apt-get install -y \
sockets \
xsl \
zip \
&& apt-get clean && rm -rf /var/lib/apt/lists/* \
&& docker-php-ext-enable redis xdebug
&& docker-php-ext-enable \
redis \
xdebug \
&& echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.client_host=${M2_HOST}" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.log_level=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& sed -i 's/^/;/' "/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini" \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

# Install composer
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer

# Enable apache modules
RUN a2enmod rewrite
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf
# Apache configuration
RUN a2enmod rewrite && echo "ServerName localhost" >> /etc/apache2/apache2.conf

# PHP configuration
COPY ./docker-php-m2.ini /usr/local/etc/php/conf.d/docker-php-m2.ini

# Custom scripts
COPY ./m2-entrypoint.sh /usr/local/bin/m2-entrypoint
RUN chmod +x /usr/local/bin/m2-entrypoint
COPY ./toggle-xdebug.sh /usr/local/bin/toggle-xdebug
RUN chmod +x /usr/local/bin/m2-entrypoint && \
chmod +x /usr/local/bin/toggle-xdebug

ARG M2_VERSION
ARG M2_REPO_KEY
ARG M2_REPO_SECRET

RUN mkdir -p /Sequra/Core && chown -R www-data:www-data /Sequra && chmod -R 755 /Sequra
RUN mkdir -p /Sequra/Core \
&& chown -R www-data:www-data /Sequra \
&& chmod -R 755 /Sequra \
&& mkdir -p /var/www/.composer/cache/files/ \
&& chown -R www-data:www-data /var/www/.composer

WORKDIR /var/www/html

RUN composer config -g http-basic.repo.magento.com $M2_REPO_KEY $M2_REPO_SECRET

RUN composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=$M2_VERSION . \
&& composer require mageplaza/magento-2-spanish-language-pack:dev-master mageplaza/magento-2-portuguese-language-pack:dev-master mageplaza/magento-2-french-language-pack:dev-master mageplaza/magento-2-italian-language-pack:dev-master \
RUN composer config -g http-basic.repo.magento.com $M2_REPO_KEY $M2_REPO_SECRET \
&& composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=$M2_VERSION . \
&& composer require n98/magerun2-dist mageplaza/magento-2-spanish-language-pack:dev-master mageplaza/magento-2-portuguese-language-pack:dev-master mageplaza/magento-2-french-language-pack:dev-master mageplaza/magento-2-italian-language-pack:dev-master \
&& chmod -R 755 ./ \
&& chown -R www-data:www-data ./

Expand Down
8 changes: 1 addition & 7 deletions .docker/magento/docker-php-m2.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,4 @@
date.timezone=Europe/Madrid
memory_limit=2G
realpath_cache_size=10M
realpath_cache_ttl=7200

# XDebug
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_host=localhost.sequrapi.com
xdebug.log_level=1
realpath_cache_ttl=7200
19 changes: 19 additions & 0 deletions .docker/magento/toggle-xdebug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
# XDebug configuration file.
CONFIG_FILE="/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini"

if [[ -f "$CONFIG_FILE" ]]; then
if grep -q "^;" "$CONFIG_FILE"; then
echo "✅ Enabling XDebug"
sed -i 's/^;//' "$CONFIG_FILE"
else
echo "✅ Disabling XDebug"
sed -i 's/^/;/' "$CONFIG_FILE"
fi
else
echo "❌ The XDebug configuration file does not exist. Make sure the XDebug PHP extension is installed."
exit 1
fi

echo "✅ Restarting Apache"
apachectl -k graceful
2 changes: 1 addition & 1 deletion bin/composer
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
docker compose exec -u daemon -w /bitnami/magento magento php vendor/bin/composer $@
docker compose exec -u www-data magento composer $@
7 changes: 0 additions & 7 deletions bin/install-sampledata

This file was deleted.

2 changes: 1 addition & 1 deletion bin/magento
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
docker compose exec -u daemon -w /bitnami/magento magento bin/magento $@
docker compose exec -u www-data magento bin/magento $@
3 changes: 0 additions & 3 deletions bin/mysql

This file was deleted.

4 changes: 1 addition & 3 deletions bin/n98-magerun2
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
#!/bin/bash
docker compose exec -u daemon -w /bitnami/magento magento bash -c \
"[ ! -f 'vendor/bin/n98-magerun2' ] && vendor/bin/composer require n98/magerun2-dist"
docker compose exec -u daemon -w /bitnami/magento magento vendor/bin/n98-magerun2 $@
docker compose exec -u www-data magento vendor/bin/n98-magerun2 $@
6 changes: 0 additions & 6 deletions bin/shell

This file was deleted.

10 changes: 2 additions & 8 deletions bin/update-sequra
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
#!/bin/bash
echo "Mount Sequra Core module"
docker compose exec -u daemon -w /bitnami/magento magento bash -c "
php ./vendor/bin/composer config repositories.sequra/magento2-core path /Sequra/Core
COMPOSER_MIRROR_PATH_REPOS=1 php ./vendor/bin/composer reinstall sequra/magento2-core
bin/magento module:enable Sequra_Core
bin/magento setup:upgrade
/opt/bitnami/scripts/php/reload.sh
"
echo "Updating Sequra_Core source code"
docker compose exec -u www-data magento /bin/bash -c "COMPOSER_MIRROR_PATH_REPOS=1 composer reinstall sequra/magento2-core && bin/magento module:enable Sequra_Core && bin/magento setup:upgrade"
2 changes: 0 additions & 2 deletions bin/update-sources

This file was deleted.

2 changes: 1 addition & 1 deletion bin/xdebug
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
docker compose exec magento /docker-entrypoint-init.d/xdebug.sh
docker compose exec magento toggle-xdebug
3 changes: 0 additions & 3 deletions docker-entrypoint-init.d/00-set-developper-mode.sh

This file was deleted.

5 changes: 0 additions & 5 deletions docker-entrypoint-init.d/01-set-order_sequence.sh

This file was deleted.

3 changes: 0 additions & 3 deletions docker-entrypoint-init.d/02-additional_setting.sh

This file was deleted.

20 changes: 0 additions & 20 deletions docker-entrypoint-init.d/install-sequra.sh

This file was deleted.

20 changes: 0 additions & 20 deletions docker-entrypoint-init.d/xdebug.sh

This file was deleted.

0 comments on commit 2037415

Please sign in to comment.