From 0c2b8623402618faf2824de3cb9ea7a68f24b9c4 Mon Sep 17 00:00:00 2001 From: Marcus Young Date: Sat, 23 Dec 2017 12:30:31 -0600 Subject: [PATCH] Alternate way to set for AWS ECS --- README.md | 4 ++++ app/entrypoint.sh | 21 ++++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 5c552474..27c53b5d 100644 --- a/README.md +++ b/README.md @@ -215,6 +215,10 @@ $ docker run -d \ * `ACME_TOS_HASH` - Let´s you pass an alternative TOS hash to simp_le, to support other CA´s ACME implentation. +* `DOCKER_PROVIDER` - Set this to change behavior on container ID retrieval. Optional. Current supported values: + * No value (empty, not set): no change in behavior. + * `ecs` [Amazon ECS using ECS_CONTAINER_METADATA_FILE environment variable](http://docs.aws.amazon.com/AmazonECS/latest/developerguide/container-metadata.html + #### Examples: If you want other examples how to use this container, look at: diff --git a/app/entrypoint.sh b/app/entrypoint.sh index f4a6f287..10e0400d 100755 --- a/app/entrypoint.sh +++ b/app/entrypoint.sh @@ -3,11 +3,22 @@ set -u -if [[ -n "${DOCKER_PROVIDER:-}" ]] && [[ "${DOCKER_PROVIDER,,}" == "aws" ]]; then - export CONTAINER_ID=$(grep ContainerID "${ECS_CONTAINER_METADATA_FILE}" | sed 's/.*: "\(.*\)",/\1/g') -else - export CONTAINER_ID=$(sed -nE 's/^.+docker[\/-]([a-f0-9]{64}).*/\1/p' /proc/self/cgroup | head -n 1) -fi +DOCKER_PROVIDER=${DOCKER_PROVIDER:-docker} + +case "${DOCKER_PROVIDER}" in +ecs|ECS) + # AWS ECS. Enabled in /etc/ecs/ecs.config (http://docs.aws.amazon.com/AmazonECS/latest/developerguide/container-metadata.html) + if [[ -n "${ECS_CONTAINER_METADATA_FILE:-}" ]]; then + export CONTAINER_ID=$(grep ContainerID "${ECS_CONTAINER_METADATA_FILE}" | sed 's/.*: "\(.*\)",/\1/g') + else + echo "${DOCKER_PROVIDER} specified as 'ecs' but not available. See: http://docs.aws.amazon.com/AmazonECS/latest/developerguide/container-metadata.html" + exit 1 + fi + ;; +*) + export CONTAINER_ID=$(sed -nE 's/^.+docker[\/-]([a-f0-9]{64}).*/\1/p' /proc/self/cgroup | head -n 1) + ;; +esac if [[ -z "$CONTAINER_ID" ]]; then echo "Error: can't get my container ID !" >&2