Skip to content

Instantly share code, notes, and snippets.

@veggiemonk
Created April 18, 2020 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save veggiemonk/0f3382158d60c86536fe2e5df8c615d3 to your computer and use it in GitHub Desktop.
Save veggiemonk/0f3382158d60c86536fe2e5df8c615d3 to your computer and use it in GitHub Desktop.
kth serverless demo
#!/bin/bash
set -xe
# Meant to be run in cloud shell
# Enable APIs if not already done
# gcloud services enable run.googleapis.com containerregistry.googleapis.com
echo
echo "download container image locally"
echo
docker pull esimov/pigo-openfaas:0.1
# if running this script on a non-CloudShell vm
# gcloud auth configure-docker
# gcloud components install docker-credential-gcr
export PROJECT_ID=$(gcloud config get-value project)
export IMAGE="eu.gcr.io/${PROJECT_ID}/pigo-openfaas:latest"
echo
echo "Tag container image"
echo
docker tag esimov/pigo-openfaas:0.1 "${IMAGE}"
echo
echo "Push container image to gcr"
echo
docker push "${IMAGE}"
echo
echo "Deploy container on Cloud Run"
echo
gcloud run deploy pigo-openfaas --platform=managed \
--region=us-central1 --image="${IMAGE}" \
--allow-unauthenticated \
--set-env-vars=output_mode=image \
--set-env-vars=input_mode=url
echo
echo "Get the service URL endpoint"
echo
export FUNCTION_URL=$(gcloud run services describe pigo-openfaas --region=us-central1 --platform=managed --format=json | jq -r '.status.url')
echo
echo "Choose an image to do face detection on"
echo
export IMG_URL="https://upload.wikimedia.org/wikipedia/commons/thumb/c/cc/NASA_Astronaut_Group_18.jpg/1200px-NASA_Astronaut_Group_18.jpg"
sleep 5
echo
echo "Using the deployed services"
echo
curl -H 'Content-Type: binary/octet-stream' \
--data-binary "${IMG_URL}" "${FUNCTION_URL}" > target.jpg
echo
echo "Done."
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment