diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f988070..20d54ea 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,12 +2,7 @@ name: Build on: workflow_dispatch: push: - branches: - - main - paths: - - "Dockerfile.template" - - ".github/workflows/build.yml" - - "rootfs/**" + pull_request: env: DOCKER_BUILDKIT: 1 @@ -19,243 +14,44 @@ permissions: packages: write jobs: - php81-arm64: - name: 8.1 on ARM64 - runs-on: hcloud-arm64-small - steps: - - uses: actions/checkout@v3 - - - name: Install Cosign - uses: sigstore/cosign-installer@v3 - - - name: Login into Docker Hub - run: echo "${{ secrets.DOCKER_HUB_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin - - - name: Login into Github Docker Registery - run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - uses: docker/build-push-action@v4 - with: - tags: ghcr.io/shopware/docker-base:8.1.26-arm64 - context: . - file: 8.1/Dockerfile - cache-from: type=registry,ref=ghcr.io/shopware/docker-cache:8.1-arm64 - cache-to: type=registry,ref=ghcr.io/shopware/docker-cache:8.1-arm64,mode=max - platforms: linux/arm64 - push: true - provenance: false - - php81-amd64: - name: 8.1 on AMD64 - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v3 - - - name: Install Cosign - uses: sigstore/cosign-installer@v3 - - - name: Login into Github Docker Registery - run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - uses: docker/build-push-action@v4 - with: - tags: ghcr.io/shopware/docker-base:8.1.26-amd64 - context: . - file: 8.1/Dockerfile - cache-from: type=registry,ref=ghcr.io/shopware/docker-cache:8.1-amd64 - cache-to: type=registry,ref=ghcr.io/shopware/docker-cache:8.1-amd64,mode=max - platforms: linux/amd64 - push: true - provenance: false - - php82-arm64: - name: 8.2 on ARM64 - runs-on: hcloud-arm64-small + generate-matrix: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.generate-matrix.outputs.matrix }} steps: - - uses: actions/checkout@v3 - - - name: Install Cosign - uses: sigstore/cosign-installer@v3 + - name: Checkout + uses: actions/checkout@v4 - - name: Login into Docker Hub - run: echo "${{ secrets.DOCKER_HUB_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin - - - name: Login into Github Docker Registery - run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - uses: docker/build-push-action@v4 - with: - tags: ghcr.io/shopware/docker-base:8.2.14-arm64 - context: . - file: 8.2/Dockerfile - cache-from: type=registry,ref=ghcr.io/shopware/docker-cache:8.2-arm64 - cache-to: type=registry,ref=ghcr.io/shopware/docker-cache:8.2-arm64,mode=max - platforms: linux/arm64 - push: true - provenance: false - - php82-amd64: - name: 8.2 on AMD64 - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v3 + - name: Generate Matrix + id: generate-matrix + run: | + MATRIX=$(php matrix.php) + echo "matrix<> $GITHUB_OUTPUT + echo "$MATRIX" >> $GITHUB_OUTPUT + echo 'EOF' >> $GITHUB_OUTPUT - - name: Install Cosign - uses: sigstore/cosign-installer@v3 - - - name: Login into Github Docker Registery - run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - uses: docker/build-push-action@v4 - with: - tags: ghcr.io/shopware/docker-base:8.2.14-amd64 - context: . - file: 8.2/Dockerfile - cache-from: type=registry,ref=ghcr.io/shopware/docker-cache:8.2-amd64 - cache-to: type=registry,ref=ghcr.io/shopware/docker-cache:8.2-amd64,mode=max - platforms: linux/amd64 - push: true - provenance: false - - php83-arm64: - name: 8.3 on ARM64 - runs-on: hcloud-arm64-small + build-fpm-amd64: + name: Build FPM AMD64 + runs-on: ubuntu-latest + needs: [generate-matrix] + strategy: ${{ fromJson(needs.generate-matrix.outputs.matrix) }} steps: - - uses: actions/checkout@v3 - - - name: Install Cosign - uses: sigstore/cosign-installer@v3 + - name: Checkout + uses: actions/checkout@v4 - name: Login into Docker Hub run: echo "${{ secrets.DOCKER_HUB_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin - - - name: Login into Github Docker Registery - run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - uses: docker/build-push-action@v4 with: - tags: ghcr.io/shopware/docker-base:8.3.1-arm64 + tags: ghcr.io/shopware/docker-base-fpm:${{ matrix.php }}-amd64 context: . - file: 8.3/Dockerfile - cache-from: type=registry,ref=ghcr.io/shopware/docker-cache:8.3-arm64 - cache-to: type=registry,ref=ghcr.io/shopware/docker-cache:8.3-arm64,mode=max + file: ${{ matrix.php }}/Dockerfile + cache-from: type=registry,ref=ghcr.io/shopware/docker-cache:${{ matrix.php }}-fpm-amd64 + cache-to: type=registry,ref=ghcr.io/shopware/docker-cache:${{ matrix.php }}-fpm-amd64,mode=max platforms: linux/arm64 - push: true + push: false provenance: false - - php83-amd64: - name: 8.3 on AMD64 - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v3 - - - name: Install Cosign - uses: sigstore/cosign-installer@v3 - - - name: Login into Github Docker Registery - run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - uses: docker/build-push-action@v4 - with: - tags: ghcr.io/shopware/docker-base:8.3.1-amd64 - context: . - file: 8.3/Dockerfile - cache-from: type=registry,ref=ghcr.io/shopware/docker-cache:8.3-amd64 - cache-to: type=registry,ref=ghcr.io/shopware/docker-cache:8.3-amd64,mode=max - platforms: linux/amd64 - push: true - provenance: false - - - merge-manifest: - name: Merge Manifest - runs-on: ubuntu-latest - needs: - - php81-arm64 - - php81-amd64 - - php82-arm64 - - php82-amd64 - - php83-arm64 - - php83-amd64 - - steps: - - name: Login into Docker Hub - run: echo "${{ secrets.DOCKER_HUB_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin - - - name: Login into Github Docker Registery - run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin - - - name: Install Cosign - uses: sigstore/cosign-installer@v3 - - - name: Install Regclient - run: | - wget https://github.com/regclient/regclient/releases/latest/download/regctl-linux-amd64 - chmod +x regctl-linux-amd64 - - - run: docker manifest create ghcr.io/shopware/docker-base:8.1 --amend ghcr.io/shopware/docker-base:8.1.26-amd64 --amend ghcr.io/shopware/docker-base:8.1.26-arm64 - - - run: docker manifest create ghcr.io/shopware/docker-base:8.1.26 --amend ghcr.io/shopware/docker-base:8.1.26-amd64 --amend ghcr.io/shopware/docker-base:8.1.26-arm64 - - - run: docker manifest push ghcr.io/shopware/docker-base:8.1 - - - run: docker manifest push ghcr.io/shopware/docker-base:8.1.26 - - - run: cosign sign --yes ghcr.io/shopware/docker-base:8.1 - - - run: cosign sign --yes ghcr.io/shopware/docker-base:8.1.26 - - - run: ./regctl-linux-amd64 image copy ghcr.io/shopware/docker-base:8.1 shopware/docker-base:8.1 - - - run: ./regctl-linux-amd64 image copy ghcr.io/shopware/docker-base:8.1.26 shopware/docker-base:8.1.26 - - - run: docker manifest create ghcr.io/shopware/docker-base:8.2 --amend ghcr.io/shopware/docker-base:8.2.14-amd64 --amend ghcr.io/shopware/docker-base:8.2.14-arm64 - - - run: docker manifest create ghcr.io/shopware/docker-base:8.2.14 --amend ghcr.io/shopware/docker-base:8.2.14-amd64 --amend ghcr.io/shopware/docker-base:8.2.14-arm64 - - - run: docker manifest push ghcr.io/shopware/docker-base:8.2 - - - run: docker manifest push ghcr.io/shopware/docker-base:8.2.14 - - - run: cosign sign --yes ghcr.io/shopware/docker-base:8.2 - - - run: cosign sign --yes ghcr.io/shopware/docker-base:8.2.14 - - - run: ./regctl-linux-amd64 image copy ghcr.io/shopware/docker-base:8.2 shopware/docker-base:8.2 - - - run: ./regctl-linux-amd64 image copy ghcr.io/shopware/docker-base:8.2.14 shopware/docker-base:8.2.14 - - - run: docker manifest create ghcr.io/shopware/docker-base:8.3 --amend ghcr.io/shopware/docker-base:8.3.1-amd64 --amend ghcr.io/shopware/docker-base:8.3.1-arm64 - - - run: docker manifest create ghcr.io/shopware/docker-base:8.3.1 --amend ghcr.io/shopware/docker-base:8.3.1-amd64 --amend ghcr.io/shopware/docker-base:8.3.1-arm64 - - - run: docker manifest push ghcr.io/shopware/docker-base:8.3 - - - run: docker manifest push ghcr.io/shopware/docker-base:8.3.1 - - - run: cosign sign --yes ghcr.io/shopware/docker-base:8.3 - - - run: cosign sign --yes ghcr.io/shopware/docker-base:8.3.1 - - - run: ./regctl-linux-amd64 image copy ghcr.io/shopware/docker-base:8.3 shopware/docker-base:8.3 - - - run: ./regctl-linux-amd64 image copy ghcr.io/shopware/docker-base:8.3.1 shopware/docker-base:8.3.1 - diff --git a/8.1/Dockerfile b/caddy/8.1/Dockerfile similarity index 100% rename from 8.1/Dockerfile rename to caddy/8.1/Dockerfile diff --git a/8.2/Dockerfile b/caddy/8.2/Dockerfile similarity index 100% rename from 8.2/Dockerfile rename to caddy/8.2/Dockerfile diff --git a/8.3/Dockerfile b/caddy/8.3/Dockerfile similarity index 100% rename from 8.3/Dockerfile rename to caddy/8.3/Dockerfile diff --git a/Dockerfile.template b/caddy/Dockerfile.template similarity index 100% rename from Dockerfile.template rename to caddy/Dockerfile.template diff --git a/rootfs/etc/caddy/Caddyfile b/caddy/rootfs/etc/caddy/Caddyfile similarity index 100% rename from rootfs/etc/caddy/Caddyfile rename to caddy/rootfs/etc/caddy/Caddyfile diff --git a/rootfs/etc/supervisord.conf b/caddy/rootfs/etc/supervisord.conf similarity index 100% rename from rootfs/etc/supervisord.conf rename to caddy/rootfs/etc/supervisord.conf diff --git a/rootfs/setup b/caddy/rootfs/setup similarity index 100% rename from rootfs/setup rename to caddy/rootfs/setup diff --git a/rootfs/usr/local/etc/php-fpm.d/docker.conf b/caddy/rootfs/usr/local/etc/php-fpm.d/docker.conf similarity index 100% rename from rootfs/usr/local/etc/php-fpm.d/docker.conf rename to caddy/rootfs/usr/local/etc/php-fpm.d/docker.conf diff --git a/rootfs/usr/local/etc/php/conf.d/docker.ini b/caddy/rootfs/usr/local/etc/php/conf.d/docker.ini similarity index 100% rename from rootfs/usr/local/etc/php/conf.d/docker.ini rename to caddy/rootfs/usr/local/etc/php/conf.d/docker.ini diff --git a/rootfs/usr/local/shopware/functions.sh b/caddy/rootfs/usr/local/shopware/functions.sh similarity index 92% rename from rootfs/usr/local/shopware/functions.sh rename to caddy/rootfs/usr/local/shopware/functions.sh index 7eb1b00..7a04d4e 100644 --- a/rootfs/usr/local/shopware/functions.sh +++ b/caddy/rootfs/usr/local/shopware/functions.sh @@ -48,9 +48,9 @@ run_hooks() { hook=$1 if [ -d "/usr/local/shopware/$hook.d" ]; then for file in "/usr/local/shopware/$hook.d"/*.sh; do - echo "Running $file for $hook" - # shellcheck source=/dev/null - . "$file" - done + echo "Running $file for $hook" + # shellcheck source=../../../../../../../../../dev/null + . "$file" +done fi } diff --git a/rootfs/usr/local/shopware/setup_6.5.x b/caddy/rootfs/usr/local/shopware/setup_6.5.x similarity index 100% rename from rootfs/usr/local/shopware/setup_6.5.x rename to caddy/rootfs/usr/local/shopware/setup_6.5.x diff --git a/rootfs/usr/local/shopware/setup_6.6.x b/caddy/rootfs/usr/local/shopware/setup_6.6.x similarity index 91% rename from rootfs/usr/local/shopware/setup_6.6.x rename to caddy/rootfs/usr/local/shopware/setup_6.6.x index edf6d32..52e5828 100755 --- a/rootfs/usr/local/shopware/setup_6.6.x +++ b/caddy/rootfs/usr/local/shopware/setup_6.6.x @@ -12,9 +12,9 @@ if console system:is-installed; then run_hooks pre_update if [ "${SHOPWARE_SKIP_ASSET_COPY-""}" ]; then - console system:update:finish --skip-asset-build + console system:update:finish --skip-asset-build else - console system:update:finish + console system:update:finish fi if [ "${SHOPWARE_SKIP_ASSET_COPY-""}" ]; then diff --git a/fpm/rootfs/setup b/fpm/rootfs/setup new file mode 100755 index 0000000..343a60e --- /dev/null +++ b/fpm/rootfs/setup @@ -0,0 +1,15 @@ +#!/usr/bin/env sh + +set -e +set -x + +shopware_version=$(jq '.packages[] | select (.name == "shopware/core") | .version' -r < composer.lock) +# if shopware version starts with 6.6 echo 6.6 +# shellcheck disable=SC2081,SC3010 +if [[ $shopware_version == v6.6.* ]]; then + # shellcheck source-path=./rootfs source=./usr/local/shopware/setup_6.6.x + . /usr/local/shopware/setup_6.6.x +else + # shellcheck source-path=./rootfs source=./usr/local/shopware/setup_6.5.x + . /usr/local/shopware/setup_6.5.x +fi diff --git a/fpm/rootfs/usr/local/etc/php-fpm.d/docker.conf b/fpm/rootfs/usr/local/etc/php-fpm.d/docker.conf new file mode 100644 index 0000000..0477ef7 --- /dev/null +++ b/fpm/rootfs/usr/local/etc/php-fpm.d/docker.conf @@ -0,0 +1,18 @@ +[global] +daemonize = no +error_log = /proc/self/fd/2 + +; https://github.com/docker-library/php/pull/725#issuecomment-443540114 +log_limit = 8192 + +[www] +listen = /tmp/php-fpm.sock +clear_env = no +pm = ${FPM_PM} +pm.max_children = ${FPM_PM_MAX_CHILDREN} +pm.start_servers = ${FPM_PM_START_SERVERS} +pm.min_spare_servers = ${FPM_PM_MIN_SPARE_SERVERS} +pm.max_spare_servers = ${FPM_PM_MAX_SPARE_SERVERS} +catch_workers_output = yes +decorate_workers_output = no +access.log = /dev/null \ No newline at end of file diff --git a/fpm/rootfs/usr/local/etc/php/conf.d/docker.ini b/fpm/rootfs/usr/local/etc/php/conf.d/docker.ini new file mode 100644 index 0000000..3c9eba5 --- /dev/null +++ b/fpm/rootfs/usr/local/etc/php/conf.d/docker.ini @@ -0,0 +1,15 @@ +upload_max_filesize = ${PHP_MAX_UPLOAD_SIZE} +post_max_size = ${PHP_MAX_UPLOAD_SIZE} +max_execution_time = ${PHP_MAX_EXECUTION_TIME} +memory_limit = ${PHP_MEMORY_LIMIT} + +session.save_handler = ${PHP_SESSION_HANDLER} +session.save_path = ${PHP_SESSION_SAVE_PATH} +error_reporting = ${PHP_ERROR_REPORTING} +zend.assertions = -1 +opcache.interned_strings_buffer=20 +opcache.enable_file_override=1 +opcache.validate_timestamps=0 +zend.detect_unicode=0 +realpath_cache_ttl=3600 +expose_php = Off diff --git a/fpm/rootfs/usr/local/shopware/functions.sh b/fpm/rootfs/usr/local/shopware/functions.sh new file mode 100644 index 0000000..7a04d4e --- /dev/null +++ b/fpm/rootfs/usr/local/shopware/functions.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env sh + +set -e + +wait_for_mysql() { + database_host=$(trurl "$DATABASE_URL" --get '{host}') + database_port=$(trurl "$DATABASE_URL" --get '{port}') + MYSQL_WAIT_SECONDS=${MYSQL_WAIT_SECONDS:-20} + + try=0 + if [ "$MYSQL_WAIT_SECONDS" != 0 ]; then + until nc -z -v -w30 "$database_host" "${database_port:-3306}"; do + echo "Waiting for database connection..." + # wait for 5 seconds before check again + sleep 1 + + try=$((try + 1)) + + if [ $try = "$MYSQL_WAIT_SECONDS" ]; then + echo "Error: We have been waiting for database connection too long already; failing." + exit 1 + fi + done + fi +} + +console() { + php -derror_reporting=E_ALL bin/console "$@" +} + +install_all_plugins() { + list_with_updates=$(php bin/console plugin:list --json | jq 'map(select(.installedAt == null)) | .[].name' -r) + + for plugin in $list_with_updates; do + console plugin:install --activate "$plugin" + done +} + +update_all_plugins() { + list_with_updates=$(php bin/console plugin:list --json | jq 'map(select(.upgradeVersion != null)) | .[].name' -r) + + for plugin in $list_with_updates; do + php -derror_reporting=E_ALL bin/console plugin:update "$plugin" + done +} + +run_hooks() { + hook=$1 + if [ -d "/usr/local/shopware/$hook.d" ]; then + for file in "/usr/local/shopware/$hook.d"/*.sh; do + echo "Running $file for $hook" + # shellcheck source=../../../../../../../../../dev/null + . "$file" +done + fi +} diff --git a/fpm/rootfs/usr/local/shopware/setup_6.5.x b/fpm/rootfs/usr/local/shopware/setup_6.5.x new file mode 100755 index 0000000..25b9d1c --- /dev/null +++ b/fpm/rootfs/usr/local/shopware/setup_6.5.x @@ -0,0 +1,33 @@ +#!/usr/bin/env sh + +set -e +set -x + +. /usr/local/shopware/functions.sh + +if php bin/console system:config:get shopware.installed; then + run_hooks pre_update + + console system:update:finish + console plugin:refresh + + update_all_plugins + install_all_plugins + + run_hooks post_update +else + run_hooks pre_install + + # Shopware is not installed + console system:install --create-database "--shop-locale=$INSTALL_LOCALE" "--shop-currency=$INSTALL_CURRENCY" --force + console user:create "$INSTALL_ADMIN_USERNAME" --admin --password="$INSTALL_ADMIN_PASSWORD" -n + console sales-channel:create:storefront --name=Storefront --url="$APP_URL" + console theme:change --all Storefront + console system:config:set core.frw.completedAt '2019-10-07T10:46:23+00:00' + console system:config:set core.usageData.shareUsageData false --json + console plugin:refresh + + install_all_plugins + + run_hooks post_install +fi diff --git a/fpm/rootfs/usr/local/shopware/setup_6.6.x b/fpm/rootfs/usr/local/shopware/setup_6.6.x new file mode 100755 index 0000000..52e5828 --- /dev/null +++ b/fpm/rootfs/usr/local/shopware/setup_6.6.x @@ -0,0 +1,42 @@ +#!/usr/bin/env sh + +set -e +set -x + +# shellcheck source=./functions.sh +. /usr/local/shopware/functions.sh + +wait_for_mysql + +if console system:is-installed; then + run_hooks pre_update + + if [ "${SHOPWARE_SKIP_ASSET_COPY-""}" ]; then + console system:update:finish --skip-asset-build + else + console system:update:finish + fi + + if [ "${SHOPWARE_SKIP_ASSET_COPY-""}" ]; then + console plugin:update:all + else + console plugin:update:all --skip-asset-build + fi + + install_all_plugins + + run_hooks post_update +else + run_hooks pre_install + + console system:install --create-database "--shop-locale=$INSTALL_LOCALE" "--shop-currency=$INSTALL_CURRENCY" --force + console user:create "$INSTALL_ADMIN_USERNAME" --admin --password="$INSTALL_ADMIN_PASSWORD" -n + console sales-channel:create:storefront --name=Storefront --url="$APP_URL" + console theme:change --all Storefront + console system:config:set core.frw.completedAt '2019-10-07T10:46:23+00:00' + console plugin:refresh + + install_all_plugins + + run_hooks post_install +fi diff --git a/matrix.php b/matrix.php new file mode 100644 index 0000000..3260c38 --- /dev/null +++ b/matrix.php @@ -0,0 +1,50 @@ +\d\.\d\.\d{1,}(RC\d)?)/m'; + +$supervisord = get_digest_of_image('shyim/supervisord', 'latest'); + +foreach ($supportedVersions as $supportedVersion) +{ + $apiResponse = json_decode(file_get_contents('https://hub.docker.com/v2/repositories/library/php/tags/?page_size=50&page=1&name=' . $supportedVersion. '.'), true); + + if (!is_array($apiResponse)) { + throw new \RuntimeException("invalid api response"); + } + + $curVersion = null; + $patchVersion = null; + $rcVersion = null; + + foreach ($apiResponse['results'] as $entry) { + preg_match($versionRegex, $entry['name'], $rcVersion); + + if (strpos($entry['name'], 'RC') !== false && !in_array($rcVersion['version'], $rcVersions)) { + continue; + } + + preg_match($versionRegex, $entry['name'], $patchVersion); + } + + if ($patchVersion === null) { + throw new \RuntimeException('There is no version found for PHP ' . $supportedVersion); + } + + $phpDigest = get_digest_of_image('library/php', $patchVersion['version'] . '-fpm-alpine'); + + $data[] = [ + 'php' => $supportedVersion, + 'phpPatch' => $patchVersion['version'], + 'phpPatchDigest' => $phpDigest, + 'supervisordDigest' => $supervisord, + ]; +} + +echo json_encode(['matrix' => ['include' => $data]], JSON_THROW_ON_ERROR);