Skip to content

Commit

Permalink
refacto: Update dockerfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
Venatum committed Dec 21, 2023
1 parent ba6b4e0 commit 415b82e
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 2,057 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion docker/config_files/docker_run.sh → assets/docker_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ if [ ! -f ./config/settings.inc.php ] && [ ! -f ./install.lock ]; then
elif [ -f ./install.lock ]; then
if [ -f ./config/settings.inc.php ]; then
echo "\n* Shop seems setup but remaining install lock still present..."
else
else
echo "\n* Another setup is currently running..."
fi
sleep 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
$domain = Tools::getHttpHost();
$old_domain = Configuration::get('PS_SHOP_DOMAIN');

if (version_compare(_PS_VERSION_, '1.5', '>=') && $domain != $old_domain && !Shop::isFeatureActive())
if $domain != $old_domain && !Shop::isFeatureActive())
{
$url = ShopUrl::getShopUrls(Configuration::get('PS_SHOP_DEFAULT'))->where('main', '=', 1)->getFirst();
if ($url)
Expand Down
38 changes: 38 additions & 0 deletions assets/php-configuration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/sh
set -eu

error() {
printf "\e[1;31m%s\e[0m" "${1:-Unknown error}"
exit "${2:-1}"
}

[ -z "$PHP_ENV" ] && error "PHP_ENV is not set" 2
[ -z "$PHP_VERSION" ] && error "PHP_VERSION is not set" 3

PS_PHP_EXT="bcmath fileinfo gd intl mbstring pdo_mysql simplexml soap zip";
PHP_GD_CONFIG="--with-jpeg";
#gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ --with-webp=/usr/include

if [ "7.1" = "$PHP_VERSION" ]; then
PS_PHP_EXT="$PS_PHP_EXT mcrypt";
PHP_GD_CONFIG="--with-gd --with-jpeg --with-jpeg-dir --with-zlib-dir";
elif [ "7.2" = "$PHP_VERSION" ] || [ "7.3" = "$PHP_VERSION" ]; then
PHP_GD_CONFIG="--with-jpeg-dir --with-zlib-dir";
fi

# shellcheck disable=SC2086
docker-php-ext-configure gd $PHP_GD_CONFIG
# shellcheck disable=SC2086
docker-php-ext-install $PS_PHP_EXT;

if [ "production" = "$PHP_ENV" ]; then
mv "${PHP_INI_DIR}/php.ini-production" "${PHP_INI_DIR}/php.ini"
rm -f "${PHP_INI_DIR}/php.ini-development";
else
mv "${PHP_INI_DIR}/php.ini-development" "${PHP_INI_DIR}/php.ini"
rm -f "${PHP_INI_DIR}/php.ini-production";
sed -i 's/memory_limit = .*/memory_limit = -1/' "${PHP_INI_DIR}/php.ini"
fi

# Remove php assets that might have been installed by package unaware of $PHP_INI_DIR
rm -rf /etc/php* /usr/lib/php*
3 changes: 1 addition & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,4 @@ docker buildx build \
--label org.opencontainers.image.created="$(date -u +"%Y-%m-%dT%H:%M:%S.%3NZ")" \
"${TARGET_IMAGES[@]}" \
"$([ "${PUSH}" == "true" ] && echo "--push" || echo "--load")" \
./docker

.
110 changes: 56 additions & 54 deletions docker/alpine.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,92 +7,94 @@ ARG PHP_FLAVOUR
# ==================================
FROM php:${PHP_FLAVOUR} AS alpine-base-prestashop
ARG PS_VERSION
ARG PS_FOLDER=/var/www/html

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 \
PHP_ENV=production

# The PHP configuration script
COPY ./assets/php-configuration.sh /tmp/

# Install base tools
RUN \

Check failure on line 39 in docker/alpine.Dockerfile

View workflow job for this annotation

GitHub Actions / Lint: dockerfile

DL3018 warning: Pin versions in apk add. Instead of `apk add <package>` use `apk add <package>=<version>`
apk --no-cache add -U \
bash less vim geoip git tzdata zip curl \
nginx nginx-mod-http-headers-more nginx-mod-http-geoip \
nginx-mod-stream nginx-mod-stream-geoip ca-certificates \
libmcrypt gnu-libiconv-libs php81-common && \
rm -rf /var/cache/apk/*

# Install PHP requirements
# see: https://olvlvl.com/2019-06-install-php-ext-source
ENV GD_DEPS="zlib-dev libjpeg-turbo-dev libpng-dev"
ENV ZIP_DEPS="libzip-dev"
ENV INTL_DEPS="icu-dev"
RUN apk --no-cache add -U $GD_DEPS $ZIP_DEPS $INTL_DEPS \
&& docker-php-ext-configure gd --with-jpeg \
&& docker-php-ext-install gd pdo_mysql zip intl;
# docker-php-ext-enable opcache

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
ca-certificates geoip tzdata zip curl jq make \
gnu-libiconv php-common mariadb-client oniguruma-dev \
zlib-dev libzip-dev libjpeg-turbo-dev libpng-dev \
icu-dev libmcrypt-dev libxml2 libxml2-dev \
&& /tmp/php-configuration.sh \
&& apk del make \
&& rm -rf /var/cache/apk/*

# The PrestaShop docker entrypoint
COPY config_files/docker_run.sh /tmp/
COPY ./assets/docker_run.sh /tmp/

# Handling a dynamic domain
COPY config_files/docker_updt_ps_domains.php /tmp/
# Probably, or at least its usage must be described in the README file
# COPY ./assets/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
# COPY ./assets/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/

# @TODO check opcache
# RUN echo '\
# opcache.interned_strings_buffer=16\n\
# opcache.load_comments=Off\n\
# opcache.max_accelerated_files=16000\n\
# opcache.save_comments=Off\n\
# ' >> /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini

# Disable IPv6
# RUN echo "net.ipv6.conf.all.disable_ipv6 = 1" | tee /etc/sysctl.conf
RUN if [ -x "$(command -v apache2-foreground)" ]; then \
a2enmod rewrite;\
fi

# =========================================
# Stage 2/3: PrestaShop sources downloader
# =========================================
FROM alpine-base-prestashop AS alpine-download-prestashop
ARG PS_VERSION
ENV PS_FOLDER=/tmp/prestashop

RUN apk --no-cache add -U git jq make

# Get PrestaShop source code
RUN if [[ "$PS_VERSION" == "nightly" ]]; then \

Check failure on line 73 in docker/alpine.Dockerfile

View workflow job for this annotation

GitHub Actions / Lint: dockerfile

SC3010 warning: In POSIX sh, [[ ]] is undefined.
git clone --depth 1 'https://github.com/PrestaShop/PrestaShop.git' /tmp/prestashop; \
rm -rf /tmp/prestashop/.git; \
make install; \
echo "Unsupported yet: https://prestashop.slack.com/archives/C03LFE4KV6K/p1703170152828039" \
&& exit 1; \
else \
DOWNLOAD_URL=$(curl -s -L --request GET 'https://api.github.com/repos/prestashop/prestashop/releases/latest' | jq -r '.assets[] | select(.name | contains(".zip")) | .browser_download_url'); \
curl -s -L -o /tmp/prestashop.zip "${DOWNLOAD_URL}"; \
unzip -n -q /tmp/prestashop.zip -d /tmp/prestashop; \
curl -s -L -o /tmp/prestashop.zip "https://github.com/PrestaShop/PrestaShop/releases/download/${PS_VERSION}/prestashop_${PS_VERSION}.zip"; \
fi

# Extract the souces
RUN mkdir -p "$PS_FOLDER" /tmp/unzip-ps \

Check failure on line 81 in docker/alpine.Dockerfile

View workflow job for this annotation

GitHub Actions / Lint: dockerfile

SC2015 info: Note that A && B || C is not if-then-else. C may run when A is true.
&& unzip -n -q /tmp/prestashop.zip -d /tmp/unzip-ps \
&& ([ -f /tmp/unzip-ps/prestashop.zip ] \
&& unzip -n -q /tmp/unzip-ps/prestashop.zip -d "$PS_FOLDER" \
|| mv /tmp/unzip-ps/prestashop/* "$PS_FOLDER")

# ============================
# Stage 3/3: Production image
# ============================
FROM alpine-base-prestashop
ARG PS_FOLDER=/var/www/html
ARG PS_FOLDER=/var/www/html/prestashop

LABEL maintainer="PrestaShop Core Team <[email protected]>"

ENV PS_VERSION $PS_VERSION

# Copy the PrestaShop sources
COPY --chown=www-data:www-data --from=alpine-download-prestashop /tmp/prestashop ${PS_FOLDER}/prestashop
COPY --chown=www-data:www-data --from=alpine-download-prestashop /tmp/prestashop ${PS_FOLDER}

CMD ["/tmp/docker_run.sh"]
Loading

0 comments on commit 415b82e

Please sign in to comment.