ovh/cds

Services options : variable expansion does not work for {{.cds.worker}}

b2p-fred opened this issue · 1 comments

When defining some options for a service, the CDS variables are not expanded. As an example:

version: v1.0
name: deploy-backend
description: Deploy the application backend
jobs:
- job: Setup the application package
  steps:
  - artifactDownload:
      path: Download installable package
      pattern: epr-backend-api
      tag: '{{.cds.version}}'
  - script:
    - 'echo "My worker hostname: {{.cds.worker}}"'
  requirements:
  - model: eprotocole/epr-PHP
  - service:
      name: nginx-api
      value: '{{.cds.env.DOCKER_REGISTRY}}{{.cds.env.DOCKER_REGISTRY_PREFIX}}epr-backend_nginx:{{.cds.env.IMAGE_TAG_NGINX}} NGINX_PHP_UPSTREAM_HOST=php-api-{{.cds.worker}} NGINX_PHP_UPSTREAM_PORT=9000'
  - service:
      name: php-api
      value: '{{.cds.env.DOCKER_REGISTRY}}{{.cds.env.DOCKER_REGISTRY_PREFIX}}epr-backend_php:{{.cds.env.IMAGE_TAG_PHP}}'

I wish using the worker name in an environment variable used to configure the Nginx server. Hence I need to use the hostname of the service running my php fpm instance ...

The {{.cds.worker}} is not replaced with the worker hostname thus resulting in an error in the nginx configuration.

Edit:
I made some more tests and I found out that some variables are expanded (e.g. {{.cds.env.VAR}}). It looks like only the {{.cds.worker}} variable is not expanded or not with the expected value...
I am still investigating to find out what is happening with this variable!

Edit:
After some more investigation, I do confirm that the {{.cds.worker}} variable is not expanded in the services options!. When I dump the environment of my nginx service I got:

[INFO]          11-dump-defined-envs.sh: Raw environment:
[INFO]          HOSTNAME af9b12426256
[INFO]          HOME /root
[INFO]          PKG_RELEASE 1 buster
[INFO]          UID 1000
[INFO]          NGINX_PHP_UPSTREAM_HOST php-api-test
[INFO]          PHP_USER www-data
[INFO]          NGINX VERSION 1.20.1
[INFO]          PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
[INFO]          NGINX PHP UPSTREAM PORT 9000
[INFO]          NJS_VERSION 0.5.3
[INFO]          NGINX_PHP_UPSTREAM_COMMENT {{.cds.worker}}
[INFO]          GID 1000
[INFO]          APP_ENV prod
[INFO]          PWD /

Note the NGINX_PHP_UPSTREAM_COMMENT comment that is not expanded... whereas the test in NGINX_PHP_UPSTREAM_HOST is the expansion of {{.cds.env.APP_ENV}}

Hi, yes. I confirm that this variable can't be used in pre-requisite.