From c171ce48dc9fda717ce9926ce6f8c9ff49deb6ff Mon Sep 17 00:00:00 2001 From: Alexandre Lematre <107846409+Alexandre-Lematre@users.noreply.github.com> Date: Tue, 19 Nov 2024 09:58:07 +0100 Subject: [PATCH] Custom prestashop release (#96) --- assets/hydrate.sh | 3 +- build.sh | 96 ++++++++++++++++++++++++++++++++--------------- 2 files changed, 68 insertions(+), 31 deletions(-) diff --git a/assets/hydrate.sh b/assets/hydrate.sh index 43f2268..2ee8cbd 100755 --- a/assets/hydrate.sh +++ b/assets/hydrate.sh @@ -67,7 +67,8 @@ sudo php -f "${PS_FOLDER}/install/index_cli.php" -- \ --all_languages=0 \ --newsletter=0 \ --send_email=0 \ - --ssl=0 + --ssl=0 \ + --modules="$(find "$PS_FOLDER"/modules/* -maxdepth 0 -type d -exec basename {} \; | paste -s -d ',')" echo "✅ PrestaShop installed" # 7. Swap off dev mode diff --git a/build.sh b/build.sh index 9f123fb..21bc339 100755 --- a/build.sh +++ b/build.sh @@ -4,18 +4,20 @@ cd "$(dirname "$0")" # Available variables # ------------------- -declare BASE_ONLY; # -- only build the base image (OS_FLAVOUR) without shipping PrestaShop -declare REBUILD_BASE; # -- force the rebuild of the base image -declare DRY_RUN; # -- if used, won't really build the image. Useful to check tags compliance -declare OS_FLAVOUR; # -- either "alpine" (default) or "debian" -declare PHP_VERSION; # -- PHP version, defaults to recommended version for PrestaShop -declare PS_VERSION; # -- PrestaShop version, defaults to latest -declare PUSH; # -- set it to "true" if you want to push the resulting image -declare SERVER_FLAVOUR; # -- not implemented, either "nginx" (default) or "apache" -declare TARGET_IMAGE; # -- docker image name, defaults to "prestashop/prestashop-flashlight" -declare TARGET_PLATFORM; # -- a comma separated list of target platforms (defaults to "linux/amd64") -declare PLATFORM; # -- alias for $TARGET_PLATFORM -declare ZIP_SOURCE; # -- the zip to unpack in flashlight +declare BASE_ONLY; # -- only build the base image (OS_FLAVOUR) without shipping PrestaShop +declare REBUILD_BASE; # -- force the rebuild of the base image +declare DRY_RUN; # -- if used, won't really build the image. Useful to check tags compliance +declare OS_FLAVOUR; # -- either "alpine" (default) or "debian" +declare PHP_VERSION; # -- PHP version, defaults to recommended version for PrestaShop +declare PS_VERSION; # -- PrestaShop version, defaults to latest +declare PUSH; # -- set it to "true" if you want to push the resulting image +declare SERVER_FLAVOUR; # -- not implemented, either "nginx" (default) or "apache" +declare TARGET_IMAGE; # -- docker image name, defaults to "prestashop/prestashop-flashlight" +declare TARGET_PLATFORM; # -- a comma separated list of target platforms (defaults to "linux/amd64") +declare PLATFORM; # -- alias for $TARGET_PLATFORM +declare ZIP_SOURCE; # -- the zip to unpack in flashlight +declare CUSTOM_LABELS; # -- only when PRIVATE : list of key=value pairs separated by a comma, for overriding official flashlight labels + # Static configuration # -------------------- @@ -45,8 +47,9 @@ help() { echo " --rebuild-base Force the rebuild of the base image" echo " --server-flavour Not implemented, either 'nginx' (default) or 'apache'" echo " --target-image Docker image name, defaults to 'prestashop/prestashop-flashlight'" + echo " --custom-labels A comma separated list of key=value pairs, for overriding official flashlight labels" echo " --target-platform A comma separated list of target platforms (defaults to 'linux/amd64')" - echo " --zip-source The zip to unpack in flashlight" + echo " --zip-source The zip containing the PrestaShop release to build a docker image upon (defaults to PrestaShop source code)" echo "" echo "$(tput bold)Environment variables:$(tput sgr0)" echo " BASE_ONLY Only build the base image (OS_FLAVOUR) without shipping PrestaShop" @@ -58,8 +61,9 @@ help() { echo " REBUILD_BASE Force the rebuild of the base image" echo " SERVER_FLAVOUR Not implemented, either 'nginx' (default) or 'apache'" echo " TARGET_IMAGE Docker image name, defaults to 'prestashop/prestashop-flashlight'" + echo " CUSTOM_LABELS A comma separated list of key=value pairs, for overriding official flashlight labels" echo " TARGET_PLATFORM A comma separated list of target platforms (defaults to 'linux/amd64')" - echo " ZIP_SOURCE The zip to unpack in flashlight" + echo " ZIP_SOURCE The zip containing the PrestaShop release to build a docker image upon (defaults to PrestaShop source code)" } # Parsing input arguments @@ -77,6 +81,7 @@ while [ "$#" -gt 0 ]; do --rebuild-base) REBUILD_BASE=true; shift;; --server-flavour) SERVER_FLAVOUR="$2"; shift; shift;; --target-image) TARGET_IMAGE="$2"; shift; shift;; + --custom-labels) CUSTOM_LABELS="$2"; shift; shift;; --zip-source) ZIP_SOURCE="$2"; shift; shift;; *) error "Unknown option: $1" 2;; esac @@ -90,6 +95,31 @@ REBUILD_BASE=${REBUILD_BASE:-$BASE_ONLY} DRY_RUN=${DRY_RUN:-false} TARGET_PLATFORM="${TARGET_PLATFORM:-${PLATFORM:-$DEFAULT_PLATFORM}}" +declare -A TARGET_IMAGE_LABELS; + +build_default_labels() { + TARGET_IMAGE_LABELS["org.opencontainers.image.title"]="Prestashop Flashlight" + TARGET_IMAGE_LABELS["org.opencontainers.image.description"]="PrestaShop Flashlight testing utility" + TARGET_IMAGE_LABELS["org.opencontainers.image.source"]="https://github.com/PrestaShop/prestashop-flashlight" + TARGET_IMAGE_LABELS["org.opencontainers.image.url"]="https://github.com/PrestaShop/prestashop-flashlight" + TARGET_IMAGE_LABELS["org.opencontainers.image.licenses"]=MIT + TARGET_IMAGE_LABELS["org.opencontainers.image.created"]="$(date -u +"%Y-%m-%dT%H:%M:%S.%3NZ")" +} + +build_labels() { + if [ -n "$CUSTOM_LABELS" ]; then + + IFS="," read -ra labels <<< "$(echo "$CUSTOM_LABELS" | sed -E 's/^[\x27\x22]|[\x27\x22]$//g')" # We don't need starting or ending quotes + for label in "${labels[@]}"; do + IFS="=" read -ra parts <<< "$label" + TARGET_IMAGE_LABELS["${parts[0]}"]="${parts[1]}" + done + + else + build_default_labels + fi +} + get_latest_prestashop_version() { curl --silent --show-error --fail --location --request GET \ 'https://api.github.com/repos/prestashop/prestashop/releases/latest' | jq -r '.tag_name' @@ -203,12 +233,28 @@ if [ -z "${TARGET_IMAGE:+x}" ]; then else read -ra TARGET_IMAGES <<<"-t $TARGET_IMAGE" fi -if [ "$PS_VERSION" == "nightly" ]; then - ZIP_SOURCE="https://storage.googleapis.com/prestashop-core-nightly/nightly.zip" -else - ZIP_SOURCE="https://github.com/PrestaShop/PrestaShop/releases/download/${PS_VERSION}/prestashop_${PS_VERSION}.zip" + +# If ZIP_SOURCE is not defined, set it based on PS_VERSION +if [ -z "$ZIP_SOURCE" ]; then + if [ "$PS_VERSION" == "nightly" ]; then + ZIP_SOURCE="https://storage.googleapis.com/prestashop-core-nightly/nightly.zip" + else + ZIP_SOURCE="https://github.com/PrestaShop/PrestaShop/releases/download/${PS_VERSION}/prestashop_${PS_VERSION}.zip" + fi fi +# Build image labels +# ------------------ +build_labels + +LABELS=() +for key in "${!TARGET_IMAGE_LABELS[@]}" +do + LABELS+=("--label") + LABELS+=("$key=\"${TARGET_IMAGE_LABELS[$key]}\"") +done + + # Build the docker image # ---------------------- CACHE_IMAGE=prestashop/prestashop-flashlight:base-${PHP_BASE_IMAGE} @@ -232,12 +278,7 @@ if [ "$REBUILD_BASE" == "true" ]; then --build-arg PHP_VERSION="$PHP_VERSION" \ --build-arg NODE_VERSION="$NODE_VERSION" \ --build-arg GIT_SHA="$GIT_SHA" \ - --label org.opencontainers.image.title="PrestaShop Flashlight Base" \ - --label org.opencontainers.image.description="PrestaShop Flashlight base image" \ - --label org.opencontainers.image.source=https://github.com/PrestaShop/prestashop-flashlight \ - --label org.opencontainers.image.url=https://hub.docker.com/r/prestashop/prestashop-flashlight \ - --label org.opencontainers.image.licenses=MIT \ - --label org.opencontainers.image.created="$(date -u +"%Y-%m-%dT%H:%M:%S.%3NZ")" \ + "${LABELS[@]}" \ --tag "prestashop/prestashop-flashlight:base-$PHP_BASE_IMAGE" \ "$([ "${PUSH}" == "true" ] && echo "--push" || echo "--load")" \ . @@ -255,12 +296,7 @@ if [ "$BASE_ONLY" == "false" ]; then --build-arg PHP_VERSION="$PHP_VERSION" \ --build-arg GIT_SHA="$GIT_SHA" \ --build-arg ZIP_SOURCE="$ZIP_SOURCE" \ - --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 \ - --label org.opencontainers.image.url=https://hub.docker.com/r/prestashop/prestashop-flashlight \ - --label org.opencontainers.image.licenses=MIT \ - --label org.opencontainers.image.created="$(date -u +"%Y-%m-%dT%H:%M:%S.%3NZ")" \ + "${LABELS[@]}" \ "${TARGET_IMAGES[@]}" \ "$([ "${PUSH}" == "true" ] && echo "--push" || echo "--load")" \ .