Skip to content

Commit

Permalink
Merge pull request #403 from PrestaShop/fix-90x-docker
Browse files Browse the repository at this point in the history
Fix 9.0.x docker
  • Loading branch information
jolelievre authored Nov 7, 2024
2 parents 602f83d + 76dcad3 commit 46abef4
Show file tree
Hide file tree
Showing 65 changed files with 1,236 additions and 59 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,7 @@ jobs:
if: ${{ github.event_name == 'pull_request' }}
working-directory: base

- name: Base Images > Docker Build & Push
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' && steps.changes.outputs.base != 'true' }}
run: ./docker_tags.sh -p
working-directory: base

- name: Base Images > Docker Build & Push
- name: Base Images > Docker Build & Force Push
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' && steps.changes.outputs.base == 'true' }}
run: ./docker_tags.sh -p -f
working-directory: base
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile-branch.model
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ LABEL maintainer="PrestaShop Core Team <[email protected]>"
RUN apt update
RUN apt -y install git

RUN git clone -b $branch_version https://github.com/PrestaShop/PrestaShop.git /tmp/data-ps
ENV PS_BRANCH=$branch_version

CMD ["/tmp/docker_run.sh"]
CMD ["/tmp/docker_branch_run.sh"]
43 changes: 43 additions & 0 deletions HOW-TO-USE.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,46 @@ $ nosetests --with-id 7
```
This will also generate a `.nodeids` binary file, when you add new test methods you need to remove this file to re-generate the list of IDs.
## Building and running PrestaShop docker locally
First to make sure you will use the local docker containers and not the ones from Docker hub make sure you remove all existing PrestaShop images (including the base images)
```
# This should be empty to be extra sure
$ docker images
```
Then you'll have to build the base image for the PHP version and server you are willing to use. If you are on MacOS this is crucial that you clean any image from cache and tun this locally,
especially if your architecture is based on linux/arm64 (processor M1, M2, ...).
```shell
docker build base/images/8.3-apache -t prestashop/base:8.3-apache
# You should see an image with Repository: prestashop Tag: 8.3-apache
docker images
```
Then you can build the image of the PrestaShop version you want to use:
```
# Now build the PrestaShop version you want based on this local base image
$ docker build images/9.0.x/8.3-apache -t prestashop/prestashop:9.0.x-8.3-apache
```
Finally, you can launch your PrestaShop container using docker compose
```
$ PS_VERSION=9.0.x PHP_VERSION=8.3 docker compose -f images/docker-compose.yml up
```
Or you can use this script that performs these actions based on the arguments
```
# Default values are nightly 8.3 apache
./build-local-docker.sh 9.0.x 8.1 fpm
```
Now you should be able to access a shop at this address: `http://localhost:8001/`
The BO is accessible at `http://localhost:8001/admin-dev` with the following login:
Email: `[email protected]`
Password: `Correct Horse Battery Staple`
2 changes: 1 addition & 1 deletion base/Dockerfile.model
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ RUN docker-php-source extract \
&& 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/
COPY config_files/ps-extractor.sh config_files/docker_run.sh config_files/docker_nightly_run.sh config_files/docker_branch_run.sh /tmp/

# If handle dynamic domain
COPY config_files/docker_updt_ps_domains.php /tmp/
Expand Down
27 changes: 27 additions & 0 deletions base/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
### Creating new base images

To add new base versions update the `tags.txt` file to add a new version of PHP (usually one for apache and one for fpm)

Then run the generation script:

```
$ ./generate_tags.sh
```

If you wan to force the regeneration of existing base images force it:

```shell
$ ./generate_tags.sh -f
```

But be careful, for image with PHP <7.4 the installation of GD is different be careful not to remove this special line:

```
# Not this line:
RUN docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ --with-webp=/usr/include
But those lines instead:
# PHP < 7.4 have an old syntax to install GD. See https://github.com/docker-library/php/issues/912
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-webp-dir=/usr/include
```
61 changes: 61 additions & 0 deletions base/config_files/docker_branch_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash

# Clone repository
if [ ! -f /var/www/html/composer.json ]; then
echo Clone PrestaShop $PS_BRANCH
git clone -b $PS_BRANCH https://github.com/PrestaShop/PrestaShop.git /var/www/html
chown -R www-data:www-data /var/www/html
fi

