-
Notifications
You must be signed in to change notification settings - Fork 573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Support setup.py & Pipfile dependencies in the python docker images #925
Changes from all commits
81de2e2
c210602
fb442df
a0293d0
75f9a7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,13 +20,13 @@ fi | |
|
||
useradd -o -m -u "${USER_ID}" -d /home/node docker-user 2>/dev/null | ||
|
||
runCmdAsDockerUser () { | ||
runCmdAsDockerUser() { | ||
su docker-user -m -c "$1" | ||
|
||
return $? | ||
} | ||
|
||
exitWithMsg () { | ||
exitWithMsg() { | ||
echo "Failed to run the process ..." | ||
|
||
if [ -f "$1" ]; then | ||
|
@@ -46,7 +46,7 @@ exitWithMsg () { | |
## README.md for more info. | ||
## | ||
|
||
TEST_SETTINGS=""; | ||
TEST_SETTINGS="" | ||
PROJECT_SUBDIR="" | ||
|
||
if [ -n "${TARGET_FILE}" ]; then | ||
|
@@ -77,11 +77,11 @@ if [ -n "${ENV_FLAGS}" ]; then | |
ADDITIONAL_ENV="-- ${ENV_FLAGS}" | ||
fi | ||
|
||
cd "${PROJECT_PATH}/${PROJECT_FOLDER}/${PROJECT_SUBDIR}" || \ | ||
exitWithMsg "Can't cd to ${PROJECT_PATH}/${PROJECT_FOLDER}/${PROJECT_SUBDIR}" 1 | ||
cd "${PROJECT_PATH}/${PROJECT_FOLDER}/${PROJECT_SUBDIR}" || | ||
exitWithMsg "Can't cd to ${PROJECT_PATH}/${PROJECT_FOLDER}/${PROJECT_SUBDIR}" 1 | ||
|
||
runCmdAsDockerUser "PATH=${PATH} snyk ${SNYK_COMMAND} ${SNYK_PARAMS} \ | ||
${ADDITIONAL_ENV} > \"${OUTPUT_FILE}\" 2>\"${ERROR_FILE}\"" | ||
${ADDITIONAL_ENV} --json > \"${OUTPUT_FILE}\" 2>\"${ERROR_FILE}\"" | ||
|
||
RC=$? | ||
|
||
|
@@ -101,6 +101,7 @@ fi | |
runCmdAsDockerUser "touch \"${PROJECT_PATH}/${PROJECT_FOLDER}/${HTML_FILE}\"" | ||
|
||
if [ -n "$MONITOR" ]; then | ||
echo "Monitoring & generating report ..." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may mess up with our CI plugins logic, which parses the output of this script. Please consult with @snyk/comet There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
runCmdAsDockerUser "PATH=$PATH snyk monitor --json ${SNYK_PARAMS} ${ADDITIONAL_ENV} > ${MONITOR_OUTPUT_FILE} 2>$ERROR_FILE" | ||
runCmdAsDockerUser "cat ${MONITOR_OUTPUT_FILE} | jq -r \".uri\" | awk '{print \"<center><a target=\\\"_blank\\\" href=\\\"\" \$0 \"\\\">View On Snyk.io</a></center>\"}' > \"${PROJECT_PATH}/${PROJECT_FOLDER}/${HTML_FILE}\" 2>>\"${ERROR_FILE}\"" | ||
fi | ||
|
@@ -114,8 +115,6 @@ sed 's/<\/head>/ <link rel=\"stylesheet\" href=\"snyk_report.css\"><\/head>/' \ | |
|
||
runCmdAsDockerUser "cat /home/node/snyk_report.css > \ | ||
\"${PROJECT_PATH}/${PROJECT_FOLDER}/snyk_report.css\"" | ||
# fi | ||
# | ||
|
||
if [ $RC -ne "0" ]; then | ||
exitWithMsg "${OUTPUT_FILE}" "$RC" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,65 @@ | ||
#!/bin/bash | ||
|
||
virtualenv -p python snyk | ||
source snyk/bin/activate | ||
pip install -U -r "${PROJECT_PATH}/requirements.txt" | ||
|
||
exitWithMsg() { | ||
echo "Failed to run the process ..." | ||
|
||
if [ -f "$1" ]; then | ||
cat "$1" | ||
else | ||
echo "$1" | ||
fi | ||
|
||
exit "$2" | ||
} | ||
|
||
installRequirementsTxtDeps() { | ||
echo "Installing dependencies from requirements file" | ||
pip install -U -r "$1" | ||
} | ||
|
||
installPipfileDeps() { | ||
pushd "${PROJECT_PATH}/" | ||
echo "Found Pipfile" | ||
pipenv lock | ||
pipenv install --system | ||
popd | ||
} | ||
|
||
PROJECT_SUBDIR="" | ||
echo "Project path = ${PROJECT_PATH}" | ||
if [ -n "${TARGET_FILE}" ]; then | ||
if [ ! -f "${PROJECT_PATH}/${PROJECT_FOLDER}/${TARGET_FILE}" ]; then | ||
exitWithMsg "\"${PROJECT_PATH}/${PROJECT_FOLDER}/${TARGET_FILE}\" does not exist" 1 | ||
fi | ||
|
||
PROJECT_SUBDIR=$(dirname "${TARGET_FILE}") | ||
MANIFEST_NAME=$(basename "${TARGET_FILE}") | ||
TEST_SETTINGS="--file=${MANIFEST_NAME} " | ||
|
||
echo "Target file = ${TARGET_FILE}" | ||
|
||
case $MANIFEST_NAME in | ||
*req*.txt) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. support custom named requirement files |
||
echo "Installing dependencies from requirements file" | ||
installRequirementsTxtDeps "${PROJECT_PATH}/$MANIFEST_NAME" | ||
;; | ||
*setup.py) | ||
echo "Installing dependencies from setup.py" | ||
pip install -U -e "${PROJECT_PATH}" | ||
;; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. support setup.py |
||
*) | ||
exitWithMsg "\"${PROJECT_PATH}/${TARGET_FILE}\" is not supported" 1 | ||
;; | ||
esac | ||
fi | ||
|
||
if [ -f "${PROJECT_PATH}/requirements.txt" ]; then | ||
echo "Found requirement.txt" | ||
installRequirementsTxtDeps "${PROJECT_PATH}/requirements.txt" | ||
elif [ -f "${PROJECT_PATH}/Pipfile" ]; then | ||
installPipfileDeps | ||
fi | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confirmed here this will have no effect https://snyk.slack.com/archives/CHAB91L0N/p1578258775055200?thread_ts=1578073050.054200&cid=CHAB91L0N |
||
bash docker-entrypoint.sh "$@" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, much better! More consistent tone of voice, I find the use of
we
confusing.