Skip to content

Commit

Permalink
docker for python3
Browse files Browse the repository at this point in the history
  • Loading branch information
ivansim committed May 28, 2020
0 parents commit a98a204
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 0 deletions.
43 changes: 43 additions & 0 deletions Dockerfile
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
11 changes: 11 additions & 0 deletions README.rst
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
46 changes: 46 additions & 0 deletions getParamStore.sh
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
22 changes: 22 additions & 0 deletions switchRole.sh
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"

0 comments on commit a98a204

Please sign in to comment.