# Install composer
if [ ! -f /usr/local/bin/composer ]; then
echo "\n* Install composer ...";
mkdir -p /var/www/.composer
chown -R www-data:www-data /var/www/.composer
runuser -g www-data -u www-data -- php -r "copy('https://getcomposer.org/installer', '/tmp/composer-setup.php');" && php /tmp/composer-setup.php --no-ansi --install-dir=/usr/local/bin --filename=composer && rm -rf /tmp/composer-setup.php
if [ ! -f /usr/local/bin/composer ]; then
echo Composer installation failed
exit 1
fi
fi

# Install vendor dependencies
if [ ! -f /var/www/html/vendor/autoload.php ]; then
echo "\n* Running composer ...";
pushd /var/www/html
# Execute composer as default user so that we can set the env variables to increase timeout, also disable default_socket_timeout for php
COMPOSER_PROCESS_TIMEOUT=600 COMPOSER_IPRESOLVE=4 php -ddefault_socket_timeout=-1 /usr/local/bin/composer install --ansi --prefer-dist --no-interaction --no-progress
# Update the owner of composer installed folders to be www-data
chown -R www-data:www-data vendor modules themes
popd
fi

# Build assets
if [ "${DISABLE_MAKE}" != "1" ]; then
mkdir -p /var/www/.npm
chown -R www-data:www-data /var/www/.npm

echo "\n* Install node $NODE_VERSION...";
export NVM_DIR=/usr/local/nvm
mkdir -p $NVM_DIR \
&& curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash \
&& . $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default

export NODE_PATH=$NVM_DIR/versions/node/v$NODE_VERSION/bin
export PATH=$PATH:$NODE_PATH

pushd /var/www/html
echo "\n* Build assets ...";
runuser -g www-data -u www-data -- /usr/bin/make assets

echo "\n* Wait for assets built...";
runuser -g www-data -u www-data -- /usr/bin/make wait-assets
popd
else
echo "\n* Build of assets was disabled...";
fi

/tmp/docker_run.sh
2 changes: 1 addition & 1 deletion base/config_files/docker_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ if [ ! -f ./config/settings.inc.php ] && [ ! -f ./install.lock ]; then
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 \
--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
Expand Down
1 change: 1 addition & 0 deletions base/generate_tags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ generate_image()

if [ -d images/$folder ] && [ -z "$FORCE" ]; then
# Do not erase what we already defined in the directory
echo Already defined, skipping Use -f to forcre update
return
fi

Expand Down
2 changes: 1 addition & 1 deletion base/images/7.1-apache/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ RUN docker-php-source extract \
&& 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/
COPY config_files/ps-extractor.sh config_files/docker_run.sh config_files/docker_nightly_run.sh config_files/docker_branch_run.sh /tmp/

# If handle dynamic domain
COPY config_files/docker_updt_ps_domains.php /tmp/
Expand Down
61 changes: 61 additions & 0 deletions base/images/7.1-apache/config_files/docker_branch_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash

# Clone repository
if [ ! -f /var/www/html/composer.json ]; then
echo Clone PrestaShop $PS_BRANCH
git clone -b $PS_BRANCH https://github.com/PrestaShop/PrestaShop.git /var/www/html
chown -R www-data:www-data /var/www/html
fi

# Install composer
if [ ! -f /usr/local/bin/composer ]; then
echo "\n* Install composer ...";
mkdir -p /var/www/.composer
chown -R www-data:www-data /var/www/.composer
runuser -g www-data -u www-data -- php -r "copy('https://getcomposer.org/installer', '/tmp/composer-setup.php');" && php /tmp/composer-setup.php --no-ansi --install-dir=/usr/local/bin --filename=composer && rm -rf /tmp/composer-setup.php
if [ ! -f /usr/local/bin/composer ]; then
echo Composer installation failed
exit 1
fi
fi

# Install vendor dependencies
if [ ! -f /var/www/html/vendor/autoload.php ]; then
echo "\n* Running composer ...";
pushd /var/www/html
# Execute composer as default user so that we can set the env variables to increase timeout, also disable default_socket_timeout for php
COMPOSER_PROCESS_TIMEOUT=600 COMPOSER_IPRESOLVE=4 php -ddefault_socket_timeout=-1 /usr/local/bin/composer install --ansi --prefer-dist --no-interaction --no-progress
# Update the owner of composer installed folders to be www-data
chown -R www-data:www-data vendor modules themes
popd
fi

