ibexa/docker

Ibexa DXP 的 Docker 文件

维护者

详细信息

github.com/ibexa/docker

源代码

问题

安装数: 221,198

依赖者: 0

建议者: 0

安全性: 0

星标: 0

关注者: 14

分支: 5

开放问题: 2

语言:Roff


README

此软件包包含用于 Ibexa 的某些自动化功能测试基础设施的不受支持的 Docker 构建块。您可自由复制用于个人使用或参考推荐的设置。

请注意以下限制

警告,主要针对自动化: 此目录中的工具旨在用于测试自动化、质量保证、支持和演示用例,以及作为如何最佳配置您自己的设置的蓝图。您可自由使用和采用它们以满足您的需求,我们非常欢迎贡献以改进它。

警告,在 MacOS 和 Windows 上的性能较低: 由于上述原因,这些工具未针对在 MacOS 或 Windows 上作为开发环境使用进行优化,并且受到 Docker for MacOS/Windows 使用共享文件夹导致的已知 I/O 性能问题的影响。这是一个已知问题,我们无意增加复杂性来绕过它。

概览

此设置目前需要 Docker Compose 1.14 和 Docker 17.06 或更高版本。默认设置在 .env 中设置,要忽略的文件在 .dockerignore 中设置。默认情况下,.env 指定使用开发设置。

注意: 由于此原因以及其他原因,所有 docker-compose 命令 必须 从您的项目目录的根目录执行。

开始之前:安装 Docker & Docker-Compose

在执行以下步骤之前,请确保您已在您的机器上安装了最新版本的 Docker 和 Docker Compose

对于 Windows,您还需要 安装 bash,或者根据需要调整以下针对 Windows 命令行的说明。

概念:Ibexa DXP 的 Docker Compose "构建块"

当前的 Docker Compose 文件是为了混合和匹配用于 QA/支持用例而制作的。目前可用

  • base-prod.yml(必需,始终需要首先使用,包含:数据库、Web 和应用程序容器)
  • base-dev.ymlbase-prod.yml 的替代方案,如果使用则适用相同规则)
  • create-dataset.yml(可选,与 base-prod.yml 一起使用,用于设置数据库和 vardir)
  • demo.yml(可选,与 base-prod.yml 一起使用,用于设置数据库和 vardir)
  • dfs.yml(可选,添加 DFS 集群处理器。注意,您需要手动运行迁移脚本,请参见以下内容)
  • blackfire.yml(可选,添加 Blackfire 服务并允许您针对设置触发分析)
  • redis.yml(可选,添加 Redis 服务并将配置追加到应用程序)
  • redis-session.yml(可选,将会话存储在单独的 Redis 实例中)
  • varnish.yml(可选,添加 Varnish 服务并将配置追加到应用程序)
  • solr.yml(可选,添加 Solr 服务并配置应用程序)
  • db-postgresql.yml(可选,将数据库引擎切换到 PostgreSQL - 实验)
  • selenium.yml(可选,始终需要最后使用,添加 Selenium 服务并将配置追加到应用程序)
  • chromium.ymlselenium.yml 的替代方案,添加无头 Chrome 服务,如果使用则适用相同规则。实验性)
  • multihost.yml(可选,向应用程序容器网络添加多主机配置)

您可以使用这些文件,在 docker-compose 中使用 -f 参数,例如:

docker-compose -f doc/docker/base-prod.yml -f doc/docker/create-dataset.yml -f doc/docker/demo.yml -f doc/docker/redis.yml up -d --force-recreate

但是,以下环境变量 COMPOSE_FILE 被使用,因为这也是在项目根目录下 .env 文件中的默认值。

项目设置

示例 "image" 使用

使用这种方法,所有内容都在容器和卷中运行。这意味着,如果您例如使用 Ibexa DXP 后端上传一个图像,该图像最终会出现在卷中,而不是在您的项目目录下的 public/var/ 之下。

从您项目的克隆副本的根目录开始,设置 composer auth.json 并执行以下操作:

