Skip to content

Commit

Permalink
Generate base images for PHP 8.3
Browse files Browse the repository at this point in the history
  • Loading branch information
jolelievre committed Feb 19, 2024
1 parent c4cf76b commit ffa6a3f
Show file tree
Hide file tree
Showing 14 changed files with 4,588 additions and 0 deletions.
69 changes: 69 additions & 0 deletions base/images/8.3-apache/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
FROM php:8.3-apache
LABEL maintainer="PrestaShop Core Team <[email protected]>"

ENV PS_DOMAIN="<to be defined>" \
DB_SERVER="<to be defined>" \
DB_PORT=3306 \
DB_NAME=prestashop \
DB_USER=root \
DB_PASSWD=admin \
DB_PREFIX=ps_ \
[email protected] \
ADMIN_PASSWD=prestashop_demo \
PS_LANGUAGE=en \
PS_COUNTRY=GB \
PS_ALL_LANGUAGES=0 \
PS_INSTALL_AUTO=0 \
PS_ERASE_DB=0 \
PS_INSTALL_DB=0 \
PS_DEV_MODE=0 \
PS_HOST_MODE=0 \
PS_DEMO_MODE=0 \
PS_ENABLE_SSL=0 \
PS_HANDLE_DYNAMIC_DOMAIN=0 \
PS_FOLDER_ADMIN=admin \
PS_FOLDER_INSTALL=install

RUN apt-get update \
&& apt-get install -y libmcrypt-dev \
libjpeg62-turbo-dev \
libpcre3-dev \
libpng-dev \
libwebp-dev \
libfreetype6-dev \
libxml2-dev \
libicu-dev \
libzip-dev \
default-mysql-client \
wget \
unzip \
libonig-dev

