forked from kubeflow/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a script to update the index and lookup file used to serve pre…
…dictions. (kubeflow#352) * This script will be the last step in a pipeline to continuously update the index for serving. * The script updates the parameters of the search index server to point to the supplied index files. It then commits them and creates a PR to push those commits. * Restructure the parameters for the search index server so that we can use ks param set to override the indexFile and lookupFile. * We do this because we want to be able to push a new index by doing ks param set in a continuously running pipeline * Remove default parameters from search-index-server * Create a dockerfile suitable for running this script.
- Loading branch information
1 parent
4f95e85
commit 5d6a4e9
Showing
8 changed files
with
158 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM ubuntu:xenial | ||
|
||
RUN apt-get update && apt-get install -y wget &&\ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
RUN wget -O /tmp/hub-linux-amd64-2.6.0.tgz https://github.com/github/hub/releases/download/v2.6.0/hub-linux-amd64-2.6.0.tgz && \ | ||
cd /usr/local && \ | ||
tar -xvf /tmp/hub-linux-amd64-2.6.0.tgz && \ | ||
ln -sf /usr/local/hub-linux-amd64-2.6.0/bin/hub /usr/local/bin/hub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Index Updater | ||
|
||
A Docker image and script suitable for updating the index served. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// TODO(jlewi): We should tag the image latest and then | ||
// use latest as a cache so that rebuilds are fast | ||
// https://cloud.google.com/cloud-build/docs/speeding-up-builds#using_a_cached_docker_image | ||
{ | ||
|
||
"steps": [ | ||
{ | ||
"id": "build", | ||
"name": "gcr.io/cloud-builders/docker", | ||
"args": ["build", "-t", "gcr.io/kubeflow-examples/code-search/index_updater:" + std.extVar("tag"), | ||
"--label=git-versions=" + std.extVar("gitVersion"), | ||
"--file=docker/index_updater/Dockerfile", | ||
"."], | ||
}, | ||
{ | ||
"id": "tag", | ||
"name": "gcr.io/cloud-builders/docker", | ||
"args": ["tag", "gcr.io/kubeflow-examples/code-search/index_updater:" + std.extVar("tag"), | ||
"gcr.io/kubeflow-examples/code-search/index_updater:latest",], | ||
"waitFor": ["build"], | ||
}, | ||
], | ||
"images": ["gcr.io/kubeflow-examples/code-search/index_updater:" + std.extVar("tag"), | ||
"gcr.io/kubeflow-examples/code-search/index_updater:latest", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#!/bin/bash | ||
# | ||
# This script creates a PR updating the nmslib index used by search-index-server. | ||
# It uses ks CLI to update the parameters. | ||
# After creating and pushing a commit it uses the hub github CLI to create a PR. | ||
# | ||
# The argument --base can be used to change the owner/org of the repo the PR is opened on. | ||
# To use the main kubeflow/examples repo use | ||
# --base=kubeflow:master | ||
# | ||
# To use user alex's fork use | ||
# --base=alex/master | ||
set -ex | ||
|
||
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null && pwd)" | ||
|
||
parseArgs() { | ||
# Parse all command line options | ||
while [[ $# -gt 0 ]]; do | ||
# Parameters should be of the form | ||
# --{name}=${value} | ||
echo parsing "$1" | ||
if [[ $1 =~ ^--(.*)=(.*)$ ]]; then | ||
name=${BASH_REMATCH[1]} | ||
value=${BASH_REMATCH[2]} | ||
|
||
eval ${name}="${value}" | ||
elif [[ $1 =~ ^--(.*)$ ]]; then | ||
name=${BASH_REMATCH[1]} | ||
value=true | ||
eval ${name}="${value}" | ||
else | ||
echo "Argument $1 did not match the pattern --{name}={value} or --{name}" | ||
fi | ||
shift | ||
done | ||
} | ||
|
||
usage() { | ||
echo "Usage: update_index.sh --base=OWNER:branch --appDir=<ksonnet app dir> --env=<ksonnet environment> --indexFile=<index file> --lookupFile=<lookup file>" | ||
} | ||
|
||
parseArgs $* | ||
|
||
if [ ! -z ${help} ]; then | ||
usage | ||
fi | ||
|
||
if [ -z ${dryrun} ]; then | ||
dryrun=false | ||
fi | ||
|
||
# List of required parameters | ||
names=(appDir env lookupFile indexFile base) | ||
|
||
|
||
missingParam=false | ||
for i in ${names[@]}; do | ||
if [ -z ${!i} ]; then | ||
echo "--${i} not set" | ||
missingParam=true | ||
fi | ||
done | ||
|
||
if ${missingParam}; then | ||
usage | ||
exit 1 | ||
fi | ||
cd ${appDir} | ||
ks param set --env=${env} search-index-server indexFile ${indexFile} | ||
ks param set --env=${env} search-index-server lookupFile ${lookupFile} | ||
git add . | ||
|
||
if (! ${dryrun}); then | ||
git commit -m "Update the lookup and index file." | ||
git push | ||
else | ||
echo "dryrun; not committing to git." | ||
fi | ||
|
||
FILE=$(mktemp tmp.create_pull_request.XXXX) | ||
|
||
cat <<EOF >$FILE | ||
Update the lookup and index file. | ||
This PR is automatically generated by update_index.sh. | ||
This PR updates the index and lookup file used to serve | ||
predictions. | ||
EOF | ||
|
||
# Create a pull request | ||
if (! ${dryrun}); then | ||
hub pull-request --base=${base} -F ${FILE} | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters