这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .circleci/cli-migrations-builder.dockerfile
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/
86 changes: 61 additions & 25 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
name: Install Docker Compose
command: |
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 extension cli
working_directory: cli-ext
name: Build cli-migrations image
working_directory: scripts/cli-migrations
command: |
npm install -g pkg
npm run build
make deploy
make ci-copy-assets
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:
Expand Down Expand Up @@ -531,7 +562,7 @@ jobs:

workflows:
version: 2
workflow_v20200120:
workflow_v20200414:
jobs:
- check_build_worthiness: *filter_only_vtags
- test_and_build_cli_ext:
Expand Down Expand Up @@ -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:
Expand All @@ -610,4 +645,5 @@ workflows:
requires:
- build_image
- test_console
- test_and_build_cli_migrations
- all_server_tests_pass
11 changes: 4 additions & 7 deletions .circleci/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down
2 changes: 1 addition & 1 deletion cli/build/builder.dockerfile
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
40 changes: 40 additions & 0 deletions scripts/cli-migrations/Makefile
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
19 changes: 19 additions & 0 deletions scripts/cli-migrations/v1/test/docker-compose.yaml
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
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
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
5 changes: 5 additions & 0 deletions scripts/cli-migrations/v1/test/migrations/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: 2
tables:
- table:
schema: public
name: test
30 changes: 30 additions & 0 deletions scripts/cli-migrations/v1/test/test.sh
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
11 changes: 11 additions & 0 deletions scripts/cli-migrations/v1/test/validation/metadata.json
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 scripts/cli-migrations/v1/test/validation/schema_migrations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"result_type": "TuplesOk",
"result": [
[
"version",
"dirty"
],
[
"1586822388261",
"f"
]
]
}
2 changes: 1 addition & 1 deletion scripts/cli-migrations/v2/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions scripts/cli-migrations/v2/test/docker-compose.yaml
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
1 change: 1 addition & 0 deletions scripts/cli-migrations/v2/test/metadata/actions.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

6 changes: 6 additions & 0 deletions scripts/cli-migrations/v2/test/metadata/actions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
actions: []
custom_types:
enums: []
input_objects: []
objects: []
scalars: []
1 change: 1 addition & 0 deletions scripts/cli-migrations/v2/test/metadata/allow_list.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
1 change: 1 addition & 0 deletions scripts/cli-migrations/v2/test/metadata/functions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
3 changes: 3 additions & 0 deletions scripts/cli-migrations/v2/test/metadata/tables.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- table:
schema: public
name: test
1 change: 1 addition & 0 deletions scripts/cli-migrations/v2/test/metadata/version.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version: 2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE "public"."test";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE "public"."test"("id" serial NOT NULL, PRIMARY KEY ("id") );
Loading