forked from kelvinlow117/rdp-python3
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ivansim
committed
May 28, 2020
0 parents
commit a98a204
Showing
4 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
FROM alpine:3.11.6 | ||
|
||
WORKDIR /app | ||
|
||
COPY [ "switchRole.sh", "getParamStore.sh", "./var/" ] | ||
|
||
ENV PYTHON_VERSION 3.8.2-r0 | ||
|
||
ENV PATH /usr/local/bin:$PATH | ||
|
||
RUN apk add --update --no-cache \ | ||
autoconf \ | ||
automake \ | ||
bash \ | ||
curl \ | ||
g++ \ | ||
gcc \ | ||
jq \ | ||
libtool \ | ||
make \ | ||
python3-dev \ | ||
python3=$PYTHON_VERSION \ | ||
zip \ | ||
&& rm -rf /var/cache/apk/* | ||
|
||
RUN cd /usr/local/bin \ | ||
&& rm -f /usr/bin/python \ | ||
&& ln -s /usr/bin/python3 python | ||
|
||
RUN pip3 install --upgrade --no-cache-dir \ | ||
pip \ | ||
autopep8 \ | ||
awscli \ | ||
boto3 \ | ||
coverage \ | ||
jq \ | ||
pandas \ | ||
pylint \ | ||
requests \ | ||
s3pypi \ | ||
setuptools \ | ||
sphinx \ | ||
sphinx-rtd-theme |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
============= | ||
rdp-python3 | ||
============= | ||
|
||
**Description:** | ||
|
||
Docker for python 3 | ||
|
||
**Note:** | ||
|
||
Please use pip3 instead of pip when instead installing python packages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/bin/bash | ||
|
||
#This script will generate a file env.sh | ||
#To use: bash getEnv.sh [path...] | ||
#Please execute | ||
# $ source env.sh | ||
#to apply environment variables | ||
|
||
if [ $# -eq 0 ]; then | ||
echo "No arguments provided" | ||
exit 1 | ||
fi | ||
ARGUMENTS="$@" | ||
OUT_FILE="/var/env.sh" | ||
echo '#!/bin/sh' > $OUT_FILE | ||
|
||
# non greedy capture group 1, | greedy capture till end of string | ||
|
||
# use for mac os | ||
# SED_COMMAND="sed \"s^\([^\|]*\)\|\(.*\)^export \\1='\\2'^\"" | ||
|
||
# use for aws linux | ||
SED_COMMAND="sed \"s^\([^|]*\)|\(.*\)^export \\1='\\2'^\"" | ||
|
||
function exportToFile() { | ||
old_IFS=$IFS | ||
#set delimiter to only newline | ||
IFS=$'\n' | ||
for param in `jq -n "$1" | jq -r '.[].Value'` | ||
do | ||
# echo $param | ||
param=$(sed "s^'^'\\\''^" <<< $param) #escape all single quotes | ||
# echo $param | ||
param=`eval $SED_COMMAND <<< $param` | ||
# echo "$param" | ||
echo $param >> $OUT_FILE | ||
# echo "echo $val" >> $OUT_FILE | ||
done | ||
#restore delimiter | ||
IFS=$old_IFS | ||
} | ||
for var in $ARGUMENTS | ||
do | ||
PARAMSTORE=`aws ssm get-parameters-by-path --path "$var" --no-paginate --recursive | jq -r '.Parameters'` | ||
exportToFile "$PARAMSTORE" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/sh | ||
|
||
if [ $# -ne 2 ]; then | ||
echo "Error! Too many arguments provided\nsource /var/switchRole.sh <AWS_ROLE> <AWS_REGION>" | ||
exit 1 | ||
fi | ||
|
||
echo "Start of Switch Role" | ||
|
||
unset AWS_ACCESS_KEY_ID | ||
unset AWS_SECRET_ACCESS_KEY | ||
unset AWS_SESSION_TOKEN | ||
unset AWS_DEFAULT_REGION | ||
|
||
# switch role | ||
aws sts assume-role --role-arn $1 --role-session-name rdp-develop-access > assume-role-output.txt | ||
export AWS_ACCESS_KEY_ID=`cat assume-role-output.txt | jq -r '.Credentials.AccessKeyId'` | ||
export AWS_SECRET_ACCESS_KEY=`cat assume-role-output.txt | jq -r '.Credentials.SecretAccessKey'` | ||
export AWS_SESSION_TOKEN=`cat assume-role-output.txt | jq -r '.Credentials.SessionToken'` | ||
export AWS_DEFAULT_REGION=$2 | ||
|
||
echo "End of Switch Role" |