@@ -23,20 +23,13 @@ phases:
2323 build :
2424 commands :
2525 # install
26- - pip3 install -U -e .
2726 - pip3 install -U -e .[test]
2827
2928 # run flake8
3029 - tox -e flake8,twine
3130
32- # run unit tests
33- - tox -e py36,py27 test/unit
34-
35- # Create pip archive
3631 - root_dir=$(pwd)
3732 - build_id="$(echo $CODEBUILD_BUILD_ID | sed -e 's/:/-/g')"
38- - python3 setup.py sdist
39- - tar_name=$(ls dist)
4033
4134 # Find build artifacts
4235 - build_artifacts=$root_dir/docker/build_artifacts
@@ -48,48 +41,54 @@ phases:
4841
4942 # prepare build context
5043 - build_dir="$root_dir/docker/$FRAMEWORK_VERSION/py2"
51- - cp $root_dir/dist/$tar_name $build_dir
5244 - cp $build_artifacts/*.py $build_dir/
5345 - cd $build_dir
5446
5547 # build cpu image
5648 - prod_tag="$FRAMEWORK_VERSION-cpu-py2"
5749 - CPU_TAG_PY2="$prod_tag-$build_id"
5850 - docker pull $PROD_IMAGE:$prod_tag
59- - docker build --cache-from $PROD_IMAGE:$prod_tag -f $CPU_DOCKERFILE -t $PREPROD_IMAGE:$CPU_TAG_PY2 .
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"
6053
6154 # build gpu image
6255 - prod_tag="$FRAMEWORK_VERSION-gpu-py2"
6356 - GPU_TAG_PY2="$prod_tag-$build_id"
6457 - docker pull $PROD_IMAGE:$prod_tag
65- - docker build --cache-from $PROD_IMAGE:$prod_tag -f $GPU_DOCKERFILE -t $PREPROD_IMAGE:$GPU_TAG_PY2 .
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"
6660
6761 # build py3 images
6862
6963 # prepare build context
7064 - build_dir="$root_dir/docker/$FRAMEWORK_VERSION/py3"
71- - cp $root_dir/dist/$tar_name $build_dir
7265 - cp $build_artifacts/*.py $build_dir/
7366 - cd $build_dir
7467
7568 # build cpu image
7669 - prod_tag="$FRAMEWORK_VERSION-cpu-py3"
7770 - CPU_TAG_PY3="$prod_tag-$build_id"
7871 - docker pull $PROD_IMAGE:$prod_tag
79- - docker build --cache-from $PROD_IMAGE:$prod_tag -f $CPU_DOCKERFILE -t $PREPROD_IMAGE:$CPU_TAG_PY3 .
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"
8074
8175 # build gpu image
8276 - prod_tag="$FRAMEWORK_VERSION-gpu-py3"
8377 - GPU_TAG_PY3="$prod_tag-$build_id"
8478 - docker pull $PROD_IMAGE:$prod_tag
85- - docker build --cache-from $PROD_IMAGE:$prod_tag -f $GPU_DOCKERFILE -t $PREPROD_IMAGE:$GPU_TAG_PY3 .
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"
8681
8782 # push images to ecr
8883 - $(aws ecr get-login --registry-ids $ACCOUNT --no-include-email --region $AWS_DEFAULT_REGION)
8984 - docker push $PREPROD_IMAGE:$CPU_TAG_PY2
85+ - execute-command-if-has-matching-changes "$push_cmd" "test/" "docker/*" "buildspec.yml"
9086 - docker push $PREPROD_IMAGE:$GPU_TAG_PY2
87+ - execute-command-if-has-matching-changes "$push_cmd" "test/" "docker/*" "buildspec.yml"
9188 - docker push $PREPROD_IMAGE:$CPU_TAG_PY3
89+ - execute-command-if-has-matching-changes "$push_cmd" "test/" "docker/*" "buildspec.yml"
9290 - docker push $PREPROD_IMAGE:$GPU_TAG_PY3
91+ - execute-command-if-has-matching-changes "$push_cmd" "test/" "docker/*" "buildspec.yml"
9392
9493 # launch remote gpu instance
9594 - instance_type='p2.xlarge'
@@ -98,37 +97,41 @@ phases:
9897
9998 # run cpu integration tests
10099 - 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"
101- - execute-command-if-has-matching-changes "$py3_cmd" "test/" "src/*.py" "setup.py" " docker/*" "buildspec.yml"
100+ - execute-command-if-has-matching-changes "$py3_cmd" "test/" "docker/*" "buildspec.yml"
102101 - 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"
103- - execute-command-if-has-matching-changes "$py2_cmd" "test/" "src/*.py" "setup.py" " docker/*" "buildspec.yml"
102+ - execute-command-if-has-matching-changes "$py2_cmd" "test/" "docker/*" "buildspec.yml"
104103
105104 # run gpu integration tests
106105 - printf "$SETUP_CMDS" > $SETUP_FILE
107106 - 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"
108107 - py3_cmd="remote-test --github-repo $GITHUB_REPO --test-cmd \"$cmd\" --setup-file $SETUP_FILE --pr-number \"$PR_NUM\""
109- - execute-command-if-has-matching-changes "$py3_cmd" "test/" "src/*.py" "setup.py" " docker/*" "buildspec.yml"
108+ - execute-command-if-has-matching-changes "$py3_cmd" "test/" "docker/*" "buildspec.yml"
110109
111110 - 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"
112111 - py2_cmd="remote-test --github-repo $GITHUB_REPO --test-cmd \"$cmd\" --setup-file $SETUP_FILE --pr-number \"$PR_NUM\" --skip-setup"
113- - execute-command-if-has-matching-changes "$py2_cmd" "test/" "src/*.py" "setup.py" " docker/*" "buildspec.yml"
112+ - execute-command-if-has-matching-changes "$py2_cmd" "test/" "docker/*" "buildspec.yml"
114113
115114 # run sagemaker tests
116115 - 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"
117- - execute-command-if-has-matching-changes "$test_cmd" "test/" "src/*.py" "setup.py" " docker/*" "buildspec.yml"
116+ - execute-command-if-has-matching-changes "$test_cmd" "test/" "docker/*" "buildspec.yml"
118117 - 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"
119- - execute-command-if-has-matching-changes "$test_cmd" "test/" "src/*.py" "setup.py" " docker/*" "buildspec.yml"
118+ - execute-command-if-has-matching-changes "$test_cmd" "test/" "docker/*" "buildspec.yml"
120119 - 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"
121- - execute-command-if-has-matching-changes "$test_cmd" "test/" "src/*.py" "setup.py" " docker/*" "buildspec.yml"
120+ - execute-command-if-has-matching-changes "$test_cmd" "test/" "docker/*" "buildspec.yml"
122121 - 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"
123- - execute-command-if-has-matching-changes "$test_cmd" "test/" "src/*.py" "setup.py" " docker/*" "buildspec.yml"
122+ - execute-command-if-has-matching-changes "$test_cmd" "test/" "docker/*" "buildspec.yml"
124123
125124 finally :
126125 # shut down remote gpu instance
127126 - cleanup-gpu-instances
128127 - cleanup-key-pairs
129128
130129 # remove ecr image
131- - aws ecr batch-delete-image --repository-name $ECR_REPO --region $AWS_DEFAULT_REGION --image-ids imageTag=$CPU_TAG_PY2
132- - aws ecr batch-delete-image --repository-name $ECR_REPO --region $AWS_DEFAULT_REGION --image-ids imageTag=$GPU_TAG_PY2
133- - aws ecr batch-delete-image --repository-name $ECR_REPO --region $AWS_DEFAULT_REGION --image-ids imageTag=$CPU_TAG_PY3
134- - aws ecr batch-delete-image --repository-name $ECR_REPO --region $AWS_DEFAULT_REGION --image-ids imageTag=$GPU_TAG_PY3
130+ - delete_cmd="aws ecr batch-delete-image --repository-name $ECR_REPO --region $AWS_DEFAULT_REGION --image-ids imageTag=$CPU_TAG_PY2"
131+ - execute-command-if-has-matching-changes "$delete_cmd" "test/" "docker/*" "buildspec.yml"
132+ - delete_cmd="aws ecr batch-delete-image --repository-name $ECR_REPO --region $AWS_DEFAULT_REGION --image-ids imageTag=$GPU_TAG_PY2"
133+ - execute-command-if-has-matching-changes "$delete_cmd" "test/" "docker/*" "buildspec.yml"
134+ - delete_cmd="aws ecr batch-delete-image --repository-name $ECR_REPO --region $AWS_DEFAULT_REGION --image-ids imageTag=$CPU_TAG_PY3"
135+ - execute-command-if-has-matching-changes "$delete_cmd" "test/" "docker/*" "buildspec.yml"
136+ - delete_cmd="aws ecr batch-delete-image --repository-name $ECR_REPO --region $AWS_DEFAULT_REGION --image-ids imageTag=$GPU_TAG_PY3"
137+ - execute-command-if-has-matching-changes "$delete_cmd" "test/" "docker/*" "buildspec.yml"
0 commit comments