Skip to content

Refactor/change cache dir location #34

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

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion bin/boxfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
cat <<-END
run.config:
cache_dirs:
- src
- .nanobox/pip
END
if [[ $(grep -c build_triggers /opt/nanobox/hooks/lib/boxfile.rb) -gt 1 ]]; then
cat <<-END
Expand Down
3 changes: 3 additions & 0 deletions bin/build
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ nos_init "$@"
# install python interpreter and pip
install_runtime_packages

# set pip env
set_pip_env

# setup python environment
setup_python_env

Expand Down
28 changes: 27 additions & 1 deletion lib/python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,15 @@ pip_install_cmd() {

# the default pip install cmd when a user-specified cmd is not present
default_pip_install() {
echo "pip install -I -r requirements.txt"
echo "\
pip install \
-I \
-r requirements.txt \
--disable-pip-version-check \
--no-cache-dir \
--target=$(nos_code_dir)/.nanobox/pip/src \
--upgrade \
--install-option='--install-scripts=$(nos_code_dir)/.nanobox/pip/bin'"
}

# Install dependencies via pip from requirements.txt
Expand All @@ -136,3 +144,21 @@ pip_install() {
cd - >/dev/null
fi
}

# Generate the payload to render the pip env profile.d template
pip_env_payload() {
cat <<-END
{
"code_dir": "$(nos_code_dir)"
}
END
}

# Since we install pip modules into a custom cache_dir, we need
# to setup the environment (with env vars) for the python app to work
set_pip_env() {
nos_template \
"profile.d/pip.sh" \
"$(nos_etc_dir)/profile.d/pip.sh" \
"$(pip_env_payload)"
}
8 changes: 8 additions & 0 deletions templates/profile.d/pip.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

# Nanobox stashes the pip module src and bin dirs inside of a cache_dir
# at {{code_dir}}/.nanobox/pip. We need to set PATH to include the bin dir
# and PYTHONPATH to include the src dir

export PATH={{code_dir}}/.nanobox/pip/bin:$PATH
export PYTHONPATH={{code_dir}}/.nanobox/pip/src:$PYTHONPATH
4 changes: 2 additions & 2 deletions test/apps/simple-python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-e git://github.com/webpy/webpy.git#egg=web.py
web.py
gunicorn
Pillow
Pillow
5 changes: 4 additions & 1 deletion test/tests/integration/simple-python.bats
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@ setup() {
# cd into the app code_dir
cd /tmp/code

# source the profile.d/pip.sh env
source /data/etc/profile.d/pip.sh

# start the server in the background
/data/bin/gunicorn -b 0.0.0.0:8080 app:wsgiapp &
/tmp/code/.nanobox/pip/bin/gunicorn -b 0.0.0.0:8080 app:wsgiapp &

# grab the pid
pid=$!
Expand Down
3 changes: 3 additions & 0 deletions test/util/env.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@

directories=(
"/tmp/code"
"/tmp/code/.nanobox"
"/tmp/code/.nanobox/pip"
"/tmp/app"
"/tmp/cache"
"/data"
"/data/etc"
"/data/etc/env.d"
"/data/etc/profile.d"
)

prepare_environment() {
Expand Down