export COMPOSE_FILE=doc/docker/base-prod.yml:doc/docker/create-dataset.yml:doc/docker/demo.yml

# Optional step if you want to use Blackfire with the setup, change <id> and <token> with your own values
#export COMPOSE_FILE=doc/docker/base-prod.yml:doc/docker/create-dataset.yml:doc/docker/demo.yml:doc/docker/blackfire.yml BLACKFIRE_SERVER_ID=<id> BLACKFIRE_SERVER_TOKEN=<token>

# First time: Install setup, and generate database dump:
docker-compose -f doc/docker/install-dependencies.yml -f doc/docker/install-database.yml up --abort-on-container-exit

# Optionally, build dbdump and vardir images.
# The dbdump image is created based on doc/docker/entrypoint/mysql/2_dump.sql which is created by above command
# The vardir image is created based on the content of public/var
# If you don't build these image explicitly, they will automaticly be builded later when running `docker-compose up`
docker-compose build dataset-vardir dataset-dbdump

# Boot up full setup:
docker-compose up -d --force-recreate

大约 5-10 秒后,您应该能够在 localhost:8080 上浏览网站,并在 localhost:8080/admin 上访问后端。

开发 "mount" 使用

当您使用这种方法时,您的项目目录将被绑定到 Nginx 和 PGP 容器中。如果您在例如 src 中更改 PHP 文件,该更改将自动应用。

警告:Dev 设置在 Linux 上的运行速度比在 Windows/Mac 上快得多,因为在 Windows/Mac 上,Docker 默认使用具有共享文件夹的虚拟机,这导致 IO 性能大大降低。

从您项目的克隆副本的根目录开始,设置 composer auth.json 并执行以下操作:

# Optional: If you use Docker Machine with NFS, you'll need to specify where project is, & give composer a valid directory.
#export COMPOSE_DIR=/data/SOURCES/MYPROJECTS/ezplatform/doc/docker COMPOSER_HOME=/tmp

# First time: Install setup, and generate database dump:
docker-compose -f doc/docker/install-dependencies.yml -f doc/docker/install-database.yml up --abort-on-container-exit

# Boot up full setup:
docker-compose up -d --force-recreate

大约 5-10 秒后,您应该能够在 localhost:8080 上浏览网站,并在 localhost:8080/admin 上访问后端。

提示:如果您看到 500 错误,或者在 APP_ENV=dev 的情况下数据库异常,请确保在 app/config/parameters.yml 中注释掉 database_* 参数,以确保环境变量被正确使用。

Behat 和 Selenium 使用

Behat 使用的 Docker Compose 设置已提供并用于内部测试 Ibexa DXP。它可以与大多数设置一起使用,这里显示了与生产设置的组合,这是在将镜像推送到 Docker Hub/Registry 之前通常需要测试的内容。

从您项目的克隆副本的根目录开始,设置 composer auth.json 并执行以下操作:

export COMPOSE_FILE=doc/docker/base-prod.yml:doc/docker/selenium.yml

# First time: Install setup, and generate database dump:
docker-compose -f doc/docker/install-dependencies.yml -f doc/docker/install-database.yml up --abort-on-container-exit

# Boot up full setup:
docker-compose up -d --force-recreate

最后一步是使用具有对 web 和 Selenium 容器访问权限的 app 容器执行 Behat 场景,例如:

docker-compose exec --user www-data app sh -c "php /scripts/wait_for_db.php; php bin/behat -vv --profile=rest --suite=fullJson --tags=~@broken"

提示:您通常可以使用以下命令重新运行安装命令,以在 Behat 运行之间回到干净安装:

docker-compose exec --user www-data app php bin/console ibexa:install

注意:如果您想使用 Chromium 驱动程序,请使用:

export COMPOSE_FILE=doc/docker/base-prod.yml:doc/docker/chromium.yml

此驱动程序在我们的测试套件中尚未完全支持,处于实验状态。

DFS

如果您想使用 DFS 集群处理器,则需要手动运行迁移脚本,在启动容器之后(首先运行 docker-compose up -d --force-create)。

