Skip to content

Commit e4d4d70

Browse files
committed
added read config from param store
1 parent 9863133 commit e4d4d70

File tree

3 files changed

+94
-1
lines changed

3 files changed

+94
-1
lines changed

Dockerfile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ MAINTAINER [email protected]
33

44
WORKDIR /opt/7park
55
COPY . /opt/7park/
6+
COPY ops/bootstrap.sh /opt/7park/bootstrap.sh
7+
COPY ops/branch_to_env.sh /opt/7park/branch_to_env.sh
8+
COPY ops/print_parameters.py /opt/7park/print_parameters.py
9+
10+
RUN apt update && apt install python3-pip -y && \
11+
pip3 install boto3
12+
613
RUN yarn --ignore-engines
714

8-
CMD [ "yarn", "start"]
15+
ENTRYPOINT ["/bin/bash", "bootstrap.sh"]
16+
CMD ["webserver"]

ops/bootstrap.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
APP_NAME=kepler
4+
5+
echo "Current env=${ENV}"
6+
7+
if [ -z "${ENV}" ]; then
8+
source branch_to_env.sh
9+
fi
10+
11+
export ENVIRONMENT="${ENV}"
12+
13+
echo "Debug variables, ENV=${ENV} APP_NAME=${APP_NAME}"
14+
python3 print_parameters.py --env="${ENV}" --app="${APP_NAME}" -d
15+
16+
# Load variable:qs to environment
17+
# shellcheck disable=SC2046
18+
eval $(python print_parameters.py --env="${ENV}" --app="${APP_NAME}")
19+
20+
case "$1" in
21+
webserver)
22+
yarn start
23+
exit
24+
;;
25+
*)
26+
# The command is something like bash. Just run it in the right environment.
27+
exec "$@"
28+
;;
29+
esac

ops/print_parameters.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import argparse
2+
3+
import boto3
4+
5+
6+
def _get_params(client, path, next_token, debug):
7+
params = []
8+
p = dict(
9+
Path=path,
10+
Recursive=True,
11+
ParameterFilters=[],
12+
WithDecryption=not debug
13+
)
14+
if next_token:
15+
p['NextToken'] = next_token
16+
response = client.get_parameters_by_path(**p)
17+
next_token = response.get('NextToken')
18+
params.extend(response['Parameters'])
19+
if next_token:
20+
params.extend(_get_params(client, path, next_token, debug))
21+
return params
22+
23+
24+
def run(env, app_name, debug=False):
25+
all_path = [
26+
'/common/',
27+
'/{env}/common/'.format(env=env),
28+
'/{env}/{app_name}/'.format(env=env, app_name=app_name)]
29+
30+
# client = boto3.client('ssm')
31+
client = boto3.client('ssm', region_name='us-east-1')
32+
33+
for path in all_path:
34+
params = _get_params(client, path, None, debug)
35+
36+
for param in params:
37+
env_var = param['Name'].split(path)[1]
38+
if debug:
39+
if param['Type'] == 'SecureString':
40+
param['Value'] = '****'
41+
print(param)
42+
else:
43+
print("export {}='{}'".format(env_var, param['Value']))
44+
45+
46+
if __name__ == '__main__':
47+
parser = argparse.ArgumentParser(description='Print varialbes from EC2 Parameter Store')
48+
parser.add_argument('-d', '--debug', required=False, action='store_true',
49+
help='Debug variables if True or print export commands otherwise')
50+
parser.add_argument('-e', '--env', required=True,
51+
help='Environment')
52+
parser.add_argument('-a', '--app', required=True,
53+
help='Application name')
54+
55+
args = parser.parse_args()
56+
run(args.env, args.app, args.debug)

0 commit comments

Comments
 (0)