如何在 Gitlab-CI Runner 上下文中连接到 Apache?

How to connect to Apache in Gitlab-CI Runner context?

我想连接到我在 gitlab-ci.yml 中创建的 Apache(为了 运行 验收测试),但我不知道如何操作。

尝试 curl -i http://localhost/ 得到:

curl: (7) Failed to connect to localhost port 80: Connection refused

gitlab-ci.yml

的内容
image: php:7.0-apache

variables:
 DEBIAN_FRONTEND: noninteractive

before_script:
  - apt-get update -yqq
  - apt-get install -yqq curl net-tools

hello-world:
  stage: test
  script:
  - ./script.sh

script.sh

的内容
#!/usr/bin/env bash

set -e

echo-run() {
    echo "===== ===== "
    echo "$()"
    echo
}

declare MYHOSTNAME="$(hostname)"

echo-run "hostname"
echo-run "netstat -antup"
echo-run "pwd"
echo-run "ls -al --color=auto ."
echo "curl -i http://${MYHOSTNAME}/"

# This does not work: "failed to connect to <hostname> port 80: Connection refused"
curl -i http://${MYHOSTNAME}/

项目托管于gitlab.com/matt.faure/debug-ci/ and here is the ouput of a failed job

据我所知,这是一个 "inception" 问题:我在哪个世界?

MYHOSTNAME 是 Docker 容器的主机名,显然这是行不通的,因为它是从 inside 容器中看到的名称,并且IP/ports 由 Runner 映射(或可能不是)。那么默认映射是什么?如何配置?

(这适用于常规 Docker 环境)

我收割了 Gitlab Runner doc 没有成功。我还在 Gitlab 论坛和 Whosebug 上进行了广泛的搜索。我发现了这些类似的问题,但其中 none 个让我找到了解决方案:

总结一下,我漏掉了什么或者误解了什么?

你的 Apache 不是 运行ning。

您的 netstat -antup 仅显示 Foreign Addresses 连接,可能来自 apt-get 运行 之前。

Gitlab Runner 启动一个容器来执行你的 before_script scriptafter_script,它覆盖了你的图像 ENTRYPOINTCMD使用依赖正常启动Apache

在你的 script.sh 中添加一个步骤到后台的 运行 apache(不确定它是否有效,我从未尝试过),或者只是 link apache 作为 service,取决于你的 objective.