forked from nasa/harmony
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-k8s-config-maps-and-secrets
executable file
·70 lines (61 loc) · 1.83 KB
/
create-k8s-config-maps-and-secrets
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
env_save=$(export -p)
set -a
source "env-defaults"
if [ -f .env ]; then
source ".env"
fi
set +a
eval "$env_save"
HARMONY_VERSION=$(grep version ./package.json \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g' \
| tr -d '[[:space:]]')
USER_AGENT="harmony/${HARMONY_VERSION} (${CLIENT_ID})"
SERVICES_YML=$(< config/services.yml)
cat <<EOF > /tmp/config_map.yml
apiVersion: v1
kind: ConfigMap
metadata:
name: harmony-env
data:
AWS_DEFAULT_REGION: "${AWS_DEFAULT_REGION}"
USE_LOCALSTACK: "${USE_LOCALSTACK}"
LOCALSTACK_HOST: "${LOCALSTACK_K8S_HOST}"
STAGING_BUCKET: "${STAGING_BUCKET}"
STAGING_PATH: "${STAGING_PATH}"
TEXT_LOGGER: "${TEXT_LOGGER}"
BACKEND_HOST: "${BACKEND_HOST}"
CALLBACK_URL_ROOT: "${CALLBACK_URL_ROOT}"
OAUTH_HOST: "${OAUTH_HOST}"
OAUTH_CLIENT_ID: "${OAUTH_CLIENT_ID}"
OAUTH_REDIRECT_URI: "${OAUTH_REDIRECT_URI}"
FALLBACK_AUTHN_ENABLED: "${FALLBACK_AUTHN_ENABLED}"
CMR_ENDPOINT: "${CMR_ENDPOINT}"
USER_AGENT: "${USER_AGENT}"
SERVICES_YML: $(echo -n "${SERVICES_YML}" | base64 | tr -d "\n")
EOF
# Add image env vars (vars that end in _IMAGE) to config map
while IFS='=' read -r name value ; do
if [[ $name == *'_IMAGE' ]]; then
echo " ${name}: \"${value}\"" >> /tmp/config_map.yml
fi
done < <(env)
kubectl -n harmony apply -f /tmp/config_map.yml
rm /tmp/config_map.yml
set +x
cat <<EOF | kubectl -n harmony apply -f -
apiVersion: v1
kind: Secret
metadata:
name: harmony-secrets
type: Opaque
data:
OAUTH_UID: $(echo -n "${OAUTH_UID}" | base64)
OAUTH_PASSWORD: $(echo -n "${OAUTH_PASSWORD}" | base64)
EDL_USERNAME: $(echo -n "${EDL_USERNAME:-unset}" | base64)
EDL_PASSWORD: $(echo -n "${EDL_PASSWORD:-unset}" | base64)
SHARED_SECRET_KEY: $(echo -n "${SHARED_SECRET_KEY}" | base64)
COOKIE_SECRET: $(echo -n "${COOKIE_SECRET}" | base64 | tr -d "\n")
EOF