Environment Variables in BuildConfig with dockerStrategy

Solution In Progress - Updated -

Issue

  • I am passing on environment variables in a build-config with dockerStrategy as follows:
"strategy": {
    "type": "Docker",
    "dockerStrategy": {
        "from": {
            "kind": "ImageStreamTag",
            "name": "${APPLICATION_NAME}-rhel7:latest"
        },
        "env": [
            {
                "name": "BUILD_LOGLEVEL",
                "value": "5"
            },
            {
                "name": "nexus_url",
                "value": "${NEXUS_URL}"
            },
            {
                "name": "http_proxy",
                "value": "${HTTP_PROXY}"
            },
            {
                "name": "https_proxy",
                "value": "${HTTPS_PROXY}"
            },
            {
                "name": "no_proxy",
                "value": "${NO_PROXY}"
            }
        ]
    }
}

On this page https://docs.openshift.com/enterprise/3.0/dev_guide/builds.html#docker-strategy-environment you state the following:
"The environment variables defined there are inserted as a single ENV Dockerfile instruction right after the FROM instruction, so that it can be referenced later on within the Dockerfile."

In the dockerfile, I do the following:

FROM rhel7

RUN echo "Nexus URL -> ${nexus_url}"
RUN curl -f -L "${nexus_url}/service/local/artifact/maven/redirect?r=releases&g=com.example.cq&a=cq&v=6.1" -o cq.jar

The run echo does not resolve the environment variable.

The curl ends with:
Step 1 : RUN curl -f -L "${nexus_url}/service/local/artifact/maven/redirect?r=releases&g=com.example.cq&a=cq&v=6.1" -o cq.jar
---> Running in 011c674d9bc3
curl: (3) malformed

According to docker reference, environment variables are not resolved in RUN command, so this could be ok.

Later on in the dockerfile, the following is done:
ADD .sti/bin/assemble /tmp/assemble
RUN chmod u+x /tmp/assemble
RUN sh /tmp/assemble

In the assemble script, I also echo the env var and execute the same curl with the same result (malformed url).

From the docker build reference https://docs.docker.com/reference/commandline/build/, I actually see that docker build command does not support environment variables (although I read that in the future, there should be something like build arguments, "Yep, closing as this is solved by --build-arg which will be in the 1.9 release.").

So my question is, should environment variables work or not? How could I achieve to pass them the assemble script? (This was an sti build before. Because of upgrading OpenShift from 3.0.1 to 3.0.2 we had to change it to dockerStrategy temporarily because of security reasons, as we always use root to do stuff...).

Environment

  • OpenShift Enterprise 3.x

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content