-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathbuildspec-release.yml
134 lines (113 loc) · 6.14 KB
/
buildspec-release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
version: 0.2
env:
variables:
FRAMEWORK_VERSION: '5.0.0'
CPU_INSTANCE_TYPE: 'ml.c5.xlarge'
GPU_INSTANCE_TYPE: 'ml.p2.xlarge'
LOCAL_BASE_REPO: 'chainer-base'
ECR_REPO: 'sagemaker-chainer'
GITHUB_REPO: 'sagemaker-chainer-container'
SETUP_FILE: 'setup_cmds.sh'
SETUP_CMDS: '#!/bin/bash\npip install --upgrade pip\npip install -U -e .\npip install -U -e .[test]'
phases:
pre_build:
commands:
- start-dockerd
- ACCOUNT=$(aws --region $AWS_DEFAULT_REGION sts --endpoint-url https://sts.$AWS_DEFAULT_REGION.amazonaws.com get-caller-identity --query 'Account' --output text)
- PREPROD_IMAGE="$ACCOUNT.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$ECR_REPO"
build:
commands:
# prepare the release
- git-release --prepare --min-version 1.0.1
# install
- pip3 install -U -e .
- pip3 install -U -e .[test]
# run unit tests
- pytest test/unit
# build cpu base image
- base_dir="docker/base"
- cpu_py2_base_tag="$FRAMEWORK_VERSION-cpu-py2"
- cpu_py3_base_tag="$FRAMEWORK_VERSION-cpu-py3"
- cpu_dockerfile="Dockerfile.cpu"
- cd $base_dir
- docker build -t $LOCAL_BASE_REPO:$cpu_py2_base_tag -f $cpu_dockerfile .
- docker build -t $LOCAL_BASE_REPO:$cpu_py3_base_tag -f $cpu_dockerfile .
- cd ../../
# build gpu base image
- gpu_py2_base_tag="$FRAMEWORK_VERSION-gpu-py2"
- gpu_py3_base_tag="$FRAMEWORK_VERSION-gpu-py3"
- gpu_dockerfile="Dockerfile.gpu"
- cd $base_dir
- docker build -t $LOCAL_BASE_REPO:$gpu_py2_base_tag -f $gpu_dockerfile .
- docker build -t $LOCAL_BASE_REPO:$gpu_py3_base_tag -f $gpu_dockerfile .
- cd ../../
# create wheel
- python3 setup.py bdist_wheel
# build cpu image
- py2_build_dir="docker/$FRAMEWORK_VERSION/final/py2"
- py3_build_dir="docker/$FRAMEWORK_VERSION/final/py3"
- CPU_PY2_TAG="$FRAMEWORK_VERSION-cpu-py2"
- CPU_PY3_TAG="$FRAMEWORK_VERSION-cpu-py3"
- docker build -f "$py2_build_dir/$cpu_dockerfile" --build-arg py_version=2 -t $PREPROD_IMAGE:$CPU_PY2_TAG .
- docker build -f "$py3_build_dir/$cpu_dockerfile" --build-arg py_version=3 -t $PREPROD_IMAGE:$CPU_PY3_TAG .
# build gpu image
- GPU_PY2_TAG="$FRAMEWORK_VERSION-gpu-py2"
- GPU_PY3_TAG="$FRAMEWORK_VERSION-gpu-py3"
- docker build -f "$py2_build_dir/$gpu_dockerfile" --build-arg py_version=2 -t $PREPROD_IMAGE:$GPU_PY2_TAG .
- docker build -f "$py3_build_dir/$gpu_dockerfile" --build-arg py_version=3 -t $PREPROD_IMAGE:$GPU_PY3_TAG .
# push images to ecr
- $(aws ecr get-login --registry-ids $ACCOUNT --no-include-email --region $AWS_DEFAULT_REGION)
- docker push $PREPROD_IMAGE:$CPU_PY2_TAG
- docker push $PREPROD_IMAGE:$CPU_PY3_TAG
- docker push $PREPROD_IMAGE:$GPU_PY2_TAG
- docker push $PREPROD_IMAGE:$GPU_PY3_TAG
# launch remote gpu instance
- prefix='ml.'
- instance_type=${GPU_INSTANCE_TYPE#"$prefix"}
- create-key-pair
- launch-ec2-instance --instance-type $instance_type --ami-name dlami-ubuntu
# run cpu integration tests
- test_cmd="pytest test/integration/local --region $AWS_DEFAULT_REGION --docker-base-name $PREPROD_IMAGE --tag $CPU_PY2_TAG --framework-version $FRAMEWORK_VERSION --py-version 2 --processor cpu"
- execute-command-if-has-matching-changes "$test_cmd" "test/" "src/*.py" "setup.py" "setup.cfg" "docker/*" "buildspec.yml"
# run gpu integration tests
- printf "$SETUP_CMDS" > $SETUP_FILE
- pytest_cmd="pytest test/integration/local --region $AWS_DEFAULT_REGION --docker-base-name $PREPROD_IMAGE --tag $GPU_PY3_TAG --framework-version $FRAMEWORK_VERSION --py-version 3 --processor gpu"
- test_cmd="remote-test --github-repo $GITHUB_REPO --branch master --test-cmd \"$pytest_cmd\" --setup-file $SETUP_FILE"
- execute-command-if-has-matching-changes "$test_cmd" "test/" "src/*.py" "setup.py" "setup.cfg" "docker/*" "buildspec.yml"
# run sagemaker tests
- test_cmd="pytest test/integration/sagemaker -n 3 --region $AWS_DEFAULT_REGION --docker-base-name $ECR_REPO --aws-id $ACCOUNT --tag $CPU_PY2_TAG --instance-type $CPU_INSTANCE_TYPE"
- execute-command-if-has-matching-changes "$test_cmd" "test/" "src/*.py" "setup.py" "setup.cfg" "docker/*" "buildspec.yml"
# run gpu sagemaker tests
- test_cmd="pytest test/integration/sagemaker -n 3 --region $AWS_DEFAULT_REGION --docker-base-name $ECR_REPO --aws-id $ACCOUNT --tag $GPU_PY3_TAG --instance-type $GPU_INSTANCE_TYPE"
- execute-command-if-has-matching-changes "$test_cmd" "test/" "src/*.py" "setup.py" "setup.cfg" "docker/*" "buildspec.yml"
- |
echo '[{
"repository": "sagemaker-chainer",
"tags": [{
"source": "5.0.0-cpu-py2",
"dest": ["5.0.0-cpu-py2", "5.0-cpu-py2", "5.0.0-cpu-py2-'${CODEBUILD_BUILD_ID#*:}'"]
},{
"source": "5.0.0-cpu-py3",
"dest": ["5.0.0-cpu-py3", "5.0-cpu-py3", "5.0.0-cpu-py3-'${CODEBUILD_BUILD_ID#*:}'"]
},{
"source": "5.0.0-gpu-py2",
"dest": ["5.0.0-gpu-py2", "5.0-gpu-py2", "5.0.0-gpu-py2-'${CODEBUILD_BUILD_ID#*:}'"]
},{
"source": "5.0.0-gpu-py3",
"dest": ["5.0.0-gpu-py3", "5.0-gpu-py3", "5.0.0-gpu-py3-'${CODEBUILD_BUILD_ID#*:}'"]
}],
"test": [
"IGNORE_COVERAGE=- tox -e py36 -- -m deploy_test test/integration/sagemaker -n 4 --py-version 2,3 --processor cpu --region {region} --docker-base-name '$ECR_REPO' --aws-id {aws-id} --framework-version '$FRAMEWORK_VERSION' --instance-type {cpu-instance-type}",
"IGNORE_COVERAGE=- tox -e py36 -- -m deploy_test test/integration/sagemaker -n 4 --py-version 2,3 --processor gpu --region {region} --docker-base-name '$ECR_REPO' --aws-id {aws-id} --framework-version '$FRAMEWORK_VERSION' --instance-type '$GPU_INSTANCE_TYPE'"
]
}]' > deployments.json
# publish the release to github
- git-release --publish
finally:
# shut down remote gpu instance
- cleanup-gpu-instances
- cleanup-key-pairs
artifacts:
files:
- deployments.json
name: ARTIFACT_1