fix: register-consul utilise network_mode host (localhost:8500 = consul reel)

172.17.0.1:8500 passe par les regles iptables DOCKER et n'atteint pas
le meme consul que Fabio. Avec host network, localhost:8500 est direct.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
syoul
2026-03-17 20:03:25 +01:00
parent 6dec47a3bd
commit 9d1406c79d

View File

@@ -70,21 +70,21 @@ steps:
- docker inspect prestashop --format '{{.NetworkSettings.Networks.sonic.IPAddress}}' > $CI_WORKSPACE/.container_ip
# Etape 3c : Enregistrement dans Consul (Registrator ne peut pas ecrire prestashop : ACL)
# network_mode host : localhost:8500 = consul reel (172.17.0.1 passe par iptables DOCKER)
- name: register-consul
image: alpine:3.20
network_mode: host
environment:
TEST_STATIC: hello
CONSUL_TOKEN:
from_secret: consul_token
commands:
- apk add --no-cache --quiet curl iproute2
- apk add --no-cache --quiet curl
- |
CONSUL_HOST=$(ip route show default | awk '/default/{print $3; exit}')
CONSUL_HOST=${CONSUL_HOST:-172.17.0.1}
CONTAINER_IP=$(cat .container_ip)
DOMAIN=$(grep '^PS_DOMAIN=' .env.deploy | cut -d= -f2)
CONTAINER_IP=$(cat $CI_WORKSPACE/.container_ip)
DOMAIN=$(grep '^PS_DOMAIN=' $CI_WORKSPACE/.env.deploy | cut -d= -f2)
CTOK=$(env | grep '^CONSUL_TOKEN=' | cut -d= -f2-)
curl -sf -X PUT "http://$CONSUL_HOST:8500/v1/agent/service/register" \
curl -sf -X PUT "http://localhost:8500/v1/agent/service/register" \
-H "Content-Type: application/json" \
-H "X-Consul-Token: $CTOK" \
-d "{\"Name\":\"prestashop\",\"Address\":\"$CONTAINER_IP\",\"Port\":80,\"Tags\":[\"urlprefix-$DOMAIN/\"]}"