# Build assets
if [ "${DISABLE_MAKE}" != "1" ]; then
mkdir -p /var/www/.npm
chown -R www-data:www-data /var/www/.npm

echo "\n* Install node $NODE_VERSION...";
export NVM_DIR=/usr/local/nvm
mkdir -p $NVM_DIR \
&& curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash \
&& . $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default

export NODE_PATH=$NVM_DIR/versions/node/v$NODE_VERSION/bin
export PATH=$PATH:$NODE_PATH

pushd /var/www/html
echo "\n* Build assets ...";
runuser -g www-data -u www-data -- /usr/bin/make assets

echo "\n* Wait for assets built...";
runuser -g www-data -u www-data -- /usr/bin/make wait-assets
popd
else
echo "\n* Build of assets was disabled...";
fi

/tmp/docker_run.sh
2 changes: 1 addition & 1 deletion base/images/7.1-apache/config_files/docker_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ if [ ! -f ./config/settings.inc.php ] && [ ! -f ./install.lock ]; then
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 \
--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
Expand Down
2 changes: 1 addition & 1 deletion base/images/7.1-fpm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ RUN docker-php-source extract \
&& 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/
COPY config_files/ps-extractor.sh config_files/docker_run.sh config_files/docker_nightly_run.sh config_files/docker_branch_run.sh /tmp/

# If handle dynamic domain
COPY config_files/docker_updt_ps_domains.php /tmp/
Expand Down
61 changes: 61 additions & 0 deletions base/images/7.1-fpm/config_files/docker_branch_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash

# Clone repository
if [ ! -f /var/www/html/composer.json ]; then
echo Clone PrestaShop $PS_BRANCH
git clone -b $PS_BRANCH https://github.com/PrestaShop/PrestaShop.git /var/www/html
chown -R www-data:www-data /var/www/html
fi

# Install composer
if [ ! -f /usr/local/bin/composer ]; then
echo "\n* Install composer ...";
mkdir -p /var/www/.composer
chown -R www-data:www-data /var/www/.composer
runuser -g www-data -u www-data -- php -r "copy('https://getcomposer.org/installer', '/tmp/composer-setup.php');" && php /tmp/composer-setup.php --no-ansi --install-dir=/usr/local/bin --filename=composer && rm -rf /tmp/composer-setup.php
if [ ! -f /usr/local/bin/composer ]; then
echo Composer installation failed
exit 1
fi
fi

# Install vendor dependencies
if [ ! -f /var/www/html/vendor/autoload.php ]; then
echo "\n* Running composer ...";
pushd /var/www/html
# Execute composer as default user so that we can set the env variables to increase timeout, also disable default_socket_timeout for php
COMPOSER_PROCESS_TIMEOUT=600 COMPOSER_IPRESOLVE=4 php -ddefault_socket_timeout=-1 /usr/local/bin/composer install --ansi --prefer-dist --no-interaction --no-progress
# Update the owner of composer installed folders to be www-data
chown -R www-data:www-data vendor modules themes
popd
fi

# Build assets
if [ "${DISABLE_MAKE}" != "1" ]; then
mkdir -p /var/www/.npm
chown -R www-data:www-data /var/www/.npm

echo "\n* Install node $NODE_VERSION...";
export NVM_DIR=/usr/local/nvm
mkdir -p $NVM_DIR \
&& curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash \
&& . $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default

export NODE_PATH=$NVM_DIR/versions/node/v$NODE_VERSION/bin
export PATH=$PATH:$NODE_PATH

pushd /var/www/html
echo "\n* Build assets ...";
runuser -g www-data -u www-data -- /usr/bin/make assets

echo "\n* Wait for assets built...";
runuser -g www-data -u www-data -- /usr/bin/make wait-assets
popd
else
echo "\n* Build of assets was disabled...";
fi

/tmp/docker_run.sh
2 changes: 1 addition & 1 deletion base/images/7.1-fpm/config_files/docker_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ if [ ! -f ./config/settings.inc.php ] && [ ! -f ./install.lock ]; then
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 \
--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
Expand Down
2 changes: 1 addition & 1 deletion base/images/7.2-apache/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ RUN docker-php-source extract \
&& 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/
COPY config_files/ps-extractor.sh config_files/docker_run.sh config_files/docker_nightly_run.sh config_files/docker_branch_run.sh /tmp/

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

0 comments on commit 46abef4

Please sign in to comment.