Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,6 @@ $ docker run -d \

* The `com.github.jrcs.letsencrypt_nginx_proxy_companion.docker_gen` label - set this label on the docker-gen container to tell the docker-letsencrypt-nginx-proxy-companion container to use it as the docker-gen when it's split from nginx (separate containers).

* `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)

* `DHPARAM_BITS` - Change the size of the Diffie-Hellman key generated by the container from the default value of 2048 bits. For example `-e DHPARAM_BITS=1024` to support some older clients like Java 6 and 7.

#### Examples:
Expand Down
14 changes: 5 additions & 9 deletions app/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ function check_docker_socket {

function check_writable_directory {
local dir="$1"
docker_api "/containers/${SELF_CID:-$(get_self_cid)}/json" | jq ".Mounts[].Destination" | grep -q "^\"$dir\"$"
if [[ $? -ne 0 ]]; then
echo "Warning: '$dir' does not appear to be a mounted volume."
if [[ $(get_self_cid) ]]; then
docker_api "/containers/$(get_self_cid)/json" | jq ".Mounts[].Destination" | grep -q "^\"$dir\"$"
[[ $? -ne 0 ]] && echo "Warning: '$dir' does not appear to be a mounted volume."
else
echo "Warning: can't check if '$dir' is a mounted volume without self container ID."
fi
if [[ ! -d "$dir" ]]; then
echo "Error: can't access to '$dir' directory !" >&2
Expand Down Expand Up @@ -139,12 +141,6 @@ if [[ "$*" == "/bin/bash /app/start.sh" ]]; then
exit 1
fi
check_docker_socket
if [[ -z "$(get_self_cid)" ]]; then
echo "Error: can't get my container ID !" >&2
exit 1
else
export SELF_CID="$(get_self_cid)"
fi
if [[ -z "$(get_nginx_proxy_container)" ]]; then
echo "Error: can't get nginx-proxy container ID !" >&2
echo "Check that you are doing one of the following :" >&2
Expand Down
29 changes: 11 additions & 18 deletions app/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,15 @@ function check_cert_min_validity {
}

function get_self_cid {
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
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" >&2
exit 1
fi
;;
*)
sed -nE 's/^.+docker[\/-]([a-f0-9]{64}).*/\1/p' /proc/self/cgroup | head -n 1
;;
esac
local self_cid
self_cid="$(basename "$(cat /proc/1/cpuset)")"
if [[ -n "$self_cid" ]]; then
echo "$self_cid"
return 0
else
echo "$(date "+%Y/%m/%d %T"), Error: can't get my container ID !" >&2
return 1
fi
}

## Docker API
Expand Down Expand Up @@ -162,8 +155,8 @@ function get_nginx_proxy_container {
if [[ -n "${NGINX_PROXY_CONTAINER:-}" ]]; then
nginx_cid="$NGINX_PROXY_CONTAINER"
# ... else try to get the container ID with the volumes_from method.
else
volumes_from=$(docker_api "/containers/${SELF_CID:-$(get_self_cid)}/json" | jq -r '.HostConfig.VolumesFrom[]' 2>/dev/null)
elif [[ $(get_self_cid) ]]; then
volumes_from=$(docker_api "/containers/$(get_self_cid)/json" | jq -r '.HostConfig.VolumesFrom[]' 2>/dev/null)
for cid in $volumes_from; do
cid="${cid%:*}" # Remove leading :ro or :rw set by remote docker-compose (thx anoopr)
if [[ $(docker_api "/containers/$cid/json" | jq -r '.Config.Env[]' | egrep -c '^NGINX_VERSION=') = "1" ]];then
Expand Down