forked from hasura/graphql-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: add tests for cli-migrations image (hasura#4396)
- Created new job test_and_build_cli_migrations which runs after test_and_build_cli - Build the cli-migrations and cli-migrations-v2 and save the images as tar image. - Run the test defined in each workflow v1 and v2. - Load the image that was built earlier in deploy step
- Loading branch information
1 parent
21a4dff
commit 1ada662
Showing
27 changed files
with
306 additions
and
34 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
FROM ubuntu:16.04 | ||
|
||
ARG docker_ver="17.09.0-ce" | ||
|
||
RUN apt-get -y update \ | ||
&& apt-get install -y curl make xz-utils git python jq \ | ||
&& curl -Lo /tmp/docker-${docker_ver}.tgz https://download.docker.com/linux/static/stable/x86_64/docker-${docker_ver}.tgz \ | ||
&& tar -xz -C /tmp -f /tmp/docker-${docker_ver}.tgz \ | ||
&& mv /tmp/docker/* /usr/bin \ | ||
&& apt-get -y auto-remove \ | ||
&& apt-get -y clean \ | ||
&& rm -rf /var/lib/apt/lists/* \ | ||
&& rm -rf /usr/share/doc/ \ | ||
&& rm -rf /usr/share/man/ \ | ||
&& rm -rf /usr/share/locale/ |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM golang:1.10 | ||
FROM golang:1.13 | ||
|
||
# setup the working directory | ||
WORKDIR /go/src/github.com/hasura/graphql-engine/cli |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
PWD := $(shell pwd) | ||
PARENT_DIR := $(shell dirname $(PWD)) | ||
VERSION ?= $(shell ../get-version.sh) | ||
BUILD_DIR ?= /build | ||
BINARY ?= $(BUILD_DIR)/_cli_output/binaries/cli-hasura-linux-amd64 | ||
IMAGE_TAG ?= cli-migrations | ||
BUILD_OUTPUT ?= $(BUILD_DIR)/_cli_migrations_output | ||
CLI_EXT_MANIFEST_FILE ?= $(BUILD_DIR)/_cli_ext_output/manifest-dev.yaml | ||
|
||
.PHONY: build-cli-migrations-v1 | ||
.ONESHELL: | ||
build-cli-migrations-v1: | ||
cd v1 | ||
cp ${BINARY} . | ||
docker build -t ${IMAGE_TAG} . | ||
docker save -o '$(BUILD_OUTPUT)/v1.tar' '$(IMAGE_TAG)' | ||
|
||
.PHONY: test-cli-migrations-v1 | ||
.ONESHELL: | ||
test-cli-migrations-v1: | ||
cd v1/test | ||
./test.sh | ||
|
||
.PHONY: build-cli-migrations-v2 | ||
.ONESHELL: | ||
build-cli-migrations-v2: | ||
cd v2 | ||
cp ${BINARY} . | ||
cp ${CLI_EXT_MANIFEST_FILE} manifest.yaml | ||
docker build -t '${IMAGE_TAG}-v2' . | ||
docker save -o '$(BUILD_OUTPUT)/v2.tar' '$(IMAGE_TAG)-v2' | ||
|
||
.PHONY: test-cli-migrations-v2 | ||
.ONESHELL: | ||
test-cli-migrations-v2: | ||
cd v2/test | ||
./test.sh | ||
|
||
.PHONY: all | ||
all: build-cli-migrations-v1 build-cli-migrations-v2 test-cli-migrations-v1 test-cli-migrations-v2 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
version: '3.6' | ||
services: | ||
postgres: | ||
image: postgres:12 | ||
restart: always | ||
environment: | ||
POSTGRES_PASSWORD: postgrespassword | ||
graphql-engine: | ||
container_name: graphql-engine | ||
image: cli-migrations | ||
ports: | ||
- "8080:8080" | ||
depends_on: | ||
- "postgres" | ||
restart: always | ||
environment: | ||
HASURA_GRAPHQL_DATABASE_URL: postgres://postgres:postgrespassword@postgres:5432/postgres | ||
HASURA_GRAPHQL_ENABLE_CONSOLE: "true" # set to "false" to disable console | ||
HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log |
5 changes: 5 additions & 0 deletions
5
scripts/cli-migrations/v1/test/migrations/1586822388261_create_table_public_test/down.yaml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
- args: | ||
cascade: false | ||
read_only: false | ||
sql: DROP TABLE "public"."test"; | ||
type: run_sql |
9 changes: 9 additions & 0 deletions
9
scripts/cli-migrations/v1/test/migrations/1586822388261_create_table_public_test/up.yaml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
- args: | ||
cascade: false | ||
read_only: false | ||
sql: CREATE TABLE "public"."test"("id" serial NOT NULL, PRIMARY KEY ("id") ); | ||
type: run_sql | ||
- args: | ||
name: test | ||
schema: public | ||
type: add_existing_table_or_view |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
version: 2 | ||
tables: | ||
- table: | ||
schema: public | ||
name: test |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -evo pipefail | ||
IFS=$'\n\t' | ||
ROOT="$(readlink -f ${BASH_SOURCE[0]%/*}/../../)" | ||
|
||
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 | ||
echo -n . | ||
sleep 1 | ||
done | ||
echo "Failed waiting for server" && exit 1 | ||
} | ||
|
||
# start postgres | ||
docker-compose up --no-start graphql-engine | ||
# copy migrations directory to /hasura-migrations | ||
docker cp migrations/. graphql-engine:/hasura-migrations | ||
# start graphql-engine | ||
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 - | ||
# 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 - | ||
# delete postgres and graphql-engine | ||
docker-compose down -v |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"version": 2, | ||
"tables": [ | ||
{ | ||
"table": { | ||
"schema": "public", | ||
"name": "test" | ||
} | ||
} | ||
] | ||
} |
13 changes: 13 additions & 0 deletions
13
scripts/cli-migrations/v1/test/validation/schema_migrations.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"result_type": "TuplesOk", | ||
"result": [ | ||
[ | ||
"version", | ||
"dirty" | ||
], | ||
[ | ||
"1586822388261", | ||
"f" | ||
] | ||
] | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
version: '3.6' | ||
services: | ||
postgres: | ||
image: postgres:12 | ||
restart: always | ||
environment: | ||
POSTGRES_PASSWORD: postgrespassword | ||
graphql-engine: | ||
container_name: graphql-engine | ||
image: cli-migrations-v2 | ||
ports: | ||
- "8080:8080" | ||
depends_on: | ||
- "postgres" | ||
restart: always | ||
environment: | ||
HASURA_GRAPHQL_DATABASE_URL: postgres://postgres:postgrespassword@postgres:5432/postgres | ||
HASURA_GRAPHQL_ENABLE_CONSOLE: "true" # set to "false" to disable console | ||
HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
actions: [] | ||
custom_types: | ||
enums: [] | ||
input_objects: [] | ||
objects: [] | ||
scalars: [] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
- table: | ||
schema: public | ||
name: test |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
version: 2 |
1 change: 1 addition & 0 deletions
1
scripts/cli-migrations/v2/test/migrations/1586823136625_create_table_public_test/down.sql
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE "public"."test"; |
1 change: 1 addition & 0 deletions
1
scripts/cli-migrations/v2/test/migrations/1586823136625_create_table_public_test/up.sql
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CREATE TABLE "public"."test"("id" serial NOT NULL, PRIMARY KEY ("id") ); |
Oops, something went wrong.