Skip to content

Commit

Permalink
Merge branch 'main' into feat/29-add-nightly-support
Browse files Browse the repository at this point in the history
  • Loading branch information
jokesterfr authored Feb 7, 2024
2 parents 4e1a688 + d3faccd commit 6792997
Show file tree
Hide file tree
Showing 21 changed files with 269 additions and 156 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@
.scannerwork
sonar-project.properties

PrestaShop/
PrestaShop/
vendor/
.prestashop-tags
.prestashop-minor-tags
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ On error, PrestaShop Flashlight can quit with these exit codes:

Partially yes. As there is no console within the sources, the modules cannot be automatically installed right now. Feel free to contribute!

## Developing a module with RW (known Linux issue)

The [develop-a-module](https://github.com/PrestaShop/prestashop-flashlight/tree/main/examples/develop-a-module) example is provided as a local environment for a developer. At PrestaShop we could successfully use it with Mac OSx and Windows, but due to the nature of the Docker implementation on Linux (no virtualization), we could not yet allow the module to write content from PrestaShop to the host. Will keep you posted here, feel free to suggest your ideas in this project issues.

## Api calls within a docker network

**Disclaimer**: PrestaShop is sensitive to the `Host` header of your client, and can behave surprisingly. In fact, since the Multi-shop feature is available, you cannot just call any front controller from any endpoint unless you set the `Host` or the `id_shop` you are targeting.
Expand Down
2 changes: 1 addition & 1 deletion assets/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ http {
index index.php;

# This should match the `post_max_size` and/or `upload_max_filesize` in your php.ini.
client_max_body_size 8M;
client_max_body_size 40M;

# Uploaded files temporary dir
client_body_temp_path /tmp/client_body;
Expand Down
46 changes: 46 additions & 0 deletions assets/php-configuration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/sh
set -eu

# Install PHP extensions
# @see https://olvlvl.com/2019-06-install-php-ext-source
# @see https://stackoverflow.com/a/73834081
# @see https://packages.sury.org/php/dists/

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="gd pdo_mysql zip intl fileinfo mbstring simplexml soap bcmath"
PHP_GD_CONFIG="--with-jpeg --with-freetype";

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 --with-freetype-dir";
elif [ "7.2" = "$PHP_VERSION" ] || [ "7.3" = "$PHP_VERSION" ]; then
PHP_GD_CONFIG="--with-jpeg-dir --with-zlib-dir --with-freetype-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";
fi

# Flashlight is a testinf platform, keep things simple
sed -i 's/memory_limit = .*/memory_limit = -1/' "$PHP_INI_DIR/php.ini"
sed -i 's/upload_max_filesize = .*/upload_max_filesize = 40M/' "$PHP_INI_DIR/php.ini"
sed -i 's/post_max_size = .*/post_max_size = 40M/' "$PHP_INI_DIR/php.ini"

# Remove php assets that might have been installed by package unaware of $PHP_INI_DIR
rm -rf /etc/php* /usr/lib/php*
30 changes: 10 additions & 20 deletions docker/alpine.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,16 @@ ENV PHP_INI_DIR=/usr/local/etc/php
ENV COMPOSER_HOME=/var/composer

# Install base tools, PHP requirements and dev-tools
# see: https://olvlvl.com/2019-06-install-php-ext-source
ENV PHP_ENV=development
COPY ./assets/php-configuration.sh /tmp/
RUN apk --no-cache add -U \
bash less vim geoip git tzdata zip curl jq make \
nginx nginx-mod-http-headers-more nginx-mod-http-geoip \
nginx-mod-stream nginx-mod-stream-geoip ca-certificates \
gnu-libiconv php-common mariadb-client sudo \
zlib-dev libjpeg-turbo-dev libpng-dev \
gnu-libiconv php-common mariadb-client sudo freetype-dev \
zlib-dev libjpeg-turbo-dev libpng-dev oniguruma-dev \
libzip-dev icu-dev libmcrypt-dev libxml2 libxml2-dev \
&& export PS_PHP_EXT="gd pdo_mysql zip intl fileinfo simplexml" \
&& if [ "7.1" = "$PHP_VERSION" ]; \
then docker-php-ext-configure gd --with-gd --with-jpeg --with-jpeg-dir --with-zlib-dir \
&& docker-php-ext-install $PS_PHP_EXT mcrypt; \
elif [ "7.2" = "$PHP_VERSION" ] || [ "7.3" = "$PHP_VERSION" ]; \
then docker-php-ext-configure gd --with-jpeg-dir --with-zlib-dir \
&& docker-php-ext-install $PS_PHP_EXT; \
else \
docker-php-ext-configure gd --with-jpeg \
&& docker-php-ext-install $PS_PHP_EXT; \
fi \
&& mv $PHP_INI_DIR/php.ini-development $PHP_INI_DIR/php.ini \
&& sed -i 's/memory_limit = .*/memory_limit = -1/' $PHP_INI_DIR/php.ini \
&& rm -rf /etc/php* /usr/lib/php*
&& /tmp/php-configuration.sh

# Configure php-fpm and nginx
RUN rm -rf /var/log/php* /etc/php*/php-fpm.conf /etc/php*/php-fpm.d \
Expand Down Expand Up @@ -88,10 +76,12 @@ ARG ZIP_SOURCE
ADD ${ZIP_SOURCE} /tmp/prestashop.zip

# Extract the souces
RUN mkdir -p $PS_FOLDER /tmp/unzip-ps \
RUN mkdir -p "$PS_FOLDER" /tmp/unzip-ps \
&& 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) \
&& chown -R www-data:www-data $PS_FOLDER \
&& ([ -f /tmp/unzip-ps/prestashop.zip ] \
&& unzip -n -q /tmp/unzip-ps/prestashop.zip -d "$PS_FOLDER" \
|| mv /tmp/unzip-ps/prestashop/* "$PS_FOLDER") \
&& chown -R www-data:www-data "$PS_FOLDER" \
&& rm -rf /tmp/prestashop.zip /tmp/unzip-ps

# Install and configure MariaDB
Expand Down
55 changes: 28 additions & 27 deletions docker/debian.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,41 @@ ARG NODE_VERSION
ENV PS_FOLDER=/var/www/html
ENV COMPOSER_HOME=/var/composer

# Update certificates
# Update certificates and install base deps
RUN export DEBIAN_FRONTEND=noninteractive \
&& curl -s -L -H "Content-Type: application/octet-stream" --data-binary "@/etc/apt/trusted.gpg.d/php.gpg" "https://packages.sury.org/php/apt.gpg" \
&& apt-get update \
&& apt-get install --no-install-recommends -qqy \
ca-certificates bash less vim git tzdata zip unzip curl wget make jq netcat-traditional \
lsb-release libgnutls30 gnupg libiconv-hook1 \
&& apt-get install --no-install-recommends -qqy ca-certificates \
&& apt-get install --no-install-recommends -qqy bash less vim git \
tzdata zip unzip curl wget make jq netcat-traditional \
lsb-release libgnutls30 gnupg libiconv-hook1 libonig-dev \
nginx libnginx-mod-http-headers-more-filter libnginx-mod-http-geoip \
libnginx-mod-http-geoip libnginx-mod-stream mariadb-client sudo
libnginx-mod-http-geoip libnginx-mod-stream mariadb-client sudo \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# PHP requirements and dev-tools
# see: https://olvlvl.com/2019-06-install-php-ext-source
# see: https://stackoverflow.com/a/73834081
# see: https://packages.sury.org/php/dists/
ENV PHP_ENV=development

COPY ./assets/php-configuration.sh /tmp/
RUN . /etc/os-release \
&& echo "deb [trusted=yes] https://packages.sury.org/php/ ${VERSION_CODENAME} main" > /etc/apt/sources.list.d/php.list \
&& rm /etc/apt/preferences.d/no-debian-php \
&& export DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get install --no-install-recommends -qqy \
php-gd libghc-zlib-dev libjpeg-dev libpng-dev libzip-dev libicu-dev libmcrypt-dev libxml2-dev \
php-gd \
libfreetype-dev \
libghc-zlib-dev \
libjpeg-dev \
libpng-dev \
libzip-dev \
libicu-dev \
libmcrypt-dev \
libxml2-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& export PS_PHP_EXT="gd pdo_mysql zip intl fileinfo simplexml" \
&& if [ "7.1" = "$PHP_VERSION" ]; \
then docker-php-ext-configure gd --with-gd --with-jpeg --with-jpeg-dir --with-zlib-dir \
&& docker-php-ext-install $PS_PHP_EXT mcrypt; \
elif [ "7.2" = "$PHP_VERSION" ] || [ "7.3" = "$PHP_VERSION" ]; \
then docker-php-ext-configure gd --with-jpeg-dir --with-zlib-dir \
&& docker-php-ext-install $PS_PHP_EXT; \
else \
docker-php-ext-configure gd --with-jpeg \
&& docker-php-ext-install $PS_PHP_EXT; \
fi \
&& mv $PHP_INI_DIR/php.ini-development $PHP_INI_DIR/php.ini \
&& sed -i 's/memory_limit = .*/memory_limit = -1/' $PHP_INI_DIR/php.ini \
&& rm -rf /etc/php* /usr/lib/php*
&& /tmp/php-configuration.sh

# Configure php-fpm and nginx
RUN rm -rf /var/log/php* /etc/php*/php-fpm.conf /etc/php*/php-fpm.d \
Expand Down Expand Up @@ -85,7 +84,7 @@ RUN PHP_CS_FIXER=$(jq -r '."'"${PHP_VERSION}"'".php_cs_fixer' < /tmp/php-flavour

# Install Node.js and pnpm (yarn and npm are included)
RUN if [ "0.0.0" = "$NODE_VERSION" ]; then exit 0; fi \
&& export DEBIAN_FRONTEND=noninteractive \
&& export DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get install --no-install-recommends -qqy nodejs python3 npm \
&& apt-get clean \
Expand All @@ -107,10 +106,12 @@ ARG ZIP_SOURCE
ADD ${ZIP_SOURCE} /tmp/prestashop.zip

# Extract the souces
RUN mkdir -p $PS_FOLDER /tmp/unzip-ps \
RUN mkdir -p "$PS_FOLDER" /tmp/unzip-ps \
&& 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) \
&& chown -R www-data:www-data $PS_FOLDER \
&& ([ -f /tmp/unzip-ps/prestashop.zip ] \
&& unzip -n -q /tmp/unzip-ps/prestashop.zip -d "$PS_FOLDER" \
|| mv /tmp/unzip-ps/prestashop/* "$PS_FOLDER") \
&& chown -R www-data:www-data "$PS_FOLDER" \
&& rm -rf /tmp/prestashop.zip /tmp/unzip-ps

# Install and configure MariaDB
Expand Down
2 changes: 1 addition & 1 deletion examples/basic-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This example runs the latest available image of PrestaShop Flashlight, which is
The expected output of this example is:

```sh
docker compose up prestashop
docker compose up prestashop --force-recreate
[+] Building 0.0s (0/0) docker-container:thirsty_khorana
[+] Running 3/3
✔ Network basic-example_default Created 0.0s
Expand Down
1 change: 1 addition & 0 deletions examples/basic-example/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ services:
condition: service_healthy
environment:
- PS_DOMAIN=localhost:8000
# - DEBUG_MODE=true
ports:
- 8000:80

Expand Down
37 changes: 16 additions & 21 deletions examples/develop-a-module/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,20 @@ This example demonstrates how a local module can be mounted in your PrestaShop F

## Bind a local module to your instance in your manifest

Let's consider we have a `testmodule` PrestaShop Module.

Create a `modules/` directory, and drop in your `testmodule` directory.

Create a bind mount in your docker-compose.yml:

```yaml
...
prestashop:
container_name: prestashop
...
volumes:
- type: bind
source: ./modules/testmodule # local path to the module
target: /var/www/html/modules/testmodule # path to be mounted in the container
...
Install the module's dependencies:

```
cd ./modules/testmodule
composer install
```

And that's it: your module is available on the `prestashop` Docker container, and changes made in the local directory of the module are automatically synchronized on the `prestashop` Docker container.
Run flashlight with a RW bind mount (see ./docker-compose.yml)

```
docker compose up prestashop --force-recreate
```

And that's it: your module is available on the `prestashop` Docker container, and changes made in the local directory of the module are automatically synchronized on the `prestashop` Docker container.

## Install / test the module

Expand All @@ -31,16 +26,16 @@ You can access to PrestaShop in your browser:
- http://localhost:8000
- http://localhost:8000/admin-dev/ (back office, login/password described [here](../../README.md))

You can go to modules > install and install your module, or install it with cli:
You can go to modules > install and install your module, or install it with cli:

1. obtain container name:
1. obtain container name:

```sh
docker ps
```

2. execute the install module command in the container:
2. execute the install module command in the container:

```sh
docker exec -ti container_name php /var/www/html/bin/console prestashop:module install testmodule
```
```
2 changes: 2 additions & 0 deletions examples/develop-a-module/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ services:
condition: service_healthy
environment:
- PS_DOMAIN=localhost:8000
- INIT_SCRIPTS_DIR=/tmp/init-scripts
ports:
- 8000:80
volumes:
- ./init-scripts:/tmp/init-scripts:ro
- type: bind
source: ./modules/testmodule # local path to the module
target: /var/www/html/modules/testmodule # path to be mounted in the container
Expand Down
12 changes: 12 additions & 0 deletions examples/develop-a-module/init-scripts/module-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh
#
# This is an init-script for prestashop-flashlight.
#
# Storing a folder in /var/www/html/modules is not enough to register the module
# into PrestaShop, hence why we have to call the console install CLI.
#
set -eu

cd "$PS_FOLDER"
echo "* [testmodule] installing the module..."
php -d memory_limit=-1 bin/console prestashop:module --no-interaction install "testmodule"
32 changes: 32 additions & 0 deletions examples/develop-a-module/modules/testmodule/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "prestashopcorp/testmodule",
"description": "a simple module example",
"type": "prestashop-module",
"authors": [
{
"name": "Clément Désiles",
"email": "[email protected]"
}
],
"license": "AFL-3.0",
"autoload": {
"classmap": [
"testmodule.php"
],
"psr-4": {
"PrestaShop\\Module\\TestModule\\": "src/"
}
},
"config": {
"preferred-install": "dist",
"platform": {
"php": "7.2.5"
},
"optimize-autoloader": true,
"prepend-autoloader": false,
"platform-check": false
},
"require": {
"php": ">=7.2.5"
}
}
23 changes: 23 additions & 0 deletions examples/develop-a-module/modules/testmodule/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions examples/develop-a-module/modules/testmodule/config.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>
<module>
<name>testmodule</name>
<displayName><![CDATA[TestModule]]></displayName>
<name>modulea</name>
<displayName><![CDATA[Testmodule]]></displayName>
<version><![CDATA[1.0.0]]></version>
<description><![CDATA[TestModule module description]]></description>
<description><![CDATA[Test module description]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[]]></tab>
<is_configurable>0</is_configurable>
Expand Down
8 changes: 0 additions & 8 deletions examples/develop-a-module/modules/testmodule/index.php

This file was deleted.

Loading

0 comments on commit 6792997

Please sign in to comment.