{"action":"created","issue":{"url":"https://api.github.com/repos/joyent/containerpilot/issues/242","repository_url":"https://api.github.com/repos/joyent/containerpilot","labels_url":"https://api.github.com/repos/joyent/containerpilot/issues/242/labels{/name}","comments_url":"https://api.github.com/repos/joyent/containerpilot/issues/242/comments","events_url":"https://api.github.com/repos/joyent/containerpilot/issues/242/events","html_url":"https://github.com/joyent/containerpilot/issues/242","id":189772893,"number":242,"title":"question: Exposure of 'CONTAINERPILOT_<SERVICE>_IP' variable in management lifecycle","user":{"login":"cmacrae","id":3392199,"avatar_url":"https://avatars.githubusercontent.com/u/3392199?v=3","gravatar_id":"","url":"https://api.github.com/users/cmacrae","html_url":"https://github.com/cmacrae","followers_url":"https://api.github.com/users/cmacrae/followers","following_url":"https://api.github.com/users/cmacrae/following{/other_user}","gists_url":"https://api.github.com/users/cmacrae/gists{/gist_id}","starred_url":"https://api.github.com/users/cmacrae/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cmacrae/subscriptions","organizations_url":"https://api.github.com/users/cmacrae/orgs","repos_url":"https://api.github.com/users/cmacrae/repos","events_url":"https://api.github.com/users/cmacrae/events{/privacy}","received_events_url":"https://api.github.com/users/cmacrae/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-11-16T17:05:06Z","updated_at":"2016-11-16T17:48:19Z","closed_at":null,"body":"As per the documentation, I'd been wanting to use the `CONTAINERPILOT_<SERVICE>_IP` variable in the early stage of a container's lifecycle -- specifically, in the `preStart` stage.  \r\n\r\nWhilst testing, it doesn't seem this variable is exposed this early on. I'm just wondering if this is a design choice, or a limitation (perhaps impossible to expose, as the container doesn't even have any interfaces up when `preStart` is called?)?\r\n\r\nRight now, I'm having to use a workaround, in which I render some templates from my `startUp` function in my script, which is what's being executed by ContainerPilot to start the container's service. To better explain this, here's an example of my `containerpilot.json`:\r\n``` json\r\n{\r\n    \"consul\": \"{{.CONSUL}}:8500\",\r\n    \"preStart\": \"/usr/local/bin/kafkaManage.sh preStart\",\r\n    \"logging\": {\r\n\t\"level\": \"INFO\",\r\n\t\"format\": \"default\",\r\n\t\"output\": \"stdout\"\r\n    },\r\n    \"stopTimeout\": 5,\r\n    \"preStop\": \"/usr/local/bin/kafkaManage.sh preStop\",\r\n    \"postStop\": \"/usr/local/bin/kafkaManage.sh postStop\",\r\n    \"services\": [\r\n\t{\r\n\t    \"name\": \"kafka\",\r\n\t    \"port\": 9092,\r\n\t    \"health\": [\"/usr/local/bin/health.sh\"],\r\n\t    \"interfaces\": [\"eth0\"],\r\n\t    \"poll\": 10,\r\n\t    \"ttl\": 30,\r\n\t    \"timeout\": \"10s\",\r\n\t    \"tags\": [\"kafka\", \"streaming\"]\r\n\t}\r\n    ],\r\n    \"backends\": [\r\n\t{\r\n\t    \"name\": \"zookeeper\",\r\n\t    \"poll\": 30,\r\n\t    \"timeout\": \"30s\",\r\n\t    \"onChange\": \"/usr/local/bin/kafkaManage.sh onChange\"\r\n\t}\r\n    ]\r\n}\r\n```\r\n\r\nThen, here are the relevant portions of my `kafkaManage.sh` script:\r\n``` bash\r\n#! /usr/bin/env bash\r\n\r\n# Runs before the shimmed process\r\npreStart(){\r\n    echo \"No preStart actions\"\r\n}\r\n\r\nstartUp() {\r\n    # Expose the container IP address\r\n    if [[ $1 == '-a' && -n $2 ]]; then\r\n\texport CONTAINER_IP=$2\r\n    fi\r\n\r\n    echo \"CONTAINER_IP configured as: ${CONTAINER_IP}\"\r\n    writeHealthCheck &\r\n    configure && /usr/local/bin/createTopics.sh &\r\n    $KAFKA_HOME/bin/kafka-server-start.sh $KAFKA_HOME/config/server.properties\r\n}\r\n\r\nconfigure() {\r\n    echo \"Configuring createTopics.sh\"\r\n    # Configure the createTopics script\r\n    consul-template \\\r\n\t-once \\\r\n\t-dedup \\\r\n\t-consul ${CONSUL}:8500 \\\r\n\t-template \"/etc/createTopics.sh.ctmpl:/usr/local/bin/createTopics.sh\"\r\n\r\n    chmod 755 /usr/local/bin/createTopics.sh\r\n\r\n    echo \"Configuring Kafka server.properties\"\r\n    # Configure the main Kafka properties\r\n    consul-template \\\r\n\t-once \\\r\n\t-dedup \\\r\n\t-consul ${CONSUL}:8500 \\\r\n\t-template \"/etc/kafka_properties.ctmpl:${KAFKA_HOME}/config/server.properties\"\r\n\r\n}\r\n\r\necho \"Running: $@\"\r\n$@\r\n```\r\n\r\nAnd, lastly, here's the `CMD` I'm using in my Dockerfile so you can see how I'm exposing the container's IP as an argument to the script:\r\n```\r\nCMD [\"/usr/local/bin/containerpilot\",\"/usr/local/bin/kafkaManage.sh\",\"startUp\",\"-a\",\"{{.CONTAINERPILOT_KAFKA_IP}}\"]\r\n```\r\n\r\nThis works fine, but it'd be nice to run the `consul-template` steps with the `{{.CONTAINERPILOT_KAFKA_IP}}` available in the `preStart` function."},"comment":{"url":"https://api.github.com/repos/joyent/containerpilot/issues/comments/261018501","html_url":"https://github.com/joyent/containerpilot/issues/242#issuecomment-261018501","issue_url":"https://api.github.com/repos/joyent/containerpilot/issues/242","id":261018501,"user":{"login":"cmacrae","id":3392199,"avatar_url":"https://avatars.githubusercontent.com/u/3392199?v=3","gravatar_id":"","url":"https://api.github.com/users/cmacrae","html_url":"https://github.com/cmacrae","followers_url":"https://api.github.com/users/cmacrae/followers","following_url":"https://api.github.com/users/cmacrae/following{/other_user}","gists_url":"https://api.github.com/users/cmacrae/gists{/gist_id}","starred_url":"https://api.github.com/users/cmacrae/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cmacrae/subscriptions","organizations_url":"https://api.github.com/users/cmacrae/orgs","repos_url":"https://api.github.com/users/cmacrae/repos","events_url":"https://api.github.com/users/cmacrae/events{/privacy}","received_events_url":"https://api.github.com/users/cmacrae/received_events","type":"User","site_admin":false},"created_at":"2016-11-16T17:48:19Z","updated_at":"2016-11-16T17:48:19Z","body":"@fitz123 Perhaps you missed this specific part of my question:\r\n> I'm just wondering if this is a design choice, or a limitation (perhaps impossible to expose, as the container doesn't even have any interfaces up when preStart is called?)?\r\n\r\nAlso, pretty sure the container has definitely been created, considering it has to before the ContainerPilot runtime executes.\r\nPerhaps you mean before the container has a chance to get an IP? In which case, see my first point"}}
{"actor":{"display_login":"cmacrae"}}