Skip to content

Commit

Permalink
Next !
Browse files Browse the repository at this point in the history
  • Loading branch information
jokesterfr committed Mar 8, 2024
1 parent 2a8d6ae commit 2a06251
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 131 deletions.
9 changes: 9 additions & 0 deletions .hadolint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ignored:
- DL3006
- DL3008
- DL3009
- DL3018
- DL4006
- DL4001
- SC1091
- SC2086
5 changes: 5 additions & 0 deletions assets/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# www.robotstxt.org/
# www.google.com/support/webmasters/bin/answer.py?hl=en&answer=156449

User-agent: *
Allow: /
62 changes: 30 additions & 32 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,41 +1,39 @@
#!/bin/bash
set -e
cd "$(dirname "$0")"

# Available variables
# -------------------
declare PLATFORM; # -- a comma separated list of target platforms (defaults to "linux/amd64")
declare OS_FLAVOUR; # -- either "debian" (default) or "alpine"
declare PHP_VERSION; # -- PHP version, defaults to recommended version for PrestaShop
declare PHP_FLAVOUR; # -- PHP flavour, defaults apache
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 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
declare ZIP_SOURCE; # -- the zip to unpack in flashlight
declare DRY_RUN; # -- if used, won't really build the image. Useful to check tags compliance

# Static configuration
# --------------------
DEFAULT_OS="debian";
DEFAULT_SERVER="apache";
DEFAULT_DOCKER_IMAGE=prestashop/prestashop
DEFAULT_PLATFORM=linux/amd64
DEFAULT_PLATFORM=$(docker system info --format '{{.OSType}}/{{.Architecture}}')
GIT_SHA=$(git rev-parse HEAD)
TARGET_PLATFORM="${TARGET_PLATFORM:-${PLATFORM:-$DEFAULT_PLATFORM}}"

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

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

