-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance Docker setup for Magento: add Dockerfile, PHP configuration, …
…and teardown script improvements
- Loading branch information
1 parent
19939f0
commit 9c71ef9
Showing
7 changed files
with
480 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
ARG PHP_VERSION=8.2 | ||
|
||
FROM php:${PHP_VERSION}-apache | ||
|
||
SHELL ["/bin/bash", "-c"] | ||
|
||
RUN apt-get update && apt-get install -y \ | ||
mariadb-client \ | ||
libfreetype6-dev \ | ||
libjpeg62-turbo-dev \ | ||
libmcrypt-dev \ | ||
libedit-dev \ | ||
libedit2 \ | ||
libpng-dev \ | ||
libjpeg-dev \ | ||
libicu-dev \ | ||
libxslt1-dev \ | ||
libzip-dev \ | ||
libssl-dev \ | ||
git \ | ||
wget \ | ||
curl \ | ||
lynx \ | ||
psmisc \ | ||
unzip \ | ||
tar \ | ||
cron \ | ||
libpcre3 \ | ||
libpcre3-dev \ | ||
&& pecl install \ | ||
xdebug \ | ||
redis \ | ||
oauth \ | ||
&& echo "extension=oauth.so" > /usr/local/etc/php/conf.d/docker-php-ext-oauth.ini \ | ||
&& docker-php-ext-configure gd --with-freetype --with-jpeg \ | ||
&& docker-php-ext-install \ | ||
opcache \ | ||
bcmath \ | ||
gd \ | ||
intl \ | ||
mysqli \ | ||
pdo_mysql \ | ||
soap \ | ||
sockets \ | ||
xsl \ | ||
zip \ | ||
&& apt-get clean && rm -rf /var/lib/apt/lists/* \ | ||
&& docker-php-ext-enable redis xdebug | ||
|
||
# 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 | ||
|
||
COPY ./docker-php-m2.ini /usr/local/etc/php/conf.d/docker-php-m2.ini | ||
|
||
COPY ./m2-entrypoint.sh /usr/local/bin/m2-entrypoint | ||
RUN chmod +x /usr/local/bin/m2-entrypoint | ||
|
||
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 | ||
|
||
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 \ | ||
&& chmod -R 755 ./ \ | ||
&& chown -R www-data:www-data ./ | ||
|
||
# Modify base entry point to run our custom setup script | ||
RUN sed -i 's/exec "$@"/\/usr\/local\/bin\/m2-entrypoint \&\& exec "$@"/g' /usr/local/bin/docker-php-entrypoint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Magento 2 requirements | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#!/bin/bash | ||
|
||
# Check if need to install WordPress | ||
if [ ! -f /var/www/html/.post-install-complete ]; then | ||
|
||
function handle_failure { | ||
touch /var/www/html/.post-install-failed | ||
echo "❌ Magento 2 installation failed" | ||
exit 1 | ||
} | ||
|
||
rm -f /var/www/html/.post-install-failed | ||
|
||
cd /var/www/html | ||
export XDEBUG_MODE=off | ||
|
||
# Override WP_URL if PUBLIC_URL is set | ||
if [ -n "$PUBLIC_URL" ]; then | ||
M2_URL="$PUBLIC_URL" | ||
fi | ||
|
||
session_save="--session-save=$M2_SESSION_SAVE" | ||
if [ "$M2_SESSION_SAVE" == 'redis' ]; then | ||
session_save="$session_save\ | ||
--session-save-redis-host=$M2_SESSION_SAVE_REDIS_HOST \ | ||
--session-save-redis-port=$M2_SESSION_SAVE_REDIS_PORT \ | ||
--session-save-redis-password=$M2_SESSION_SAVE_REDIS_PASSWORD \ | ||
--session-save-redis-timeout=$M2_SESSION_SAVE_REDIS_TIMEOUT \ | ||
--session-save-redis-persistent-id=$M2_SESSION_SAVE_REDIS_PERSISTENT_IDENTIFIER \ | ||
--session-save-redis-db=$M2_SESSION_SAVE_REDIS_DB \ | ||
--session-save-redis-compression-threshold=$M2_SESSION_SAVE_REDIS_COMPRESSION_THRESHOLD \ | ||
--session-save-redis-compression-lib=$M2_SESSION_SAVE_REDIS_COMPRESSION_LIB \ | ||
--session-save-redis-log-level=$M2_SESSION_SAVE_REDIS_LOG_LEVEL \ | ||
--session-save-redis-max-concurrency=$M2_SESSION_SAVE_REDIS_MAX_CONCURRENCY \ | ||
--session-save-redis-break-after-frontend=$M2_SESSION_SAVE_REDIS_BREAK_AFTER_FRONTEND \ | ||
--session-save-redis-break-after-adminhtml=$M2_SESSION_SAVE_REDIS_BREAK_AFTER_ADMINHTML \ | ||
--session-save-redis-first-lifetime=$M2_SESSION_SAVE_REDIS_FIRST_LIFETIME \ | ||
--session-save-redis-bot-first-lifetime=$M2_SESSION_SAVE_REDIS_BOT_FIRST_LIFETIME \ | ||
--session-save-redis-bot-lifetime=$M2_SESSION_SAVE_REDIS_BOT_LIFETIME \ | ||
--session-save-redis-disable-locking=$M2_SESSION_SAVE_REDIS_DISABLE_LOCKING \ | ||
--session-save-redis-min-lifetime=$M2_SESSION_SAVE_REDIS_MIN_LIFETIME \ | ||
--session-save-redis-max-lifetime=$M2_SESSION_SAVE_REDIS_MAX_LIFETIME \ | ||
--session-save-redis-sentinel-master=$M2_SESSION_SAVE_REDIS_SENTINEL_MASTER \ | ||
--session-save-redis-sentinel-servers=$M2_SESSION_SAVE_REDIS_SENTINEL_SERVERS \ | ||
--session-save-redis-sentinel-verify-master=$M2_SESSION_SAVE_REDIS_SENTINEL_VERIFY_MASTER \ | ||
--session-save-redis-sentinel-connect-retries=$M2_SESSION_SAVE_REDIS_SENTINEL_CONNECT_RETRIES" | ||
fi | ||
|
||
disable_modules="" | ||
if [ -n "$M2_DISABLE_MODULES" ]; then | ||
disable_modules="--disable-modules=$M2_DISABLE_MODULES" | ||
fi | ||
|
||
# Install Magento 2 | ||
su -s /bin/bash www-data -c "bin/magento setup:install \ | ||
--base-url=$M2_URL \ | ||
--db-host=$M2_DB_HOST \ | ||
--db-name=$M2_DB_NAME \ | ||
--db-user=$M2_DB_USER \ | ||
--db-password=$M2_DB_PASSWORD \ | ||
--skip-db-validation \ | ||
--backend-frontname=$M2_BACKEND_FRONTNAME \ | ||
--admin-firstname=$M2_ADMIN_FIRSTNAME \ | ||
--admin-lastname=$M2_ADMIN_LASTNAME \ | ||
--admin-email=$M2_ADMIN_EMAIL \ | ||
--admin-user=$M2_ADMIN_USER \ | ||
--admin-password=$M2_ADMIN_PASSWORD \ | ||
--language=$M2_LANGUAGE \ | ||
--currency=$M2_CURRENCY \ | ||
--timezone=$M2_TIMEZONE \ | ||
--use-rewrites=1 \ | ||
--search-engine=elasticsearch7 \ | ||
--elasticsearch-host=$M2_ELASTICSEARCH_HOST \ | ||
--elasticsearch-port=$M2_ELASTICSEARCH_PORT \ | ||
--elasticsearch-enable-auth=0 \ | ||
--elasticsearch-index-prefix=$M2_ELASTICSEARCH_INDEX_PREFIX \ | ||
--elasticsearch-timeout=$M2_ELASTICSEARCH_TIMEOUT \ | ||
$session_save $disable_modules" \ | ||
&& su -s /bin/bash www-data -c "composer config http-basic.repo.magento.com $M2_COMPOSER_REPO_KEY $M2_COMPOSER_REPO_SECRET" \ | ||
&& su -s /bin/bash www-data -c "bin/magento deploy:mode:set developer" \ | ||
&& su -s /bin/bash www-data -c "bin/magento sampledata:deploy && bin/magento setup:upgrade && bin/magento cache:flush" \ | ||
|| handle_failure | ||
|
||
# Set auto increment to current timestamp for Order Sequence tables | ||
echo "ALTER TABLE sequence_order_0 AUTO_INCREMENT = $(date +%s);ALTER TABLE sequence_order_1 AUTO_INCREMENT = $(date +%s);" \ | ||
| mysql -h $M2_DB_HOST -P 3306 -u $M2_DB_USER -p$M2_DB_PASSWORD $M2_DB_NAME || handle_failure | ||
|
||
# Install seQura plugin | ||
su -s /bin/bash www-data -c "composer config repositories.sequra/magento2-core path /Sequra/Core" \ | ||
&& su -s /bin/bash www-data -c "COMPOSER_MIRROR_PATH_REPOS=1 composer require sequra/magento2-core:^2.5" \ | ||
&& su -s /bin/bash www-data -c "bin/magento config:set dev/template/allow_symlink $M2_ALLOW_SYMLINK" \ | ||
&& su -s /bin/bash www-data -c "bin/magento module:enable Sequra_Core" \ | ||
&& su -s /bin/bash www-data -c "bin/magento setup:upgrade" \ | ||
&& su -s /bin/bash www-data -c "bin/magento sequra:configure --merchant_ref="$SQ_MERCHANT_REF" --username="$SQ_USER_NAME" --password="$SQ_USER_SECRET" --assets_key="$SQ_ASSETS_KEY" --endpoint="$SQ_ENDPOINT"" || handle_failure | ||
|
||
touch /var/www/html/.post-install-complete && echo "✅ Magento 2 installed and configured." | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,123 @@ | ||
MAGENTO_VERSION=2 | ||
# The version of MariaDB to use. See available tags at https://hub.docker.com/_/mariadb/tags | ||
MARIADB_TAG=10.6 | ||
|
||
SQ_M2_CORE_VERSION=* | ||
# Use "local" to run code in local directory | ||
#SQ_M2_CORE_VERSION=local | ||
# The name of the database to create | ||
MARIADB_DATABASE=magentodb | ||
# The name of the database user to create | ||
MARIADB_USER=magentouser | ||
# The password for the database user | ||
MARIADB_PASSWORD=magentopass | ||
# The password for the root user | ||
MARIADB_ROOT_PASSWORD=root | ||
# The port to expose the Database service | ||
MARIADB_PORT=3328 | ||
|
||
# The version of Redis to use. See available tags at https://hub.docker.com/_/redis/tags | ||
REDIS_TAG=7.2 | ||
# The port to expose the Redis service | ||
REDIS_PORT=6380 | ||
|
||
# The version of Elasticsearch to use. See available tags at https://hub.docker.com/_/elasticsearch/tags | ||
# ELASTICSEARCH_TAG=8.11.4 # Use this version for Magento 2.4.7 | ||
ELASTICSEARCH_TAG=7.16.3 # Use this version for Magento 2.4.3, 2.4.4, 2.4.5, 2.4.6 | ||
|
||
# The port to expose the Elasticsearch service | ||
ELASTICSEARCH_API_PORT=9200 | ||
ELASTICSEARCH_INTERNODE_PORT=9300 | ||
|
||
# The version of PHP to use. | ||
PHP_VERSION=8.2 # Compatible with Magento 2.4.7, 2.4.6 | ||
# PHP_VERSION=8.1 # Compatible with Magento 2.4.5, 2.4.4 | ||
# PHP_VERSION=7.4 # Compatible with Magento 2.4.3 | ||
|
||
# The version of Magento 2 to use. | ||
# M2_VERSION=2.4.3-p3 | ||
# M2_VERSION=2.4.4-p11 | ||
# M2_VERSION=2.4.5-p10 | ||
# M2_VERSION=2.4.6-p8 | ||
M2_VERSION=2.4.7-p3 | ||
|
||
# The hostname of the database server | ||
M2_DB_HOST=mariadb | ||
# Same as MARIADB_USER | ||
M2_DB_USER=$MARIADB_USER | ||
# Same as MARIADB_PASSWORD | ||
M2_DB_PASSWORD=$MARIADB_PASSWORD | ||
#Same as MARIADB_DATABASE | ||
M2_DB_NAME=$MARIADB_DATABASE | ||
# The port to expose the Magento 2 service | ||
M2_HTTP_PORT=8018 | ||
M2_HTTP_HOST=localhost.sequrapi.com | ||
# The site URL | ||
M2_URL=http://$M2_HTTP_HOST:$M2_HTTP_PORT | ||
|
||
M2_BACKEND_FRONTNAME="admin" | ||
M2_ADMIN_USER="admin" | ||
M2_ADMIN_PASSWORD="Admin123" | ||
M2_ADMIN_EMAIL="magento@sequra.com" | ||
M2_ADMIN_FIRSTNAME="Admin" | ||
M2_ADMIN_LASTNAME="Admin" | ||
M2_LANGUAGE="en_US" | ||
M2_CURRENCY="EUR" | ||
M2_TIMEZONE="Europe/Madrid" | ||
|
||
M2_ELASTICSEARCH_HOST=elasticsearch | ||
M2_ELASTICSEARCH_PORT=9200 | ||
M2_ELASTICSEARCH_INDEX_PREFIX=m2 | ||
M2_ELASTICSEARCH_TIMEOUT=60 | ||
|
||
M2_DISABLE_MODULES="Magento_TwoFactorAuth" | ||
# M2_DISABLE_MODULES="Magento_TwoFactorAuth,Magento_AdminAdobeIms,Magento_AdminAnalytics,Magento_AdobeIms,Magento_AdobeImsApi,Magento_AdobeStockAdminUi,Magento_AdobeStockClient,Magento_AdobeStockClientApi,Magento_AdobeStockImage,Magento_AdobeStockImageApi,Magento_AdobeStockImageAdminUi,Magento_Analytics,Magento_ApplicationPerformanceMonitor,Magento_ApplicationPerformanceMonitorNewRelic,Magento_Backup,Magento_CardinalCommerce,Magento_Captcha,Magento_Dhl,Magento_Fedex,Magento_GoogleAdwords,Magento_GoogleAnalytics,Magento_GoogleGtag,Magento_GoogleOptimizer,Magento_Paypal,Magento_PaypalCaptcha,Magento_PaypalGraphQl,Magento_PaymentServicesPaypal,Magento_PaymentServicesPaypalGraphQl,PayPal_Braintree,PayPal_BraintreeCustomerBalance,PayPal_BraintreeGiftCardAccount,PayPal_BraintreeGiftWrapping,PayPal_BraintreeGraphQl" | ||
|
||
# Choose the session save handler. Options are files, redis, db. | ||
# For redis, the REDIS_TAG must be set and you must provide the | ||
# extra environment variables having M2_SESSION_SAVE_REDIS_ prefix. | ||
M2_SESSION_SAVE=files | ||
# M2_SESSION_SAVE=db | ||
# M2_SESSION_SAVE=redis | ||
# M2_SESSION_SAVE_REDIS_HOST=redis | ||
# M2_SESSION_SAVE_REDIS_PORT=6379 | ||
# M2_SESSION_SAVE_REDIS_PASSWORD='' # Default is empty | ||
# M2_SESSION_SAVE_REDIS_TIMEOUT=4 # Default is 4 | ||
# M2_SESSION_SAVE_REDIS_PERSISTENT_IDENTIFIER='' # Default is empty | ||
# M2_SESSION_SAVE_REDIS_DB=2 # Default is 2 | ||
# M2_SESSION_SAVE_REDIS_COMPRESSION_THRESHOLD=2048 # Default is 2048 | ||
# M2_SESSION_SAVE_REDIS_COMPRESSION_LIB=gzip # Default is gzip | ||
# M2_SESSION_SAVE_REDIS_LOG_LEVEL=3 # Default is 1 | ||
# M2_SESSION_SAVE_REDIS_MAX_CONCURRENCY=25 # Default is 6 | ||
# M2_SESSION_SAVE_REDIS_BREAK_AFTER_FRONTEND=5 # Default is 5 | ||
# M2_SESSION_SAVE_REDIS_BREAK_AFTER_ADMINHTML=30 # Default is 30 | ||
# M2_SESSION_SAVE_REDIS_FIRST_LIFETIME=600 # Default is 600 | ||
# M2_SESSION_SAVE_REDIS_BOT_FIRST_LIFETIME=60 # Default is 60 | ||
# M2_SESSION_SAVE_REDIS_BOT_LIFETIME=7200 # Default is 7200 | ||
# M2_SESSION_SAVE_REDIS_DISABLE_LOCKING=1 # Default is 0 | ||
# M2_SESSION_SAVE_REDIS_MIN_LIFETIME=7776000 # Default is 60 | ||
# M2_SESSION_SAVE_REDIS_MAX_LIFETIME=2592000 # Default is 2592000 | ||
# M2_SESSION_SAVE_REDIS_SENTINEL_MASTER='' # Default is empty | ||
# M2_SESSION_SAVE_REDIS_SENTINEL_SERVERS='' # Default is empty | ||
# M2_SESSION_SAVE_REDIS_SENTINEL_VERIFY_MASTER=0 # Default is 0 | ||
# M2_SESSION_SAVE_REDIS_SENTINEL_CONNECT_RETRIES=5 # Default is 5 | ||
|
||
M2_ALLOW_SYMLINK=1 | ||
|
||
# Public and private keys for Magento 2 composer repository | ||
M2_COMPOSER_REPO_KEY= | ||
M2_COMPOSER_REPO_SECRET= | ||
|
||
# SeQura configuration | ||
SQ_MERCHANT_REF=dummy | ||
SQ_USER_NAME=dummy | ||
SQ_USER_SECRET=ZqbjrN6bhPYVIyram3wcuQgHUmP1C4 | ||
SQ_ASSETS_KEY=ADc3ZdOLh4 | ||
SQ_ENDPOINT=https://sandbox.sequrapi.com/orders | ||
|
||
MAGENTO_HTTP_PORT=8018 | ||
MAGENTO_EXTERNAL_HTTP_PORT_NUMBER=${MAGENTO_HTTP_PORT} | ||
MAGENTO_HTTPS_PORT=8019 | ||
MAGENTO_EXTERNAL_HTTPS_PORT_NUMBER=${MAGENTO_HTTPS_PORT} | ||
MAGENTO_MYSQL_PORT=8020 | ||
|
||
# More options available at https://hub.docker.com/r/bitnami/magento | ||
MAGENTO_HOST=localhost | ||
MAGENTO_DATABASE_HOST=mariadb | ||
MAGENTO_DATABASE_PORT_NUMBER=3306 | ||
MAGENTO_DATABASE_USER=bn_magento | ||
MAGENTO_DATABASE_NAME=bitnami_magento | ||
ELASTICSEARCH_HOST=elasticsearch | ||
ELASTICSEARCH_PORT_NUMBER=9200 | ||
MAGENTO_EMAIL=magento@sequra.com | ||
MAGENTO_FIRST_NAME=admin_first_name | ||
MAGENTO_LAST_NAME=admin_last_name | ||
MAGENTO_USERNAME=admin | ||
MAGENTO_PASSWORD=password123 | ||
MAGENTO_FRONTNAME=admin | ||
MAGENTO_COUNTRY=ES | ||
|
||
MAGENTO_LOCALE=es_ES | ||
MAGENTO_CURRENCY=EUR | ||
MAGENTO_TIMEZONE=Europe/Berlin | ||
MAGENTO_SAMPLEDATA=yes | ||
MAGENTO_EXTRA_INSTALL_ARGS="--currency=${MAGENTO_CURRENCY} --timezone=${MAGENTO_TIMEZONE} --language=${MAGENTO_LOCALE} --cleanup-database" | ||
MAGENTO_ENABLE_HTTP_CACHE=no | ||
|
||
# ALLOW_EMPTY_PASSWORD is recommended only for development. | ||
ALLOW_EMPTY_PASSWORD=yes | ||
#MAGENTO_DATABASE_PASSWORD=supersecret | ||
COMPOSER_AUTH='{"http-basic":{"repo.magento.com":{"username":"<public-key>","password":"<private-key>"}}}' | ||
# Outside /bitnami/magento/ | ||
COMPOSER_CACHE_DIR=/opt/.composer/cache | ||
|
||
BITNAMI_DEBUG=false | ||
# Set with the ngrok authtoken (get it from https://dashboard.ngrok.com/) | ||
NGROK_AUTHTOKEN= | ||
# The port to expose the ngrok service to the host. | ||
NGROK_PORT=4740 | ||
# The name of the ngrok container | ||
NGROK_CONTAINER_NAME=magento-ngrok | ||
# This is the URL where the website will be accessible on the internet. | ||
# It is automatically generated by ngrok and will be overwritten by the script. | ||
# Do not modify this value manually. | ||
PUBLIC_URL= |
Oops, something went wrong.