Skip to content

Commit

Permalink
Add Node.js support
Browse files Browse the repository at this point in the history
  • Loading branch information
jokesterfr committed Dec 4, 2023
1 parent c3cb3ec commit 39da558
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 27 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
platforms: ${{ env.TARGET_PLATFORMS }}
platforms: ${{ env.TARGET_PLATFORM }}
use: true

- name: Login to Docker Hub
Expand All @@ -73,7 +73,7 @@ jobs:
- name: Build and push
run: ./build.sh
env:
PLATFORM: ${{ inputs.target_platforms }}
TARGET_PLATFORM: ${{ inputs.target_platforms }}
PS_VERSION: ${{ inputs.ps_version }}
PHP_VERSION: ${{ inputs.php_version }}
OS_FLAVOUR: ${{ inputs.os_flavour }}
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ on:
pull_request:
types: [opened, reopened, synchronize]

env:
TARGET_PLATFORM: "linux/amd64"

jobs:
lint_shell:
name: "Lint: shell"
Expand Down Expand Up @@ -38,6 +41,7 @@ jobs:
env:
OS_FLAVOUR: ${{ matrix.os_flavour }}
PS_VERSION: ${{ matrix.ps_version }}
TARGET_PLATFORM: ${{ env.TARGET_PLATFORM }}

- name: Test the image with a dry run
run: docker run --env PS_DOMAIN='localhost:80' --env DRY_RUN='true' $DOCKER_IMAGE
Expand Down
1 change: 1 addition & 0 deletions .hadolint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ ignored:
- DL4006
- DL4001
- SC1091
- SC2086
6 changes: 3 additions & 3 deletions assets/patch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
set -eu

PS_FOLDER=${PS_FOLDER:?missing PS_FOLDER}
PS_VERSION=$(awk 'NR==1{print $2}' "${PS_FOLDER}/VERSION")
PS_VERSION=$(awk 'NR==1{print $2}' "$PS_FOLDER/VERSION")

patch_1_6 () {
# Add robots file
echo "User-agent: *" > "${PS_FOLDER}/robots.txt"
echo "Disallow: /" >> "${PS_FOLDER}/robots.txt"
echo "User-agent: *" > "$PS_FOLDER/robots.txt"
echo "Disallow: /" >> "$PS_FOLDER/robots.txt"
}

if echo "$PS_VERSION" | grep "^1.6" > /dev/null; then
Expand Down
25 changes: 22 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ declare PS_VERSION; # -- PrestaShop version, defaults to latest
declare PHP_VERSION; # -- PHP version, defaults to recommended version for PrestaShop
declare OS_FLAVOUR; # -- either "alpine" (default) or "debian"
declare SERVER_FLAVOUR; # -- not implemented, either "nginx" (default) or "apache"
declare PLATFORM; # -- a comma separated list of target platforms (defaults to "linux/amd64")
declare TARGET_PLATFORM; # -- a comma separated list of target platforms (defaults to "linux/amd64")
declare PLATFORM; # -- alias for $TARGET_PLATFORM
declare TARGET_IMAGE; # -- docker image name, defaults to "prestashop/prestashop-flashlight"
declare PUSH; # -- set it to "true" if you want to push the resulting image

Expand All @@ -19,14 +20,16 @@ DEFAULT_SERVER="nginx";
DEFAULT_DOCKER_IMAGE=prestashop/prestashop-flashlight
DEFAULT_PLATFORM=linux/amd64
GIT_SHA=$(git rev-parse HEAD)
TARGET_PLATFORM="${TARGET_PLATFORM:-$DEFAULT_PLATFORM}"
[ -n "$PLATFORM" ] && TARGET_PLATFORM=$PLATFORM;

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

get_latest_prestashop_version() {
curl --silent --location --request GET \
curl --silent --show-error --fail --location --request GET \
'https://api.github.com/repos/prestashop/prestashop/releases/latest' | jq -r '.tag_name'
}

Expand All @@ -43,6 +46,19 @@ get_recommended_php_version() {
echo "$RECOMMENDED_VERSION";
}

get_recommended_nodejs_version() {
local PS_VERSION=$1;
local RECOMMENDED_VERSION=;
REGEXP_LIST=$(jq -r 'keys_unsorted | .[]' <prestashop-versions.json)
while IFS= read -r regExp; do
if [[ $PS_VERSION =~ $regExp ]]; then
RECOMMENDED_VERSION=$(jq -r '."'"${regExp}"'".nodejs.recommended' <prestashop-versions.json)
break;
fi
done <<<"$REGEXP_LIST"
echo "$RECOMMENDED_VERSION";
}

