Skip to content

Commit

Permalink
refactor(tensorflow-cpu): install python virtual environment
Browse files Browse the repository at this point in the history
Signed-off-by: Massimiliano Giovagnoli <massimiliano.giovagnoli@chainguard.dev>
  • Loading branch information
maxgio92 committed Jan 10, 2025
1 parent 575a740 commit 6ce4725
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions tensorflow-cpu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ package:
- license: Apache-2.0
target-architecture:
- x86_64
options:
# We're creating a virtual environment.
# Don't pull in other packages if dependencies are already vendored.
no-depends: true
# Don't install if something is vendored that another package depends on.
no-provides: true
dependencies:
runtime:
- bash
Expand All @@ -21,7 +27,7 @@ package:
vars:
py-version: 3.11
pypi-package: tensorflow-cpu
prefix: /usr
shared: /usr/share/tensorflow

environment:
contents:
Expand All @@ -37,34 +43,43 @@ environment:
pipeline:
- uses: git-checkout
with:
expected-commit: 35a7dbc754193523e5582ce5b5cbbb4c07cff7b2
expected-commit: e23ae5591020ef3cb2917293ed92af7ea70bcdb1
repository: https://github.com/tensorflow/build
branch: master

- working-directory: tensorflow_runtime_dockerfiles
pipeline:
- name: Create virtual environment
runs: |
python -m venv .venv
- name: Install cpu requirements
runs: |
source .venv/bin/activate
pip${{vars.py-version}} install \
--no-cache-dir \
--root ${{targets.contextdir}} \
--prefix ${{vars.prefix}} \
-r cpu.requirements.txt
- name: Install Tensorflow
runs: |
source .venv/bin/activate
pip${{vars.py-version}} install \
--no-cache-dir \
--root ${{targets.contextdir}} \
--prefix ${{vars.prefix}} \
${{vars.pypi-package}}
- name: Install jupyter requirements
runs: |
source .venv/bin/activate
pip${{vars.py-version}} install \
--no-cache-dir \
--root ${{targets.contextdir}} \
--prefix ${{vars.prefix}} \
-r jupyter.requirements.txt \
-U
- name: Cleanup the virtual environment
runs: |
find .venv -name "*.pyc" -delete
find .venv -name "__pycache__" -exec rm -rf {} +
- name: Install the virtual environment
runs: |
mkdir -p ${{targets.contextdir}}/${{vars.shared}}
mv .venv/* ${{targets.contextdir}}/${{vars.shared}}
sed -i "s|/home/build/tensorflow_runtime_dockerfiles/.venv|${{vars.shared}}|g" ${{targets.contextdir}}/${{vars.shared}}/bin/*
- name: Install bashrc
runs: |
mkdir -p ${{targets.contextdir}}/etc
Expand All @@ -73,15 +88,14 @@ pipeline:
runs: |
mkdir -p ${{targets.contextdir}}/tf/tensorflow-tutorials
cp jupyter.readme.md ${{targets.contextdir}}/tf/tensorflow-tutorials/README.md
- name: Cleanup pycache
runs: |
find . -name '__pycache__' -exec rm -rf {} +
test:
environment:
contents:
packages:
- curl
environment:
PYTHONPATH: ${{vars.shared}}/lib/python${{vars.py-version}}/site-packages
pipeline:
- name: Test import of IPython kernel for Jupyter
uses: python/import
Expand Down Expand Up @@ -113,7 +127,7 @@ test:
uses: test/daemon-check-output
with:
start: |
jupyter notebook --notebook-dir=/tf --ip 0.0.0.0 --no-browser --allow-root
${{vars.shared}}/bin/jupyter notebook --notebook-dir=/tf --ip 0.0.0.0 --no-browser --allow-root
post: |
curl --fail --location --request GET --head --silent localhost:8888
expected_output: "is running at:"
Expand Down

0 comments on commit 6ce4725

Please sign in to comment.