Sign inSign up

croneu/neos

By croneu

•Updated over 4 years ago

cron Development Docker Image for Neos

Image
0

10K+

croneu/neos repository overview

⁠croneu/neos⁠

⁠Abstract

Opinionated Docker Images for Neos⁠ Development.

⁠Compatibility

Currently the included images do support only newer Neos Versions, basically all versions which run with PHP 7.2 or PHP 7.3.

⁠Docker Images included

This repository builds two distinct Docker Images:

TagDescription
7.2PHP 7.2 based docker image, useful to run a Neos project in docker for development purposes.
7.2-behatPHP 7.2 based image with some add-ons for behat tests (supports also unattended use for e.g. circleCI/Travis)
7.3PHP 7.3 based docker image, useful to run a Neos project in docker for development purposes.
7.3-behatPHP 7.3 based image with some add-ons for behat tests (supports also unattended use for e.g. circleCI/Travis)

⁠Usage in a nutshell

Checkout your Neos Project in ./ and use a docker-compose.yml:

Note: make sure to put your GitHub Username (instead of your-github-user-name) using the IMPORT_GITHUB_PUB_KEYS env var in your docker-compose.yml file.

---
version: '3.7'

services:
  web:
    image: croneu/neos:7.3
    ports:
      - '8080:8080'
      - '1122:22'
    links:
      - db:db
    volumes:
      - data:/data
      # needed only for initial provisioning, if REPOSITORY_URL not set
      - .:/src/
    environment:
      WWW_PORT: 8080
      ADMIN_PASSWORD: 'password'
      IMPORT_GITHUB_PUB_KEYS: 'my-github-username'
      #IMPORT_GITLAB_PUB_KEYS: 'my-gitlab-username'
      #GITLAB_URL: 'https://gitlab.my-company.org'
  db:
    image: mariadb:latest
    expose:
      - 3306
    volumes:
      - /var/lib/data
    environment:
      MYSQL_DATABASE: 'db'
      MYSQL_USER: 'admin'
      MYSQL_PASSWORD: 'pass'
      MYSQL_RANDOM_ROOT_PASSWORD: 'yes'

volumes:
  data:

networks:
  default:

Run docker-compose up:

docker-compose up -d

You can monitor the container logs, for example for the web container, where interesting things happen, with:

docker-compose logs -f web
⁠Web Server

The web container will start a web-server listening on WWW_PORT. To access the web-server, make sure you have a DNS entry in your local /etc/hosts or local DNS server, e.g. (when using docker-machine):

/etc/hosts:

192.168.99.100 dev.neos-playground.docker neos-playground.docker

Then you can access the web-server using:

open http://dev.neos-playground.docker:8080/

