Last active
September 27, 2015 13:21
-
-
Save rjeczalik/1a5296bbdf67445edd49 to your computer and use it in GitHub Desktop.
Migrate your app from DEIS to Build.io
This file contains hidden or 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 | |
# Copyright (c) 2015 Build.io. All rights reserved. | |
set -euo pipefail | |
APP_NAME= | |
REPO= | |
BRANCH= | |
DEIS_NAME= | |
usage() { | |
echo "usage: migrate-deis -a <BUILDIO_APP_NAME> -r <GITHUB_USER_PROJECT> -b <BRANCH_NAME> -d <DEIS_NAME>" >&2 | |
} | |
die() { | |
if [[ ! -z "$*" ]]; then | |
echo "$*" >&2 | |
fi | |
exit 1 | |
} | |
# write_config <FILE> | |
write_config() { | |
cat >"$1" <<EOF | jq -c . | tr -d '\n' | |
{ | |
"app": "$APP_NAME", | |
"repo": "$REPO", | |
"branch": "$BRANCH", | |
"config": { | |
$(deis config:list --app "$DEIS_NAME" | tail -n +2 | tr -s ' ' | while read key val; do echo \"$key\": \"$val\",; done) | |
"MIGRATED_FROM_DEIS": "$DEIS_NAME" | |
} | |
} | |
EOF | |
} | |
while getopts ":a:r:b:d:h" opt; do | |
case $opt in | |
a) | |
APP_NAME="$OPTARG" | |
;; | |
r) | |
REPO="$OPTARG" | |
;; | |
b) | |
BRANCH="$OPTARG" | |
;; | |
d) | |
DEIS_NAME="$OPTARG" | |
;; | |
h) | |
usage | |
exit 0 | |
;; | |
\?) | |
echo "invalid flag: $OPTARG" >&2 | |
exit 1 | |
;; | |
:) | |
echo "missing value for $OPTARG" >&2 | |
exit | |
;; | |
esac | |
done | |
shift $(($OPTIND - 1)) | |
[[ -z "$APP_NAME" ]] && die "value for -a flag is empty or missing" | |
[[ -z "$REPO" ]] && die "value for -r flag is empty or missing" | |
[[ -z "$BRANCH" ]] && die "value for -b flag is empty or missing" | |
[[ -z "$DEIS_NAME" ]] && die "value for -d flag is empty or missing" | |
TMP=$(mktemp /tmp/XXXXXX)-buildio.json | |
write_config $TMP | |
echo "# build apps:create -f $TMP" | |
build apps:create -f $TMP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment