Skip to content

Commit

Permalink
ci(SW-27127): add docker container for zips (#42)
Browse files Browse the repository at this point in the history
* ci(SW-27127): add docker container for zips

* ci(SW-27127): push branches only on main branch
  • Loading branch information
PascalThesing authored Jul 18, 2023
1 parent 52ffe2b commit 2d05cac
Show file tree
Hide file tree
Showing 12 changed files with 178 additions and 13 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/setup-current-shopware.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ on:
- cron:
'0 0 * * *'
push:
branches:
- main

jobs:
setup-shopware:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/setup-old-shopware.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Setup older Shopware Version

on:
workflow_dispatch:
push:

jobs:
setup-shopware:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/setup-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}

55 changes: 55 additions & 0 deletions .github/workflows/setup-zip.yml
Original file line number Diff line number Diff line change
@@ -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 }}
14 changes: 9 additions & 5 deletions Dockerfile.twig → Install_Dockerfile.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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}" \
Expand All @@ -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 %}
Expand Down
68 changes: 68 additions & 0 deletions Zip_Dockerfile.twig
Original file line number Diff line number Diff line change
@@ -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#}
2 changes: 1 addition & 1 deletion debug_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
],

'logger' => [
'level' => \Shopware\Components\Logger::DEBUG,
'level' => 100,
],

'front' => [
Expand Down
13 changes: 12 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./
Expand All @@ -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"
3 changes: 0 additions & 3 deletions running/Dockerfile.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions running/rootfs/etc/nginx/sites-enabled/default
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 1 addition & 1 deletion running/rootfs/etc/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions start-mysql.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2d05cac

Please sign in to comment.