From 1d4adefb0099716dde3f6cfca7b8affdbd6d7e34 Mon Sep 17 00:00:00 2001 From: Takashi Matsuo Date: Wed, 20 May 2020 02:18:27 +0000 Subject: [PATCH 1/4] [vision] chore: parameterized FROM, add cloudbuild.yaml also update README with how to build and upload the images. --- .../automl/edge_container_predict/Dockerfile | 3 ++- .../automl/edge_container_predict/README.md | 7 ++++++ .../edge_container_predict/cloudbuild.yaml | 25 +++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 vision/automl/edge_container_predict/cloudbuild.yaml diff --git a/vision/automl/edge_container_predict/Dockerfile b/vision/automl/edge_container_predict/Dockerfile index b8c66c909c0..df4dde5fb2e 100644 --- a/vision/automl/edge_container_predict/Dockerfile +++ b/vision/automl/edge_container_predict/Dockerfile @@ -12,7 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM tensorflow/serving:1.14.0 +ARG FROM_SUFFIX +FROM tensorflow/serving:1.14.0${FROM_SUFFIX} ENV GCS_READ_CACHE_MAX_STALENESS 300 ENV GCS_STAT_CACHE_MAX_AGE 300 diff --git a/vision/automl/edge_container_predict/README.md b/vision/automl/edge_container_predict/README.md index 84116f41394..da8cc50ed66 100644 --- a/vision/automl/edge_container_predict/README.md +++ b/vision/automl/edge_container_predict/README.md @@ -69,3 +69,10 @@ The outputs are ```bash sudo docker stop ${CONTAINER_NAME} ``` + +Note: The docker image is uploaded with the following command. + +```bash +gcloud builds --project=cloud-devrel-public-resources \ + submit --config cloudbuild.yaml +``` diff --git a/vision/automl/edge_container_predict/cloudbuild.yaml b/vision/automl/edge_container_predict/cloudbuild.yaml new file mode 100644 index 00000000000..bd1a7f5b993 --- /dev/null +++ b/vision/automl/edge_container_predict/cloudbuild.yaml @@ -0,0 +1,25 @@ +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +timeout: 3600s + +steps: + - name: 'gcr.io/cloud-builders/docker' + args: ['build', '-t', 'gcr.io/$PROJECT_ID/gcloud-container-1.14.0', '.'] + - name: 'gcr.io/cloud-builders/docker' + args: ['build', '--build-arg', 'FROM_SUFFIX=-gpu', + '-t', 'gcr.io/$PROJECT_ID/gcloud-container-1.14.0-gpu', '.'] +images: + - 'gcr.io/$PROJECT_ID/gcloud-container-1.14.0' + - 'gcr.io/$PROJECT_ID/gcloud-container-1.14.0-gpu' From 5e06c883457a7a22a8709d63427150c6c6175a06 Mon Sep 17 00:00:00 2001 From: Takashi Matsuo Date: Wed, 20 May 2020 20:39:37 +0000 Subject: [PATCH 2/4] made the ARG to cover the whole tag --- vision/automl/edge_container_predict/Dockerfile | 4 ++-- vision/automl/edge_container_predict/cloudbuild.yaml | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/vision/automl/edge_container_predict/Dockerfile b/vision/automl/edge_container_predict/Dockerfile index df4dde5fb2e..d447bcc5754 100644 --- a/vision/automl/edge_container_predict/Dockerfile +++ b/vision/automl/edge_container_predict/Dockerfile @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -ARG FROM_SUFFIX -FROM tensorflow/serving:1.14.0${FROM_SUFFIX} +ARG TF_SERVING_IMAGE_TAG +FROM tensorflow/serving:${TF_SERVING_IMAGE_TAG} ENV GCS_READ_CACHE_MAX_STALENESS 300 ENV GCS_STAT_CACHE_MAX_AGE 300 diff --git a/vision/automl/edge_container_predict/cloudbuild.yaml b/vision/automl/edge_container_predict/cloudbuild.yaml index bd1a7f5b993..5b0760254b4 100644 --- a/vision/automl/edge_container_predict/cloudbuild.yaml +++ b/vision/automl/edge_container_predict/cloudbuild.yaml @@ -16,10 +16,11 @@ timeout: 3600s steps: - name: 'gcr.io/cloud-builders/docker' - args: ['build', '-t', 'gcr.io/$PROJECT_ID/gcloud-container-1.14.0', '.'] + args: ['build', '-t', 'gcr.io/$PROJECT_ID/gcloud-container-1.14.0', + '--build-arg', 'TF_SERVING_IMAGE_TAG=1.14.0', '.'] - name: 'gcr.io/cloud-builders/docker' - args: ['build', '--build-arg', 'FROM_SUFFIX=-gpu', - '-t', 'gcr.io/$PROJECT_ID/gcloud-container-1.14.0-gpu', '.'] + args: ['build', '-t', 'gcr.io/$PROJECT_ID/gcloud-container-1.14.0-gpu', + '--build-arg', 'TF_SERVING_IMAGE_TAG=1.14.0-gpu', '.'] images: - 'gcr.io/$PROJECT_ID/gcloud-container-1.14.0' - 'gcr.io/$PROJECT_ID/gcloud-container-1.14.0-gpu' From dd29214f700d653c08236f879b1ded8cdc9ccda1 Mon Sep 17 00:00:00 2001 From: Takashi Matsuo Date: Wed, 20 May 2020 21:12:55 +0000 Subject: [PATCH 3/4] add an envvar for avoid docker error --- .../automl_vision_edge_container_predict_test.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vision/automl/edge_container_predict/automl_vision_edge_container_predict_test.py b/vision/automl/edge_container_predict/automl_vision_edge_container_predict_test.py index f673ada422c..3f38c589f7a 100644 --- a/vision/automl/edge_container_predict/automl_vision_edge_container_predict_test.py +++ b/vision/automl/edge_container_predict/automl_vision_edge_container_predict_test.py @@ -60,7 +60,9 @@ def edge_container_predict_server_port(): # set up # Pull the CPU docker. - subprocess.check_output(['docker', 'pull', CPU_DOCKER_GCS_PATH]) + subprocess.check_output( + ['docker', 'pull', CPU_DOCKER_GCS_PATH], + env={'DOCKER_API_VERSION': '1.38'}) # Get the sample saved model. if not os.path.exists(MODEL_PATH): From ce69a43aa30d6827b753101cba0d4ac97202ae6a Mon Sep 17 00:00:00 2001 From: Takashi Matsuo Date: Wed, 20 May 2020 21:28:49 +0000 Subject: [PATCH 4/4] add more envvars to avoid docker error --- .../automl_vision_edge_container_predict_test.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/vision/automl/edge_container_predict/automl_vision_edge_container_predict_test.py b/vision/automl/edge_container_predict/automl_vision_edge_container_predict_test.py index 3f38c589f7a..4acf451f47d 100644 --- a/vision/automl/edge_container_predict/automl_vision_edge_container_predict_test.py +++ b/vision/automl/edge_container_predict/automl_vision_edge_container_predict_test.py @@ -68,13 +68,14 @@ def edge_container_predict_server_port(): if not os.path.exists(MODEL_PATH): os.mkdir(MODEL_PATH) subprocess.check_output( - ['gsutil', '-m', 'cp', SAMPLE_SAVED_MODEL, MODEL_PATH]) + ['gsutil', '-m', 'cp', SAMPLE_SAVED_MODEL, MODEL_PATH]) # Start the CPU docker. subprocess.Popen(['docker', 'run', '--rm', '--name', NAME, '-v', MODEL_PATH + ':/tmp/mounted_model/0001', '-p', str(PORT_NUMBER) + ':8501', '-t', - CPU_DOCKER_GCS_PATH]) + CPU_DOCKER_GCS_PATH], + env={'DOCKER_API_VERSION': '1.38'}) # Sleep a few seconds to wait for the container running. time.sleep(10) @@ -82,9 +83,12 @@ def edge_container_predict_server_port(): # tear down # Stop the container. - subprocess.check_output(['docker', 'stop', NAME]) + subprocess.check_output( + ['docker', 'stop', NAME], env={'DOCKER_API_VERSION': '1.38'}) # Remove the docker image. - subprocess.check_output(['docker', 'rmi', CPU_DOCKER_GCS_PATH]) + subprocess.check_output( + ['docker', 'rmi', CPU_DOCKER_GCS_PATH], + env={'DOCKER_API_VERSION': '1.38'}) def test_edge_container_predict(capsys, edge_container_predict_server_port):