build cli-migrations image on tagged deploys (close #534) (#953)

This commit is contained in:
Shahidh K Muhammed
2018-11-02 19:38:25 +05:30
committed by GitHub
parent 0e9d6994ac
commit fbcae53efa
7 changed files with 128 additions and 4 deletions

1
scripts/cli-migrations/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
cli-hasura-linux-amd64

View File

@@ -0,0 +1,11 @@
FROM hasura/graphql-engine:v1.0.0-alpha27
ENV HASURA_GRAPHQL_ENABLE_CONSOLE=true
COPY docker-entrypoint.sh /bin/
COPY cli-hasura-linux-amd64 /bin/hasura-cli
RUN chmod +x /bin/hasura-cli
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["graphql-engine", "serve"]

View File

@@ -0,0 +1,55 @@
#!/bin/sh
set -e
DEFAULT_MIGRATIONS_DIR="/hasura-migrations"
TEMP_MIGRATIONS_DIR="/tmp/hasura-migrations"
# wait for a port to be ready
wait_for_port() {
local PORT=$1
echo "waiting for $PORT"
for i in `seq 1 30`;
do
nc localhost $PORT > /dev/null 2>&1 && echo "port $PORT is ready" && return
echo -n .
sleep 1
done
echo "failed waiting for $PORT" && exit 1
}
echo "starting graphql engine on port 8080..."
# start graphql engine
graphql-engine serve &
# store the pid to kill it later
PID=$!
# wait for port 8080 to be ready
wait_for_port 8080
# check if migration directory is set, default otherwise
if [ -z ${HASURA_GRAPHQL_MIGRATIONS_DIR+x} ]; then
echo "env var HASURA_GRAPHQL_MIGRATIONS_DIR is not set"
echo "defaulting to $DEFAULT_MIGRATIONS_DIR"
HASURA_GRAPHQL_MIGRATIONS_DIR="$DEFAULT_MIGRATIONS_DIR"
fi
# apply migrations if the directory exist
if [ -d "$HASURA_GRAPHQL_MIGRATIONS_DIR" ]; then
echo "applying migrations in $HASURA_GRAPHQL_MIGRATIONS_DIR..."
mkdir -p "$TEMP_MIGRATIONS_DIR"
cp -a "$HASURA_GRAPHQL_MIGRATIONS_DIR/." "$TEMP_MIGRATIONS_DIR/migrations/"
cd "$TEMP_MIGRATIONS_DIR"
echo "endpoint: http://localhost:8080" > config.yaml
hasura-cli migrate apply
else
echo "directory $HASURA_GRAPHQL_MIGRATIONS_DIR does not exist"
echo "skipping migration apply"
fi
# kill graphql engine that we started earlier
kill $PID
# pass control to CMD
exec "$@"

View File

@@ -16,6 +16,9 @@ set -e
# get the repo root
ROOT="$(readlink -f ${BASH_SOURCE[0]%/*}/../)"
# paths to replace versions
VERSION_PATHS="$ROOT/install-manifests $ROOT/scripts/cli-migrations"
# check if required argument is set
if [ -z "$1" ]; then
echo "Usage: ./tag-release.sh <tag> [<optional-tag-message>]"
@@ -32,10 +35,10 @@ if [ -z "$MESSAGE" ]; then
fi
# replace the image version with latest tag for all references in install-manifests
find "$ROOT/install-manifests" -type f -exec sed -i -E 's#(hasura/graphql-engine:)v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(\-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?( \\)*$#\1'"${TAG}"'\9#' {} \;
find "$VERSION_PATHS" -type f -exec sed -i -E 's#(hasura/graphql-engine:)v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(\-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?( \\)*$#\1'"${TAG}"'\9#' {} \;
git add "$ROOT/install-manifests"
git commit -m "update installation manifests to $TAG"
git add "$VERSION_PATHS"
git commit -m "update manifests to $TAG"
git tag -a "$TAG" -m "$MESSAGE"