Skip to content

Commit

Permalink
Shorten the build time in Cloud Build.
Browse files Browse the repository at this point in the history
This change shorten the build time in Cloud Build by using methods below:
- Introduce Kaniko cache when building and pushing a docker image.
- Run steps in parallel.

PiperOrigin-RevId: 422246953
  • Loading branch information
rihito0907 authored and starmandeluxe committed Apr 7, 2022
1 parent ff719d9 commit 83c881b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 46 deletions.
88 changes: 43 additions & 45 deletions cicd/deploy_shoptimizer_to_cloud_run.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,50 @@
# limitations under the License.

steps:
# Install dependencies & run unit tests
- name: python:3.8-slim
id: ShoptimizerUnitTests
entrypoint: /bin/sh
dir: shoptimizer_api
args:
- -c
- |
apt-get update \
&& apt-get -y install swig mecab libmecab-dev mecab-ipadic-utf8 git make curl xz-utils file sudo \
&& git clone --depth 1 https://github.com/neologd/mecab-ipadic-neologd.git \
&& echo yes | mecab-ipadic-neologd/bin/install-mecab-ipadic-neologd -n -a \
&& pip install --upgrade pip && pip install tensorflow pipenv \
&& pipenv install --dev --system --deploy --ignore-pipfile \
&& cp /etc/mecabrc /usr/local/etc/ \
&& python test_runner.py
# Install dependencies & run unit tests
- name: python:3.8-slim
id: ShoptimizerUnitTests
entrypoint: /bin/sh
dir: shoptimizer_api
args:
- -c
- |
apt-get update \
&& apt-get -y install swig mecab libmecab-dev mecab-ipadic-utf8 git make curl xz-utils file sudo \
&& git clone --depth 1 https://github.com/neologd/mecab-ipadic-neologd.git \
&& echo yes | mecab-ipadic-neologd/bin/install-mecab-ipadic-neologd -n -a \
&& pip install --upgrade pip && pip install tensorflow pipenv \
&& pipenv install --dev --system --deploy --ignore-pipfile \
&& cp /etc/mecabrc /usr/local/etc/ \
&& python test_runner.py
# Docker Build and Push
- name: gcr.io/kaniko-project/executor:latest
id: DockerBuildAndPush
args:
- --destination=gcr.io/${_GCP_PROJECT}/shoptimizer
- --cache=true
- --cache-ttl=336h
- --snapshotMode=redo
- --context=dir:///workspace/shoptimizer_api
waitFor:
- "-"

# Docker Build
- name: gcr.io/cloud-builders/docker
args:
- image
- build
- -t
- gcr.io/${_GCP_PROJECT}/shoptimizer
- .
dir: shoptimizer_api

# Docker push to Google Artifact Registry
- name: gcr.io/cloud-builders/docker
args:
- image
- push
- gcr.io/${_GCP_PROJECT}/shoptimizer

# Deploy to Cloud Run
- name: gcr.io/cloud-builders/gcloud
args:
- run
- deploy
- shoptimizer
- --image=gcr.io/${_GCP_PROJECT}/shoptimizer:latest
- --region=us-central1
- --platform=managed
- --memory=2G
# Deploy to Cloud Run
- name: gcr.io/cloud-builders/gcloud
args:
- run
- deploy
- shoptimizer
- --image=gcr.io/${_GCP_PROJECT}/shoptimizer:latest
- --region=us-central1
- --platform=managed
- --memory=2G
waitFor:
- "ShoptimizerUnitTests"
- "DockerBuildAndPush"
timeout: 3600s
tags: ['shoptimizer']
tags: ["shoptimizer"]
options:
machineType: 'E2_HIGHCPU_32'
# High-end machineType is necessary to use Kaniko cache, otherwise the process is killed due to memory shortage.
machineType: "N1_HIGHCPU_32"
2 changes: 1 addition & 1 deletion docs/install-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Finally, push the code to your GCP project's Cloud Source Repository.

`git push gcp master`

Allow the deployment to run in Cloud Build. This will take several minutes. You can monitor the progress from your GCP project's Cloud Build dashboard in the admin console.
Allow the deployment to run in Cloud Build. This will take several minutes. You can monitor the progress from your GCP project's Cloud Build dashboard in the admin console. If a build fails, something may be wrong with cache files generated during the build. In this case, open Container Registry on the GCP console, delete the directory `shoptimizer/cache` and try running the build again.

Congratulations, you should now have Shoptimizer running in Docker on Cloud Run!

Expand Down

0 comments on commit 83c881b

Please sign in to comment.