This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
[CD] Adds python docker image pipeline #16435
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
59e7781
Adds docker utilities
perdasilva 8eafd39
Adds python docker pipeline
perdasilva 2a5509e
Fixes Dockerfile instruction order, build context, and re-uses existi…
perdasilva daaebf8
Refactors docker login functionality out of docker_cache script and r…
perdasilva 57093a4
Cleans up docker container on sigterm and sigint
perdasilva File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# -*- mode: dockerfile -*- | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
# Python MXNet Dockerfile | ||
|
||
# NOTE: Assumes wheel_build directory is the context root when building | ||
|
||
ARG BASE_IMAGE | ||
FROM ${BASE_IMAGE} | ||
|
||
ARG PYTHON_CMD=python | ||
RUN apt-get update && \ | ||
apt-get install -y wget ${PYTHON_CMD}-dev gcc && \ | ||
wget https://bootstrap.pypa.io/get-pip.py && \ | ||
${PYTHON_CMD} get-pip.py | ||
|
||
ARG MXNET_COMMIT_ID | ||
ENV MXNET_COMMIT_ID=${MXNET_COMMIT_ID} | ||
|
||
RUN mkdir -p /mxnet | ||
COPY dist/*.whl /mxnet/. | ||
|
||
WORKDIR /mxnet | ||
RUN WHEEL_FILE=$(ls -t /mxnet | head -n 1) && pip install ${WHEEL_FILE} && rm -f ${WHEEL_FILE} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# -*- mode: dockerfile -*- | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
# Python MXNet Dockerfile | ||
|
||
# NOTE: Assumes 'ci' directory is root of the context when building | ||
|
||
ARG BASE_IMAGE | ||
FROM ${BASE_IMAGE} | ||
|
||
ARG USER_ID=1001 | ||
ARG GROUP_ID=1001 | ||
|
||
COPY ./docker/install/ubuntu_adduser.sh /scripts/ubuntu_adduser.sh | ||
|
||
RUN mkdir -p /work | ||
RUN /scripts/ubuntu_adduser.sh | ||
|
||
WORKDIR /work/mxnet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// -*- mode: groovy -*- | ||
|
||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
// | ||
// Jenkins pipeline | ||
// See documents at https://jenkins.io/doc/book/pipeline/jenkinsfile/ | ||
|
||
// NOTE: | ||
// ci_utils and cd_utils are loaded by the originating Jenkins job, e.g. jenkins/Jenkinsfile_release_job | ||
|
||
def get_pipeline(mxnet_variant) { | ||
def node_type = mxnet_variant.startsWith('cu') ? NODE_LINUX_GPU : NODE_LINUX_CPU | ||
return cd_utils.generic_pipeline(mxnet_variant, this, node_type) | ||
} | ||
|
||
// Returns the (Docker) environment for the given variant | ||
// The environment corresponds to the docker files in the 'docker' directory | ||
def get_environment(mxnet_variant) { | ||
if (mxnet_variant.startsWith("cu")) { | ||
// Remove 'mkl' suffix from variant to properly format test environment | ||
return "ubuntu_gpu_${mxnet_variant.replace('mkl', '')}" | ||
} | ||
return "ubuntu_cpu" | ||
} | ||
|
||
|
||
def build(mxnet_variant) { | ||
ws("workspace/python_docker/${mxnet_variant}/${env.BUILD_NUMBER}") { | ||
ci_utils.init_git() | ||
cd_utils.restore_artifact(mxnet_variant, 'static') | ||
|
||
// package wheel file | ||
def nvidia_docker = mxnet_variant.startsWith('cu') | ||
def environment = get_environment(mxnet_variant) | ||
ci_utils.docker_run(environment, "cd_package_pypi ${mxnet_variant}", nvidia_docker) | ||
|
||
// build python docker images | ||
sh "./cd/python/docker/python_images.sh build ${mxnet_variant} py3" | ||
sh "./cd/python/docker/python_images.sh build ${mxnet_variant} py2" | ||
} | ||
} | ||
|
||
def test(mxnet_variant) { | ||
ws("workspace/python_docker/${mxnet_variant}/${env.BUILD_NUMBER}") { | ||
// test python docker images | ||
sh "./cd/python/docker/python_images.sh test ${mxnet_variant} py3" | ||
sh "./cd/python/docker/python_images.sh test ${mxnet_variant} py2" | ||
} | ||
} | ||
|
||
def push(mxnet_variant) { | ||
ws("workspace/python_docker/${mxnet_variant}/${env.BUILD_NUMBER}") { | ||
// push python docker images | ||
sh "./cd/python/docker/python_images.sh push ${mxnet_variant} py3" | ||
sh "./cd/python/docker/python_images.sh push ${mxnet_variant} py2" | ||
} | ||
} | ||
|
||
return this |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
# Executes mxnet python images pipeline functions: build, test, publish | ||
# Assumes script is run from the root of the mxnet repository | ||
# Assumes script is being run within MXNet CD infrastructure | ||
|
||
set -xe | ||
|
||
usage="Usage: python_images.sh <build|test|publish> MXNET-VARIANT <py2|py3>" | ||
|
||
command=${1:?$usage} | ||
mxnet_variant=${2:?$usage} | ||
python_version=${3:?usage} | ||
|
||
cd_utils='cd/utils' | ||
ci_utils='ci/' | ||
|
||
case ${python_version} in | ||
py3) | ||
python_cmd="python3" | ||
;; | ||
py2) | ||
python_cmd="python" | ||
;; | ||
*) | ||
echo "Error: specify python version with either 'py2' or 'py3'" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
docker_tags=($(./${cd_utils}/docker_tag.sh ${mxnet_variant})) | ||
main_tag="${docker_tags[0]}_${python_version}" | ||
base_image=$(./${cd_utils}/mxnet_base_image.sh ${mxnet_variant}) | ||
repository="python" | ||
image_name="${repository}:${main_tag}" | ||
|
||
resources_path='cd/python/docker' | ||
|
||
container_name=`uuidgen` | ||
|
||
if [ ! -z "${RELEASE_DOCKERHUB_REPOSITORY}" ]; then | ||
image_name="${RELEASE_DOCKERHUB_REPOSITORY}/${image_name}" | ||
fi | ||
|
||
docker_clean_up() { | ||
docker rm -f "${container_name}" | ||
} | ||
|
||
|
||
# Builds runtime image | ||
build() { | ||
# NOTE: Ensure the correct context root is passed in when building - Dockerfile expects ./wheel_build | ||
docker build -t "${image_name}" --build-arg PYTHON_CMD=${python_cmd} --build-arg BASE_IMAGE="${base_image}" --build-arg MXNET_COMMIT_ID=${GIT_COMMIT} -f ${resources_path}/Dockerfile ./wheel_build | ||
} | ||
|
||
# Tests the runtime image by executing runtime_images/test_image.sh within the image | ||
# Assumes image exists locally | ||
test() { | ||
local runtime_param="" | ||
if [[ ${mxnet_variant} == cu* ]]; then | ||
runtime_param="--runtime=nvidia" | ||
fi | ||
local test_image_name="${image_name}_test" | ||
|
||
# Ensure the correct context root is passed in when building - Dockerfile.test expects ci directory | ||
docker build -t "${test_image_name}" --build-arg USER_ID=`id -u` --build-arg GROUP_ID=`id -g` --build-arg BASE_IMAGE="${image_name}" -f ${resources_path}/Dockerfile.test ./ci | ||
|
||
# Trap the SIGINT and SIGTERM signals and quickly kill the container | ||
# This avoid leaving zombie containers hanging around on the host | ||
trap docker_clean_up SIGINT SIGTERM | ||
docker run ${runtime_param} --name "${container_name}" -u `id -u`:`id -g` -v `pwd`:/mxnet "${test_image_name}" ${resources_path}/test_python_image.sh "${mxnet_variant}" "${python_cmd}" | ||
} | ||
|
||
# Pushes the runtime image to the repository | ||
# Assumes image exists locally | ||
push() { | ||
if [ -z "${RELEASE_DOCKERHUB_REPOSITORY}" ]; then | ||
echo "Cannot publish image without RELEASE_DOCKERHUB_REPOSITORY environment variable being set." | ||
exit 1 | ||
fi | ||
|
||
./${ci_utils}/docker_login.py | ||
|
||
# Push image | ||
docker push "${image_name}" | ||
|
||
# Iterate over remaining tags, if any | ||
for ((i=1;i<${#docker_tags[@]};i++)); do | ||
local docker_tag="${docker_tags[${i}]}" | ||
local latest_image_name="${RELEASE_DOCKERHUB_REPOSITORY}/${repository}:${docker_tag}" | ||
|
||
# latest and latest gpu should only be pushed for py3 | ||
if [[ ${docker_tag} == "latest" || ${docker_tag} == "latest_gpu" ]]; then | ||
if [[ ${python_version} == "py2" ]]; then | ||
continue | ||
fi | ||
else | ||
latest_image_name="${latest_image_name}_${python_version}" | ||
fi | ||
|
||
docker tag "${image_name}" "${latest_image_name}" | ||
docker push "${latest_image_name}" | ||
done | ||
} | ||
|
||
case ${command} in | ||
"build") | ||
build | ||
;; | ||
|
||
"test") | ||
test | ||
;; | ||
|
||
"push") | ||
push | ||
;; | ||
|
||
*) | ||
echo $usage | ||
exit 1 | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
# To be run _within_ a runtime image | ||
# Tests the Runtime docker image | ||
# Assumes the mxnet source directory is mounted on /mxnet and cwd is /mxnet | ||
|
||
set -ex | ||
|
||
# Variant parameter should be passed in | ||
mxnet_variant=${1:?"Missing mxnet variant"} | ||
python_cmd=${2:?"Missing python version (python or python3)"} | ||
|
||
if [ -z "${MXNET_COMMIT_ID}" ]; then | ||
echo "MXNET_COMMIT_ID environment variable is empty. Please rebuild the image with MXNET_COMMIT_ID build-arg specified." | ||
exit 1 | ||
fi | ||
|
||
# Execute tests | ||
if [[ $mxnet_variant == cu* ]]; then | ||
mnist_params="--gpu 0" | ||
test_conv_params="--gpu" | ||
fi | ||
|
||
if [[ $mxnet_variant == *mkl ]]; then | ||
${python_cmd} tests/python/mkl/test_mkldnn.py | ||
fi | ||
|
||
${python_cmd} tests/python/train/test_conv.py ${test_conv_params} | ||
${python_cmd} example/image-classification/train_mnist.py ${mnist_params} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the point of this file? It feels like you're replicating mechanisms we have in the regular CI dockerfiles
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a base image for the tests. Because we mount the local fs we need to use that same user. Same problem as in CI. I'll use the ubuntu_adduser.sh script, though...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done