RUN rm -rf /var/lib/apt/lists/*
RUN docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ --with-webp=/usr/include
RUN docker-php-ext-install iconv intl pdo_mysql mbstring soap gd zip bcmath

RUN docker-php-source extract \
&& if [ -d "/usr/src/php/ext/mysql" ]; then docker-php-ext-install mysql; fi \
&& if [ -d "/usr/src/php/ext/mcrypt" ]; then docker-php-ext-install mcrypt; fi \
&& if [ -d "/usr/src/php/ext/opcache" ]; then docker-php-ext-install opcache; fi \
&& docker-php-source delete

# Prepare install and CMD script
COPY config_files/ps-extractor.sh config_files/docker_run.sh config_files/docker_nightly_run.sh /tmp/

# If handle dynamic domain
COPY config_files/docker_updt_ps_domains.php /tmp/

# PHP env for dev / demo modes
COPY config_files/defines_custom.inc.php /tmp/
RUN chown www-data:www-data /tmp/defines_custom.inc.php

# Apache configuration
RUN if [ -x "$(command -v apache2-foreground)" ]; then a2enmod rewrite; fi

# PHP configuration
COPY config_files/php.ini /usr/local/etc/php/

# Run
CMD ["/tmp/docker_run.sh"]
32 changes: 32 additions & 0 deletions base/images/8.3-apache/config_files/defines_custom.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop-project.org/ for more information.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/
if ((bool) getenv('PS_DEV_MODE')) {
define('_PS_MODE_DEV_', (bool) getenv('PS_DEV_MODE'));
}
// FYI: Defining env var _PS_HOST_MODE_ as true also works natively
if ((bool) getenv('PS_HOST_MODE')) {
define('_PS_HOST_MODE_', (bool) getenv('PS_HOST_MODE'));
}
16 changes: 16 additions & 0 deletions base/images/8.3-apache/config_files/docker_nightly_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

# Download nightly build
if [ ! -d /tmp/data-ps ]; then
gsutil cp `gsutil ls gs://prestashop-core-nightly/ | grep -E 'develop.+\.zip$$' | tail -1` /tmp/prestashop.zip

mkdir -p /tmp/data-ps
unzip -q /tmp/prestashop.zip -d /tmp/data-ps/

bash /tmp/ps-extractor.sh /tmp/data-ps

# Remove downloaded zip
rm /tmp/prestashop.zip
fi

/tmp/docker_run.sh
145 changes: 145 additions & 0 deletions base/images/8.3-apache/config_files/docker_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
#!/bin/sh

if [ "$DB_SERVER" = "<to be defined>" -a $PS_INSTALL_AUTO = 1 ]; then
echo >&2 'error: You requested automatic PrestaShop installation but MySQL server address is not provided '
echo >&2 ' You need to specify DB_SERVER in order to proceed'
exit 1
elif [ "$DB_SERVER" != "<to be defined>" -a $PS_INSTALL_AUTO = 1 ]; then
RET=1
while [ $RET -ne 0 ]; do
echo "\n* Checking if $DB_SERVER is available..."
mysql -h $DB_SERVER -P $DB_PORT -u $DB_USER -p$DB_PASSWD -e "status" > /dev/null 2>&1
RET=$?

if [ $RET -ne 0 ]; then
echo "\n* Waiting for confirmation of MySQL service startup";
sleep 5
fi
done
echo "\n* DB server $DB_SERVER is available, let's continue !"
fi

# From now, stop at error
set -e

if [ ! -f ./config/settings.inc.php ] && [ ! -f ./install.lock ]; then

echo "\n* Setting up install lock file..."
touch ./install.lock

echo "\n* Reapplying PrestaShop files for enabled volumes ...";

if [ -d /tmp/data-ps ]; then
# init if empty
cp -n -R -p /tmp/data-ps/prestashop/* /var/www/html
fi

if [ -f /tmp/defines_custom.inc.php ]; then
cp -n -p /tmp/defines_custom.inc.php /var/www/html/config/defines_custom.inc.php
fi

if [ -d /tmp/pre-install-scripts/ ]; then
echo "\n* Running pre-install script(s)..."

for i in `ls /tmp/pre-install-scripts/`;do
/tmp/pre-install-scripts/$i
done
else
echo "\n* No pre-install script found, let's continue..."
fi

if [ $PS_FOLDER_INSTALL != "install" ] && [ -d /var/www/html/install ]; then
echo "\n* Renaming install folder as $PS_FOLDER_INSTALL ...";
mv /var/www/html/install /var/www/html/$PS_FOLDER_INSTALL/
fi

if [ $PS_FOLDER_ADMIN != "admin" ] && [ -d /var/www/html/admin ]; then
echo "\n* Renaming admin folder as $PS_FOLDER_ADMIN ...";
mv /var/www/html/admin /var/www/html/$PS_FOLDER_ADMIN/
fi

if [ $PS_HANDLE_DYNAMIC_DOMAIN = 1 ]; then
cp /tmp/docker_updt_ps_domains.php /var/www/html
sed -ie "s/DirectoryIndex\ index.php\ index.html/DirectoryIndex\ docker_updt_ps_domains.php\ index.php\ index.html/g" $APACHE_CONFDIR/conf-available/docker-php.conf
fi

if [ $PS_ERASE_DB = 1 ]; then
echo "\n* Drop mysql database...";
echo "\n* Dropping existing database $DB_NAME..."
mysql -h $DB_SERVER -P $DB_PORT -u $DB_USER -p$DB_PASSWD -e "drop database if exists $DB_NAME;"
fi

if [ $PS_INSTALL_DB = 1 ]; then
echo "\n* Create mysql database...";
echo "\n* Creating database $DB_NAME..."
mysqladmin -h $DB_SERVER -P $DB_PORT -u $DB_USER create $DB_NAME -p$DB_PASSWD --force;
fi

if [ $PS_INSTALL_AUTO = 1 ]; then
echo "\n* Installing PrestaShop, this may take a while ...";

if [ "$PS_DOMAIN" = "<to be defined>" ]; then
export PS_DOMAIN=$(hostname -i)
fi

echo "\n* Launching the installer script..."
runuser -g www-data -u www-data -- php -d memory_limit=-1 /var/www/html/$PS_FOLDER_INSTALL/index_cli.php \
--domain="$PS_DOMAIN" --db_server=$DB_SERVER:$DB_PORT --db_name="$DB_NAME" --db_user=$DB_USER \
--db_password=$DB_PASSWD --prefix="$DB_PREFIX" --firstname="John" --lastname="Doe" \
--password=$ADMIN_PASSWD --email="$ADMIN_MAIL" --language=$PS_LANGUAGE --country=$PS_COUNTRY \
--all_languages=$PS_ALL_LANGUAGES --newsletter=0 --send_email=0 --ssl=$PS_ENABLE_SSL

if [ $? -ne 0 ]; then
echo 'warning: PrestaShop installation failed.'
else
echo "\n* Removing install folder..."
rm -r /var/www/html/$PS_FOLDER_INSTALL/
fi
fi

if [ -d /tmp/post-install-scripts/ ]; then
echo "\n* Running post-install script(s)..."

for i in `ls /tmp/post-install-scripts/`;do
/tmp/post-install-scripts/$i
done
else
echo "\n* No post-install script found, let's continue..."
fi

echo "\n* Setup completed, removing lock file..."
rm ./install.lock

elif [ ! -f ./config/settings.inc.php ] && [ -f ./install.lock ]; then

echo "\n* Another setup is currently running..."
sleep 10
exit 42

elif [ -f ./config/settings.inc.php ] && [ -f ./install.lock ]; then

echo "\n* Shop seems setup but remaining install lock still present..."
sleep 10
exit 42

else
echo "\n* PrestaShop Core already installed...";
fi

if [ $PS_DEMO_MODE -ne 0 ]; then
echo "\n* Enabling DEMO mode ...";
sed -ie "s/define('_PS_MODE_DEMO_', false);/define('_PS_MODE_DEMO_',\ true);/g" /var/www/html/config/defines.inc.php
fi

echo "\n* Almost ! Starting web server now\n";

if [ -d /tmp/init-scripts/ ]; then
echo "\n* Running init script(s)..."
for i in `ls /tmp/init-scripts/`;do
/tmp/init-scripts/$i
done
else
echo "\n* No init script found, let's continue..."
fi

exec apache2-foreground
62 changes: 62 additions & 0 deletions base/images/8.3-apache/config_files/docker_updt_ps_domains.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop-project.org/ for more information.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/

// Workaround for redirection on init
$_POST['id_shop'] = 1;

require_once 'config/config.inc.php';

if (!defined('_PS_VERSION_'))
exit;

// First, we get the URL used to reach this page.
$domain = Tools::getHttpHost();
$old_domain = Configuration::get('PS_SHOP_DOMAIN');

if (version_compare(_PS_VERSION_, '1.5', '>=') && $domain != $old_domain && !Shop::isFeatureActive())
{
$url = ShopUrl::getShopUrls(Configuration::get('PS_SHOP_DEFAULT'))->where('main', '=', 1)->getFirst();
if ($url)
{
$url->domain = $domain;
$url->domain_ssl = $domain;
$url->save();

// Then, we update the configuration table
Configuration::updateValue('PS_SHOP_DOMAIN', $domain);
Configuration::updateValue('PS_SHOP_DOMAIN_SSL', $domain);

// Finally, update all the files that depend on the domain name
Tools::generateHtaccess();
Tools::generateRobotsFile();
Tools::clearSmartyCache();
Media::clearCache();
}
}

//unlink(__FILE__);
Tools::redirect("index.php");
die();
Loading

0 comments on commit ffa6a3f

Please sign in to comment.