Skip to content

Commit

Permalink
cleaning CM Docker
Browse files Browse the repository at this point in the history
  • Loading branch information
gfursin committed Aug 5, 2023
1 parent fce3db2 commit 973bb29
Show file tree
Hide file tree
Showing 38 changed files with 38 additions and 942 deletions.
35 changes: 0 additions & 35 deletions cm-mlops/script/build-docker-image/examples/Dockerfile.cm

This file was deleted.

32 changes: 0 additions & 32 deletions cm-mlops/script/build-docker-image/examples/Dockerfile.cm-min

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion cm-mlops/script/build-docker-image/examples/build-cm.bat

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion cm-mlops/script/build-docker-image/examples/push-cm.bat

This file was deleted.

This file was deleted.

This file was deleted.

8 changes: 4 additions & 4 deletions cm-mlops/script/build-docker-image/run.bat
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
if exist %CM_DOCKERFILE_WITH_PATH% (
echo .git > .dockerignore
rem echo docker build %CM_DOCKER_CACHE_ARG% %CM_DOCKER_BUILD_ARGS% -f %CM_DOCKERFILE_WITH_PATH% -t %CM_DOCKER_IMAGE_REPO%/%CM_DOCKER_IMAGE_NAME%:%CM_DOCKER_IMAGE_TAG% .
echo.
echo docker build %CM_DOCKER_CACHE_ARG% %CM_DOCKER_BUILD_ARGS% -f %CM_DOCKERFILE_WITH_PATH% -t %CM_DOCKER_IMAGE_REPO%:%CM_DOCKER_IMAGE_TAG% .
echo docker build %CM_DOCKER_CACHE_ARG% %CM_DOCKER_BUILD_ARGS% -f %CM_DOCKERFILE_WITH_PATH% -t %CM_DOCKER_IMAGE_REPO%/%CM_DOCKER_IMAGE_NAME%:%CM_DOCKER_IMAGE_TAG% .
rem echo.
rem echo docker build %CM_DOCKER_CACHE_ARG% %CM_DOCKER_BUILD_ARGS% -f %CM_DOCKERFILE_WITH_PATH% -t %CM_DOCKER_IMAGE_REPO%:%CM_DOCKER_IMAGE_TAG% .

rem docker build %CM_DOCKER_CACHE_ARG% %CM_DOCKER_BUILD_ARGS% -f "%CM_DOCKERFILE_WITH_PATH%" -t "%CM_DOCKER_IMAGE_REPO%/%CM_DOCKER_IMAGE_NAME%:%CM_DOCKER_IMAGE_TAG%" .
echo.
docker build %CM_DOCKER_CACHE_ARG% %CM_DOCKER_BUILD_ARGS% -f "%CM_DOCKERFILE_WITH_PATH%" -t "%CM_DOCKER_IMAGE_REPO%:%CM_DOCKER_IMAGE_TAG%" .
docker build %CM_DOCKER_CACHE_ARG% %CM_DOCKER_BUILD_ARGS% -f "%CM_DOCKERFILE_WITH_PATH%" -t "%CM_DOCKER_IMAGE_REPO%/%CM_DOCKER_IMAGE_NAME%:%CM_DOCKER_IMAGE_TAG%" .
IF %ERRORLEVEL% NEQ 0 EXIT %ERRORLEVEL%

rem TO CHECK IMAGE RUN FROM HERE LATER ...
Expand Down
4 changes: 2 additions & 2 deletions cm-mlops/script/build-docker-image/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

if [ -f "${CM_DOCKERFILE_WITH_PATH}" ]; then
echo ".git" > .dockerignore
echo "docker build ${CM_DOCKER_CACHE_ARG} ${CM_DOCKER_BUILD_ARGS} -f ${CM_DOCKERFILE_WITH_PATH} -t ${CM_DOCKER_IMAGE_REPO}:${CM_DOCKER_IMAGE_TAG} ."
echo "docker build ${CM_DOCKER_CACHE_ARG} ${CM_DOCKER_BUILD_ARGS} -f ${CM_DOCKERFILE_WITH_PATH} -t ${CM_DOCKER_IMAGE_REPO}/${CM_DOCKER_IMAGE_NAME}:${CM_DOCKER_IMAGE_TAG} ."

docker build ${CM_DOCKER_CACHE_ARG} ${CM_DOCKER_BUILD_ARGS} -f "${CM_DOCKERFILE_WITH_PATH}" -t "${CM_DOCKER_IMAGE_REPO}:${CM_DOCKER_IMAGE_TAG}" .
docker build ${CM_DOCKER_CACHE_ARG} ${CM_DOCKER_BUILD_ARGS} -f "${CM_DOCKERFILE_WITH_PATH}" -t "${CM_DOCKER_IMAGE_REPO}/${CM_DOCKER_IMAGE_NAME}:${CM_DOCKER_IMAGE_TAG}" .
test $? -eq 0 || exit 1

fi
3 changes: 2 additions & 1 deletion cm-mlops/script/build-dockerfile/_cm.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"pre_run_cmds": "CM_DOCKER_PRE_RUN_COMMANDS",
"post_run_cmds": "CM_DOCKER_POST_RUN_COMMANDS",
"copy_files": "CM_DOCKER_COPY_FILES",
"pip_extra_flags": "CM_DOCKER_PIP_INSTALL_EXTRA_FLAGS"
"pip_extra_flags": "CM_DOCKER_PIP_INSTALL_EXTRA_FLAGS",
"package_manager_update_cmd": "CM_PACKAGE_MANAGER_UPDATE_CMD"
},
"default_env": {
"CM_DOCKER_BUILD_SLIM": "no",
Expand Down
17 changes: 0 additions & 17 deletions cm-mlops/script/build-dockerfile/build_dockerfiles.py

This file was deleted.

33 changes: 30 additions & 3 deletions cm-mlops/script/build-dockerfile/customize.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,29 @@ def preprocess(i):
if env["CM_DOCKER_OS"] not in [ "ubuntu", "rhel", "arch" ]:
return {'return': 1, 'error': "Currently only ubuntu, rhel and arch are supported in CM docker"}
path = i['run_script_input']['path']

with open(os.path.join(path, "dockerinfo.json")) as f:
config = json.load(f)

build_args = []
input_args = []
copy_files = []

if 'CM_DOCKER_RUN_SCRIPT_TAGS' in env:
script_tags=env['CM_DOCKER_RUN_SCRIPT_TAGS']
found_scripts = cm.access({'action': 'search', 'automation': 'script', 'tags': script_tags})
scripts_list = found_scripts['list']

if not scripts_list:
return {'return': 1, 'error': 'No CM script found for tags ' + script_tags}

if len(scripts_list) > 1:
return {'return': 1, 'error': 'More than one scripts found for tags '+ script_tags}

script = scripts_list[0]
input_mapping = script.meta.get('input_mapping', {})
default_env = script.meta.get('default_env', {})

for input_,env_ in input_mapping.items():
if input_ == "docker":
continue
Expand Down Expand Up @@ -57,11 +64,22 @@ def preprocess(i):
dockerfile_with_path = env['CM_DOCKERFILE_WITH_PATH']
dockerfile_dir = os.path.dirname(dockerfile_with_path)

os.makedirs(os.path.dirname(dockerfile_with_path), exist_ok=True)
extra_dir = os.path.dirname(dockerfile_with_path)

if extra_dir!='':
os.makedirs(extra_dir, exist_ok=True)

f = open(dockerfile_with_path, "w")
EOL = env['CM_DOCKER_IMAGE_EOL']
f.write('FROM ' + docker_image_base + EOL)

# Maintainers
f.write(EOL)
f.write('# Maintained by the MLCommons taskforce on automation and reproducibility' + EOL)
f.write('LABEL github="https://github.com/mlcommons/ck"' + EOL)
f.write('LABEL maintainer="https://cKnowledge.org/mlcommons-taskforce"' + EOL)
f.write(EOL)

image_label = get_value(env, config, 'LABEL', 'CM_DOCKER_IMAGE_LABEL')
if image_label:
f.write('LABEL ' + image_label + EOL)
Expand Down Expand Up @@ -89,14 +107,15 @@ def preprocess(i):
f.write('COPY '+ filename+" "+copy_split[1] + EOL)

f.write(EOL+'# Notes: https://runnable.com/blog/9-common-dockerfile-mistakes'+EOL+'# Install system dependencies' + EOL)
f.write('RUN ' + get_value(env, config, 'package-manager-update-cmd') + EOL)
f.write('RUN ' + get_value(env, config, 'package-manager-update-cmd', 'CM_PACKAGE_MANAGER_UPDATE_CMD') + EOL)
f.write('RUN '+ get_value(env, config, 'package-manager-get-cmd') + " " + " ".join(get_value(env, config,
'packages')) + EOL)

pip_extra_flags = env.get('CM_DOCKER_PIP_INSTALL_EXTRA_FLAGS', '')

f.write(EOL+'# Install python packages' + EOL)
f.write('RUN python3 -m pip install ' + " ".join(get_value(env, config, 'python-packages')) + ' ' + pip_extra_flags + ' ' + EOL)

f.write(EOL+'# Setup docker environment' + EOL)

entry_point = get_value(env, config, 'ENTRYPOINT', 'CM_DOCKER_IMAGE_ENTRYPOINT')
Expand Down Expand Up @@ -160,15 +179,23 @@ def preprocess(i):
for comment in env.get('CM_DOCKER_RUN_COMMENTS', []):
f.write(comment + EOL)

skip_extra = False
if 'CM_DOCKER_RUN_CMD' not in env:
if 'CM_DOCKER_RUN_SCRIPT_TAGS' not in env:
env['CM_DOCKER_RUN_CMD']="cm version"
skip_extra = True
else:
env['CM_DOCKER_RUN_CMD']="cm run script --quiet --tags=" + env['CM_DOCKER_RUN_SCRIPT_TAGS']

fake_run = " --fake_run" + dockerfile_env_input_string
fake_run = fake_run + " --fake_deps" if env.get('CM_DOCKER_FAKE_DEPS') else fake_run
f.write('RUN ' + env['CM_DOCKER_RUN_CMD'] + fake_run + ' --quiet ' + run_cmd_extra + EOL)

x = 'RUN ' + env['CM_DOCKER_RUN_CMD']

if not skip_extra:
x += fake_run + ' --quiet ' + run_cmd_extra

f.write(x + EOL)

#fake_run to install the dependent scripts and caching them
if not "run" in env['CM_DOCKER_RUN_CMD'] and env.get('CM_REAL_RUN', None):
Expand Down
7 changes: 0 additions & 7 deletions docker/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions docker/cm--purge-docker.bat

This file was deleted.

3 changes: 0 additions & 3 deletions docker/cm--purge-docker.sh

This file was deleted.

32 changes: 0 additions & 32 deletions docker/cm-archlinux.Dockerfile

This file was deleted.

14 changes: 0 additions & 14 deletions docker/cm-rhel-cpu-build.bat

This file was deleted.

16 changes: 0 additions & 16 deletions docker/cm-rhel-cpu-build.sh

This file was deleted.

3 changes: 0 additions & 3 deletions docker/cm-rhel-cpu-run-bash.bat

This file was deleted.

3 changes: 0 additions & 3 deletions docker/cm-rhel-cpu-run-image-classification.bat

This file was deleted.

3 changes: 0 additions & 3 deletions docker/cm-rhel-cpu-run-image-corner-detection.bat

This file was deleted.

Loading

0 comments on commit 973bb29

Please sign in to comment.