Created
November 28, 2016 14:26
-
-
Save afoninsky/7f04302e49ed207a9ccd1e17ba0b0244 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
### run deployment from local machine (not CI) | |
# rollback | |
# kubectl --namespace=fulldive-staging rollout history deployment/fulldive-api | |
# kubectl --namespace=fulldive-staging rollout undo deployment/fulldive-api --to-revision=10 | |
REGISTRY_URL="us.gcr.io" | |
GOOGLE_PROJECT_NAME="spair-api" | |
NAME=`node -e "console.log(require('./package').name)"` | |
VERSION=${2:-v`node -e "console.log(require('./package').version)"`} | |
CLUSTER_NAME="edissons" | |
ENV=$1 | |
echo "Deploying $ENV app [$NAME:$VERSION]..." | |
case "$1" in | |
"staging") | |
NAMESPACE="fulldive-staging" | |
URL=https://staging.api.fulldive.com | |
;; | |
"production") | |
NAMESPACE="fulldive" | |
URL=https://api.fulldive.com | |
;; | |
*) | |
echo "usage: script.sh staging|production [version]" | |
exit | |
;; | |
esac | |
IMAGE_TAG=$REGISTRY_URL/$GOOGLE_PROJECT_NAME/$NAME:$VERSION | |
# ensure specified image exists | |
gcloud docker pull $IMAGE_TAG | |
# update configmap for specified env | |
echo "Generate config..." | |
config_dir=`mktemp -d` | |
cp config/default.js $config_dir/default.js | |
cp config/$ENV.js $config_dir/local.js | |
sleep 1 | |
kubectl create configmap api-config --from-file=$config_dir --dry-run -o yaml | kubectl --namespace=$NAMESPACE replace configmap api-config -f - | |
sleep 3 | |
rm -R $config_dir | |
# update api documentation | |
echo "Build API documentation..." | |
yarn build:apidoc | |
gsutil -m rm -r gs://static.fulldive.com/apidoc/${ENV} | |
gsutil -m cp -r static gs://static.fulldive.com/apidoc/${ENV} | |
# update deployment | |
echo "Pushing new image into server..." | |
kubectl --namespace=$NAMESPACE set image deployment/fulldive-api service=$IMAGE_TAG --record | |
sleep 3 | |
while true | |
do | |
kubectl --namespace=$NAMESPACE rollout status deployment/fulldive-api | |
if [ "$?" -eq "0" ]; then | |
break | |
fi | |
sleep 3 | |
echo "Retry..." | |
done | |
echo $URL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment