From 7388f1c25d1c0b792d0b0fd4031bfbfb114e4130 Mon Sep 17 00:00:00 2001 From: Richard Herndon Date: Thu, 14 Nov 2024 14:40:35 -0800 Subject: [PATCH] update the cli-migrations docker images so that their entrypoints allow use of the --disallow-inconsistent-metadata flag when applying metadata (fixes #10599) --- .../auto-apply-migrations.mdx | 7 +++++++ packaging/cli-migrations/v2/README.md | 8 ++++++++ packaging/cli-migrations/v2/docker-entrypoint.sh | 12 +++++++++++- packaging/cli-migrations/v3/README.md | 8 ++++++++ packaging/cli-migrations/v3/docker-entrypoint.sh | 12 +++++++++++- 5 files changed, 45 insertions(+), 2 deletions(-) diff --git a/docs/docs/migrations-metadata-seeds/auto-apply-migrations.mdx b/docs/docs/migrations-metadata-seeds/auto-apply-migrations.mdx index ab2d41687b446..0dcfce2032353 100644 --- a/docs/docs/migrations-metadata-seeds/auto-apply-migrations.mdx +++ b/docs/docs/migrations-metadata-seeds/auto-apply-migrations.mdx @@ -105,3 +105,10 @@ If you're managing Migrations with a different tool and want to use this image t `metadata` directory of your Hasura Project at the `/hasura-metadata` [path of this Docker container the container's entry point script](https://github.com/hasura/graphql-engine/blob/master/packaging/cli-migrations/v3/docker-entrypoint.sh#L13) will apply the Metadata before starting the server. + +## Disallowing Inconsistent Metadata + +If you set the `HASURA_GRAPHQL_DISALLOW_INCONSISTENT_METADATA` environment variable to `true`, the entrypoint script will +reject inconsistent metadata and exit with a non-zero exit code. This has the same behavior as the +`--disallow-inconsistent-metadata` flag in the `hasura metadata apply` command documented +[here](/hasura-cli/commands/hasura_metadata_apply.mdx). diff --git a/packaging/cli-migrations/v2/README.md b/packaging/cli-migrations/v2/README.md index 04254b3f2e1bb..6e97b8fd49e7b 100644 --- a/packaging/cli-migrations/v2/README.md +++ b/packaging/cli-migrations/v2/README.md @@ -134,3 +134,11 @@ At least one of these **must** be configured to migrate the database successfull - `HASURA_GRAPHQL_MIGRATIONS_SERVER_TIMEOUT` (default=`30s`) Specify the server timeout threshold. + +### Disallow Inconsistent Metadata (Optional) + +- `HASURA_GRAPHQL_DISALLOW_INCONSISTENT_METADATA` (default=`false`) + + If set to true, inconsistent metadata will be rejected, causing the entrypoint script to exit with a non-zero exit code. + Has the same behavior as the `--disallow-inconsistent-metadata` flag in the `hasura metadata apply` command documented + [here](https://hasura.io/docs/latest/hasura-cli/commands/hasura_metadata_apply). diff --git a/packaging/cli-migrations/v2/docker-entrypoint.sh b/packaging/cli-migrations/v2/docker-entrypoint.sh index 81548b240f25e..d1f50841a6ecb 100755 --- a/packaging/cli-migrations/v2/docker-entrypoint.sh +++ b/packaging/cli-migrations/v2/docker-entrypoint.sh @@ -11,6 +11,7 @@ log() { DEFAULT_MIGRATIONS_DIR="/hasura-migrations" DEFAULT_METADATA_DIR="/hasura-metadata" +DEFAULT_DISALLOW_INCONSISTENT_METADATA_FLAG="" TEMP_PROJECT_DIR="/tmp/hasura-project" # configure the target database for migrations @@ -72,6 +73,15 @@ if [ -z ${HASURA_GRAPHQL_METADATA_DIR+x} ]; then HASURA_GRAPHQL_METADATA_DIR="$DEFAULT_METADATA_DIR" fi +# check if disallow metadata inconsistency is set to true (case insensitive), default otherwise +if [ "$(echo "$HASURA_GRAPHQL_DISALLOW_INCONSISTENT_METADATA" | tr '[:upper:]' '[:lower:]')" = "true" ]; then + log "migrations-startup" "env var HASURA_GRAPHQL_DISALLOW_INCONSISTENT_METADATA is set to true, disallowing inconsistent metadata" + HASURA_GRAPHQL_DISALLOW_INCONSISTENT_METADATA="--disallow-inconsistent-metadata" +else + log "migrations-startup" "env var HASURA_GRAPHQL_DISALLOW_INCONSISTENT_METADATA is not true, falling back to default CLI behavior" + HASURA_GRAPHQL_DISALLOW_INCONSISTENT_METADATA="$DEFAULT_DISALLOW_INCONSISTENT_METADATA_FLAG" +fi + # apply migrations if the directory exist if [ -d "$HASURA_GRAPHQL_MIGRATIONS_DIR" ]; then log "migrations-apply" "applying migrations from $HASURA_GRAPHQL_MIGRATIONS_DIR" @@ -95,7 +105,7 @@ if [ -d "$HASURA_GRAPHQL_METADATA_DIR" ]; then echo "version: 2" > config.yaml echo "endpoint: http://localhost:$HASURA_GRAPHQL_MIGRATIONS_SERVER_PORT" >> config.yaml echo "metadata_directory: metadata" >> config.yaml - hasura-cli metadata apply + hasura-cli metadata apply $HASURA_GRAPHQL_DISALLOW_INCONSISTENT_METADATA else log "migrations-apply" "directory $HASURA_GRAPHQL_METADATA_DIR does not exist, skipping metadata" fi diff --git a/packaging/cli-migrations/v3/README.md b/packaging/cli-migrations/v3/README.md index f4303978b25d0..d81e451a48e63 100644 --- a/packaging/cli-migrations/v3/README.md +++ b/packaging/cli-migrations/v3/README.md @@ -71,3 +71,11 @@ Optional configuration for the server which boots during migrations. - `HASURA_GRAPHQL_MIGRATIONS_SERVER_TIMEOUT` (default=`30s`) Specify the server timeout threshold. + +### Disallow Inconsistent Metadata (Optional) + +- `HASURA_GRAPHQL_DISALLOW_INCONSISTENT_METADATA` (default=`false`) + + If set to true, inconsistent metadata will be rejected, causing the entrypoint script to exit with a non-zero exit code. + Has the same behavior as the `--disallow-inconsistent-metadata` flag in the `hasura metadata apply` command documented + [here](https://hasura.io/docs/latest/hasura-cli/commands/hasura_metadata_apply). diff --git a/packaging/cli-migrations/v3/docker-entrypoint.sh b/packaging/cli-migrations/v3/docker-entrypoint.sh index ec6d1c78699e4..f32c5faf487e4 100755 --- a/packaging/cli-migrations/v3/docker-entrypoint.sh +++ b/packaging/cli-migrations/v3/docker-entrypoint.sh @@ -11,6 +11,7 @@ log() { DEFAULT_MIGRATIONS_DIR="/hasura-migrations" DEFAULT_METADATA_DIR="/hasura-metadata" +DEFAULT_DISALLOW_INCONSISTENT_METADATA_FLAG="" TEMP_PROJECT_DIR="/tmp/hasura-project" if [ -z ${HGE_BINARY+x} ]; then @@ -67,6 +68,15 @@ if [ -z ${HASURA_GRAPHQL_METADATA_DIR+x} ]; then HASURA_GRAPHQL_METADATA_DIR="$DEFAULT_METADATA_DIR" fi +# check if disallow metadata inconsistency is set to true (case insensitive), default otherwise +if [ "$(echo "$HASURA_GRAPHQL_DISALLOW_INCONSISTENT_METADATA" | tr '[:upper:]' '[:lower:]')" = "true" ]; then + log "migrations-startup" "env var HASURA_GRAPHQL_DISALLOW_INCONSISTENT_METADATA is set to true, disallowing inconsistent metadata" + HASURA_GRAPHQL_DISALLOW_INCONSISTENT_METADATA="--disallow-inconsistent-metadata" +else + log "migrations-startup" "env var HASURA_GRAPHQL_DISALLOW_INCONSISTENT_METADATA is not true, falling back to default CLI behavior" + HASURA_GRAPHQL_DISALLOW_INCONSISTENT_METADATA="$DEFAULT_DISALLOW_INCONSISTENT_METADATA_FLAG" +fi + # apply metadata if the directory exist if [ -d "$HASURA_GRAPHQL_METADATA_DIR" ]; then rm -rf "$TEMP_PROJECT_DIR" @@ -77,7 +87,7 @@ if [ -d "$HASURA_GRAPHQL_METADATA_DIR" ]; then echo "version: 3" > config.yaml echo "endpoint: http://localhost:$HASURA_GRAPHQL_MIGRATIONS_SERVER_PORT" >> config.yaml echo "metadata_directory: metadata" >> config.yaml - hasura-cli metadata apply + hasura-cli metadata apply $HASURA_GRAPHQL_DISALLOW_INCONSISTENT_METADATA else log "migrations-apply" "directory $HASURA_GRAPHQL_METADATA_DIR does not exist, skipping metadata" fi