forked from dimagi/required-labels
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·34 lines (29 loc) · 1.16 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/sh
# Please set environment variables:
# HOST, PORT -- gunicorn host and port;
# GITHUB_USER, GITHUB_TOKEN -- GitHub API credentials with repo read permissions;
# or
# VAULT_ADDR, APPROLE_ROLE_ID, APPROLE_SECRET_ID -- Vault address and credentials;
# VAULT_SECRET_PATH, VAULT_SECRET_KEY_USER, VAULT_SECRET_KEY_TOKEN -- Vault path to get GitHub credentials.
VAULT_ADDR="${VAULT_ADDR:-127.0.0.1:8200}"
get_token() {
curl -s --request POST \
--data "{\"role_id\":\"${APPROLE_ROLE_ID}\",\"secret_id\":\"${APPROLE_SECRET_ID}\"}" \
${VAULT_ADDR}/v1/auth/approle/login | jq -r '.auth.client_token'
}
get_secret() {
SECRET_PATH="${1}"
SECRET_KEY="${2}"
curl -s --header "X-Vault-Token: ${VAULT_TOKEN}" ${VAULT_ADDR}/v1/${SECRET_PATH} \
| jq -r --arg k "${SECRET_KEY}" '.data | .[$k]'
}
main() {
export GITHUB_PW="none"
if [ -z ${GITHUB_USER} -o -z ${GITHUB_TOKEN} ]; then
VAULT_TOKEN="$(get_token)"
GITHUB_USER="$(get_secret ${VAULT_SECRET_PATH} ${VAULT_SECRET_KEY_USER})"
GITHUB_TOKEN="$(get_secret ${VAULT_SECRET_PATH} ${VAULT_SECRET_KEY_TOKEN})"
fi
gunicorn -b ${HOST}:${PORT:-8080} main:app
}
main