From 2d05cac5732aac773a2d5101ae8b8f81b92272dc Mon Sep 17 00:00:00 2001
From: Pascal Thesing
Date: Tue, 18 Jul 2023 13:16:23 +0200
Subject: [PATCH] ci(SW-27127): add docker container for zips (#42)
* ci(SW-27127): add docker container for zips
* ci(SW-27127): push branches only on main branch
---
.github/workflows/setup-current-shopware.yml | 2 -
.github/workflows/setup-old-shopware.yml | 1 +
.github/workflows/setup-workflow.yml | 2 +
.github/workflows/setup-zip.yml | 55 +++++++++++++++
Dockerfile.twig => Install_Dockerfile.twig | 14 ++--
Zip_Dockerfile.twig | 68 +++++++++++++++++++
debug_config.php | 2 +-
makefile | 13 +++-
running/Dockerfile.twig | 3 -
.../rootfs/etc/nginx/sites-enabled/default | 12 ++++
running/rootfs/etc/supervisord.conf | 2 +-
start-mysql.sh | 17 +++++
12 files changed, 178 insertions(+), 13 deletions(-)
create mode 100644 .github/workflows/setup-zip.yml
rename Dockerfile.twig => Install_Dockerfile.twig (89%)
create mode 100644 Zip_Dockerfile.twig
create mode 100644 running/rootfs/etc/nginx/sites-enabled/default
create mode 100755 start-mysql.sh
diff --git a/.github/workflows/setup-current-shopware.yml b/.github/workflows/setup-current-shopware.yml
index e0f8100..0929622 100644
--- a/.github/workflows/setup-current-shopware.yml
+++ b/.github/workflows/setup-current-shopware.yml
@@ -5,8 +5,6 @@ on:
- cron:
'0 0 * * *'
push:
- branches:
- - main
jobs:
setup-shopware:
diff --git a/.github/workflows/setup-old-shopware.yml b/.github/workflows/setup-old-shopware.yml
index 00d3443..152c0d9 100644
--- a/.github/workflows/setup-old-shopware.yml
+++ b/.github/workflows/setup-old-shopware.yml
@@ -2,6 +2,7 @@ name: Setup older Shopware Version
on:
workflow_dispatch:
+ push:
jobs:
setup-shopware:
diff --git a/.github/workflows/setup-workflow.yml b/.github/workflows/setup-workflow.yml
index 79d6014..f3a98c5 100644
--- a/.github/workflows/setup-workflow.yml
+++ b/.github/workflows/setup-workflow.yml
@@ -46,6 +46,7 @@ jobs:
run: make running:shopware_${{ env.SHOPWARE_VERSION }}_${{ env.MYSQL_VERSION }}_${{ env.PHP_VERSION }}
- name: Push base image
+ if: ${{ github.ref == 'refs/heads/main' }}
run: docker push ghcr.io/shopware5/docker-images-testing/running:shopware_${{ env.SHOPWARE_VERSION }}_${{ env.MYSQL_VERSION }}_${{ env.PHP_VERSION }}
- name: Create allInOne Image
@@ -55,5 +56,6 @@ jobs:
run: make test:shopware_${{ env.SHOPWARE_VERSION }}_${{ env.MYSQL_VERSION }}_${{ env.PHP_VERSION }}_${{ env.CONSENT_MANAGER }}
- name: Push allInOne Image
+ if: ${{ github.ref == 'refs/heads/main' }}
run: docker push ghcr.io/shopware5/docker-images-testing/install:shopware_${{ env.SHOPWARE_VERSION }}_${{ env.MYSQL_VERSION }}_${{ env.PHP_VERSION }}_${{ env.CONSENT_MANAGER }}
diff --git a/.github/workflows/setup-zip.yml b/.github/workflows/setup-zip.yml
new file mode 100644
index 0000000..4e3b611
--- /dev/null
+++ b/.github/workflows/setup-zip.yml
@@ -0,0 +1,55 @@
+on:
+ workflow_dispatch:
+ push:
+
+jobs:
+ setup-shopware:
+ name: Setup Shopware
+ runs-on: ubuntu-latest
+
+ strategy:
+ matrix:
+ versions:
+ - shopware-zip: 'install_5.6.10_b9471cf7c3f30dfc05d7c959f555c2a8d1c24420'
+ shopware: '5.6.10'
+ php: '7.4'
+ mysql: '5.7'
+ consentManager: 'none'
+
+ - shopware-zip: 'install_5.4.6_f667f6471a77bb5af0c115f3e243594e6353747e'
+ shopware: '5.4.5'
+ php: '7.1'
+ mysql: '5.7'
+ consentManager: 'none'
+ steps:
+ - uses: actions/checkout@v3
+ - uses: actions/setup-node@v3
+ with:
+ node-version: current
+
+ - name: Login to GitHub Container Registry
+ uses: docker/login-action@v2
+ with:
+ registry: ghcr.io
+ username: ${{ github.actor }}
+ password: ${{ github.token }}
+
+ - name: Install dependencies
+ run: npm install
+
+ - name: Create base image
+ run: make running:shopware_${{ matrix.versions.shopware }}_${{ matrix.versions.mysql }}_${{ matrix.versions.php }}
+
+ - name: Push base image
+ if: ${{ github.ref == 'refs/heads/main' }}
+ run: docker push ghcr.io/shopware5/docker-images-testing/running:shopware_${{ matrix.versions.shopware }}_${{ matrix.versions.mysql }}_${{ matrix.versions.php }}
+
+ - name: Create zip Image
+ run: make zip:shopware_${{ matrix.versions.shopware }}_${{ matrix.versions.shopware-zip }}_${{ matrix.versions.mysql }}_${{ matrix.versions.php }}_${{ matrix.versions.consentManager }}
+
+ - name: Test zip Image
+ run: make test-zip:shopware_${{ matrix.versions.shopware }}_${{ matrix.versions.shopware-zip }}_${{ matrix.versions.mysql }}_${{ matrix.versions.php }}_${{ matrix.versions.consentManager }}
+
+ - name: Push zip Image
+ if: ${{ github.ref == 'refs/heads/main' }}
+ run: docker push ghcr.io/shopware5/docker-images-testing/zip:shopware_${{ matrix.versions.shopware }}_${{ matrix.versions.shopware-zip }}_${{ matrix.versions.mysql }}_${{ matrix.versions.php }}_${{ matrix.versions.consentManager }}
diff --git a/Dockerfile.twig b/Install_Dockerfile.twig
similarity index 89%
rename from Dockerfile.twig
rename to Install_Dockerfile.twig
index b817f88..78a829d 100644
--- a/Dockerfile.twig
+++ b/Install_Dockerfile.twig
@@ -31,6 +31,7 @@ RUN npm install --prefix ./themes && \
FROM ghcr.io/shopware5/docker-images-testing/running:shopware_{{ shopwareVersion }}_{{ mysqlVersion }}_{{ phpVersion }}
COPY --from="js-deps" /shopware /shopware
+COPY start-mysql.sh /shopware/start-mysql.sh
WORKDIR /shopware
@@ -45,11 +46,15 @@ ENV SW_BASE_PATH=
COPY debug_config.php /shopware/config.php.dist
+
+RUN ./start-mysql.sh \
+&& mysqladmin --user=root password 'root'
+
{% if shopwareVersion < 5.7 %}
RUN composer install
RUN sed -e "s/%db\.user%/${DB_USER}/g" -e "s/%db\.password%/${DB_PASSWORD}/g" -e "s/%db\.database%/${DB_NAME}/g" -e "s/%db\.host%/${DB_HOST}/g" -e "s/%db\.port%/${DB_PORT}/g" < config.php.dist > config.php
- RUN /bin/bash -c "/usr/bin/mysqld_safe --skip-grant-tables &" \
- && sleep 7 \
+ RUN ./start-mysql.sh \
+ && mysql -e "CREATE DATABASE shopware" \
&& php bin/console sw:database:setup --steps=drop,create,import,importDemodata \
&& php bin/console sw:cache:clear \
&& php bin/console sw:database:setup --steps=setupShop --shop-url="http://${SW_HOST}${SW_BASE_PATH}" \
@@ -61,12 +66,11 @@ COPY debug_config.php /shopware/config.php.dist
RUN npm install --prefix ./themes && npm install --prefix ./themes/Frontend/Responsive
{% else %}
- RUN /bin/bash -c "/usr/bin/mysqld_safe --skip-grant-tables &" && make init && make .make.install.npm-dependencies
+ RUN ./start-mysql.sh && mysql -e "CREATE DATABASE shopware" && make init && make .make.install.npm-dependencies
{% endif %}
{% if consentManagerRequired %}
- RUN /bin/bash -c "/usr/bin/mysqld_safe --skip-grant-tables &" \
- && sleep 7 \
+ RUN ./start-mysql.sh \
&& php bin/console sw:plugin:refresh \
&& php bin/console sw:plugin:install SwagCookieConsentManager
{% endif %}
diff --git a/Zip_Dockerfile.twig b/Zip_Dockerfile.twig
new file mode 100644
index 0000000..2e12a0c
--- /dev/null
+++ b/Zip_Dockerfile.twig
@@ -0,0 +1,68 @@
+{% set shopwareVersion = imageName|split('_')[1] %}
+{% set shopwareUrl = imageName|split('_').slice(2, 5).join('_') %}
+{% set mysqlVersion = imageName|split('_')[5] %}
+{% set phpVersion = imageName|split('_')[6] %}
+{% set consentManagerVersion = imageName|split('_')[7] %}
+{% set consentManagerRequired = consentManagerVersion != 'none' %}
+
+# Check out shopware source
+FROM alpine/git:latest AS clone
+
+RUN wget --header="User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_0) AppleWebKit/600.1.17 (KHTML, like Gecko)a Version/8.0 Safari/600.1.17" https://releases.shopware.com/{{ shopwareUrl }}.zip -O install.zip && unzip install.zip -d /shopware
+RUN cd /shopware
+
+{% if consentManagerRequired %}
+ RUN cd /shopware/custom/plugins && \
+ git clone https://github.com/shopware5/SwagCookieConsentManager.git SwagCookieConsentManager --depth=1 --branch={{ consentManagerVersion }}
+{% endif %}
+
+# Inherit files, install NodeJS-dependencies
+FROM node:10 AS js-deps
+
+COPY --from="clone" /shopware /shopware
+
+WORKDIR /shopware
+
+RUN npm install --prefix ./themes && \
+ npm install --prefix ./themes/Frontend/Resposnsive && \
+ touch .make.install.npm-dependencies
+
+
+FROM ghcr.io/shopware5/docker-images-testing/running:shopware_{{ shopwareVersion }}_{{ mysqlVersion }}_{{ phpVersion }}
+
+COPY --from="js-deps" /shopware /shopware
+COPY start-mysql.sh /shopware/start-mysql.sh
+
+
+WORKDIR /shopware
+
+ENV COMPOSER_ALLOW_SUPERUSER=1
+ENV DB_USER=root
+ENV DB_PORT=3306
+ENV DB_NAME=shopware
+ENV DB_HOST=127.0.0.1
+ENV DB_PASSWORD=root
+ENV SW_HOST=localhost
+ENV SW_BASE_PATH=
+
+
+RUN ./start-mysql.sh \
+&& mysqladmin --user=root password 'root'
+
+RUN ./start-mysql.sh \
+ && mysql -e "CREATE DATABASE shopware" \
+ && php recovery/install/index.php --db-port=${DB_PORT} --db-user=${DB_USER} --db-password=${DB_PASSWORD} --db-name=${DB_NAME} --shop-name=Demo --shop-host=${SW_HOST} --shop-path=${SW_BASE_PATH} --shop-locale=en_GB --admin-locale=en_GB --shop-currency=EUR --admin-username=demo --admin-password=demo --admin-name=Demo --admin-email=demo@demo.de --no-interaction
+
+{% if consentManagerRequired %}
+ RUN ./start-mysql.sh \
+ && php bin/console sw:plugin:refresh \
+ && php bin/console sw:plugin:install SwagCookieConsentManager
+{% endif %}
+
+COPY --chown="root:root" entrypoint.sh /entrypoint.sh
+
+RUN chown -R www-data:www-data /shopware
+
+ENTRYPOINT ["bash", "-c", "/entrypoint.sh"]
+
+{#RUN php bin/console sw:cache:clear#}
diff --git a/debug_config.php b/debug_config.php
index 3f2eb00..fbdeb40 100644
--- a/debug_config.php
+++ b/debug_config.php
@@ -14,7 +14,7 @@
],
'logger' => [
- 'level' => \Shopware\Components\Logger::DEBUG,
+ 'level' => 100,
],
'front' => [
diff --git a/makefile b/makefile
index 60f7a2e..f0ce1ae 100644
--- a/makefile
+++ b/makefile
@@ -13,8 +13,15 @@ running\:%:
-f ./running/Dockerfile ./running/
--progress=plain
+zip\:%:
+ node "twig.js" Zip_Dockerfile.twig "{\"imageName\": \"$@\"}" > Dockerfile
+ docker build --no-cache --progress=plain \
+ -t "ghcr.io/shopware5/docker-images-testing/$@" \
+ -f ./Dockerfile ./
+ --progress=plain
+
install\:%:
- node "twig.js" Dockerfile.twig "{\"imageName\": \"$@\"}" > Dockerfile
+ node "twig.js" Install_Dockerfile.twig "{\"imageName\": \"$@\"}" > Dockerfile
docker build \
-t "ghcr.io/shopware5/docker-images-testing/$@" \
-f ./Dockerfile ./
@@ -25,3 +32,7 @@ test\:%:
sleep 15s
curl http://localhost | grep "shopware"
+test-zip\:%:
+ docker run -d -p 80:80 "ghcr.io/shopware5/docker-images-testing/zip:$*"
+ sleep 15s
+ curl http://localhost | grep "shopware"
diff --git a/running/Dockerfile.twig b/running/Dockerfile.twig
index 6580fb2..978cc3f 100644
--- a/running/Dockerfile.twig
+++ b/running/Dockerfile.twig
@@ -62,17 +62,14 @@ RUN usermod -u 1000 www-data
RUN yes | apt install mariadb-server mariadb-client
{% endif %}
-
RUN curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
RUN sudo apt-get install -y nodejs
RUN echo "NODE Version:" && node --version
RUN echo "NPM Version:" && npm --version
-
RUN curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php
RUN php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer
-
COPY rootfs/ /
EXPOSE 80
WORKDIR /var/www/html
diff --git a/running/rootfs/etc/nginx/sites-enabled/default b/running/rootfs/etc/nginx/sites-enabled/default
new file mode 100644
index 0000000..ad3cde9
--- /dev/null
+++ b/running/rootfs/etc/nginx/sites-enabled/default
@@ -0,0 +1,12 @@
+server {
+ listen 80;
+
+ server_name localhost;
+ root /shopware;
+
+ set $shopware_env 'production';
+ set $fpm_upstream 127.0.0.1:9000;
+
+ ## Include shopware configuration.
+ include global/shopware.conf;
+}
diff --git a/running/rootfs/etc/supervisord.conf b/running/rootfs/etc/supervisord.conf
index 5bef157..15f06ad 100644
--- a/running/rootfs/etc/supervisord.conf
+++ b/running/rootfs/etc/supervisord.conf
@@ -17,7 +17,7 @@ stdout_logfile=/dev/stderr
stdout_logfile_maxbytes=0
[program:mysql]
-command=/usr/bin/mysqld_safe --skip-grant-tables
+command=/usr/bin/mysqld_safe --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin
redirect_stderr=true
stdout_logfile=/dev/stderr
stdout_logfile_maxbytes=0
diff --git a/start-mysql.sh b/start-mysql.sh
new file mode 100755
index 0000000..a8d01e4
--- /dev/null
+++ b/start-mysql.sh
@@ -0,0 +1,17 @@
+#!/usr/bin/env bash
+
+set -eu
+
+echo "Starting mysql server"
+/usr/bin/mysqld_safe --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql &
+
+while true; do
+ sleep 1
+
+ exit_code=0
+ mysql -e ";" 2> /dev/null || exit_code=$?
+ if [ "${exit_code}" -eq "0" ]; then
+ echo "Started mysql server"
+ exit
+ fi
+done