origin icon indicating copy to clipboard operation
origin copied to clipboard

BuildConfig ENV Variables are not passed to Docker

Open gemafra opened this issue 11 years ago • 8 comments

I'm running a local installation at the moment. When passing ENV via BuildConfig they are not used during the actual build. May be the issue if the used Dockerfile already has ENV Variables build in?

Georg

gemafra avatar Oct 26 '15 22:10 gemafra

can you please supply the json for your buildconfig as well as verbose logging for your build (https://docs.openshift.org/latest/dev_guide/builds.html#accessing-build-logs)

Also please tell me what openshift version you are running.

If you define env variables in your BuildConfig they are supposed to be appended to your Dockerfile, if the Dockerfile already has those ENV variables defined, the values should be overwritten by what you defined in your BuildConfig: https://docs.openshift.org/latest/dev_guide/builds.html#docker-strategy-environment

@rhcarvalho fyi

bparees avatar Oct 27 '15 13:10 bparees

BuildConfig

apiVersion: v1 kind: BuildConfig metadata: creationTimestamp: 2015-10-26T22:39:07Z labels: app: docker-atlassian-jira name: docker-atlassian-jira namespace: atlassian-dev resourceVersion: "97976" selfLink: /oapi/v1/namespaces/atlassian-dev/buildconfigs/docker-atlassian-jira uid: 5dfb0d2c-7c32-11e5-b069-00155d006532 spec: output: to: kind: ImageStreamTag name: docker-atlassian-jira:latest resources: {} source: git: ref: openshift uri: https://github.com/gorg3b/docker-atlassian-jira type: Git strategy: dockerStrategy: env: - name: JIRA_URL value: dev2.stephanbartl.at from: kind: ImageStreamTag name: java:8 namespace: atlassian-dev type: Docker triggers:

  • github: secret: zI-W8tqn-irrmTHDdEPP type: GitHub
  • generic: secret: H8i-S8LO54PwebgeW4GG type: Generic
  • type: ConfigChange
  • imageChange: lastTriggeredImageID: library/java@sha256:678c7387dc367c8db12c5735b4efc83db8049e9da4e98839da323b70761dd4c5 type: ImageChange status: lastVersion: 3

BuildLog

I1028 10:47:12.960735 1 docker.go:203] Cloning source from https://github.com/gorg3b/docker-atlassian-jira Switched to a new branch 'openshift' Branch openshift set up to track remote branch openshift from origin. Step 0 : FROM library/java@sha256:678c7387dc367c8db12c5735b4efc83db8049e9da4e98839da323b70761dd4c5 ---> 4cd29d33e3f4 Step 1 : ENV JIRA_HOME /var/atlassian/jira ---> Using cache ---> e482811f421d Step 2 : ENV JIRA_INSTALL /opt/atlassian/jira ---> Using cache ---> beb743837639 Step 3 : ENV JIRA_VERSION 7.0.0 ---> Using cache ---> 89fedf0a04c0 Step 4 : ENV JIRA_PORT 8080 ---> Running in 6a132e1fb75e ---> 5ab4726289f2 Removing intermediate container 6a132e1fb75e Step 5 : ENV JIRA_SCHEME https ---> Running in 61ca5e0c5564 Branch openshift set up to track remote branch openshift from origin. Step 0 : FROM library/java@sha256:678c7387dc367c8db12c5735b4efc83db8049e9da4e98839da323b70761dd4c5 ---> 4cd29d33e3f4 Step 1 : ENV JIRA_HOME /var/atlassian/jira ---> Using cache ---> e482811f421d Step 2 : ENV JIRA_INSTALL /opt/atlassian/jira ---> Using cache ---> beb743837639 Step 3 : ENV JIRA_VERSION 7.0.0 ---> Using cache ---> 89fedf0a04c0 Step 4 : ENV JIRA_PORT 8080 ---> Running in 6a132e1fb75e ---> 5ab4726289f2 Removing intermediate container 6a132e1fb75e Step 5 : ENV JIRA_SCHEME https ---> Running in 61ca5e0c5564 ---> 383da238befb Removing intermediate container 61ca5e0c5564 Step 6 : ENV JIRA_PROXYP 443 ---> Running in c5ab8daee548 ---> 0623998c94fb Removing intermediate container c5ab8daee548 Step 7 : ENV JIRA_SECURE true ---> Running in 29d52668ff6d ---> e63e8f0bf0f0 Removing intermediate container 29d52668ff6d Step 8 : RUN set -x && apt-get update --quiet && apt-get install --quiet --yes --no-install-recommends libtcnative-1 xmlstarlet && apt-get clean && mkdir -p "${JIRA_HOME}" && mkdir -p "${JIRA_HOME}/caches/indexes" && chmod -R 700 "${JIRA_HOME}" && chown -R daemon:daemon "${JIRA_HOME}" && mkdir -p "${JIRA_INSTALL}/conf/Catalina" && curl -Ls "https://www.atlassian.com/software/jira/downloads/binary/atlassian-jira-core-${JIRA_VERSION}.tar.gz" | tar -xz --directory "${JIRA_INSTALL}" --strip-components=1 --no-same-owner && curl -Ls "https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.36.tar.gz" | tar -xz --directory "${JIRA_INSTALL}/lib" --strip-components=1 --no-same-owner "mysql-connector-java-5.1.36/mysql-connector-java-5.1.36-bin.jar" && chmod -R 700 "${JIRA_INSTALL}/conf" && chmod -R 700 "${JIRA_INSTALL}/logs" && chmod -R 700 "${JIRA_INSTALL}/temp" && chmod -R 700 "${JIRA_INSTALL}/work" && chown -R daemon:daemon "${JIRA_INSTALL}/conf" && chown -R daemon:daemon "${JIRA_INSTALL}/logs" && chown -R daemon:daemon "${JIRA_INSTALL}/temp" && chown -R daemon:daemon "${JIRA_INSTALL}/work" && sed --in-place "s/java version/openjdk version/g" "${JIRA_INSTALL}/bin/check-java.sh" && echo -e "\njira.home=$JIRA_HOME" >> "${JIRA_INSTALL}/atlassian-jira/WEB-INF/classes/jira-application.properties" && sed --in-place "s/port="8080"/port=""${JIRA_PORT}""/" "${JIRA_INSTALL}/conf/server.xml" && sed --in-place "57 a scheme=""${JIRA_SCHEME}""" "${JIRA_INSTALL}/conf/server.xml" && sed --in-place "57 a proxyName=""${JIRA_URL}""" "${JIRA_INSTALL}/conf/server.xml" && sed --in-place "57 a proxyPort=""${JIRA_PROXYP}""" "${JIRA_INSTALL}/conf/server.xml" && sed --in-place "57 a secure=""${JIRA_SECURE}""" "${JIRA_INSTALL}/conf/server.xml" ---> Running in ade7f2f3947d Setting up libxslt1.1:amd64 (1.1.28-2+b2) ... Setting up libtcnative-1:amd64 (1.1.32~repack-2) ... Setting up xmlstarlet (1.6.1-1) ... Processing triggers for libc-bin (2.19-18+deb8u1) ...

  • apt-get clean
  • mkdir -p /var/atlassian/jira
  • mkdir -p /var/atlassian/jira/caches/indexes
  • chmod -R 700 /var/atlassian/jira
  • chown -R daemon:daemon /var/atlassian/jira
  • mkdir -p /opt/atlassian/jira/conf/Catalina
  • tar -xz --directory /opt/atlassian/jira --strip-components=1 --no-same-owner
  • curl -Ls https://www.atlassian.com/software/jira/downloads/binary/atlassian-jira-core-7.0.0.tar.gz
  • curl -Ls https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.36.tar.gz
  • tar -xz --directory /opt/atlassian/jira/lib --strip-components=1 --no-same-owner mysql-connector-java-5.1.36/mysql-connector-java-5.1.36-bin.jar

