Git Product home page Git Product logo

platform-plugin-dev-docker's Introduction

What is this?

A docker image with preinstalled Shopware 6, without a webserver, but including some helper tools. These images are meant to be useful for debugging Shopware plugins or running plugin tasks in CI with different Shopware versions.

Available Docker image tags

We provide a tag for each minor Shopware 6 release, which should always point to the latest patch release, e.g:

v6.3.0
v6.3.1
v6.3.2
v6.3.3

Available scripts and commands

Inside the Docker container you can use the following commands

plugin-uploader

For more information see the offical documentation of the plugin uploader.

start-mysql

Simple script which will start the mysql server and return 0 if it was successfully started.

pack-plugin <plugin name>

This command will install the plugin with <plugin name> and compile all JavaScript files needed for the storefront and the administration. If the environment variable SHOPWARE_ROOT is set, this will be used as alternative Shopware location, otherwise if this variable is empty, the default Shopware setup from this image /opt/shopware will be used.

Make sure that the plugin folder is present in ${SHOPWARE_ROOT}/custom/plugins/. If you use the default SHOPWARE_ROOT you can place them in /plugins.

pack-app <app name>

This command will install the app with <app name> and compile all JavaScript files needed for the storefront. If the environment variable SHOPWARE_ROOT is set, this will be used as alternative Shopware location, otherwise if this variable is empty, the default Shopware setup from this image /opt/shopware will be used.

Make sure that the app folder is present in ${SHOPWARE_ROOT}/custom/apps/. If you use the default SHOPWARE_ROOT you can place them in /apps.

Build Docker image for specific Shopware version

It is possible to specify the Shopware version or even the template with the Docker option --build-arg, e.g.:

docker build --build-arg SHOPWARE_VERSION=6.3 . -t platform-plugin-dev:6.3

In the same way it is also possible to specify the template Git repository URL:

docker build --build-arg SHOPWARE_VERSION=6.3 \
    --build-arg TEMPLATE_REPOSITORY='https://github.com/FriendsOfShopware/production' \
    . -t platform-plugin-dev:6.3

Examples

Pack Plugin in .gitlab-ci.yml

build:pack-plugin:
  image:
    name: ghcr.io/friendsofshopware/platform-plugin-dev:v6.3.1
    entrypoint: [""]
  script:
    - start-mysql
    - ln -s "$(pwd)" "/plugins/${CI_PROJECT_NAME}"
    - pack-plugin "${CI_PROJECT_NAME}"
    - plugin-uploader ext:validate "$(realpath "${CI_PROJECT_NAME}.zip")"
  artifacts:
    paths:
      - "${CI_PROJECT_NAME}.zip"
    expire_in: 1 week

Pack App in .gitlab-ci.yml

build:pack-app:
  image:
    name: ghcr.io/friendsofshopware/platform-plugin-dev:v6.4.7
    entrypoint: [""]
  script:
    - start-mysql
    - ln -s "$(pwd)" "/apps/${CI_PROJECT_NAME}"
    - rm -rf "/apps/${CI_PROJECT_NAME}/store" # Remove the store folder manually since it is not removed in the pack process for apps
    - pack-app "${CI_PROJECT_NAME}"
    - plugin-uploader ext:validate "$(realpath "${CI_PROJECT_NAME}.zip")" || true
  artifacts:
    paths:
      - "${CI_PROJECT_NAME}.zip"
    expire_in: 1 week

PHPUnit tests

The docker images contains phpunit constrained via the Shopware composer.json. Additionally a TestBootstrapper is included, either the one from the Shopware repository or a fallback one for Shopware versions < 6.4.5.0. This can be utilized inside your plugin (e.g. in tests/TestBootstrap.php)

<?php declare(strict_types=1);

use Shopware\Core\TestBootstrapper;

$testBootstrapper = null;
if (is_readable('/opt/share/shopware/tests/TestBootstrapper.php')) {
    // For Docker image: ghcr.io/friendsofshopware/platform-plugin-dev
    $testBootstrapper = require '/opt/share/shopware/tests/TestBootstrapper.php';
} else {
    // Create your own TestBootstrapper
}

return $testBootstrapper
    ->setLoadEnvFile(true)
    ->setForceInstallPlugins(true)
    ->addActivePlugins('MyTechnicalPluginName')
    ->bootstrap()
    ->getClassLoader()
;

The associate phpunit.xml.dist would than look something like

<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
         backupGlobals="false"
         colors="true"
         bootstrap="tests/TestBootstrap.php"
         cacheResult="false">
    <coverage processUncoveredFiles="true">
        <include>
            <directory suffix=".php">src</directory>
        </include>
    </coverage>
    <php>
        <ini name="error_reporting" value="-1"/>
        <server name="APP_ENV" value="test" force="true"/>
        <env name="APP_DEBUG" value="1"/>
        <env name="APP_SECRET" value="s$cretf0rt3st"/>
        <env name="SHELL_VERBOSITY" value="-1"/>
        <env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled" />
    </php>
    <testsuites>
        <testsuite name="MyTechnicalPluginName">
            <directory>tests</directory>
        </testsuite>
    </testsuites>
</phpunit>

Locally execute the tests using the provided docker images, assuming you are currently inside the plugin directory

docker run --rm -it -v "${PWD}:/plugins/MyTechnicalPluginName" ghcr.io/friendsofshopware/platform-plugin-dev:v6.4.0 sh -c 'start-mysql && cd /plugins/MyTechnicalPluginName && phpunit'

Run the tests in .gitlab-ci.yml

test:phpunit:
  stage: test
  image:
    name: ghcr.io/friendsofshopware/platform-plugin-dev:${SHOPWARE_VERSION}
    entrypoint: [""]
  script:
    - start-mysql
    - ln -s "$(pwd)" "/plugins/${CI_PROJECT_NAME}"
    - phpunit
  parallel:
    matrix:
      - SHOPWARE_VERSION: ['v6.4.0', 'v6.4.5', 'v6.4.10', 'v6.4.15']

platform-plugin-dev-docker's People

Contributors

aragon999 avatar cngjo avatar marggx avatar powli avatar shyim avatar tanzb33r avatar tinect avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.