mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-10-05 14:28:08 +03:00
ci: add tests for cli-migrations image (#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
This commit is contained in:
parent
21a4dff993
commit
1ada6627b0
15
.circleci/cli-migrations-builder.dockerfile
Normal file
15
.circleci/cli-migrations-builder.dockerfile
Normal file
@ -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/
|
@ -312,6 +312,46 @@ jobs:
|
||||
path: /build/_cli_output
|
||||
destination: cli
|
||||
|
||||
# test and build cli extension
|
||||
test_and_build_cli_ext:
|
||||
docker:
|
||||
- image: hasura/graphql-engine-extension-cli-builder:20200225
|
||||
working_directory: ~/graphql-engine
|
||||
steps:
|
||||
- attach_workspace:
|
||||
at: /build
|
||||
- *skip_job_on_ciignore
|
||||
- checkout
|
||||
- restore_cache:
|
||||
key:
|
||||
cli-ext-npm-cache-v2-{{ checksum "cli-ext/package.json" }}-{{ checksum "cli-ext/package-lock.json" }}
|
||||
- run:
|
||||
name: install dependencies
|
||||
working_directory: cli-ext
|
||||
command: make ci-deps
|
||||
- save_cache:
|
||||
key:
|
||||
cli-ext-npm-cache-v2-{{ checksum "cli-ext/package.json" }}-{{ checksum "cli-ext/package-lock.json" }}
|
||||
paths:
|
||||
- cli-ext/node_modules
|
||||
- ~/.npm
|
||||
- ~/.cache
|
||||
- run:
|
||||
name: build extension cli
|
||||
working_directory: cli-ext
|
||||
command: |
|
||||
npm install -g pkg
|
||||
npm run build
|
||||
make deploy
|
||||
make ci-copy-assets
|
||||
- store_artifacts:
|
||||
path: /build/_cli_ext_output
|
||||
destination: cli_ext
|
||||
- persist_to_workspace:
|
||||
root: /build
|
||||
paths:
|
||||
- _cli_ext_output
|
||||
|
||||
# test and build cli
|
||||
test_and_build_cli:
|
||||
docker:
|
||||
@ -356,44 +396,35 @@ jobs:
|
||||
paths:
|
||||
- _cli_output
|
||||
|
||||
test_and_build_cli_ext:
|
||||
test_and_build_cli_migrations:
|
||||
docker:
|
||||
- image: hasura/graphql-engine-extension-cli-builder:20200225
|
||||
- image: hasura/graphql-engine-cli-migrations-builder:20200415
|
||||
working_directory: ~/graphql-engine
|
||||
steps:
|
||||
- attach_workspace:
|
||||
at: /build
|
||||
- *skip_job_on_ciignore
|
||||
- checkout
|
||||
- restore_cache:
|
||||
key:
|
||||
cli-ext-npm-cache-v2-{{ checksum "cli-ext/package.json" }}-{{ checksum "cli-ext/package-lock.json" }}
|
||||
- *setup_remote_docker
|
||||
- run:
|
||||
name: install dependencies
|
||||
working_directory: cli-ext
|
||||
command: make ci-deps
|
||||
- save_cache:
|
||||
key:
|
||||
cli-ext-npm-cache-v2-{{ checksum "cli-ext/package.json" }}-{{ checksum "cli-ext/package-lock.json" }}
|
||||
paths:
|
||||
- cli-ext/node_modules
|
||||
- ~/.npm
|
||||
- ~/.cache
|
||||
- run:
|
||||
name: build extension cli
|
||||
working_directory: cli-ext
|
||||
name: Install Docker Compose
|
||||
command: |
|
||||
npm install -g pkg
|
||||
npm run build
|
||||
make deploy
|
||||
make ci-copy-assets
|
||||
set -x
|
||||
curl -L https://github.com/docker/compose/releases/download/1.25.3/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
|
||||
chmod +x /usr/local/bin/docker-compose
|
||||
- run:
|
||||
name: Build cli-migrations image
|
||||
working_directory: scripts/cli-migrations
|
||||
command: |
|
||||
mkdir -p /build/_cli_migrations_output
|
||||
make all
|
||||
- store_artifacts:
|
||||
path: /build/_cli_ext_output
|
||||
destination: cli_ext
|
||||
path: /build/_cli_migrations_output
|
||||
destination: cli-migrations
|
||||
- persist_to_workspace:
|
||||
root: /build
|
||||
paths:
|
||||
- _cli_ext_output
|
||||
- _cli_migrations_output
|
||||
|
||||
# build console assets
|
||||
build_console:
|
||||
@ -531,7 +562,7 @@ jobs:
|
||||
|
||||
workflows:
|
||||
version: 2
|
||||
workflow_v20200120:
|
||||
workflow_v20200414:
|
||||
jobs:
|
||||
- check_build_worthiness: *filter_only_vtags
|
||||
- test_and_build_cli_ext:
|
||||
@ -599,6 +630,10 @@ workflows:
|
||||
requires:
|
||||
- test_and_build_cli_ext
|
||||
- build_server
|
||||
- test_and_build_cli_migrations:
|
||||
<<: *filter_only_vtags
|
||||
requires:
|
||||
- test_and_build_cli
|
||||
- test_console:
|
||||
<<: *filter_only_vtags
|
||||
requires:
|
||||
@ -610,4 +645,5 @@ workflows:
|
||||
requires:
|
||||
- build_image
|
||||
- test_console
|
||||
- test_and_build_cli_migrations
|
||||
- all_server_tests_pass
|
||||
|
@ -136,19 +136,16 @@ deploy_cli_ext() {
|
||||
# build and push container for auto-migrations
|
||||
build_and_push_cli_migrations_image_v1() {
|
||||
IMAGE_TAG="hasura/graphql-engine:${CIRCLE_TAG}.cli-migrations"
|
||||
cd "$ROOT/scripts/cli-migrations/v1"
|
||||
cp /build/_cli_output/binaries/cli-hasura-linux-amd64 .
|
||||
docker build -t "$IMAGE_TAG" .
|
||||
docker load -i /build/_cli_migrations_output/v1.tar
|
||||
docker tag cli-migrations "$IMAGE_TAG"
|
||||
docker push "$IMAGE_TAG"
|
||||
}
|
||||
|
||||
# build and push container for auto-migrations-v2
|
||||
build_and_push_cli_migrations_image_v2() {
|
||||
IMAGE_TAG="hasura/graphql-engine:${CIRCLE_TAG}.cli-migrations-v2"
|
||||
cd "$ROOT/scripts/cli-migrations/v2"
|
||||
cp /build/_cli_output/binaries/cli-hasura-linux-amd64 .
|
||||
cp /build/_cli_ext_output/manifest-dev.yaml manifest.yaml
|
||||
docker build -t "$IMAGE_TAG" .
|
||||
docker load -i /build/_cli_migrations_output/v2.tar
|
||||
docker tag cli-migrations-v2 "$IMAGE_TAG"
|
||||
docker push "$IMAGE_TAG"
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
40
scripts/cli-migrations/Makefile
Normal file
40
scripts/cli-migrations/Makefile
Normal file
@ -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
|
19
scripts/cli-migrations/v1/test/docker-compose.yaml
Normal file
19
scripts/cli-migrations/v1/test/docker-compose.yaml
Normal file
@ -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
|
@ -0,0 +1,5 @@
|
||||
- args:
|
||||
cascade: false
|
||||
read_only: false
|
||||
sql: DROP TABLE "public"."test";
|
||||
type: run_sql
|
@ -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
|
5
scripts/cli-migrations/v1/test/migrations/metadata.yaml
Normal file
5
scripts/cli-migrations/v1/test/migrations/metadata.yaml
Normal file
@ -0,0 +1,5 @@
|
||||
version: 2
|
||||
tables:
|
||||
- table:
|
||||
schema: public
|
||||
name: test
|
30
scripts/cli-migrations/v1/test/test.sh
Executable file
30
scripts/cli-migrations/v1/test/test.sh
Executable file
@ -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
|
11
scripts/cli-migrations/v1/test/validation/metadata.json
Normal file
11
scripts/cli-migrations/v1/test/validation/metadata.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"version": 2,
|
||||
"tables": [
|
||||
{
|
||||
"table": {
|
||||
"schema": "public",
|
||||
"name": "test"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
{
|
||||
"result_type": "TuplesOk",
|
||||
"result": [
|
||||
[
|
||||
"version",
|
||||
"dirty"
|
||||
],
|
||||
[
|
||||
"1586822388261",
|
||||
"f"
|
||||
]
|
||||
]
|
||||
}
|
@ -4,7 +4,7 @@ RUN apt-get update && apt-get download libstdc++6
|
||||
|
||||
FROM hasura/graphql-engine:v1.1.1
|
||||
|
||||
# install libstdc++6
|
||||
# install libstdc++6 from .deb file
|
||||
COPY --from=packager /tmp/libstdc++6* .
|
||||
RUN busybox dpkg-deb -x libstdc++6*.deb / \
|
||||
&& rm libstdc++6*.deb
|
||||
|
19
scripts/cli-migrations/v2/test/docker-compose.yaml
Normal file
19
scripts/cli-migrations/v2/test/docker-compose.yaml
Normal file
@ -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
|
1
scripts/cli-migrations/v2/test/metadata/actions.graphql
Normal file
1
scripts/cli-migrations/v2/test/metadata/actions.graphql
Normal file
@ -0,0 +1 @@
|
||||
|
6
scripts/cli-migrations/v2/test/metadata/actions.yaml
Normal file
6
scripts/cli-migrations/v2/test/metadata/actions.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
actions: []
|
||||
custom_types:
|
||||
enums: []
|
||||
input_objects: []
|
||||
objects: []
|
||||
scalars: []
|
1
scripts/cli-migrations/v2/test/metadata/allow_list.yaml
Normal file
1
scripts/cli-migrations/v2/test/metadata/allow_list.yaml
Normal file
@ -0,0 +1 @@
|
||||
[]
|
1
scripts/cli-migrations/v2/test/metadata/functions.yaml
Normal file
1
scripts/cli-migrations/v2/test/metadata/functions.yaml
Normal file
@ -0,0 +1 @@
|
||||
[]
|
@ -0,0 +1 @@
|
||||
[]
|
@ -0,0 +1 @@
|
||||
[]
|
3
scripts/cli-migrations/v2/test/metadata/tables.yaml
Normal file
3
scripts/cli-migrations/v2/test/metadata/tables.yaml
Normal file
@ -0,0 +1,3 @@
|
||||
- table:
|
||||
schema: public
|
||||
name: test
|
1
scripts/cli-migrations/v2/test/metadata/version.yaml
Normal file
1
scripts/cli-migrations/v2/test/metadata/version.yaml
Normal file
@ -0,0 +1 @@
|
||||
version: 2
|
@ -0,0 +1 @@
|
||||
DROP TABLE "public"."test";
|
@ -0,0 +1 @@
|
||||
CREATE TABLE "public"."test"("id" serial NOT NULL, PRIMARY KEY ("id") );
|
32
scripts/cli-migrations/v2/test/test.sh
Executable file
32
scripts/cli-migrations/v2/test/test.sh
Executable file
@ -0,0 +1,32 @@
|
||||
#!/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
|
||||
# copy metadata directory to /hasura-metadata
|
||||
docker cp metadata/. graphql-engine:/hasura-metadata
|
||||
# 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
|
11
scripts/cli-migrations/v2/test/validation/metadata.json
Normal file
11
scripts/cli-migrations/v2/test/validation/metadata.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"version": 2,
|
||||
"tables": [
|
||||
{
|
||||
"table": {
|
||||
"schema": "public",
|
||||
"name": "test"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
{
|
||||
"result_type": "TuplesOk",
|
||||
"result": [
|
||||
[
|
||||
"version",
|
||||
"dirty"
|
||||
],
|
||||
[
|
||||
"1586823136625",
|
||||
"f"
|
||||
]
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user