From 9b7495c4aed4e14e9bdbff88eecf7b2dd6b510e1 Mon Sep 17 00:00:00 2001 From: Vishnu Bharathi Date: Tue, 14 Dec 2021 20:20:25 +0530 Subject: [PATCH] ci: add build and test job for arm64 oss cli migrations PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3128 GitOrigin-RevId: a8ab8fc8e022166e27fcc68199311b1626930759 --- scripts/cli-migrations/Makefile | 27 ------------------- scripts/cli-migrations/v2/Dockerfile | 4 +-- scripts/cli-migrations/v2/build.sh | 20 -------------- .../v2/test/docker-compose.yaml | 3 ++- scripts/cli-migrations/v2/test/test.sh | 19 ++++++++++--- scripts/cli-migrations/v3/Dockerfile | 2 +- scripts/cli-migrations/v3/build.sh | 20 -------------- .../v3/test/docker-compose.yaml | 3 ++- scripts/cli-migrations/v3/test/test.sh | 16 ++++++++--- 9 files changed, 36 insertions(+), 78 deletions(-) delete mode 100755 scripts/cli-migrations/v2/build.sh delete mode 100755 scripts/cli-migrations/v3/build.sh diff --git a/scripts/cli-migrations/Makefile b/scripts/cli-migrations/Makefile index a43170acc68..0737b37e2d3 100644 --- a/scripts/cli-migrations/Makefile +++ b/scripts/cli-migrations/Makefile @@ -8,30 +8,6 @@ CLI_BUILD_OUTPUT := $(BUILD_DIR)/_cli_output SHELL := /bin/bash .SHELLFLAGS := -ce -.PHONY: build-cli-migrations-v2 -.ONESHELL: -build-cli-migrations-v2: - cd v2 - ./build.sh $(SERVER_BUILD_OUTPUT) $(CLI_BUILD_OUTPUT) $(BUILD_OUTPUT) - -.PHONY: test-cli-migrations-v2 -.ONESHELL: -test-cli-migrations-v2: - cd v2/test - ./test.sh - -.PHONY: build-cli-migrations-v3 -.ONESHELL: -build-cli-migrations-v3: - cd v3 - ./build.sh $(SERVER_BUILD_OUTPUT) $(CLI_BUILD_OUTPUT) $(BUILD_OUTPUT) - -.PHONY: test-cli-migrations-v3 -.ONESHELL: -test-cli-migrations-v3: - cd v3/test - ./test.sh - .ONESHELL: prepare-local-env: # works on *nix systems @@ -48,6 +24,3 @@ prepare-local-env: cd $$MAKEFILE_DIR && sed -i 's/BUILD_DIR ?= \/build/BUILD_DIR ?= \/tmp\/build/' Makefile reset-local-env: sed -i 's/BUILD_DIR ?= \/tmp\/build/BUILD_DIR ?= \/build/' Makefile - -.PHONY: all -all: build-cli-migrations-v2 test-cli-migrations-v2 build-cli-migrations-v3 test-cli-migrations-v3 diff --git a/scripts/cli-migrations/v2/Dockerfile b/scripts/cli-migrations/v2/Dockerfile index 58244eb47cd..fe4db1c4314 100644 --- a/scripts/cli-migrations/v2/Dockerfile +++ b/scripts/cli-migrations/v2/Dockerfile @@ -9,9 +9,9 @@ RUN apt-get update && apt-get install -y netcat ENV HASURA_GRAPHQL_SHOW_UPDATE_NOTIFICATION=false COPY docker-entrypoint.sh /bin/ -COPY cli-hasura-linux-amd64 /bin/hasura-cli +COPY hasura-cli /bin/hasura-cli -RUN chmod +x /bin/hasura-cli +RUN chmod +x /bin/hasura-cli # set an env var to let the cli know that # it is running in server environment diff --git a/scripts/cli-migrations/v2/build.sh b/scripts/cli-migrations/v2/build.sh deleted file mode 100755 index 619ecdfc1ad..00000000000 --- a/scripts/cli-migrations/v2/build.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash - -set -evo pipefail - -SERVER_BUILD_OUTPUT="$1" -CLI_BUILD_OUTPUT="$2" -BUILD_OUTPUT="$3" -CLI_MIGRATIONS_IMAGE="cli-migrations-v2" - -SERVER_IMAGE=$(docker load -i "${SERVER_BUILD_OUTPUT}/image.tar" | grep "^Loaded image: " | sed "s/Loaded image: //g") -SERVER_IMAGE_TAG=$(echo "$SERVER_IMAGE" | sed "s/.*:\(.*\)$/\1/") - -echo "SERVER_IMAGE is ${SERVER_IMAGE}" -echo "SERVER_IMAGE_TAG is ${SERVER_IMAGE_TAG}" - -BINARY=${CLI_BUILD_OUTPUT}/binaries/cli-hasura-linux-amd64 -cp ${BINARY} . - -docker build -t "${CLI_MIGRATIONS_IMAGE}" . --build-arg SERVER_IMAGE_TAG=$SERVER_IMAGE_TAG -docker save -o "${BUILD_OUTPUT}/v2.tar" "${CLI_MIGRATIONS_IMAGE}" \ No newline at end of file diff --git a/scripts/cli-migrations/v2/test/docker-compose.yaml b/scripts/cli-migrations/v2/test/docker-compose.yaml index ca2ba3f45dd..9b793d38c05 100644 --- a/scripts/cli-migrations/v2/test/docker-compose.yaml +++ b/scripts/cli-migrations/v2/test/docker-compose.yaml @@ -7,7 +7,8 @@ services: POSTGRES_PASSWORD: postgrespassword graphql-engine: container_name: graphql-engine - image: cli-migrations-v2 + image: ${TEST_IMAGE_NAME} + platform: ${TEST_PLATFORM} ports: - "8080:8080" depends_on: diff --git a/scripts/cli-migrations/v2/test/test.sh b/scripts/cli-migrations/v2/test/test.sh index a3479558fdd..a4a903785ef 100755 --- a/scripts/cli-migrations/v2/test/test.sh +++ b/scripts/cli-migrations/v2/test/test.sh @@ -4,11 +4,24 @@ set -evo pipefail IFS=$'\n\t' ROOT="$(readlink -f ${BASH_SOURCE[0]%/*}/../../)" +echo "TEST_IMAGE_NAME = $TEST_IMAGE_NAME" +echo "TEST_PLATFORM = $TEST_PLATFORM" + +if [[ -z "$TEST_IMAGE_NAME" ]]; then + echo "please set TEST_IMAGE_NAME env to be a non-empty value and retry." + exit 1 +fi + +if [[ -z "$TEST_PLATFORM" ]]; then + echo "please set TEST_PLATFORM env to be a non-empty value and retry." + exit 1 +fi + wait_for_server() { echo "waiting for server" for _ in $(seq 1 60); do - docker run --network container:graphql-engine appropriate/curl http://127.0.0.1:8080/v1/version && return + docker run --rm --network container:graphql-engine curlimages/curl http://127.0.0.1:8080/v1/version && return echo -n . sleep 1 done @@ -25,8 +38,8 @@ docker cp metadata/. graphql-engine:/hasura-metadata docker-compose up -d --no-recreate graphql-engine wait_for_server # export metadata and run diff with validation/metadata.json -docker run --network container:graphql-engine appropriate/curl -s -f -d'{"type" : "export_metadata", "args" : {} }' localhost:8080/v1/query | jq -j '.' | diff validation/metadata.json - +docker run --network container:graphql-engine curlimages/curl -s -f -d'{"type" : "export_metadata", "args" : {} }' localhost:8080/v1/query | jq -j '.' | diff validation/metadata.json - # get list of migrations applied from graphql-engine server -docker run --network container:graphql-engine appropriate/curl -s -f -d'{"type" : "run_sql", "args" : {"sql": "select * from hdb_catalog.schema_migrations"} }' localhost:8080/v1/query | jq -j '.' | diff validation/schema_migrations.json - +docker run --network container:graphql-engine curlimages/curl -s -f -d'{"type" : "run_sql", "args" : {"sql": "select * from hdb_catalog.schema_migrations"} }' localhost:8080/v1/query | jq -j '.' | diff validation/schema_migrations.json - # delete postgres and graphql-engine docker-compose down -v \ No newline at end of file diff --git a/scripts/cli-migrations/v3/Dockerfile b/scripts/cli-migrations/v3/Dockerfile index 58244eb47cd..d659a8960c9 100644 --- a/scripts/cli-migrations/v3/Dockerfile +++ b/scripts/cli-migrations/v3/Dockerfile @@ -9,7 +9,7 @@ RUN apt-get update && apt-get install -y netcat ENV HASURA_GRAPHQL_SHOW_UPDATE_NOTIFICATION=false COPY docker-entrypoint.sh /bin/ -COPY cli-hasura-linux-amd64 /bin/hasura-cli +COPY hasura-cli /bin/hasura-cli RUN chmod +x /bin/hasura-cli diff --git a/scripts/cli-migrations/v3/build.sh b/scripts/cli-migrations/v3/build.sh deleted file mode 100755 index 5172699a282..00000000000 --- a/scripts/cli-migrations/v3/build.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash - -set -evo pipefail - -SERVER_BUILD_OUTPUT="$1" -CLI_BUILD_OUTPUT="$2" -BUILD_OUTPUT="$3" -CLI_MIGRATIONS_IMAGE="cli-migrations-v3" - -SERVER_IMAGE=$(docker load -i "${SERVER_BUILD_OUTPUT}/image.tar" | grep "^Loaded image: " | sed "s/Loaded image: //g") -SERVER_IMAGE_TAG=$(echo "$SERVER_IMAGE" | sed "s/.*:\(.*\)$/\1/") - -echo "SERVER_IMAGE is ${SERVER_IMAGE}" -echo "SERVER_IMAGE_TAG is ${SERVER_IMAGE_TAG}" - -BINARY=${CLI_BUILD_OUTPUT}/binaries/cli-hasura-linux-amd64 -cp ${BINARY} . - -docker build -t "${CLI_MIGRATIONS_IMAGE}" . --build-arg SERVER_IMAGE_TAG=$SERVER_IMAGE_TAG -docker save -o "${BUILD_OUTPUT}/v3.tar" "${CLI_MIGRATIONS_IMAGE}" \ No newline at end of file diff --git a/scripts/cli-migrations/v3/test/docker-compose.yaml b/scripts/cli-migrations/v3/test/docker-compose.yaml index 96f362ddda1..9b793d38c05 100644 --- a/scripts/cli-migrations/v3/test/docker-compose.yaml +++ b/scripts/cli-migrations/v3/test/docker-compose.yaml @@ -7,7 +7,8 @@ services: POSTGRES_PASSWORD: postgrespassword graphql-engine: container_name: graphql-engine - image: cli-migrations-v3 + image: ${TEST_IMAGE_NAME} + platform: ${TEST_PLATFORM} ports: - "8080:8080" depends_on: diff --git a/scripts/cli-migrations/v3/test/test.sh b/scripts/cli-migrations/v3/test/test.sh index 9d5d0758eed..f111e4bbc73 100755 --- a/scripts/cli-migrations/v3/test/test.sh +++ b/scripts/cli-migrations/v3/test/test.sh @@ -4,11 +4,21 @@ set -evo pipefail IFS=$'\n\t' ROOT="$(readlink -f ${BASH_SOURCE[0]%/*}/../../)" +if [[ -z "$TEST_IMAGE_NAME" ]]; then + echo "please set TEST_IMAGE_NAME env to be a non-empty value and retry." + exit 1 +fi + +if [[ -z "$TEST_PLATFORM" ]]; then + echo "please set TEST_PLATFORM env to be a non-empty value and retry." + exit 1 +fi + wait_for_server() { echo "waiting for server" for _ in $(seq 1 60); do - docker run --network container:graphql-engine appropriate/curl http://127.0.0.1:8080/v1/version && return + docker run --rm --network container:graphql-engine curlimages/curl http://127.0.0.1:8080/v1/version && return echo -n . sleep 1 done @@ -25,8 +35,8 @@ docker cp metadata/. graphql-engine:/hasura-metadata docker-compose up -d --no-recreate graphql-engine wait_for_server # export metadata and run diff with validation/metadata.json -docker run --network container:graphql-engine appropriate/curl -s -f -d'{"type" : "export_metadata", "args" : {} }' localhost:8080/v1/metadata | jq -j '.' | diff validation/metadata.json - +docker run --network container:graphql-engine curlimages/curl -s -f -d'{"type" : "export_metadata", "args" : {} }' localhost:8080/v1/metadata | jq -j '.' | diff validation/metadata.json - # get list of migrations applied from graphql-engine server -docker run --network container:graphql-engine appropriate/curl -s -f -d'{"type" : "get_catalog_state", "args" : {} }' localhost:8080/v1/metadata | jq .cli_state | diff validation/catalog_cli_state.json - +docker run --network container:graphql-engine curlimages/curl -s -f -d'{"type" : "get_catalog_state", "args" : {} }' localhost:8080/v1/metadata | jq .cli_state | diff validation/catalog_cli_state.json - # delete postgres and graphql-engine docker-compose down -v \ No newline at end of file