Skip to content

Commit 22db0f6

Browse files
committed
Working container build
1 parent 2fd4f5f commit 22db0f6

File tree

3 files changed

+110
-6
lines changed

3 files changed

+110
-6
lines changed

docker/cpython.dockerfile

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ RUN inv cpython
2121
# Set up crossenv
2222
RUN ./bin/crossenv_setup.sh
2323

24+
# Install cross-compiled python packages
25+
RUN . ./cross_venv/bin/activate && inv libs.install
26+
27+
# TODO - enable these once the MXNet/ Horovod work is completed
2428
# Build mxnet
25-
RUN inv mxnet
29+
# RUN inv mxnet
2630

27-
# Build cpython
28-
RUN inv cpython
31+
# Install experimental pacakges
32+
# RUN . ./cross_venv/bin/activate && inv libs.install --experimental
2933

30-
# Cross-compile packages
31-
RUN . ./cross_venv/bin/activate && inv libs.install
32-
RUN . ./cross_venv/bin/activate && inv libs.install --experimental
34+
# Copy files into place
35+
RUN inv runtime

tasks/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
git,
77
libs,
88
mxnet,
9+
runtime,
910
)
1011

1112
ns = Collection(
@@ -14,4 +15,5 @@
1415
git,
1516
libs,
1617
mxnet,
18+
runtime,
1719
)

tasks/runtime.py

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import glob
2+
3+
from os.path import join, exists
4+
from shutil import rmtree, copytree
5+
from subprocess import run
6+
from os import makedirs, remove
7+
8+
from invoke import task
9+
10+
from tasks.env import PROJ_ROOT, THIRD_PARTY_DIR
11+
12+
FAASM_RUNTIME_ROOT = "/usr/local/faasm/runtime_root"
13+
CPYTHON_SRC = join(THIRD_PARTY_DIR, "cpython")
14+
CPYTHON_INSTALL_DIR = join(CPYTHON_SRC, "install", "wasm")
15+
CROSSENV_WASM_DIR = join(PROJ_ROOT, "cross_venv", "cross")
16+
17+
18+
def _glob_remove(glob_pattern, recursive=False, directory=False):
19+
print("Recursive remove: {}".format(glob_pattern))
20+
for filename in glob.iglob(glob_pattern, recursive=recursive):
21+
print("Removing {}".format(filename))
22+
if directory:
23+
rmtree(filename)
24+
else:
25+
remove(filename)
26+
27+
28+
def _clear_pyc_files(dir_path):
29+
pyc_glob = "{}/**/*.pyc".format(dir_path)
30+
_glob_remove(pyc_glob, recursive=True)
31+
32+
pycache_glob = "{}/**/__pycache__".format(dir_path)
33+
_glob_remove(pycache_glob, recursive=True, directory=True)
34+
35+
36+
@task(default=True)
37+
def copy(ctx):
38+
"""
39+
Copies the CPython archive and all installed modules from the cpython build
40+
into the Faasm runtime root
41+
"""
42+
43+
include_root = join(FAASM_RUNTIME_ROOT, "include")
44+
lib_root = join(FAASM_RUNTIME_ROOT, "lib")
45+
46+
if not exists(lib_root):
47+
print("Creating {}".format(lib_root))
48+
makedirs(lib_root)
49+
50+
if not exists(include_root):
51+
print("Creating {}".format(include_root))
52+
makedirs(include_root)
53+
54+
include_src_dir = join(CPYTHON_INSTALL_DIR, "include", "python3.8")
55+
lib_src_dir = join(CPYTHON_INSTALL_DIR, "lib", "python3.8")
56+
site_packages_src_dir = join(
57+
CROSSENV_WASM_DIR, "lib", "python3.8", "site-packages"
58+
)
59+
60+
include_dest_dir = join(include_root, "python3.8")
61+
lib_dest_dir = join(lib_root, "python3.8")
62+
site_packages_dest_dir = join(lib_dest_dir, "site-packages")
63+
64+
# Clear out pyc files
65+
print("Clearing out pyc files")
66+
_clear_pyc_files(lib_src_dir)
67+
_clear_pyc_files(site_packages_src_dir)
68+
69+
# Remove dirs to be replaced by those we copy in
70+
if exists(include_dest_dir):
71+
print("Removing {}".format(include_dest_dir))
72+
rmtree(include_dest_dir)
73+
74+
if exists(lib_dest_dir):
75+
print("Removing {}".format(lib_dest_dir))
76+
rmtree(lib_dest_dir)
77+
78+
# Copy CPython includes
79+
print("Copying {} to {}".format(include_src_dir, include_dest_dir))
80+
copytree(include_src_dir, include_dest_dir)
81+
82+
# Copy CPython libs
83+
print("Copying {} to {}".format(lib_src_dir, lib_dest_dir))
84+
copytree(lib_src_dir, lib_dest_dir)
85+
86+
# Copy cross-compiled modules
87+
if not exists(site_packages_dest_dir):
88+
makedirs(site_packages_dest_dir)
89+
90+
print(
91+
"Copying {} to {}".format(
92+
site_packages_src_dir, site_packages_dest_dir
93+
)
94+
)
95+
run(
96+
"cp -r {}/* {}/".format(site_packages_src_dir, site_packages_dest_dir),
97+
shell=True,
98+
check=True,
99+
)

0 commit comments

Comments
 (0)