Skip to content

Commit fa766a4

Browse files
Changes for CD pipeline (aws#160)
adds buildspec file to build pip wheels, and updates install_smdebug script.
1 parent 91eb151 commit fa766a4

File tree

4 files changed

+106
-23
lines changed

4 files changed

+106
-23
lines changed

config/buildspec_build_wheel.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Build Spec for AWS CodeBuild CI to build smdebug pip wheels
2+
3+
version: 0.2
4+
env:
5+
variables:
6+
CORE_COMMIT: ""
7+
RULES_COMMIT: ""
8+
9+
phases:
10+
install:
11+
commands:
12+
- su && apt-get update
13+
- apt-get install sudo -qq -o=Dpkg::Use-Pty=0
14+
- sudo apt-get update -qq -o=Dpkg::Use-Pty=0
15+
- sudo apt-get install unzip -qq -o=Dpkg::Use-Pty=0
16+
- cd $CODEBUILD_SRC_DIR && chmod +x config/protoc_downloader.sh && ./config/protoc_downloader.sh
17+
- pip install --upgrade pip==19.3.1
18+
- pip install -q pytest wheel pyYaml pytest-html pre-commit
19+
- pip uninstall -y boto3 && pip uninstall -y aiobotocore && pip uninstall -y botocore
20+
21+
build:
22+
commands:
23+
- cd $CODEBUILD_SRC_DIR && if [ -z "$CORE_COMMIT" ]; then export CORE_COMMIT=$(git log -1 --pretty=%h); fi
24+
- cd $CODEBUILD_SRC_DIR && echo $CORE_COMMIT > smdebug/CORE_COMMIT
25+
- cd $CODEBUILD_SRC_DIR && git checkout $CORE_COMMIT && python setup.py bdist_wheel --universal
26+
- cd $CODEBUILD_SRC_DIR_RULES && if [ -z "$RULES_COMMIT" ]; then export RULES_COMMIT=$(git log -1 --pretty=%h); fi
27+
- cd $CODEBUILD_SRC_DIR_RULES && echo $RULES_COMMIT > smdebug_rules/RULES_COMMIT
28+
- cd $CODEBUILD_SRC_DIR_RULES && git checkout $RULES_COMMIT && python setup.py bdist_wheel --universal
29+
30+
post_build:
31+
commands:
32+
- if [ "$CODEBUILD_BUILD_SUCCEEDING" -eq 0 ]; then echo "ERROR BUILD FAILED " && exit 1 ; fi
33+
- if [ "$CODEBUILD_BUILD_SUCCEEDING" -eq 1 ]; then echo "INFO BUILD SUCCEEDED !!! " ; fi
34+
35+
artifacts:
36+
files:
37+
- $CODEBUILD_SRC_DIR/dist/*.whl
38+
- $CODEBUILD_SRC_DIR/smdebug/CORE_COMMIT
39+
- $CODEBUILD_SRC_DIR_RULES/dist/*.whl
40+
- $CODEBUILD_SRC_DIR_RULES/smdebug_rules/RULES_COMMIT
41+
name: $(date +%F)
42+
discard-paths: yes

config/buildspec_zero_code_change.yml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,24 @@ env:
1818
phases:
1919
install:
2020
commands:
21-
- . config/change_branch.sh
2221
- su && apt-get update
23-
- apt-get install sudo -qq -o=Dpkg::Use-Pty=0 # silence output: https://askubuntu.com/a/668859/724247
22+
- apt-get install sudo -qq -o=Dpkg::Use-Pty=0
2423
- sudo apt-get update -qq -o=Dpkg::Use-Pty=0
2524
- sudo apt-get install unzip -qq -o=Dpkg::Use-Pty=0
2625
- cd $CODEBUILD_SRC_DIR && chmod +x config/protoc_downloader.sh && ./config/protoc_downloader.sh
27-
- pip install -U pip
28-
- pip install -q pytest wheel pyYaml pytest-html pre-commit
26+
- pip install --upgrade pip==19.3.1
27+
- pip install -q pytest wheel pyYaml pytest-html pre-commit awscli
28+
- cd $CODEBUILD_SRC_DIR && chmod +x config/install_smdebug.sh && chmod +x config/check_smdebug_install.sh && ./config/install_smdebug.sh;
2929

3030
build:
3131
commands:
32-
- cd $CODEBUILD_SRC_DIR && chmod +x config/install_smdebug.sh && chmod +x config/check_smdebug_install.sh && ./config/install_smdebug.sh && cd ..
33-
- cd $RULES_CODEBUILD_SRC_DIR && python setup.py bdist_wheel --universal && pip install dist/*.whl && cd ..
34-
- cd $CODEBUILD_SRC_DIR && chmod +x config/tests.sh && PYTHONPATH=. ./config/tests.sh && mkdir -p upload/$CURRENT_COMMIT_PATH/wheels && cp ./dist/*.whl upload/$CURRENT_COMMIT_PATH/wheels && cd ..
35-
- cd $RULES_CODEBUILD_SRC_DIR && chmod +x config/tests.sh && mkdir -p upload/$CURRENT_COMMIT_PATH/wheels && PYTHONPATH=. ./config/tests.sh && cp ./dist/*.whl upload/$CURRENT_COMMIT_PATH/wheels && cd ..
32+
- cd $CODEBUILD_SRC_DIR && chmod +x config/tests.sh && mkdir -p upload/$CURRENT_COMMIT_PATH/wheels && PYTHONPATH=. ./config/tests.sh && cp ./dist/*.whl upload/$CURRENT_COMMIT_PATH/wheels && cd ..
33+
- cd $CODEBUILD_SRC_DIR_RULES && chmod +x config/tests.sh && mkdir -p upload/$CURRENT_COMMIT_PATH/wheels && PYTHONPATH=. ./config/tests.sh && cp ./dist/*.whl upload/$CURRENT_COMMIT_PATH/wheels && cd ..
3634

3735
post_build:
3836
commands:
3937
- . $CODEBUILD_SRC_DIR/config/upload_on_end.sh
4038
- rm -rf $CODEBUILD_SRC_DIR/upload/$CURRENT_COMMIT_PATH
41-
- rm -rf $RULES_CODEBUILD_SRC_DIR/upload/$CURRENT_COMMIT_PATH
39+
- rm -rf $CODEBUILD_SRC_DIR_RULES/upload/$CURRENT_COMMIT_PATH
4240
- if [ "$CODEBUILD_BUILD_SUCCEEDING" -eq 0 ]; then echo "ERROR BUILD FAILED " && exit 1 ; fi
4341
- if [ "$CODEBUILD_BUILD_SUCCEEDING" -eq 1 ]; then echo "INFO BUILD SUCCEEDED !!! " ; fi

config/check_smdebug_install.sh

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
#!/bin/bash
22
set -ex
33
set -o pipefail
4+
5+
echo "Checking if smdebug has been installed"
46
python -c "import smdebug"
57
res="$?"
6-
echo "output of import smdebug is: $res"
7-
8-
#version=python -c "exec(\"import smdebug\nprint(smdebug.__version__)\")`
9-
version="$(python -c "exec(\"import smdebug\nprint(smdebug.__version__)\")")"
10-
# force check version, you can set this env variable in build env when releasing
8+
if [ $res -gt 0 ]; then
9+
echo "output of import smdebug is: $res"
10+
exit $res
11+
else
12+
echo "Successfully imported smdebug package."
13+
fi
1114

12-
if [ "$force_check_smdebug_version" ] && [ "$force_check_smdebug_version" != "${version}" ]; then
13-
echo "force_check_version $force_check_smdebug_version doesn't match version found: ${version}"
14-
exit 1
15+
echo "Check if smdebug_rules has been installed"
16+
python -c "import smdebug_rules"
17+
res="$?"
18+
if [ $res -gt 0 ]; then
19+
echo "output of import smdebug_rules is: $res"
20+
exit $res
21+
else
22+
echo "Successfully imported smdebug_rules package"
1523
fi
1624

1725
if [ $1 ]; then

config/install_smdebug.sh

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,53 @@
22
set -ex
33
set -o pipefail
44

5+
CORE_REPO="https://github.com/awslabs/sagemaker-debugger.git"
6+
RULES_REPO="https://$RULES_ACCESS_USER:$RULES_ACCESS_TOKEN@github.com/awslabs/sagemaker-debugger-rules.git"
7+
SMDEBUG_S3_BINARY="s3://smdebug-nightly-binaries/$(date +%F)/"
58

6-
cd $CODEBUILD_SRC_DIR
7-
# you can provide bip binary as s3 path in the build environment
9+
# Uninstall the built-in version of smdebug and assert that it no longer exists.
10+
pip uninstall -y smdebug
11+
#python -c "import smdebug"
12+
13+
code_dir=$(basename "$PWD")
14+
echo "Cloning sagemaker-debugger repository."
15+
cd $CODEBUILD_SRC_DIR && cd .. && rm -rf "$code_dir" && git clone "$CORE_REPO" "$code_dir"
16+
echo "sagemaker-debugger repository cloned in the path $CODEBUILD_SRC_DIR"
17+
18+
cd $CODEBUILD_SRC_DIR_RULES && code_dir=$(basename "$PWD")
19+
echo "Cloning sagemaker-debugger-rules repository."
20+
cd $CODEBUILD_SRC_DIR_RULES && cd .. && rm -rf "$code_dir" && git clone "$RULES_REPO" "$code_dir"
21+
echo "sagemaker-debugger-rules repository cloned in the path $CODEBUILD_SRC_DIR_RULES"
22+
export RULES_CODEBUILD_SRC_DIR="$CODEBUILD_SRC_DIR_RULES"
23+
24+
export CODEBUILD_ACCOUNT_ID=$(aws sts get-caller-identity --query 'Account' --output text)
25+
export CODEBUILD_PROJECT=${CODEBUILD_BUILD_ID%:$CODEBUILD_LOG_PATH}
26+
export CODEBUILD_BUILD_URL=https://$AWS_DEFAULT_REGION.console.aws.amazon.com/codebuild/home?region=$AWS_DEFAULT_REGION#/builds/$CODEBUILD_BUILD_ID/view/new
27+
28+
# you can provide pip binary as s3 path in the build environment
829
if [ "$SMDEBUG_S3_BINARY" ]; then
30+
cd $CODEBUILD_SRC_DIR
31+
echo "Installing smdebug and smdebug_rules from pre-generated pip wheels located at $SMDEBUG_S3_BINARY"
932
mkdir -p s3_pip_binary
10-
aws s3 cp "$SMDEBUG_S3_BINARY" s3_pip_binary
11-
pip install --upgrade s3_pip_binary/*.whl
33+
aws s3 cp --recursive "$SMDEBUG_S3_BINARY" s3_pip_binary
34+
pip install --upgrade --force-reinstall s3_pip_binary/smdebug_rules-*.whl
35+
pip install --upgrade --force-reinstall s3_pip_binary/smdebug-*.whl
36+
CORE_COMMIT=`cat s3_pip_binary/CORE_COMMIT`
37+
RULES_COMMIT=`cat s3_pip_binary/RULES_COMMIT`
38+
echo "Commit hash on sagemaker-debugger-rules repository being used: $RULES_COMMIT"
39+
cd $CODEBUILD_SRC_DIR_RULES && git checkout "$RULES_COMMIT"
40+
python setup.py bdist_wheel --universal && pip install --force-reinstall dist/*.whl
41+
echo "Commit hash on sagemaker-debugger repository being used: $CORE_COMMIT"
42+
cd $CODEBUILD_SRC_DIR && git checkout "$CORE_COMMIT"
43+
python setup.py bdist_wheel --universal && pip install --force-reinstall dist/*.whl
44+
export CURRENT_DATETIME=$(date +'%Y%m%d_%H%M%S')
45+
export CURRENT_COMMIT_PATH="$CURRENT_DATETIME/$CORE_COMMIT"
1246
else
13-
python setup.py bdist_wheel --universal && pip install --upgrade --force-reinstall dist/*.whl
47+
./config/change_branch.sh
48+
cd $CODEBUILD_SRC_DIR_RULES && python setup.py bdist_wheel --universal && pip install --force-reinstall dist/*.whl
49+
cd $CODEBUILD_SRC_DIR && python setup.py bdist_wheel --universal && pip install --force-reinstall dist/*.whl
1450
fi
1551

16-
1752
if [ "$run_pytest_mxnet" == 'enable' ]; then
1853
./config/check_smdebug_install.sh mxnet
1954
fi

0 commit comments

Comments
 (0)