Skip to content

[custom build] image isn't getting custom environment variables that are set #1272

Closed

Description

@rawlingsj

I've double checked and I can't see that I'm doing anything wrong but I admit what I'm seeing does sound strange.

I'm using a custom build image to run a bash script. The default openshift env vars (for example $OUTPUT_IMAGE and $OUTPUT_REGISTRY) are available however any custom ones I use in the build strategy don't seem to be available - I followed the same approach detailed here https://github.com/openshift/origin/blob/master/docs/builds.md#custom-builds

Activity

  1. rawlingsj commented on Mar 10, 2015

    @rawlingsj
    Author

    This is using the Openshift v0.3.4 docker image

  2. rawlingsj commented on Mar 12, 2015

    @rawlingsj
    Author

    I've created a simple custom builder image that recreates the issue. The build config is below, the image is on docker hub so anyone can run it. The image runs a bash script

    https://github.com/rawlingsj/builder-issue/blob/master/builder.sh

    and echo's an openshift env var as well as a custom one set in the build config, the later is not available in the image and can be seen by looking at the echo results in the builder image logs after it is exited.

    Steps to recreate..

    copy json below to a file and apply it to openshift..

    cat issue1272.json | osc create -f -

    osc start-build test

    docker ps -a # until image rawlingsj/builder-issue:latest has exited

    docker logs [rawlingsj/builder-issue:latest cid]

    {  
       "annotations":{  
          "description":"issue #1272 test config"
       },
       "apiVersion":"v1beta1",
       "kind":"List",
       "items":[ 
          {  
             "apiVersion":"v1beta1",
             "kind":"BuildConfig",
             "metadata":{  
                "labels":{  
                   "name":"test"
                },
                "name":"test"
             },
             "parameters":{  
                "output":{  
                   "to":{  
                      "name":"test-image"
                   }
                },
                "source":{  
                   "git":{  
                      "uri":"https://github.com/rawlingsj/builder-issue"
                   },
                   "type":"Git"
                },
                "strategy":{  
                   "customStrategy":{  
                      "image":"rawlingsj/builder-issue",
                      "exposeDockerSocket":true
                   },
                   "type":"Custom",
                   "env":[  
                      {  
                         "name":"CUSTOM_ENV_VAR",
                         "value":"XXXXXXXXXXXX"
                      }
                   ]
                }
             }
          },
          {  
             "apiVersion":"v1beta1",
             "kind":"ImageRepository",
             "metadata":{  
                "labels":{  
                   "name":"test"
                },
                "name":"test-image"
             }
          }
       ]
    }
  3. rawlingsj commented on Mar 12, 2015

    @rawlingsj
    Author

    Output from running the above is..

    [fabric8@jrawlings-fabric8 ~]$ docker logs e2e33f27c90c
    CUSTOM_ENV_VAR:
    OUTPUT_REGISTRY:  172.30.17.190:5000
    

    You can see the custom env vars are not set.

  4. soltysh commented on Mar 13, 2015

    @soltysh
    Contributor

    You have an error in strategy definition, env is part of customStrategy (see here). So that part should look like this:

    "strategy":{
      "type":"Custom",
      "customStrategy":{
        "image":"rawlingsj/builder-issue",
        "exposeDockerSocket":true,
        "env":[
          {
            "name":"CUSTOM_ENV_VAR",
            "value":"XXXXXXXXXXXX"
          }
        ]
      }
    }
  5. rawlingsj commented on Mar 13, 2015

    @rawlingsj
    Author

    ah many thanks @soltysh!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions