Skip to content

Commit b4a73a8

Browse files
authored
infra: fix PR build (#297)
1 parent 5ab086d commit b4a73a8

File tree

2 files changed

+40
-25
lines changed

2 files changed

+40
-25
lines changed

buildspec.yml

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@ version: 0.2
22

33
env:
44
variables:
5-
FRAMEWORK_VERSION: '1.15.0'
5+
FRAMEWORK_VERSION: '1.15.2'
66
ECR_REPO: 'sagemaker-test'
77
GITHUB_REPO: 'sagemaker-tensorflow-container'
88
SETUP_FILE: 'setup_cmds.sh'
99
SETUP_CMDS: '#!/bin/bash\npip install --upgrade pip\npip install -U -e .\npip install -U -e .[test]'
10+
CPU_DOCKERFILE: 'Dockerfile.cpu'
11+
GPU_DOCKERFILE: 'Dockerfile.gpu'
1012

1113
phases:
1214
pre_build:
1315
commands:
1416
- start-dockerd
1517
- ACCOUNT=$(aws --region $AWS_DEFAULT_REGION sts --endpoint-url https://sts.$AWS_DEFAULT_REGION.amazonaws.com get-caller-identity --query 'Account' --output text)
1618
- PREPROD_IMAGE="$ACCOUNT.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$ECR_REPO"
19+
- PROD_IMAGE="763104351884.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/tensorflow-training"
1720
- PR_NUM=$(echo $CODEBUILD_SOURCE_VERSION | grep -o '[0-9]\+')
1821
- echo 'Pull request number:' $PR_NUM '. No value means this build is not from pull request.'
1922

@@ -36,43 +39,50 @@ phases:
3639
- tar_name=$(ls dist)
3740

3841
# Find build artifacts
39-
- build_artifacts=$root_dir/docker/artifacts
42+
- build_artifacts=$root_dir/docker/build_artifacts
43+
44+
# login so we can pull prod images for cache
45+
- $(aws ecr get-login --registry-ids 763104351884 --no-include-email --region $AWS_DEFAULT_REGION)
4046

4147
# build py2 images
4248

4349
# prepare build context
4450
- build_dir="$root_dir/docker/$FRAMEWORK_VERSION/py2"
4551
- cp $root_dir/dist/$tar_name $build_dir
46-
- cp $build_artifacts/* $build_dir/
52+
- cp $build_artifacts/*.py $build_dir/
4753
- cd $build_dir
4854

4955
# build cpu image
50-
- cpu_dockerfile="Dockerfile.cpu"
51-
- CPU_TAG_PY2="$FRAMEWORK_VERSION-cpu-py2-$build_id"
52-
- docker build -f $cpu_dockerfile -t $PREPROD_IMAGE:$CPU_TAG_PY2 .
56+
- prod_tag="$FRAMEWORK_VERSION-cpu-py2"
57+
- CPU_TAG_PY2="$prod_tag-$build_id"
58+
- docker pull $PROD_IMAGE:$prod_tag
59+
- docker build --cache-from $PROD_IMAGE:$prod_tag -f $CPU_DOCKERFILE -t $PREPROD_IMAGE:$CPU_TAG_PY2 .
5360

5461
# build gpu image
55-
- gpu_dockerfile="Dockerfile.gpu"
56-
- GPU_TAG_PY2="$FRAMEWORK_VERSION-gpu-py2-$build_id"
57-
- docker build -f $gpu_dockerfile -t $PREPROD_IMAGE:$GPU_TAG_PY2 .
62+
- prod_tag="$FRAMEWORK_VERSION-gpu-py2"
63+
- GPU_TAG_PY2="$prod_tag-$build_id"
64+
- docker pull $PROD_IMAGE:$prod_tag
65+
- docker build --cache-from $PROD_IMAGE:$prod_tag -f $GPU_DOCKERFILE -t $PREPROD_IMAGE:$GPU_TAG_PY2 .
5866

5967
# build py3 images
6068

6169
# prepare build context
6270
- build_dir="$root_dir/docker/$FRAMEWORK_VERSION/py3"
6371
- cp $root_dir/dist/$tar_name $build_dir
64-
- cp $build_artifacts/* $build_dir/
72+
- cp $build_artifacts/*.py $build_dir/
6573
- cd $build_dir
6674

6775
# build cpu image
68-
- cpu_dockerfile="Dockerfile.cpu"
69-
- CPU_TAG_PY3="$FRAMEWORK_VERSION-cpu-py3-$build_id"
70-
- docker build -f $cpu_dockerfile -t $PREPROD_IMAGE:$CPU_TAG_PY3 .
76+
- prod_tag="$FRAMEWORK_VERSION-cpu-py3"
77+
- CPU_TAG_PY3="$prod_tag-$build_id"
78+
- docker pull $PROD_IMAGE:$prod_tag
79+
- docker build --cache-from $PROD_IMAGE:$prod_tag -f $CPU_DOCKERFILE -t $PREPROD_IMAGE:$CPU_TAG_PY3 .
7180

7281
# build gpu image
73-
- gpu_dockerfile="Dockerfile.gpu"
74-
- GPU_TAG_PY3="$FRAMEWORK_VERSION-gpu-py3-$build_id"
75-
- docker build -f $gpu_dockerfile -t $PREPROD_IMAGE:$GPU_TAG_PY3 .
82+
- prod_tag="$FRAMEWORK_VERSION-gpu-py3"
83+
- GPU_TAG_PY3="$prod_tag-$build_id"
84+
- docker pull $PROD_IMAGE:$prod_tag
85+
- docker build --cache-from $PROD_IMAGE:$prod_tag -f $GPU_DOCKERFILE -t $PREPROD_IMAGE:$GPU_TAG_PY3 .
7686

7787
# push images to ecr
7888
- $(aws ecr get-login --registry-ids $ACCOUNT --no-include-email --region $AWS_DEFAULT_REGION)
@@ -87,29 +97,29 @@ phases:
8797
- launch-ec2-instance --instance-type $instance_type --ami-name dlami-ubuntu
8898

8999
# run cpu integration tests
90-
- py3_cmd="pytest test/integration/local --region $AWS_DEFAULT_REGION --docker-base-name $PREPROD_IMAGE --tag $CPU_TAG_PY2 --framework-version $FRAMEWORK_VERSION --py-version 2 --processor cpu"
91-
- py2_cmd="pytest test/integration/local --region $AWS_DEFAULT_REGION --docker-base-name $PREPROD_IMAGE --tag $CPU_TAG_PY3 --framework-version $FRAMEWORK_VERSION --py-version 3 --processor cpu"
100+
- py3_cmd="IGNORE_COVERAGE=- tox -e py36 -- test/integration/local --region $AWS_DEFAULT_REGION --docker-base-name $PREPROD_IMAGE --tag $CPU_TAG_PY3 --framework-version $FRAMEWORK_VERSION --py-version 3 --processor cpu --durations 10"
92101
- execute-command-if-has-matching-changes "$py3_cmd" "test/" "src/*.py" "setup.py" "docker/*" "buildspec.yml"
102+
- py2_cmd="IGNORE_COVERAGE=- tox -e py27 -- test/integration/local --region $AWS_DEFAULT_REGION --docker-base-name $PREPROD_IMAGE --tag $CPU_TAG_PY2 --framework-version $FRAMEWORK_VERSION --py-version 2 --processor cpu --durations 10"
93103
- execute-command-if-has-matching-changes "$py2_cmd" "test/" "src/*.py" "setup.py" "docker/*" "buildspec.yml"
94104

95105
# run gpu integration tests
96106
- printf "$SETUP_CMDS" > $SETUP_FILE
97-
- cmd="pytest test/integration/local --region $AWS_DEFAULT_REGION --docker-base-name $PREPROD_IMAGE --tag $GPU_TAG_PY2 --framework-version $FRAMEWORK_VERSION --py-version 2 --processor gpu"
107+
- cmd="IGNORE_COVERAGE=- tox -e py36 -- test/integration/local -n 4 --region $AWS_DEFAULT_REGION --docker-base-name $PREPROD_IMAGE --tag $GPU_TAG_PY3 --framework-version $FRAMEWORK_VERSION --py-version 3 --processor gpu --durations 10"
98108
- py3_cmd="remote-test --github-repo $GITHUB_REPO --test-cmd \"$cmd\" --setup-file $SETUP_FILE --pr-number \"$PR_NUM\""
99109
- execute-command-if-has-matching-changes "$py3_cmd" "test/" "src/*.py" "setup.py" "docker/*" "buildspec.yml"
100110

101-
- cmd="pytest test/integration/local --region $AWS_DEFAULT_REGION --docker-base-name $PREPROD_IMAGE --tag $GPU_TAG_PY3 --framework-version $FRAMEWORK_VERSION --py-version 3 --processor gpu"
102-
- py2_cmd="remote-test --github-repo $GITHUB_REPO --test-cmd \"$cmd\" --setup-file $SETUP_FILE --pr-number \"$PR_NUM\""
111+
- cmd="IGNORE_COVERAGE=- tox -e py27 -- test/integration/local -n 4 --region $AWS_DEFAULT_REGION --docker-base-name $PREPROD_IMAGE --tag $GPU_TAG_PY2 --framework-version $FRAMEWORK_VERSION --py-version 2 --processor gpu --durations 10"
112+
- py2_cmd="remote-test --github-repo $GITHUB_REPO --test-cmd \"$cmd\" --setup-file $SETUP_FILE --pr-number \"$PR_NUM\" --skip-setup"
103113
- execute-command-if-has-matching-changes "$py2_cmd" "test/" "src/*.py" "setup.py" "docker/*" "buildspec.yml"
104114

105115
# run sagemaker tests
106-
- test_cmd="pytest test/integration/sagemaker -n 8 --region $AWS_DEFAULT_REGION --docker-base-name $ECR_REPO --account-id $ACCOUNT --tag $CPU_TAG_PY2 --py-version 2 --processor cpu"
116+
- test_cmd="IGNORE_COVERAGE=- tox -e py36 -- test/integration/sagemaker -n 8 --region $AWS_DEFAULT_REGION --docker-base-name $ECR_REPO --account-id $ACCOUNT --tag $CPU_TAG_PY3 --py-version 3 --processor cpu --durations 10"
107117
- execute-command-if-has-matching-changes "$test_cmd" "test/" "src/*.py" "setup.py" "docker/*" "buildspec.yml"
108-
- test_cmd="pytest test/integration/sagemaker -n 8 --region $AWS_DEFAULT_REGION --docker-base-name $ECR_REPO --account-id $ACCOUNT --tag $GPU_TAG_PY2 --py-version 2 --processor gpu"
118+
- test_cmd="IGNORE_COVERAGE=- tox -e py36 -- test/integration/sagemaker -n 8 --region $AWS_DEFAULT_REGION --docker-base-name $ECR_REPO --account-id $ACCOUNT --tag $GPU_TAG_PY3 --py-version 3 --processor gpu --durations 10"
109119
- execute-command-if-has-matching-changes "$test_cmd" "test/" "src/*.py" "setup.py" "docker/*" "buildspec.yml"
110-
- test_cmd="pytest test/integration/sagemaker -n 8 --region $AWS_DEFAULT_REGION --docker-base-name $ECR_REPO --account-id $ACCOUNT --tag $CPU_TAG_PY3 --py-version 3 --processor cpu"
120+
- test_cmd="IGNORE_COVERAGE=- tox -e py27 -- test/integration/sagemaker -n 8 --region $AWS_DEFAULT_REGION --docker-base-name $ECR_REPO --account-id $ACCOUNT --tag $CPU_TAG_PY2 --py-version 2 --processor cpu --durations 10"
111121
- execute-command-if-has-matching-changes "$test_cmd" "test/" "src/*.py" "setup.py" "docker/*" "buildspec.yml"
112-
- test_cmd="pytest test/integration/sagemaker -n 8 --region $AWS_DEFAULT_REGION --docker-base-name $ECR_REPO --account-id $ACCOUNT --tag $GPU_TAG_PY3 --py-version 3 --processor gpu"
122+
- test_cmd="IGNORE_COVERAGE=- tox -e py27 -- test/integration/sagemaker -n 8 --region $AWS_DEFAULT_REGION --docker-base-name $ECR_REPO --account-id $ACCOUNT --tag $GPU_TAG_PY2 --py-version 2 --processor gpu --durations 10"
113123
- execute-command-if-has-matching-changes "$test_cmd" "test/" "src/*.py" "setup.py" "docker/*" "buildspec.yml"
114124

115125
finally:

pytest.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[pytest]
2+
markers =
3+
deploy_test
4+
skip_cpu
5+
skip_gpu

0 commit comments

Comments
 (0)