在 Github actions/workflows 中使用 ddev

using ddev in Github actions/workflows

我使用 ddev 设置了验收测试。他们在 ddev composer cookieman:test 本地获得 运行。我想对 Github 操作使用相同的设置。

在 Github actions/workflow 中有人对 ddev 有好感吗?我一直到这里 ddev 的健康检查失败:

...
Creating ddev-router ... done

Failed to start extension-cookieman-master: ddev-router failed to become ready: logOutput=2019/11/15 02:24:19 [emerg] 1630#1630: no servers are inside upstream in /etc/nginx/conf.d/default.conf:89
nginx: [emerg] no servers are inside upstream in /etc/nginx/conf.d/default.conf:89
nginx: configuration file /etc/nginx/nginx.conf test failed
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (22) The requested URL returned error: 404 Not Found
ddev-router healthcheck endpoint not responding 
, err=container /ddev-router unhealthy: 2019/11/15 02:24:19 [emerg] 1630#1630: no servers are inside upstream in /etc/nginx/conf.d/default.conf:89
nginx: [emerg] no servers are inside upstream in /etc/nginx/conf.d/default.conf:89
nginx: configuration file /etc/nginx/nginx.conf test failed
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (22) The requested URL returned error: 404 Not Found
ddev-router healthcheck endpoint not responding 

##[error]Process completed with exit code 1.

.github/workflows/tests.yml:

name: Tests
on: [push, pull_request]
jobs:
    tests-via-ddev:
        runs-on: ubuntu-latest
        steps:
            -   uses: actions/checkout@v1
            -   run: export DEBIAN_FRONTEND=noninteractive
            # update docker
            -   run: sudo -E apt-get purge -y docker docker-engine docker.io containerd runc nginx
            -   run: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
            -   run: sudo -E add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
            -   run: sudo -E apt-get update
            -   run: sudo -E apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce
            # install linuxbrew
            -   run: sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)"
            -   run: echo "::add-path::/home/linuxbrew/.linuxbrew/bin"
            # install ddev + docker-compose
            -   run: brew tap drud/ddev && brew install ddev docker-compose
            # Start ddev
            -   run: ddev start || exit 0
            # Debug
            -   run: ls -als .ddev/
            -   run: curl 127.0.0.1 || exit 0
            -   run: curl 127.0.0.1/healthcheck || exit 0
            -   run: docker ps || exit 0
            # we want Clover coverage
            -   run: ddev exec enable_xdebug
            # Run tests
            -   run: ddev composer cookieman:test

我试过了

如果我强制它继续 ddev start || exit 0 我可以看到容器启动并且 运行ning:

- run: docker ps || exit 0
CONTAINER ID        IMAGE                                   COMMAND                  CREATED             STATUS                      PORTS                                                                                                    NAMES
c36601a06fd6        drud/ddev-router:v1.11.0                "/app/docker-entrypo…"   27 seconds ago      Up 24 seconds (unhealthy)   0.0.0.0:4430->4430/tcp, 0.0.0.0:4444->4444/tcp, 0.0.0.0:8025->8025/tcp, 80/tcp, 0.0.0.0:8080->8080/tcp   ddev-router
18152602a054        drud/ddev-webserver:v1.11.0-built       "/start.sh"              30 seconds ago      Up 28 seconds (healthy)     8025/tcp, 127.0.0.1:32770->80/tcp, 127.0.0.1:32769->443/tcp                                              ddev-extension-cookieman-master-web
33aca55715f2        selenium/standalone-chrome:3.12         "/opt/bin/entry_poin…"   32 seconds ago      Up 30 seconds               4444/tcp                                                                                                 ddev-extension-cookieman-master-chrome
6c852ae62974        drud/ddev-dbserver:v1.11.0-10.2-built   "/docker-entrypoint.…"   32 seconds ago      Up 30 seconds (healthy)     127.0.0.1:32768->3306/tcp                                                                                ddev-extension-cookieman-master-db

curl 127.0.0.1 生成默认的 nginx 起始页(而我期望“503:没有可用的 ddev 后端站点”)

curl 127.0.0.1/healthcheck 产生 404

到目前为止,我的结论是:ddev-router 是可访问的,但它的 nginx 没有适当的配置(/etc/nginx/conf.d/default.conf 中的上游没有服务器)。因此 ddev 仅 运行s 预启动挂钩形式 config.yaml。 post-未到达起点。

您可以在此处查看最后 运行 的输出 https://github.com/dmind-gmbh/extension-cookieman/actions?query=branch%3Afeat%2Facceptance-tests

EDIT/AMEND: 这是从 ddev-router:

生成的(错误的)/etc/nginx/conf.d/default.conf
# If we receive X-Forwarded-Proto, pass it through; otherwise, pass along the
# scheme used to connect to this server
map $http_x_forwarded_proto $proxy_x_forwarded_proto {
  default $http_x_forwarded_proto;
  ''      $scheme;
}
# If we receive X-Forwarded-Port, pass it through; otherwise, pass along the
# server port the client connected to
map $http_x_forwarded_port $proxy_x_forwarded_port {
  default $http_x_forwarded_port;
  ''      $server_port;
}
# If we receive Upgrade, set Connection to "upgrade"; otherwise, delete any
# Connection header that may have been passed to this server
map $http_upgrade $proxy_connection {
  default upgrade;
  '' close;
}
# Apply fix for very long server names
server_names_hash_bucket_size 128;
# Default dhparam
# ssl_dhparam /etc/nginx/dhparam/dhparam.pem;
# Set appropriate X-Forwarded-Ssl header
map $scheme $proxy_x_forwarded_ssl {
  default off;
  https on;
}

rfay 提到了 ddev-router 和底层 docker 守护进程之间通过套接字的错误通信。

编辑: 我将我的发现放入一个 Github 行动中,该行动也可以包含在其他项目中:https://github.com/marketplace/actions/setup-ddev

我得出的结论是 docker-gen.

有问题

在模板的第一行(https://github.com/drud/ddev/blob/master/containers/ddev-router/nginx.tmpl or also jwilder's https://github.com/jwilder/nginx-proxy/blob/master/nginx.tmpl) the .Docker.CurrentContainerID is empty which seemed to happen to some people in some contexts https://github.com/jwilder/docker-gen/issues/196#issuecomment-225412753.

建议删除“-only-exposed”对我不起作用。我稍微更改了模板以不依赖容器,仅此而已。

:)

这仍然有点脏,只是一个概念证明:

  • 这是更改后的模板https://github.com/jonaseberle/github-action-setup-ddev/blob/master/.ddev/patches/ddev-router/nginx.tmpl(比较我在上游 {} 部分删除了容器是否与路由器位于同一网络的检查)

  • 我做的工作流程

    • ddev start || exit 0 # 这会失败并且不会执行任何 post-start hooks
    • docker cp nginx-debug.tmpl ddev-router:/app/nginx-debug.tmpl
    • docker exec ddev-router sh -c "docker-gen -only-exposed -notify 'sleep 1 && nginx -s reload' /app/nginx-debug.tmpl /etc/nginx/conf.d/default.conf"
    • ...ddev 现在正常运行

尚未决定如何从这里继续前进。也许@rfay 会知道如何更改 nginx 模板。或者我将使用带有 docker-compose.ddev-router.yaml 的 ddev-router 的自定义 Dockerfile 来仅针对 Github 操作 运行 更改文件。 ..

EDIT/AMEND:

经过测试的较短版本是:

  • ddev start || docker cp .ddev/patches/ddev-router/nginx.tmpl ddev-router:/app/nginx.tmpl
  • ddev start - 这会触发容器重启,从而触发 docker-gen 运行