1
1
version : 0.2
2
2
3
- env :
4
- variables :
5
- FRAMEWORK_VERSION : ' 1.15.2'
6
- ECR_REPO : ' sagemaker-test'
7
- GITHUB_REPO : ' sagemaker-tensorflow-container'
8
- SETUP_FILE : ' setup_cmds.sh'
9
- 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'
12
-
13
3
phases :
14
4
pre_build :
15
5
commands :
16
- - start-dockerd
17
- - ACCOUNT=$(aws --region $AWS_DEFAULT_REGION sts --endpoint-url https://sts.$AWS_DEFAULT_REGION.amazonaws.com get-caller-identity --query 'Account' --output text)
18
- - 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"
20
6
- PR_NUM=$(echo $CODEBUILD_SOURCE_VERSION | grep -o '[0-9]\+')
21
7
- echo 'Pull request number:' $PR_NUM '. No value means this build is not from pull request.'
22
8
23
9
build :
24
10
commands :
25
- # install
26
- - pip3 install -U -e .[test]
27
-
28
- # run flake8
29
- - tox -e flake8,twine
30
-
31
- - root_dir=$(pwd)
32
- - build_id="$(echo $CODEBUILD_BUILD_ID | sed -e 's/:/-/g')"
33
-
34
- # Find build artifacts
35
- - build_artifacts=$root_dir/docker/build_artifacts
36
-
37
- # login so we can pull prod images for cache
38
- - $(aws ecr get-login --registry-ids 763104351884 --no-include-email --region $AWS_DEFAULT_REGION)
39
-
40
- # build py2 images
41
-
42
- # prepare build context
43
- - build_dir="$root_dir/docker/$FRAMEWORK_VERSION/py2"
44
- - cp $build_artifacts/*.py $build_dir/
45
- - cd $build_dir
46
-
47
- # build cpu image
48
- - prod_tag="$FRAMEWORK_VERSION-cpu-py2"
49
- - CPU_TAG_PY2="$prod_tag-$build_id"
50
- - docker pull $PROD_IMAGE:$prod_tag
51
- - build_cmd="docker build --cache-from $PROD_IMAGE:$prod_tag -f $CPU_DOCKERFILE -t $PREPROD_IMAGE:$CPU_TAG_PY2 . "
52
- - execute-command-if-has-matching-changes "$build_cmd" "test/" "docker/*" "buildspec.yml"
53
-
54
- # build gpu image
55
- - prod_tag="$FRAMEWORK_VERSION-gpu-py2"
56
- - GPU_TAG_PY2="$prod_tag-$build_id"
57
- - docker pull $PROD_IMAGE:$prod_tag
58
- - build_cmd="docker build --cache-from $PROD_IMAGE:$prod_tag -f $GPU_DOCKERFILE -t $PREPROD_IMAGE:$GPU_TAG_PY2 . "
59
- - execute-command-if-has-matching-changes "$build_cmd" "test/" "docker/*" "buildspec.yml"
60
-
61
- # build py3 images
62
-
63
- # prepare build context
64
- - build_dir="$root_dir/docker/$FRAMEWORK_VERSION/py3"
65
- - cp $build_artifacts/*.py $build_dir/
66
- - cd $build_dir
67
-
68
- # build cpu image
69
- - prod_tag="$FRAMEWORK_VERSION-cpu-py3"
70
- - CPU_TAG_PY3="$prod_tag-$build_id"
71
- - docker pull $PROD_IMAGE:$prod_tag
72
- - build_cmd="docker build --cache-from $PROD_IMAGE:$prod_tag -f $CPU_DOCKERFILE -t $PREPROD_IMAGE:$CPU_TAG_PY3 . "
73
- - execute-command-if-has-matching-changes "$build_cmd" "test/" "docker/*" "buildspec.yml"
74
-
75
- # build gpu image
76
- - prod_tag="$FRAMEWORK_VERSION-gpu-py3"
77
- - GPU_TAG_PY3="$prod_tag-$build_id"
78
- - docker pull $PROD_IMAGE:$prod_tag
79
- - build_cmd="docker build --cache-from $PROD_IMAGE:$prod_tag -f $GPU_DOCKERFILE -t $PREPROD_IMAGE:$GPU_TAG_PY3 . "
80
- - execute-command-if-has-matching-changes "$build_cmd" "test/" "docker/*" "buildspec.yml"
81
-
82
- # build py37 images
83
-
84
- # prepare build context
85
- - build_dir="$root_dir/docker/$FRAMEWORK_VERSION/py37"
86
- - cp $build_artifacts/*.py $build_dir/
87
- - cd $build_dir
88
-
89
- # build cpu image
90
- - prod_tag="$FRAMEWORK_VERSION-cpu-py37"
91
- - CPU_TAG_PY37="$prod_tag-$build_id"
92
- - build_cmd="docker build --no-cache -f $CPU_DOCKERFILE -t $PREPROD_IMAGE:$CPU_TAG_PY37 . "
93
- - execute-command-if-has-matching-changes "$build_cmd" "test/" "docker/*" "buildspec.yml"
94
-
95
- # build gpu image
96
- - prod_tag="$FRAMEWORK_VERSION-gpu-py37"
97
- - GPU_TAG_PY37="$prod_tag-$build_id"
98
- - build_cmd="docker build --no-cache -f $GPU_DOCKERFILE -t $PREPROD_IMAGE:$GPU_TAG_PY37 . "
99
- - execute-command-if-has-matching-changes "$build_cmd" "test/" "docker/*" "buildspec.yml"
100
-
101
- # push images to ecr
102
- - $(aws ecr get-login --registry-ids $ACCOUNT --no-include-email --region $AWS_DEFAULT_REGION)
103
- - push_cmd="docker push $PREPROD_IMAGE:$CPU_TAG_PY2"
104
- - execute-command-if-has-matching-changes "$push_cmd" "test/" "docker/*" "buildspec.yml"
105
- - push_cmd="docker push $PREPROD_IMAGE:$GPU_TAG_PY2"
106
- - execute-command-if-has-matching-changes "$push_cmd" "test/" "docker/*" "buildspec.yml"
107
- - push_cmd="docker push $PREPROD_IMAGE:$CPU_TAG_PY3"
108
- - execute-command-if-has-matching-changes "$push_cmd" "test/" "docker/*" "buildspec.yml"
109
- - push_cmd="docker push $PREPROD_IMAGE:$GPU_TAG_PY3"
110
- - execute-command-if-has-matching-changes "$push_cmd" "test/" "docker/*" "buildspec.yml"
111
- - push_cmd="docker push $PREPROD_IMAGE:$CPU_TAG_PY37"
112
- - execute-command-if-has-matching-changes "$push_cmd" "test/" "docker/*" "buildspec.yml"
113
- - push_cmd="docker push $PREPROD_IMAGE:$GPU_TAG_PY37"
114
- - execute-command-if-has-matching-changes "$push_cmd" "test/" "docker/*" "buildspec.yml"
115
-
116
- # launch remote gpu instance
117
- - instance_type='p2.xlarge'
118
- - create-key-pair
119
- - launch-ec2-instance --instance-type $instance_type --ami-name dlami-ubuntu
120
-
121
- # run cpu integration tests
122
- - 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"
123
- - execute-command-if-has-matching-changes "$py3_cmd" "test/" "docker/*" "buildspec.yml"
124
- - py37_cmd="IGNORE_COVERAGE=- tox -e py37 -- test/integration/local --region $AWS_DEFAULT_REGION --docker-base-name $PREPROD_IMAGE --tag $CPU_TAG_PY37 --framework-version $FRAMEWORK_VERSION --py-version 3 --processor cpu --durations 10"
125
- - execute-command-if-has-matching-changes "$py37_cmd" "test/" "docker/*" "buildspec.yml"
126
- - 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"
127
- - execute-command-if-has-matching-changes "$py2_cmd" "test/" "docker/*" "buildspec.yml"
128
-
129
- # run gpu integration tests
130
- - printf "$SETUP_CMDS" > $SETUP_FILE
131
- - 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"
132
- - py3_cmd="remote-test --github-repo $GITHUB_REPO --test-cmd \"$cmd\" --setup-file $SETUP_FILE --pr-number \"$PR_NUM\""
133
- - execute-command-if-has-matching-changes "$py3_cmd" "test/" "docker/*" "buildspec.yml"
134
-
135
- - 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"
136
- - py2_cmd="remote-test --github-repo $GITHUB_REPO --test-cmd \"$cmd\" --setup-file $SETUP_FILE --pr-number \"$PR_NUM\" --skip-setup"
137
- - execute-command-if-has-matching-changes "$py2_cmd" "test/" "docker/*" "buildspec.yml"
138
-
139
- - cmd="IGNORE_COVERAGE=- tox -e py37 -- test/integration/local -n 4 --region $AWS_DEFAULT_REGION --docker-base-name $PREPROD_IMAGE --tag $GPU_TAG_PY37 --framework-version $FRAMEWORK_VERSION --py-version 3 --processor gpu --durations 10"
140
- - py37_cmd="remote-test --github-repo $GITHUB_REPO --test-cmd \"$cmd\" --setup-file $SETUP_FILE --pr-number \"$PR_NUM\" --skip-setup"
141
- - execute-command-if-has-matching-changes "$py37_cmd" "test/" "docker/*" "buildspec.yml"
142
-
143
- # run sagemaker tests
144
- - 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"
145
- - execute-command-if-has-matching-changes "$test_cmd" "test/" "docker/*" "buildspec.yml"
146
- - 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"
147
- - execute-command-if-has-matching-changes "$test_cmd" "test/" "docker/*" "buildspec.yml"
148
- - test_cmd="IGNORE_COVERAGE=- tox -e py37 -- test/integration/sagemaker -n 8 --region $AWS_DEFAULT_REGION --docker-base-name $ECR_REPO --account-id $ACCOUNT --tag $CPU_TAG_PY37 --py-version 3 --processor cpu --durations 10"
149
- - execute-command-if-has-matching-changes "$test_cmd" "test/" "docker/*" "buildspec.yml"
150
- - test_cmd="IGNORE_COVERAGE=- tox -e py37 -- test/integration/sagemaker -n 8 --region $AWS_DEFAULT_REGION --docker-base-name $ECR_REPO --account-id $ACCOUNT --tag $GPU_TAG_PY37 --py-version 3 --processor gpu --durations 10"
151
- - execute-command-if-has-matching-changes "$test_cmd" "test/" "docker/*" "buildspec.yml"
152
- - 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"
153
- - execute-command-if-has-matching-changes "$test_cmd" "test/" "docker/*" "buildspec.yml"
154
- - 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"
155
- - execute-command-if-has-matching-changes "$test_cmd" "test/" "docker/*" "buildspec.yml"
156
-
157
- finally :
158
- # shut down remote gpu instance
159
- - cleanup-gpu-instances
160
- - cleanup-key-pairs
161
11
162
- # remove ecr image
163
- - delete_cmd="aws ecr batch-delete-image --repository-name $ECR_REPO --region $AWS_DEFAULT_REGION --image-ids imageTag=$CPU_TAG_PY2"
164
- - execute-command-if-has-matching-changes "$delete_cmd" "test/" "docker/*" "buildspec.yml"
165
- - delete_cmd="aws ecr batch-delete-image --repository-name $ECR_REPO --region $AWS_DEFAULT_REGION --image-ids imageTag=$GPU_TAG_PY2"
166
- - execute-command-if-has-matching-changes "$delete_cmd" "test/" "docker/*" "buildspec.yml"
167
- - delete_cmd="aws ecr batch-delete-image --repository-name $ECR_REPO --region $AWS_DEFAULT_REGION --image-ids imageTag=$CPU_TAG_PY3"
168
- - execute-command-if-has-matching-changes "$delete_cmd" "test/" "docker/*" "buildspec.yml"
169
- - delete_cmd="aws ecr batch-delete-image --repository-name $ECR_REPO --region $AWS_DEFAULT_REGION --image-ids imageTag=$GPU_TAG_PY3"
170
- - execute-command-if-has-matching-changes "$delete_cmd" "test/" "docker/*" "buildspec.yml"
171
- - delete_cmd="aws ecr batch-delete-image --repository-name $ECR_REPO --region $AWS_DEFAULT_REGION --image-ids imageTag=$CPU_TAG_PY37"
172
- - execute-command-if-has-matching-changes "$delete_cmd" "test/" "docker/*" "buildspec.yml"
173
- - delete_cmd="aws ecr batch-delete-image --repository-name $ECR_REPO --region $AWS_DEFAULT_REGION --image-ids imageTag=$GPU_TAG_PY37"
174
- - execute-command-if-has-matching-changes "$delete_cmd" "test/" "docker/*" "buildspec.yml"
12
+ - error_cmd="echo 'In order to make changes to the docker files, please, use https://github.com/aws/deep-learning-containers repository.' && exit 1"
13
+ - execute-command-if-has-matching-changes "$error_cmd" "docker/"
0 commit comments