get_php_flavour() {
local OS_FLAVOUR=${1:-};
local SERVER_FLAVOUR=${2:-};
Expand Down Expand Up @@ -108,6 +124,7 @@ fi
OS_FLAVOUR=${OS_FLAVOUR:-$DEFAULT_OS};
SERVER_FLAVOUR=${SERVER_FLAVOUR:-$DEFAULT_SERVER};
PHP_FLAVOUR=$(get_php_flavour "$OS_FLAVOUR" "$SERVER_FLAVOUR" "$PHP_VERSION");
NODE_VERSION=$(get_recommended_nodejs_version "$PS_VERSION");
if [ "$PHP_FLAVOUR" == "null" ]; then
error "Could not find a PHP flavour for $OS_FLAVOUR + $SERVER_FLAVOUR + $PHP_VERSION" 2;
fi
Expand All @@ -123,13 +140,15 @@ CACHE_IMAGE=${TARGET_IMAGES[1]}
docker pull "$CACHE_IMAGE" 2> /dev/null || true
docker buildx build \
--file "./docker/${OS_FLAVOUR}.Dockerfile" \
--platform "${PLATFORM:-$DEFAULT_PLATFORM}" \
--platform "$TARGET_PLATFORM" \
--cache-from type=registry,ref="$CACHE_IMAGE" \
--cache-to type=inline \
--build-arg PHP_FLAVOUR="$PHP_FLAVOUR" \
--build-arg PS_VERSION="$PS_VERSION" \
--build-arg PHP_VERSION="$PHP_VERSION" \
--build-arg GIT_SHA="$GIT_SHA" \
--build-arg NODE_VERSION="$NODE_VERSION" \
--build-arg TARGET_PLATFORM="$TARGET_PLATFORM" \
--label org.opencontainers.image.title="PrestaShop Flashlight" \
--label org.opencontainers.image.description="PrestaShop Flashlight testing utility" \
--label org.opencontainers.image.source=https://github.com/PrestaShop/prestashop-flashlight \
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ services:
env_file:
- .env
healthcheck:
test: ["CMD", "curl", "-Ss", "http://localhost/robots.txt"]
test: ["CMD", "curl", "-Isf", "http://localhost/robots.txt"]
interval: 30s
timeout: 10s
retries: 5
Expand Down
33 changes: 21 additions & 12 deletions docker/alpine.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
# -------------------------------------
# PrestaShop Flashlight: Alpine image
# -------------------------------------
ARG PS_VERSION
ARG PHP_VERSION
ARG PHP_FLAVOUR
ARG GIT_SHA
ARG NODE_VERSION
ARG TARGET_PLATFORM

# -------------------------------------
# PrestaShop Flashlight: Alpine image
# -------------------------------------
FROM php:${PHP_FLAVOUR} AS base-prestashop
ARG PS_VERSION
ARG PHP_VERSION
ARG NODE_VERSION
ARG TARGET_PLATFORM
ENV PS_FOLDER=/var/www/html

# Install base tools
Expand All @@ -25,15 +30,6 @@ RUN apk --no-cache add -U composer zlib-dev libjpeg-turbo-dev libpng-dev libzip-
docker-php-ext-configure gd --with-jpeg && docker-php-ext-install gd pdo_mysql zip intl; \
fi;

# TODO check opcache configuration
# RUN docker-php-ext-enable 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

# Configure php-fpm and nginx
RUN rm -rf /var/log/php* /etc/php*/php-fpm.conf /etc/php*/php-fpm.d \
&& mkdir -p /var/log/php /var/run/php /var/run/nginx \
Expand All @@ -58,6 +54,19 @@ RUN PHP_CS_FIXER=$(jq -r '."'"${PHP_VERSION}"'".php_cs_fixer' < /tmp/php-flavour
&& wget -q -O /usr/bin/php-cs-fixer "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/releases/download/${PHP_CS_FIXER}/php-cs-fixer.phar" \
&& chmod a+x /usr/bin/php-cs-fixer

# Install Node.js and pnpm (yarn and npm are included)
RUN apk --no-cache add -U gcompat && \
if [ "linux/arm64" = "$TARGET_PLATFORM" ]; \
then export DISTRO="linux-arm64"; \
else export DISTRO="linux-x64"; \
fi \
&& curl --silent --show-error --fail --location --output /tmp/node.tar.xz "https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-${DISTRO}.tar.xz" \
&& mkdir /tmp/nodejs && tar -xJf /tmp/node.tar.xz -C /tmp/nodejs \
&& mv "/tmp/nodejs/node-v${NODE_VERSION}-${DISTRO}" /usr/local/lib/nodejs && rmdir /tmp/nodejs \
&& rm -f /tmp/node.tar.xz \
&& PATH="$PATH:/usr/local/lib/nodejs/bin" npm install -g pnpm@latest --force
ENV PATH "$PATH:/usr/local/lib/nodejs/bin"

# --------------------------------
# Flashlight install and dump SQL
# --------------------------------
Expand Down
28 changes: 23 additions & 5 deletions docker/debian.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
# -------------------------------------
# PrestaShop Flashlight: Debian image
# -------------------------------------
ARG PS_VERSION
ARG PHP_VERSION
ARG PHP_FLAVOUR
ARG GIT_SHA
ARG NODE_VERSION
ARG TARGET_PLATFORM

# -------------------------------------
# PrestaShop Flashlight: Debian image
# -------------------------------------
FROM php:${PHP_FLAVOUR} AS base-prestashop
ARG PS_VERSION
ARG PHP_VERSION
ARG GIT_SHA
ARG NODE_VERSION
ARG TARGET_PLATFORM
ENV PS_FOLDER=/var/www/html

# Install base tools
Expand All @@ -21,8 +28,7 @@ RUN apt-get update \
# see: https://olvlvl.com/2019-06-install-php-ext-source
# see: https://stackoverflow.com/a/73834081
# see: https://packages.sury.org/php/dists/
RUN curl -sSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg \
&& . /etc/os-release \
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;
RUN apt-get update \
Expand Down Expand Up @@ -64,6 +70,18 @@ RUN PHP_CS_FIXER=$(jq -r '."'"${PHP_VERSION}"'".php_cs_fixer' < /tmp/php-flavour
&& wget -q -O /usr/bin/php-cs-fixer "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/releases/download/${PHP_CS_FIXER}/php-cs-fixer.phar" \
&& chmod a+x /usr/bin/php-cs-fixer

# Install Node.js and pnpm (yarn and npm are included)
RUN if [ "linux/arm64" = "$TARGET_PLATFORM" ]; \
then export DISTRO="linux-arm64"; \
else export DISTRO="linux-x64"; \
fi \
&& curl --silent --show-error --fail --location --output /tmp/node.tar.xz "https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-${DISTRO}.tar.xz" \
&& mkdir /tmp/nodejs && tar -xJf /tmp/node.tar.xz -C /tmp/nodejs \
&& mv "/tmp/nodejs/node-v${NODE_VERSION}-${DISTRO}" /usr/local/lib/nodejs && rmdir /tmp/nodejs \
&& rm -f /tmp/node.tar.xz \
&& PATH="$PATH:/usr/local/lib/nodejs/bin" npm install -g pnpm@latest --force
ENV PATH "$PATH:/usr/local/lib/nodejs/bin"

# --------------------------------
# Flashlight install and dump SQL
# --------------------------------
Expand Down
2 changes: 1 addition & 1 deletion examples/auto-install-modules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Add a module like this:

```sh
mkdir -p ./modules
curl -s -L -o modules/psxmarketingwithgoogle-v1.61.1.zip "https://github.com/PrestaShopCorp/psxmarketingwithgoogle/releases/download/v1.61.1/psxmarketingwithgoogle-v1.61.1.zip"
curl --silent --show-error --fail --location --output modules/psxmarketingwithgoogle-v1.61.1.zip "https://github.com/PrestaShopCorp/psxmarketingwithgoogle/releases/download/v1.61.1/psxmarketingwithgoogle-v1.61.1.zip"
```

The expected output of this example is:
Expand Down
27 changes: 27 additions & 0 deletions prestashop-versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,80 @@
"php": {
"recommended": "7.1",
"compatible": ["5.2", "5.3", "5.4", "5.5", "5.6", "7.0", "7.1"]
},
"nodejs": {
"recommended": "10.24.1"
}
},
"^1.7.[0-3]": {
"php": {
"recommended": "7.1",
"compatible": ["5.4", "5.5", "5.6", "7.0", "7.1"]
},
"nodejs": {
"recommended": "10.24.1"
}
},
"^1.7.7.4": {
"php": {
"recommended": "7.1",
"compatible": ["5.6", "7.0", "7.1"]
},
"nodejs": {
"recommended": "10.24.1"
}
},
"^1.7.[5-6]": {
"php": {
"recommended": "7.2",
"compatible": ["5.6", "7.0", "7.1", "7.2"]
},
"nodejs": {
"recommended": "10.24.1"
}
},
"^1.7.7": {
"php": {
"recommended": "7.3",
"compatible": ["7.1", "7.2", "7.3"]
},
"nodejs": {
"recommended": "10.24.1"
}
},
"^1.7.8": {
"php": {
"recommended": "7.4",
"compatible": ["7.1", "7.2", "7.3", "7.4"]
},
"nodejs": {
"recommended": "14.19.0"
}
},
"^8.0": {
"php": {
"recommended": "8.1",
"compatible": ["7.2", "7.3", "7.4", "8.0", "8.1"]
},
"nodejs": {
"recommended": "16.16.0"
}
},
"^8.1": {
"php": {
"recommended": "8.1",
"compatible": ["7.2", "7.3", "7.4", "8.0", "8.1"]
},
"nodejs": {
"recommended": "16.16.0"
}
},
"nightly": {
"php": {
"recommended": "8.1"
},
"nodejs": {
"recommended": "16.16.0"
}
}
}

0 comments on commit 39da558

Please sign in to comment.