2

I want to connect to the Apache created in my gitlab-ci.yml (in order to run acceptance tests), but I don't understand how to do it.

Trying to curl -i http://localhost/ gives:

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

Content of 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

Content of script.sh

#!/usr/bin/env bash

set -e

echo-run() {
    echo "===== ===== $1"
    echo "$($1)"
    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}/

The project is hosted at gitlab.com/matt.faure/debug-ci/ and here is the ouput of a failed job

As far as I understand this an "inception" problem: in which world am I ?

MYHOSTNAME is the hostname of the Docker container, obviously this won't work as is it the name seen from inside the container, and IP/ports are mapped by the Runner (or maybe not). So what is the default mapping ? How to configure it ?

(This works in a regular Docker environment)

I harvested the Gitlab Runner doc without success. I also did extensive searches on Gitlab Forum and StackOverflow. I found these similar questions but none of them led me to a solution:

Summed up, what am I missing or misunderstanding ?

Matthieu FAURE
  • 383
  • 3
  • 11

1 Answers1

3

Your Apache is just not running.

Your netstat -antup just shows Foreign Addresses connections, likely from apt-get ran before.

Gitlab Runner starts a container to execute your before_script script and after_script, it's overriding the ENTRYPOINT and CMD that the image you're using rely on to start Apache normally.

Add a step in your script.sh to run apache in the background (not sure it will work though, I never tried), or just link apache as a service, depending on your objective.

Hiruma
  • 629
  • 5
  • 14
  • Thank you! I was facing a similar problem but with MySQL. Your answer led me to place the copy CMD from my Dockerfile into the before_script portion of my .gitlab-ci.yml and everything started working. – Clayton Jun 12 '19 at 10:22