Skip to content

Commit

Permalink
Custom release build capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre-Lematre committed Oct 28, 2024
1 parent 631506e commit 8049560
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 29 deletions.
3 changes: 2 additions & 1 deletion assets/hydrate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
"$([ "$PRE_INSTALLED_MODULES" == "true" ] && echo "--modules=$(find "$PS_FOLDER"/modules/* -maxdepth 0 -type d -exec basename {} \; | paste -s -d ',')" || echo "" )"
echo "✅ PrestaShop installed"

# 7. Swap off dev mode
Expand Down
91 changes: 63 additions & 28 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ 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 PRE_INSTALLED_MODULES; # -- install modules during zip installation
declare CUSTOM_LABELS; # -- only when PRIVATE : list of key=value pairs separated by a comma, for overriding official flashlight labels

declare -A IMAGE_LABELS;

# Static configuration
# --------------------
Expand Down Expand Up @@ -90,6 +94,31 @@ REBUILD_BASE=${REBUILD_BASE:-$BASE_ONLY}
DRY_RUN=${DRY_RUN:-false}
TARGET_PLATFORM="${TARGET_PLATFORM:-${PLATFORM:-$DEFAULT_PLATFORM}}"



build_default_labels() {
IMAGE_LABELS["org.opencontainers.image.title"]="Prestashop Flashlight"
IMAGE_LABELS["org.opencontainers.image.description"]="PrestaShop Flashlight testing utility"
IMAGE_LABELS["org.opencontainers.image.source"]="https://github.com/PrestaShop/prestashop-flashlight"
IMAGE_LABELS["org.opencontainers.image.url"]="https://github.com/PrestaShop/prestashop-flashlight"
IMAGE_LABELS["org.opencontainers.image.licenses"]=MIT
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"
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'
Expand Down Expand Up @@ -203,12 +232,27 @@ 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 [ -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

COMPUTED_LABELS=()
for key in "${!IMAGE_LABELS[@]}"
do
COMPUTED_LABELS+=("--label")
COMPUTED_LABELS+=("$key=\"${IMAGE_LABELS[$key]}\"")
done


# Build the docker image
# ----------------------
CACHE_IMAGE=prestashop/prestashop-flashlight:base-${PHP_BASE_IMAGE}
Expand All @@ -232,12 +276,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")" \
"${COMPUTED_LABELS[@]}" \
--tag "prestashop/prestashop-flashlight:base-$PHP_BASE_IMAGE" \
"$([ "${PUSH}" == "true" ] && echo "--push" || echo "--load")" \
.
Expand All @@ -255,12 +294,8 @@ 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")" \
--build-arg PRE_INSTALLED_MODULES="$PRE_INSTALLED_MODULES" \
"${COMPUTED_LABELS[@]}" \
"${TARGET_IMAGES[@]}" \
"$([ "${PUSH}" == "true" ] && echo "--push" || echo "--load")" \
.
Expand Down
2 changes: 2 additions & 0 deletions docker/flashlight.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ ARG PHP_VERSION
ARG GIT_SHA
ARG PS_FOLDER=/var/www/html
ARG ZIP_SOURCE
ARG PRE_INSTALLED_MODULES
ENV PRE_INSTALLED_MODULES=$PRE_INSTALLED_MODULES

# Get PrestaShop source code
# hadolint ignore=DL3020
Expand Down

0 comments on commit 8049560

Please sign in to comment.