# Get recommended PHP version from `prestashop-versions.json`
#
# $1 - PrestaShop version
#
# Examples:
# - get_recommended_php_version "8.0.4"
get_recommended_php_version() {
local PS_VERSION=$1;
local RECOMMENDED_VERSION=;
Expand Down Expand Up @@ -96,6 +94,7 @@ get_php_version() {
#
# if the build is for the latest image of the default OS with the recommended PHP version, these tags will be like:
# * latest
# * php-8.2
# * 8.1.1
# * 8.1.1-8.2
# * 8.1.1-8.2-alpine
Expand Down Expand Up @@ -134,37 +133,36 @@ if [ "$PHP_FLAVOUR" == "null" ]; then
error "Could not find a PHP flavour for $OS_FLAVOUR + $SERVER_FLAVOUR + $PHP_VERSION" 2;
fi
if [ -z "${TARGET_IMAGE:+x}" ]; then
read -ra TARGET_IMAGES <<<"$(get_target_images "$PHP_FLAVOUR" "$PS_VERSION" "$PHP_VERSION" "$OS_FLAVOUR" "$LATEST")"
read -ra TARGET_IMAGES <<<"$(get_target_images "$PHP_FLAVOUR" "$PS_VERSION" "$PHP_VERSION" "$OS_FLAVOUR")"
else
read -ra TARGET_IMAGES <<<"-t $TARGET_IMAGE"
fi

#if [[ "$PS_VERSION" == "nightly" ]]; then
# TAGS="--tag $TARGET_IMAGE:nightly";
# echo "Ready to create: $TARGET_IMAGE:nightly"
#else
# TAGS="--tag $TARGET_IMAGE:$PS_VERSION-$PHP_FLAVOUR --tag $TARGET_IMAGE:latest";
# echo "Ready to create: $TARGET_IMAGE:$PS_VERSION-$PHP_FLAVOUR"
#fi

# Info
# ----------------------
echo "🐳 Use $DEFAULT_DOCKER_IMAGE"
echo "Use PrestaShop $PS_VERSION with PHP $PHP_VERSION on $OS_FLAVOUR"
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

# Build the docker image
# ----------------------
CACHE_IMAGE=${TARGET_IMAGES[1]}
if [ -n "${DRY_RUN}" ]; then
docker() {
echo docker "$@"
}
fi
docker pull "$CACHE_IMAGE" 2> /dev/null || true
docker buildx build \
--progress=plain \
--file "./docker/${OS_FLAVOUR}.Dockerfile" \
--platform "${PLATFORM:-$DEFAULT_PLATFORM}" \
--build-arg PHP_VERSION="$PHP_VERSION" \
--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" \
--cache-from type=registry,ref="$CACHE_IMAGE" \
--cache-to type=inline \
--build-arg ZIP_SOURCE="$ZIP_SOURCE" \
--label org.opencontainers.image.title="PrestaShop" \
--label org.opencontainers.image.description="PrestaShop docker image" \
--label org.opencontainers.image.source=https://github.com/PrestaShop/docker \
Expand Down
101 changes: 59 additions & 42 deletions docker/alpine.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,47 +1,50 @@
ARG PS_VERSION
ARG PHP_VERSION
ARG PHP_FLAVOUR
ARG GIT_SHA
ARG ZIP_SOURCE

# ==================================
# Stage 1/3: PHP base configuration
# ==================================
FROM php:${PHP_FLAVOUR} AS alpine-base-prestashop
ARG PS_VERSION
ARG PHP_VERSION

ENV PS_DOMAIN="<to be defined>" \
DB_SERVER="<to be defined>" \
DB_PORT=3306 \
DB_NAME=prestashop \
DB_USER=root \
DB_PASSWD=admin \
DB_PREFIX=ps_ \
[email protected] \
ADMIN_PASSWD=prestashop_demo \
PS_LANGUAGE=en \
PS_COUNTRY=GB \
PS_ALL_LANGUAGES=0 \
PS_INSTALL_AUTO=0 \
PS_ERASE_DB=0 \
PS_INSTALL_DB=0 \
PS_DEV_MODE=0 \
PS_HOST_MODE=0 \
PS_DEMO_MODE=0 \
PS_ENABLE_SSL=0 \
PS_HANDLE_DYNAMIC_DOMAIN=0 \
PS_FOLDER_ADMIN=admin \
PS_FOLDER_INSTALL=install \
PHP_ENV=production
DB_SERVER="<to be defined>" \
DB_PORT=3306 \
DB_NAME=prestashop \
DB_USER=root \
DB_PASSWD=admin \
DB_PREFIX=ps_ \
[email protected] \
ADMIN_PASSWD=prestashop_demo \
PS_LANGUAGE=en \
PS_COUNTRY=GB \
PS_ALL_LANGUAGES=0 \
PS_INSTALL_AUTO=0 \
PS_ERASE_DB=0 \
PS_INSTALL_DB=0 \
PS_DEV_MODE=0 \
PS_HOST_MODE=0 \
PS_DEMO_MODE=0 \
PS_ENABLE_SSL=0 \
PS_HANDLE_DYNAMIC_DOMAIN=0 \
PS_FOLDER_ADMIN=admin \
PS_FOLDER_INSTALL=install \
PHP_ENV=production

# The PHP configuration script
COPY ./assets/php-configuration.sh /tmp/

# Install base tools
RUN \
apk --no-cache add -U \
ca-certificates geoip tzdata zip curl jq make \
gnu-libiconv php-common mariadb-client oniguruma-dev \
zlib-dev libzip-dev libjpeg-turbo-dev libpng-dev \
icu-dev libmcrypt-dev libxml2 libxml2-dev \
ca-certificates geoip tzdata zip curl jq make \
gnu-libiconv php-common mariadb-client oniguruma-dev \
zlib-dev libzip-dev libjpeg-turbo-dev libpng-dev \
icu-dev libmcrypt-dev libxml2 libxml2-dev \
&& /tmp/php-configuration.sh \
&& apk del make \
&& rm -rf /var/cache/apk/*
Expand All @@ -59,42 +62,56 @@ COPY ./assets/docker_run.sh /tmp/

# Apache configuration
RUN if [ -x "$(command -v apache2-foreground)" ]; then \
a2enmod rewrite;\
fi
a2enmod rewrite;\
fi

# =========================================
# Stage 2/3: PrestaShop sources downloader
# =========================================
FROM alpine-base-prestashop AS alpine-download-prestashop
ARG PS_VERSION
ENV PS_FOLDER=/tmp/prestashop
ARG GIT_SHA
ARG PHP_VERSION
ARG PS_FOLDER=/var/www/html
ARG ZIP_SOURCE

# Get PrestaShop source code
RUN if [[ "$PS_VERSION" == "nightly" ]]; then \
echo "Unsupported yet: https://prestashop.slack.com/archives/C03LFE4KV6K/p1703170152828039" \
&& exit 1; \
else \
curl -s -L -o /tmp/prestashop.zip "https://github.com/PrestaShop/PrestaShop/releases/download/${PS_VERSION}/prestashop_${PS_VERSION}.zip"; \
fi
# hadolint ignore=DL3020
ADD ${ZIP_SOURCE} /tmp/prestashop.zip

# Extract the souces
RUN mkdir -p "$PS_FOLDER" /tmp/unzip-ps \
&& unzip -n -q /tmp/prestashop.zip -d /tmp/unzip-ps \
&& ([ -f /tmp/unzip-ps/prestashop.zip ] \
&& unzip -n -q /tmp/unzip-ps/prestashop.zip -d "$PS_FOLDER" \
|| mv /tmp/unzip-ps/prestashop/* "$PS_FOLDER")
&& unzip -n -q /tmp/unzip-ps/prestashop.zip -d "$PS_FOLDER" \
|| mv /tmp/unzip-ps/prestashop/* "$PS_FOLDER") \
&& chown -R www-data:www-data "$PS_FOLDER" \
&& rm -rf /tmp/prestashop.zip /tmp/unzip-ps

# Ship a VERSION file
RUN echo "PrestaShop $PS_VERSION" > "$PS_FOLDER/VERSION" \
&& echo "PHP $PHP_VERSION" >> "$PS_FOLDER/VERSION" \
&& echo "Flashlight $GIT_SHA" >> "$PS_FOLDER/VERSION"

# Adds a robots.txt file
ADD ./assets/robots.txt $PS_FOLDER

Check failure on line 97 in docker/alpine.Dockerfile

View workflow job for this annotation

GitHub Actions / Lint: dockerfile

DL3020 error: Use COPY instead of ADD for files and folders

# ============================
# Stage 3/3: Production image
# ============================
FROM alpine-base-prestashop
ARG PS_FOLDER=/var/www/html/prestashop
ARG PS_FOLDER=/var/www/html
ARG PS_VERSION

LABEL maintainer="PrestaShop Core Team <[email protected]>"

ENV PS_VERSION $PS_VERSION
COPY --chown=www-data:www-data --from=alpine-download-prestashop ${PS_FOLDER} ${PS_FOLDER}

HEALTHCHECK --interval=5s --timeout=5s --retries=10 --start-period=10s \
CMD curl -Isf http://localhost:80/robots.txt || exit 1

EXPOSE 80

# Copy the PrestaShop sources
COPY --chown=www-data:www-data --from=alpine-download-prestashop /tmp/prestashop ${PS_FOLDER}
STOPSIGNAL SIGQUIT

CMD ["/tmp/docker_run.sh"]
ENTRYPOINT ["/tmp/docker_run.sh"]
Loading

0 comments on commit 2a06251

Please sign in to comment.