Created
March 20, 2017 08:55
-
-
Save christippett/93845fd5e7b2cf1f9a9c488426764934 to your computer and use it in GitHub Desktop.
Automate deployment of Google Cloud Endpoints, including updating App Engine's app.yaml with latest config_id
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 script is designed to be run in a post-commit build script. | |
# It checks if openapi.yaml has been modified and deploys the latest | |
# API specification to Google Cloud Endpoints and updates app.yaml | |
# with the latest config_id | |
SERVICE_NAME=sample.endpoints.[PROJECT_ID].appspot.com | |
if $(git diff-tree --no-commit-id --name-only -r HEAD | grep -q openapi.yaml); then | |
echo "Detected changes to openapi.yaml in last commit, deploying new version to Cloud Endpoints..." | |
gcloud service-management deploy openapi.yaml | |
else | |
echo "No changes to openapi.yaml in last commit, no deployment necessary" | |
fi; | |
# Update app.yaml with latest config_id | |
config_id=$(gcloud service-management configs list --service=$SERVICE_NAME --limit=1 | awk 'NR==2{print $1}') | |
sed -i.bak 's/^\( config_id: \).*/\1'"$config_id"'/' app.yaml | |
echo "Updated config_id in app.yaml to $config_id" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Super awesome. I was looking to do something similar and the awk line was exactly what I was missing. Thanks!