Skip to content

Instantly share code, notes, and snippets.

@jordanrounds
Last active April 21, 2020 01:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jordanrounds/a2b16fd5753ee7a450b2b5486b8eebaf to your computer and use it in GitHub Desktop.
Save jordanrounds/a2b16fd5753ee7a450b2b5486b8eebaf to your computer and use it in GitHub Desktop.
example secrets from file
version: "3.7"
services:
influx:
build: .
container_name: "influxdb"
image: influxdb:secrets
restart: unless-stopped
environment:
INFLUXDB_ADMIN_PASSWORD_FILE: /run/secrets/test
secrets:
- test
ports:
- '8086:8086'
- '2003:2003'
volumes:
- ./influxdb.conf:/etc/influxdb/influxdb.conf:ro
- influx-storage:/var/lib/influxdb
volumes:
influx-storage:
name: influxdb_storage
driver: local-persist
driver_opts:
mountpoint: ${LOCAL_PERSIST}/influxdb/storage
secrets:
test:
file: ./.password
FROM influxdb:latest
COPY pre-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["pre-entrypoint.sh"]
CMD ["influxd"]
#!/bin/bash
set -e
error() {
printf '%s [%s] [Entrypoint]: %s\n' "$(date --rfc-3339=seconds)" "ERROR" "$*"
}
file_env() {
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
error "Both $var and $fileVar are set (but are exclusive)"
fi
local val="$def"
if [ "${!var:-}" ]; then
val="${!var}"
elif [ "${!fileVar:-}" ]; then
val="$(< "${!fileVar}")"
fi
export "$var"="$val"
printf "$var : $val"
unset "$fileVar"
}
file_env 'INFLUXDB_ADMIN_PASSWORD'
file_env 'INFLUXDB_USER_PASSWORD'
file_env 'INFLUXDB_READ_USER_PASSWORD'
file_env 'INFLUXDB_WRITE_USER_PASSWORD'
. /entrypoint.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment