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

Migrate Magento 2 Docker image #40

Merged
merged 18 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
7183de2
Enhance Docker setup for Magento: add Dockerfile, PHP configuration, …
mescalantea Dec 30, 2024
628e177
Update Docker Compose to use environment variable for HTTP host
mescalantea Dec 31, 2024
efebeb9
Update composer.json to exclude additional files and directories from…
mescalantea Dec 31, 2024
28088e9
Add checks for Magento repository keys in setup script
mescalantea Dec 31, 2024
798b8e4
Remove unnecessary platforms specification from Docker Compose
mescalantea Dec 31, 2024
35911e0
Fix setup script to reference the correct Docker service for post-ins…
mescalantea Dec 31, 2024
0ce0ed6
Update exclusion list used on composer require
mescalantea Dec 31, 2024
64462df
Improve Docker image and scripts
mescalantea Dec 31, 2024
fc38a6d
Update README to enhance environment setup instructions and utility s…
mescalantea Jan 2, 2025
f0028d7
Update README to emphasize the importance of modifying the hosts file…
mescalantea Jan 2, 2025
a66f5b4
Update README to include setup script arguments and post-setup inform…
mescalantea Jan 2, 2025
54af25b
Update README to correct plugin name from WooCommerce to Magento 2
mescalantea Jan 2, 2025
ffe42db
Add Docker support for Magento 2 with PHP 8.2 and custom build scripts
mescalantea Jan 2, 2025
80cf902
Add Dockerfile for PHP 7.4 with necessary extensions for Magento Open…
mescalantea Jan 2, 2025
c775c39
Refactor Dockerfiles for PHP 7.4 and PHP 8, streamline dependencies, …
mescalantea Jan 3, 2025
7b66a31
Update README to include Docker image building instructions and scrip…
mescalantea Jan 3, 2025
f07501b
MARIADB_ALLOW_EMPTY_ROOT_PASSWORD
m1k3lm Jan 15, 2025
f01e8e9
Add helper module to allow easier testing
m1k3lm Jan 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions .docker/magento/Dockerfile.php74
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Dockerfile para PHP 7.4 con las extensiones necesarias para Magento Open Source
FROM php:7.4-apache

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

RUN apt-get update && apt-get install -y --no-install-recommends \
mariadb-client \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libicu-dev \
libxslt1-dev \
libzip-dev \
libcurl4-openssl-dev \
libonig-dev \
libsodium-dev \
git \
curl \
unzip \
tar \
libpcre3 \
&& pecl install xdebug-3.1.6 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 \
bcmath \
curl \
opcache \
gd \
intl \
mbstring \
mysqli \
pdo_mysql \
simplexml \
soap \
sockets \
sodium \
tokenizer \
xmlwriter \
xsl \
zip \
&& 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

# 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.php74.sh /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

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 --mount=type=secret,id=M2_COMPOSER_REPO_KEY,env=M2_REPO_KEY \
--mount=type=secret,id=M2_COMPOSER_REPO_SECRET,env=M2_REPO_SECRET \
composer config -g --no-plugins allow-plugins true \
&& 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 ./

# 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
79 changes: 79 additions & 0 deletions .docker/magento/Dockerfile.php8
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
ARG PHP_VERSION=8.2

FROM php:${PHP_VERSION}-apache

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

RUN apt-get update && apt-get install -y --no-install-recommends \
mariadb-client \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libicu-dev \
libxslt1-dev \
libzip-dev \
libssl-dev \
git \
curl \
unzip \
tar \
libpcre3 \
&& 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 \
bcmath \
opcache \
gd \
intl \
mysqli \
pdo_mysql \
soap \
sockets \
xsl \
zip \
&& 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

# 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
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

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 --mount=type=secret,id=M2_COMPOSER_REPO_KEY,env=M2_REPO_KEY \
--mount=type=secret,id=M2_COMPOSER_REPO_SECRET,env=M2_REPO_SECRET \
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 ./

# 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
68 changes: 68 additions & 0 deletions .docker/magento/HelperModule/Sequra/Helper/Console/Setup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* Copyright © 2017 SeQura Engineering. All rights reserved.
*/

namespace Sequra\Helper\Console;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Console command to trigger DR report
*/
class Setup extends Command
{
/**
* Command name
*/
const NAME = 'sequra-helper:setup';
/**
* Initialize triggerreport command
*
* @return void
*/
protected function configure()
{
$this->setName(self::NAME)
->setDescription('Setup data for quick testing');
parent::configure();
}
/**
* Execute command.
*
* @param InputInterface $input InputInterface
* @param OutputInterface $output OutputInterface
*
* @return int 0 if everything went fine, or an exit code
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerRepository = $objectManager->create(\Magento\Customer\Api\CustomerRepositoryInterface::class);

$customer = $customerRepository->getById(1);
$customer->setLastname('Costello Costello');
$addresses = $customer->getAddresses();
if (!empty($addresses)) {
$address = reset($addresses);
$address->setStreet(['Nueva Calle', 'Piso 2']);
$address->setCity('Barcelona');
$address->setPostcode('08010');
$address->setCountryId('ES');
$address->setTelephone('666666666');
$regionFactory = $objectManager->create(\Magento\Directory\Model\RegionFactory::class);
$region = $regionFactory->create()->loadByName('Barcelona','ES');
if ($region->getId()) {
$address->setRegionId($region->getId());
}
}

$customerRepository->save($customer);
$output->writeln("Dirección actualizada correctamente");
return 0;
}
}
15 changes: 15 additions & 0 deletions .docker/magento/HelperModule/Sequra/Helper/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "sequra/magento2-helper",
"type": "magento2-module",
"autoload": {
"psr-4": {
"Sequra\\Helper\\": ""
}
},
"authors": [
{
"name": "Sequra Engineering"
}
],
"require": {}
}
3 changes: 3 additions & 0 deletions .docker/magento/HelperModule/Sequra/Helper/etc/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
</config>
5 changes: 5 additions & 0 deletions .docker/magento/HelperModule/Sequra/Helper/etc/crontab.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/crontab.xsd">
<group id="default">
</group>
</config>
11 changes: 11 additions & 0 deletions .docker/magento/HelperModule/Sequra/Helper/etc/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<!-- Commandline option to triggerrerport and update orders-->
<type name="Magento\Framework\Console\CommandList">
<arguments>
<argument name="commands" xsi:type="array">
<item name="Setup" xsi:type="object">Sequra\Helper\Console\Setup</item>
</argument>
</arguments>
</type>
</config>
3 changes: 3 additions & 0 deletions .docker/magento/HelperModule/Sequra/Helper/etc/events.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
</config>
7 changes: 7 additions & 0 deletions .docker/magento/HelperModule/Sequra/Helper/etc/module.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Sequra_Helper" setup_version="1.0.0">
<sequence>
</sequence>
</module>
</config>
9 changes: 9 additions & 0 deletions .docker/magento/HelperModule/Sequra/Helper/registration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(
ComponentRegistrar::MODULE,
'Sequra_Helper',
__DIR__
);
Loading
Loading