From 1346c2a8bf8cc8a250a3452a9f93c63220e814a1 Mon Sep 17 00:00:00 2001 From: Vincent Le Quec Date: Fri, 28 Jun 2024 16:26:17 +0200 Subject: [PATCH] wip --- README.md | 22 ++++++++++++---------- build.sh | 49 ++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 56 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 71903b0d..170d2e4e 100644 --- a/README.md +++ b/README.md @@ -30,16 +30,18 @@ prestashop/prestashop:8.0.1-8.1-apache Available env vars: -| Env var | Description | Default | -|-----------------------|-------------------------------------------------------------------------------------|------------------------------------| -| **PLATFORM** | [Docker multiplatform arch](https://docs.docker.com/build/building/multi-platform/) | `linux/amd64` | -| **OS_FLAVOUR** | `debian` or `alpine` | `debian` | -| **PHP_VERSION** | [The PHP version](https://hub.docker.com/_/php) | recommended version for PrestaShop | -| **PHP_FLAVOUR** | `fpm`, `apache` or `nginx` | `apache` | -| **PS_VERSION** | PrestaShop version | `latest` | -| **DOCKER_REPOSITORY** | the Docker image repository | `prestashop/prestashop` | - -> Note: default debian distribution is set to Debian 11 Bullseye. +| Env var | Description | Default | +|---------------------|------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------| +| **PS_VERSION** | PrestaShop version | `latest` | +| **PHP_VERSION** | [The PHP version](https://hub.docker.com/_/php) | recommended version for PrestaShop | +| **OS_FLAVOUR** | `debian` or `alpine` | `debian` | +| **SERVER_FLAVOUR** | `apache`, `fpm` or `nginx` | `apache` | +| **TARGET_PLATFORM** | a comma separated list of [target platforms](https://docs.docker.com/build/building/multi-platform/) | `docker system info --format '{{.OSType}}/{{.Architecture}}'` | +| **PLATFORM** | alias for `$TARGET_PLATFORM` | | +| **TARGET_IMAGE** | docker image name | `prestashop/prestashop` | +| **PUSH** | set it to `true` if you want to push the resulting image | | +| **ZIP_SOURCE** | the zip to unpack in flashlight | Releases from [PrestaShop/PrestaShop](https://github.com/PrestaShop/PrestaShop) | +| **DRY_RUN** | if used, won't really build the image. Useful to check tags compliance | | ## Update diff --git a/build.sh b/build.sh index 91b8434c..73520690 100755 --- a/build.sh +++ b/build.sh @@ -6,13 +6,13 @@ cd "$(dirname "$0")" # ------------------- 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 OS_FLAVOUR; # -- either "alpine" or "debian" (default) declare SERVER_FLAVOUR; # -- either "apache" (default), "fpm" (no web server) or "nginx" -declare TARGET_PLATFORM; # -- a comma separated list of target platforms (defaults to "linux/amd64") +declare TARGET_PLATFORM; # -- a comma separated list of target platforms (defaults to your operating system) declare PLATFORM; # -- alias for $TARGET_PLATFORM -declare TARGET_IMAGE; # -- docker image name, defaults to "prestashop/prestashop-flashlight" +declare TARGET_IMAGE; # -- docker image name, defaults to "prestashop/prestashop" declare PUSH; # -- set it to "true" if you want to push the resulting image -declare ZIP_SOURCE; # -- the zip to unpack in flashlight +declare ZIP_SOURCE; # -- the zip to unpack in PrestaShop declare DRY_RUN; # -- if used, won't really build the image. Useful to check tags compliance # Static configuration @@ -23,7 +23,9 @@ DEFAULT_DOCKER_IMAGE=prestashop/prestashop DEFAULT_PLATFORM=$(docker system info --format '{{.OSType}}/{{.Architecture}}') GIT_SHA=$(git rev-parse HEAD) TARGET_PLATFORM="${TARGET_PLATFORM:-${PLATFORM:-$DEFAULT_PLATFORM}}" - +PRESTASHOP_TAGS=$(git ls-remote --tags git@github.com:PrestaShop/PrestaShop.git | cut -f2 | grep -Ev '\/1.5|\/1.6.0|alpha|beta|rc|RC|\^' | cut -d '/' -f3 | sort -r -V) +#PRESTASHOP_MAJOR_TAGS=$(get_prestashop_major_tags) +PRESTASHOP_MINOR_TAGS=$(get_prestashop_minor_tags) error() { echo -e "\e[1;31m${1:-Unknown error}\e[0m" exit "${2:-1}" @@ -34,6 +36,39 @@ get_latest_prestashop_version() { 'https://api.github.com/repos/prestashop/prestashop/releases/latest' | jq -r '.tag_name' } +get_prestashop_minor_tags() { + while IFS= read -r version; do + major_minor=$(echo "$version" | cut -d. -f1-2) + major_minor_patch=$(echo "$version" | cut -d. -f1-3) + criteria=$major_minor + # shellcheck disable=SC3010 + [[ "$major_minor" == 1* ]] && criteria=$major_minor_patch + if ! grep -q "^$criteria" "$PRESTASHOP_MINOR_TAGS"; then + echo "$version" >> "$PRESTASHOP_MINOR_TAGS" + fi + done < "$PRESTASHOP_TAGS" +} + + +is_version_latest_major_version() { + X_VERSION=$(echo "$1" | cut -d. -f1) + echo $X_VERSION +} + +is_version_latest_minor_version() { + XY_VERSION=$(echo "$1" | cut -d. -f1-2) +# RES=$(echo $PRESTASHOP_TAGS | awk -F. '!seen[$1"."$2]++' | grep -x "$XY_VERSION") + echo $XY_VERSION +} + +get_prestashop_tags() { + git ls-remote --tags git@github.com:PrestaShop/PrestaShop.git \ + | cut -f2 \ + | grep -Ev '\/1.5|\/1.6.0|alpha|beta|rc|RC|\^' \ + | cut -d '/' -f3 \ + | sort -r -V > "$PRESTASHOP_TAGS" +} + get_recommended_php_version() { local PS_VERSION=$1; local RECOMMENDED_VERSION=; @@ -119,11 +154,15 @@ get_target_images() { if [ "$PHP_VERSION" = "$(get_recommended_php_version "$PS_VERSION")" ]; then RES="${RES} -t ${DEFAULT_DOCKER_IMAGE}:${PS_VERSION}"; RES="${RES} -t ${DEFAULT_DOCKER_IMAGE}:php-${PHP_VERSION}"; + # If the x.y.z version of PrestaShop is the latest version of the major + fi fi RES="${RES} -t ${DEFAULT_DOCKER_IMAGE}:${PS_VERSION}-${PHP_FLAVOUR}"; RES="${RES} -t ${DEFAULT_DOCKER_IMAGE}:${PS_VERSION}-${OS_FLAVOUR}"; fi + echo "--------------> $(is_version_latest_minor_version "8.1.7")"; + echo "--------------> $(is_version_latest_minor_version "8.1.6")"; echo "$RES"; }