迁移脚本将公共/ var 中的二进制文件复制到 nfs 挂载点(./dfsdata),并将文件的元数据添加到数据库中。如果您打算在集群中运行 Ibexa DXP,那么您必须确保 ./dfsdata 是每个节点/应用容器上的挂载 nfs 共享。

# Enter the app container
docker-compose exec --user www-data app /bin/bash

# Inside app container
php app/console ezplatform:io:migrate-files --from=default,default --to=dfs,nfs --env=prod

完成此操作后,如果您永远不会再次运行迁移脚本,则可以删除 public/var/*

生产使用

示例:使用 php 图像构建应用

在这个示例中,我们将构建一个包含 php(php_fpm)和 Ibexa DXP 应用程序的应用程序镜像,并使用 docker stack 在一个集群中运行它们。

先决条件

  • 一个正在运行的 swarm 集群(一个节点集群就足够运行此示例了)
  • 一个正在运行的 NFS 服务器。如何配置 nfs 服务器取决于发行版,但这个 ubuntu 指南 可能会有所帮助
  • 一个正在运行的 docker registry(如果您的 swarm 集群有多个节点,则此为必需项)

在这个示例中,我们假设您的 swarm 管理器名为 swarmmanager,并且该主机名在所有 swarm 主机上都可以解析。我们还假设 nfs 服务器和 docker registry 都在 swarmmanager 上运行。

以下所有命令应在您的 swarmmanager 上执行

# If not already done, install setup, and generate database dump :
docker-compose -f doc/docker/install-dependencies.yml -f doc/docker/install-database.yml up --abort-on-container-exit

# Build docker_app and docker_web images ( php and nginx )
docker-compose -f doc/docker/base-prod.yml build --no-cache app web

# Build varnish image
docker-compose -f doc/docker/base-prod.yml -f doc/docker/varnish.yml build --no-cache varnish

# Create dataset images ( my-ez-app-dataset-dbdump and my-ez-app-dataset-vardir )
# The dataset images contains a dump of the database and a dump of the var/ files ( located in public/var )
docker-compose -f doc/docker/create-dataset.yml build --no-cache

# Tag the images
docker tag docker_dataset-dbdump swarmmanager:5000/my-ez-app/dataset-dbdump
docker tag docker_dataset-vardir swarmmanager:5000/my-ez-app/dataset-vardir
docker tag docker_web swarmmanager:5000/my-ez-app/web
docker tag docker_app swarmmanager:5000/my-ez-app/app
docker tag docker_varnish swarmmanager:5000/my-ez-app/varnish

# Upload the images to the registry ( only needed if your swarm cluster has more than one node)
docker push swarmmanager:5000/my-ez-app/dataset-dbdump
docker push swarmmanager:5000/my-ez-app/dataset-vardir
docker push swarmmanager:5000/my-ez-app/web
docker push swarmmanager:5000/my-ez-app/app
docker push swarmmanager:5000/my-ez-app/varnish

# In this example we run the database in a separate stack so that you may easily have multiple Ibexa DXP installations using the same database instance
docker stack deploy --compose-file doc/docker/db-stack.yml stack-db

# Now, wait a half a minute to ensure that the database is ready to accept incomming requests before continuing

# Now, load the database dump into the db and the var dir to the nfs server
docker-compose -f doc/docker/import-dataset.yml up

# Finally, create the Ibexa DXP stack
docker stack deploy --compose-file doc/docker/my-ez-app-stack.yml my-ez-app-stack

# Cleanup
# If you want to remove the stacks again:
docker stack rm my-ez-app-stack
sleep 15
docker stack rm stack-db
sleep 15
docker volume rm my-ez-app-stack_vardir
docker volume rm stack-db_mysql

示例:分离应用程序和PHP

在这种运行Ibexa DXP的替代方式中,Ibexa DXP代码和PHP可执行文件被分离到两个不同的镜像中。这样做的好处是,可以更容易地独立于Ibexa DXP升级PHP(或任何其他发行版应用程序)。要实现这一点,只需替换为更新后的PHP容器,而无需重新构建Ibexa DXP镜像。这种方法的缺点是将所有Ibexa DXP代码复制到卷中,以便与其他容器共享。这意味着磁盘空间占用更大,容器的加载时间更长。此外,这种方法与docker stack一起使用更为复杂,因此仅提供了一个docker-compose示例。

export COMPOSE_FILE=doc/docker/base-prod.yml:doc/docker/create-dataset.yml:doc/docker/distribution.yml
# If not already done, install setup, and generate database dump :
docker-compose -f doc/docker/install-dependencies.yml -f doc/docker/install-database.yml up --abort-on-container-exit

# Build docker_app and docker_web images ( php and nginx )
# The docker_app image (which contain both php and Ibexa DXP) will be used as base image when creating the image which
# only contains the Ibexa DXP Platform files.
docker-compose -f doc/docker/base-prod.yml build --no-cache app

# Optional, only build the images, do not create containers
docker-compose build --no-cache distribution

# Note that if you set the environment variable COMPOSE_PROJECT_NAME to a non-default value, you'll need to use set the
# build argument DISTRIBUTION_IMAGE when building the distribution image
docker-compose build --no-cache --build-arg DISTRIBUTION_IMAGE=customprojectname_app distribution

# Build the "distribution" and dataset images, then start the containers
docker-compose up -d

更多信息

配置Composer

为了使Composer作为构建过程的一部分正确运行,您需要在项目根目录中创建一个auth.json文件,并包含您的GitHub只读令牌。

echo "{\"github-oauth\":{\"github.com\":\"<readonly-github-token>\"}}" > auth.json
# If you use Ibexa Content,Experiece or Commerce also include your updates.ibexa.co auth token
echo "{\"github-oauth\":{\"github.com\":\"<readonly-github-token>\"},\"http-basic\":{\"updates.ibexa.co\": {\"username\":\"<installation-key>\",\"password\":\"<token-pasword>\",}}}" > auth.json

有关更新.ibexa.co令牌的更多信息,请参阅安装指南

调试

要检查容器本身的日志,请使用docker-compose logs。这里针对app服务,但可以省略以获取所有日志。

docker-compose logs -t app

您可以使用docker-compose exec登录到任何服务,这里以app镜像和bash为例。

docker-compose exec app /bin/bash

要显示正在运行的服务

docker-compose ps

数据库转储

数据库转储放在doc/docker/entrypoint/mysql/。此文件夹由mysql/mariadb使用,执行文件夹内的所有操作。这意味着在任何给定时间,文件夹中只能有一个表示一个安装的数据。

更新服务镜像

要更新使用的服务镜像,您可以运行

docker-compose pull --ignore-pull-failures

这假设您使用了docker-compose -f,或者在使用默认值以外的.env中定义了COMPOSE_FILE

之后,您可以重新运行生产或开发步骤,以使用更新后的镜像设置容器。

清理

一旦您完成设置,您可以停止它,并删除涉及的容器。

docker-compose down -v

如果您已定义任何环境变量,您可以使用以下方法取消设置

unset COMPOSE_FILE COMPOSE_DIR COMPOSER_HOME

# To unset blackfire variables
unset BLACKFIRE_SERVER_ID BLACKFIRE_SERVER_TOKEN

版权

版权(C)1999-2024 Ibexa AS(以前称为eZ Systems AS)。保留所有权利。

许可证

此源代码可在以下许可证下单独获得

A - Ibexa商业使用许可协议(Ibexa BUL),版本2.4或更高版本(许可证条款可能随时更新)Ibexa BUL通过拥有有效的Ibexa DXP(以前称为eZ Platform Enterprise)订阅获得,如此处所述。有关完整的Ibexa BUL许可证文本,请参阅

B - GNU通用公共许可证,版本2授予一个绝对没有担保的版权开源许可证。有关完整的GPL许可证文本,请参阅