Skip to content

Commit

Permalink
Merge pull request #40 from sequra/refactor/PAR-480-Migrate-Magento-2…
Browse files Browse the repository at this point in the history
…-Docker-image

Migrate Magento 2 Docker image
  • Loading branch information
m1k3lm authored Jan 15, 2025
2 parents 445b275 + f01e8e9 commit 158ea76
Show file tree
Hide file tree
Showing 36 changed files with 1,017 additions and 255 deletions.
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

0 comments on commit 158ea76

Please sign in to comment.