Skip to content

Commit

Permalink
docker secrets in entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
apozohue10 committed Nov 20, 2019
1 parent 8e03c5c commit 027c77f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
6 changes: 5 additions & 1 deletion extras/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,8 @@ RUN apt-get install -y --no-install-recommends make gcc g++ python && \
# Ports used by idm
EXPOSE ${PEP_PROXY_PORT:-1027}

CMD ["npm", "start" ]
# Run Idm Keyrock
COPY docker-entrypoint.sh /opt/fiware-pep-proxy/docker-entrypoint.sh
RUN chmod 755 docker-entrypoint.sh

ENTRYPOINT ["/opt/fiware-pep-proxy/docker-entrypoint.sh"]
29 changes: 29 additions & 0 deletions extras/docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# usage: file_env VAR [DEFAULT]
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
file_env() {
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
exit 1
fi
local val="$def"
if [ "${!var:-}" ]; then
val="${!var}"
elif [ "${!fileVar:-}" ]; then
val="$(< "${!fileVar}")"
fi
export "$var"="$val"
unset "$fileVar"
}

file_env 'PEP_PROXY_USERNAME'
file_env 'PEP_PASSWORD'
file_env 'PEP_TOKEN_SECRET'

npm start

0 comments on commit 027c77f

Please sign in to comment.