.. ..

  • chmod -R 700 /opt/atlassian/jira/conf
  • chmod -R 700 /opt/atlassian/jira/logs
  • chmod -R 700 /opt/atlassian/jira/temp
  • chmod -R 700 /opt/atlassian/jira/work
  • chown -R daemon:daemon /opt/atlassian/jira/conf
  • chown -R daemon:daemon /opt/atlassian/jira/logs
  • chown -R daemon:daemon /opt/atlassian/jira/temp
  • chown -R daemon:daemon /opt/atlassian/jira/work
  • sed --in-place s/java version/openjdk version/g /opt/atlassian/jira/bin/check-java.sh
  • echo -e \njira.home=/var/atlassian/jira
  • sed --in-place s/port="8080"/port="8080"/ /opt/atlassian/jira/conf/server.xml
  • sed --in-place 57 a scheme="https" /opt/atlassian/jira/conf/server.xml
  • sed --in-place 57 a proxyName="dev.stephanbartl.at" /opt/atlassian/jira/conf/server.xml
  • sed --in-place 57 a proxyPort="443" /opt/atlassian/jira/conf/server.xml
  • sed --in-place 57 a secure="true" /opt/atlassian/jira/conf/server.xml ---> 927f2677627d

I did shorten the BuildLog a little to hopefully the relevant parts. For reference the Dockerfile can be found at https://github.com/gorg3b/docker-atlassian-jira branch ist openshift

