Skip to content
This repository was archived by the owner on May 23, 2024. It is now read-only.

Commit 32bb4f7

Browse files
authored
add buildspec.yml for codebuild (#4)
1 parent 3119f7e commit 32bb4f7

File tree

5 files changed

+76
-25
lines changed

5 files changed

+76
-25
lines changed

buildspec.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
version: 0.2
2+
3+
phases:
4+
pre_build:
5+
commands:
6+
- start-dockerd.sh
7+
8+
# fix permissions dropped by CodePipeline
9+
- chmod +x ./scripts/*.sh
10+
- chmod +x ./container/sagemaker/serve
11+
build:
12+
commands:
13+
- tox -e flake8,pylint,jshint
14+
15+
# build images
16+
- ./scripts/build.sh --version 1.11 --arch cpu
17+
- ./scripts/build.sh --version 1.11 --arch gpu
18+
- ./scripts/build.sh --version 1.12 --arch cpu
19+
- ./scripts/build.sh --version 1.12 --arch gpu
20+
21+
# run tests
22+
- tox -e py36

scripts/build.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ source scripts/shared.sh
88

99
parse_std_args "$@"
1010

11-
docker build -f docker/$major_version/Dockerfile.$arch \
11+
echo "pulling previous image for layer cache... "
12+
$(aws ecr get-login --no-include-email --registry-id $aws_account) &>/dev/null || echo 'warning: ecr login failed'
13+
docker pull $aws_account.dkr.ecr.$aws_region.amazonaws.com/sagemaker-tensorflow-serving:$minor_version-$arch &>/dev/null || echo 'warning: pull failed'
14+
docker logout https://$aws_account.dkr.ecr.$aws_region.amazonaws.com &>/dev/null
15+
16+
echo "building image... "
17+
docker build \
18+
--cache-from $aws_account.dkr.ecr.$aws_region.amazonaws.com/sagemaker-tensorflow-serving:$minor_version-$arch \
19+
-f docker/$major_version/Dockerfile.$arch \
1220
-t sagemaker-tensorflow-serving:$minor_version-$arch \
1321
-t sagemaker-tensorflow-serving:$major_version-$arch container

scripts/publish.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ source scripts/shared.sh
88

99
parse_std_args "$@"
1010

11-
aws_account=$(get_aws_account)
1211
$(aws ecr get-login --no-include-email --registry-id $aws_account)
1312
docker tag sagemaker-tensorflow-serving:$minor_version-$arch $aws_account.dkr.ecr.$aws_region.amazonaws.com/sagemaker-tensorflow-serving:$minor_version-$arch
1413
docker tag sagemaker-tensorflow-serving:$minor_version-$arch $aws_account.dkr.ecr.$aws_region.amazonaws.com/sagemaker-tensorflow-serving:$major_version-$arch

scripts/shared.sh

100644100755
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ function get_minor_version() {
1717
}
1818

1919
function get_default_region() {
20-
aws configure get region
20+
if [ -n "${AWS_DEFAULT_REGION:-}" ]; then
21+
echo "$AWS_DEFAULT_REGION"
22+
else
23+
aws configure get region
24+
fi
2125
}
2226

2327
function get_aws_account() {
@@ -29,6 +33,7 @@ function parse_std_args() {
2933
arch='cpu'
3034
major_version=$(get_latest_major_version)
3135
aws_region=$(get_default_region)
36+
aws_account=$(get_aws_account)
3237

3338
while [[ $# -gt 0 ]]; do
3439
key="$1"

test/integration/test_container.py

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,46 @@
2323
BASE_URL = 'http://localhost:8080/invocations'
2424

2525

26+
@pytest.fixture(scope='session', autouse=True)
27+
def volume():
28+
try:
29+
model_dir = os.path.abspath('test/resources/models')
30+
subprocess.check_call(
31+
'docker volume create --name model_volume --opt type=none '
32+
'--opt device={} --opt o=bind'.format(model_dir).split())
33+
yield model_dir
34+
finally:
35+
subprocess.check_call('docker volume rm model_volume'.split())
36+
37+
2638
@pytest.fixture(scope='module', autouse=True, params=['1.11', '1.12'])
2739
def container(request):
28-
model_dir = os.path.abspath('test/resources/models')
29-
command = 'docker run --name sagemaker-tensorflow-serving-test -v {}:/opt/ml/model:ro -p 8080:8080'.format(
30-
model_dir)
31-
command += ' -e SAGEMAKER_TFS_DEFAULT_MODEL_NAME=half_plus_three'
32-
command += ' -e SAGEMAKER_TFS_NGINX_LOGLEVEL=info'
33-
command += ' -e SAGEMAKER_BIND_TO_PORT=8080'
34-
command += ' -e SAGEMAKER_SAFE_PORT_RANGE=9000-9999'
35-
command += ' sagemaker-tensorflow-serving:{}-cpu serve'.format(request.param)
36-
proc = subprocess.Popen(command.split(), stdout=sys.stdout, stderr=subprocess.STDOUT)
37-
38-
attempts = 0
39-
while attempts < 5:
40-
time.sleep(3)
41-
try:
42-
requests.get('http://localhost:8080/ping')
43-
break
44-
except:
45-
attempts += 1
46-
pass
47-
48-
yield proc.pid
49-
subprocess.check_call('docker rm -f sagemaker-tensorflow-serving-test'.split())
40+
try:
41+
command = (
42+
'docker run --name sagemaker-tensorflow-serving-test -p 8080:8080'
43+
' --mount type=volume,source=model_volume,target=/opt/ml/model,readonly'
44+
' -e SAGEMAKER_TFS_DEFAULT_MODEL_NAME=half_plus_three'
45+
' -e SAGEMAKER_TFS_NGINX_LOGLEVEL=info'
46+
' -e SAGEMAKER_BIND_TO_PORT=8080'
47+
' -e SAGEMAKER_SAFE_PORT_RANGE=9000-9999'
48+
' sagemaker-tensorflow-serving:{}-cpu serve'
49+
).format(request.param)
50+
51+
proc = subprocess.Popen(command.split(), stdout=sys.stdout, stderr=subprocess.STDOUT)
52+
53+
attempts = 0
54+
while attempts < 5:
55+
time.sleep(3)
56+
try:
57+
requests.get('http://localhost:8080/ping')
58+
break
59+
except:
60+
attempts += 1
61+
pass
62+
63+
yield proc.pid
64+
finally:
65+
subprocess.check_call('docker rm -f sagemaker-tensorflow-serving-test'.split())
5066

5167

5268
def make_request(data, content_type='application/json', method='predict'):
@@ -94,6 +110,7 @@ def test_predict_jsons():
94110
y = make_request(x, 'application/jsons')
95111
assert y == {'predictions': [[3.5, 4.0, 5.5], [3.5, 4.0, 5.5]]}
96112

113+
97114
def test_predict_jsons_2():
98115
x = '{"x": [1.0, 2.0, 5.0]}\n{"x": [1.0, 2.0, 5.0]}'
99116
y = make_request(x)

0 commit comments

Comments
 (0)