To use the Production FLOW_CONTEXT, use the second hostname (without `dev.``):

open http://neos-playground.docker:8080/
⁠FLOW_CONTEXT magic

FLOW_CONTEXT will be set to Production by default. For development purposes, use a host name with a dev subdomain, like dev., this will use the Development context instead:

Hostname PatternFLOW_CONTEXT
dev.*Development
dev.behat.*Development/Behat
elseProduction
⁠SSH Access

You can then SSH into the container using for example:

ssh -A -p 1122 www-data@$(docker-compose ip $DOCKER_MACHINE_NAME)

Then you can run the flow CLI and do stuff:

$ flow
Neos 3.3.21 ("Development" context)
usage: ./flow <command identifier>

See "./flow help" for a list of all available commands.

⁠Behat Support

To run Behat Tests, an additional Docker Image is provided. To use this additional image, use a docker-compose overlay, e.g. docker-compose.behat.yml:

version: '3.1'

services:
  web:
    # use the neos-alpine behat image instead of the default one
    image: croneu/neos:7.3-behat
    hostname: behat-runner
    ports:
      - '5900:5900'
    environment:
      # use a separate DB container for testing
      DB_HOST: db-test
      DB_DATABASE: db

  db-test:
    image: mariadb:latest
    expose:
      - 3306
    volumes:
      - /var/lib/data
    environment:
      MYSQL_DATABASE: 'db'
      MYSQL_USER: 'admin'
      MYSQL_PASSWORD: 'pass'
      MYSQL_RANDOM_ROOT_PASSWORD: 'yes'

Then you can use this overlay to run docker-compose, e.g.:

alias docker-compose="docker-compose -f docker-compose.yml -f docker-compose.behat.yml"
docker-compose up -d

This will tweak the (existing) web container to use the Behat Image and also create a separate DB instance for testing purposes.

Docker-Compose will also setup behat correctly and also create behat.yml configuration files based on existing behat.yml.dist found in the codebase (see /setup-behat-yml.sh shell script for technical details).

To run Behat Tests, SSH into the web container as usual and run behat, e.g.:

$ behat Features/EventLog/Entities/AccountsUsers.feature
Feature: Accounts / User Entity Monitoring
  As an API user of the history
  I expect that adding/updating/deleting an account or party triggers history updates

  Background:                                                   # Features/EventLog/Entities/AccountsUsers.feature:5
    Given I have an empty history                               # FeatureContext::iHaveAnEmptyHistory()
    Given I have the following "monitorEntities" configuration: # FeatureContext::iHaveTheFollowingMonitorEntitiesConfiguration()
      """
      'Neos\Flow\Security\Account':
        events:
          created: ACCOUNT_CREATED
        data:
          accountIdentifier: '${entity.accountIdentifier}'
          authenticationProviderName: '${entity.authenticationProviderName}'
          expirationDate: '${entity.expirationDate}'
          party: '${entity.party.name.fullName}'
      'Neos\Neos\Domain\Model\User':
        events:
          created: PERSON_CREATED
        data:
          name: '${entity.name.fullName}'
          primaryElectronicAddress: '${entity.primaryElectronicAddress}'
      """

  @fixtures
  Scenario: Creating an account is monitored                    # Features/EventLog/Entities/AccountsUsers.feature:27
    When I create the following accounts:                       # FeatureContext::iCreateTheFollowingAccounts()
      | User  | Password | First Name | Last Name | Roles                   |
      | admin | password | Sebastian  | Kurfuerst | Neos.Neos:Administrator |
    Then I should have the following history entries:           # FeatureContext::iShouldHaveTheFollowingHistoryEntries()
      | Event Type      |
      | PERSON_CREATED  |
      | ACCOUNT_CREATED |

1 scenario (1 passed)
4 steps (4 passed)
0m1.796s
⁠Behat unattended use

You can also supply a command for the web container and the container will do its initialization, run this command and exits. Useful to run behat from circleCI.

See the .circleci/config.yml file for how we did that for our tests.

⁠Advanced Configuration Options

This image supports following environment variable for automatically configuring Neos at container startup:

Docker env variableDescription
WWW_PORTTCP port on which the container will serve incoming HTTP requests, defaults to 80.
REPOSITORY_URLLink to Neos website distribution
SITE_INIT_SCRIPTIf set, a path (relative to SITE_PACKAGE folder) to a bash script which will be called (synchronously) after the container is ready but prior to nginx. Note that this script will be executed as user www-data (and not root!)
VERSIONGit repository branch, commit SHA or release tag, defaults to master
SITE_PACKAGENeos website package with exported website data to be imported, optional
ADMIN_PASSWORDIf set, would create a Neos admin user with such password, optional
AWS_BACKUP_ARNAutomatically import the database from ${AWS_RESOURCES_ARN}db.sql on the first container launch. Requires AWS_ACCESS_KEY, AWS_SECRET_ACCESS_KEY and AWS_ENDPOINT (optional, for S3-compatible storage) to be set in order to work.
COMPOSER_INSTALL_PARAMScomposer install parameters, defaults to --prefer-dist --no-progress
COMPOSER_MAJOR_VERSIONdefault will use the latest (2), but you can use "1" to use the older version
XDEBUG_ENABLED0 to disable the Xdebug extension (default, if XDEBUG_CONFIG is also not defined), 1 to enabled it
XDEBUG_CONFIGPass Xdebug config string, e.g. idekey=PHPSTORM remote_enable=1
IMPORT_GITHUB_PUB_KEYSWill pull authorized keys allowed to connect to this image from your Github account(s).
IMPORT_GITLAB_PUB_KEYSWill pull authorized keys allowed to connect to this image from your Gitlab account(s). Note: please also setup the GITLAB_URL ENV var, else this will throw an error.
GITLAB_URLYour HTTPS Gitlab Server URL, e.g. https://gitlab.my-company.com⁠ (without the trailing /)
DB_DATABASEDatabase name, defaults to db
DB_HOSTDatabase host, defaults to db
DB_PASSDatabase password, defaults to pass
DB_USERDatabase user, defaults to admin
AWS_PROFILEaws profile to use when configuring the aws cli
AWS_REGIONaws region
AWS_ACCESS_KEY_IDaws access key
AWS_SECRET_ACCESS_KEYaws secret key

⁠Provisioning Process

For initial privisioning the container, you can use the REPOSITORY_URL ENV var. If so, the initialization logic will perform a git clone.

Another alternative is to use a Docker mount or volume. Mount the source dir to /src and make sure not to set the REPOSITORY_URL. Then the init logic will just rsync -a from /src to /data/www-provisioned instead.

⁠Using Xdebug with Flow / Neos

Use the flow-debugproxy⁠ to be able to set breakpoints in PhpStorm in the original files, while the real process inside the container uses the flow generated "proxy classes".

Add this to your projects docker-compose.yml:

services:

  # this is your application container
  web:
    environment:
      XDEBUG_ENABLED: "1"
      XDEBUG_CONFIG: "remote_host=debugproxy"
    links:
      - debugproxy

  # this is the additional proxy where xdebug will connect to
  debugproxy:
    image: dfeyer/flow-debugproxy:latest
    volumes:
      # make sure the proxy has access to the same files as the web container:
      - data:/data
    environment:
      # the IP of your local host (i.e. Mac) - see also https://github.com/devilbox/xdebug
      #- "IDE_IP=172.18.0.1"
      - "IDE_IP=10.254.254.254"

      # This is the default value, need to match the xdebug.remote_port on your php.ini
      - "XDEBUG_PORT=9010"

      # Use this to enable verbose debugging on the proxy
      #- "ADDITIONAL_ARGS=--vv --debug"

⁠Docker Image Development

make build

This will create both images from scratch

⁠Create a build for a specific PHP Version

Use the available targets in the Makefile, e.g.

make build-7.3

Important note: There is no automation on Docker Hub to build Docker Images other than latest. Use the push-* targets in the Makefile to push the images to Docker Hub.

docker login
make push-7.3
⁠Test the Docker Image

To test the image you can use the supplied docker-compose files in the example directory. For example, to run a behat enabled environment using the official Neos Distribution Package, do:

cd example
docker-compose -f docker-compose.yml -f docker-compose.behat.yml up -d
# ssh-keygen -R \[$(docker-machine ip $DOCKER_MACHINE_NAME)\]:1122
ssh www-data@$(docker-machine ip $DOCKER_MACHINE_NAME) -p 1122

Inside the docker container, run this simple behat test:

cd Packages/Neos/Neos.Neos/Tests/Behavior
behat Features/ExportImport.feature

⁠MIT Licence

See the LICENSE⁠ file.

⁠Author

Remus Lazar (rl@cron at eu)

Tag summary

Content type

Image

Digest

Size

129.8 MB

Last updated

almost 6 years ago

docker pull croneu/neos