Thanks in advance

Georg

gemafra avatar Oct 28 '15 10:10 gemafra

can you share your "oc version"?

bparees avatar Oct 28 '15 22:10 bparees

for reference, here's the pull that added the function to put env variables from a buildconfig into the Dockerfile: https://github.com/openshift/origin/pull/4562

bparees avatar Oct 28 '15 22:10 bparees

oc v1.0.6-2-ge2a02a8 kubernetes v1.1.0-alpha.0-1605-g44c91b1

gemafra avatar Oct 29 '15 05:10 gemafra

v1.0.6 is from mid september, i'm afraid it pre-dates this feature going in. You'll have to move to 1.07 when it releases, or build your version of origin from the current head (note that you'll also need to build the "origin-docker-builder" image as it contains the logic that proceses the env/dockerfile.

i'm closing this as it does work in the current code, but feel free to reopen if you're still having issues after moving up.

bparees avatar Oct 29 '15 13:10 bparees

moved to 1.0.7 now the ENV are passed but not replaced, relevant part of the build logs 6 Step 1 : ENV "JIRA_URL" "jira2.stephanbartl.at" 7 ---> Using cache 8 ---> a62da8397e4d 9 Step 2 : ENV JIRA_HOME /var/atlassian/jira 10 ---> Using cache 11 ---> 121b79d8763e 12 Step 3 : ENV JIRA_INSTALL /opt/atlassian/jira 13 ---> Using cache 14 ---> 575be4631ce1 15 Step 4 : ENV JIRA_VERSION 7.0.0 16 ---> Using cache 17 ---> 0966942f4f98 18 Step 5 : ENV JIRA_PORT 8080 19 ---> Using cache 20 ---> 19ca7448e665 21 Step 6 : ENV JIRA_SCHEME https 22 ---> Using cache 23 ---> 200f2cad0d3b 24 Step 7 : ENV JIRA_URL dev.stephanbartl.at 25 ---> Using cache 26 ---> d4cb1b5de6a3

BTW Amazing new Version congrats

gemafra avatar Nov 03 '15 10:11 gemafra

what do you mean by "replaced"? replacing what value with what value?

The environment variables provided in the buildconfig are injected immediately after the FROM statement in your dockerfile to ensure that the values they provide are available to later steps in your Dockerfile. If your Dockerfile already defines a particular environment variable later in the file, then yes this means that the value in the Dockerfile will be the final value of the environment variable when the image is committed.

This is by design so you can use buildconfig environment variables to inject proxy definitions that are needed by later steps in the dockerfile.

bparees avatar Nov 03 '15 14:11 bparees