Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

Support Pipfile #168

Merged
merged 6 commits into from
Jun 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ USER root
#
################################################################################

ENV PIPENV_RUNTIME 2.7

RUN easy_install virtualenv

USER buildbot
Expand All @@ -276,6 +278,8 @@ RUN virtualenv -p python3.6 --no-site-packages /opt/buildhome/python3.6 && \
/bin/bash -c 'source /opt/buildhome/python3.6/bin/activate' && \
ln -nfs /opt/buildhome/python3.6 /opt/buildhome/python3.6.4

RUN /opt/buildhome/python${PIPENV_RUNTIME}/bin/pip install pipenv

USER root


Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The specific patch versions included will depend on when the image was last buil
* 6
* 8 (default)
* Any version that `nvm` can install.
* Python - `runtime.txt`
* Python - `runtime.txt` or `Pipfile`
* 2.7 (default)
* 3.4
* 3.5
Expand All @@ -46,6 +46,8 @@ The specific patch versions included will depend on when the image was last buil
* Python
* pip
* Version corresponding with Python version. (default)
* Pipenv
* Latest version.
* PHP
* Composer
* Emacs
Expand Down
29 changes: 29 additions & 0 deletions run-build-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ export GIMME_CGO_ENABLED=true
export NVM_DIR="$HOME/.nvm"
export RVM_DIR="$HOME/.rvm"

# Pipenv configuration
export PIPENV_RUNTIME=2.7
export PIPENV_VENV_IN_PROJECT=1
export PIPENV_DEFAULT_PYTHON_VERSION=2.7

YELLOW="\033[0;33m"
NC="\033[0m" # No Color

Expand All @@ -25,6 +30,7 @@ mkdir -p $NETLIFY_CACHE_DIR/ruby_version
mkdir -p $NETLIFY_CACHE_DIR/node_modules
mkdir -p $NETLIFY_CACHE_DIR/.bundle
mkdir -p $NETLIFY_CACHE_DIR/bower_components
mkdir -p $NETLIFY_CACHE_DIR/.venv

# HOME caches
mkdir -p $NETLIFY_CACHE_DIR/.yarn_cache
Expand Down Expand Up @@ -159,6 +165,10 @@ install_dependencies() {
echo "Please see https://github.com/netlify/build-image/#included-software for current versions"
exit 1
fi
elif [ -f Pipfile ]
then
echo "Found Pipfile restoring Pipenv virtualenv"
restore_cwd_cache ".venv" "python virtualenv"
else
source $HOME/python2.7/bin/activate
fi
Expand Down Expand Up @@ -323,6 +333,24 @@ install_dependencies() {
echo "Error installing pip dependencies"
exit 1
fi
elif [ -f Pipfile ]
then
echo "Installing dependencies from Pipfile"
if $HOME/python$PIPENV_RUNTIME/bin/pipenv install
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be useful to set PIPENV_VENV_IN_PROJECT as multiple venvs are not needed on Netlify builds. setting that might improve performance a little.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, thanks! 🥇

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should move this (and the export lines from above) to the Dockerfile if possible. I'd rather pipenv be installed already, rather than done every build on-demand.

then
echo "Pipenv dependencies installed"
if source $($HOME/python$PIPENV_RUNTIME/bin/pipenv --venv)/bin/activate
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fwiw, doing this instead of pipenv shell and pipenv run means .env loading is not supported, which could break some Pipfile if it is expecting variables from .env to be present.

https://github.com/pypa/pipenv/blob/master/docs/advanced.rst#-automatic-loading-of-env
https://github.com/pypa/pipenv/blob/master/docs/advanced.rst#-support-for-environment-variables

Note that it isnt even possible to use .env vars during pipenv install. see pypa/pipenv#1906 (comment)

As a result, probably a good idea to set PIPENV_DONT_LOAD_ENV and document that .env isnt used by Netlify.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback! It seems to me that ENV variables are meant to be handled some other way on production. E.g. using https://www.netlify.com/docs/continuous-deployment/#build-environment-variables.

Based on discussion in pypa/pipenv#773 (comment) pipenv shell is meant only for development and using source .../bin/activate is OK for production.

then
echo "Python version set to $(python -V)"
else
echo "Error activating Pipenv environment"
exit 1
fi
else
echo "Error installing Pipenv dependencies"
echo "Please see https://github.com/netlify/build-image/#included-software for current versions"
exit 1
fi
fi

# NPM Dependencies
Expand Down Expand Up @@ -494,6 +522,7 @@ cache_artifacts() {
cache_cwd_directory ".bundle" "ruby gems"
cache_cwd_directory "bower_components" "bower components"
cache_cwd_directory "node_modules" "node modules"
cache_cwd_directory ".venv" "python virtualenv"

cache_home_directory ".yarn_cache" "yarn cache"
cache_home_directory ".cache" "pip cache"
Expand Down