From 41da7f69a9b370f7e6491733fb45e9265f55923c Mon Sep 17 00:00:00 2001 From: rafaelatc3sl <rpd17@c3sl> Date: Tue, 16 Oct 2018 10:10:57 -0300 Subject: [PATCH] Issue #89: Add blendb demonstration with postgres Signed-off-by: rafaelatc3sl <rpd17@c3sl> --- .dockerignore | 3 +- .gitlab-ci.yml | 4 +- config/config.env.example | 4 +- config/config.yaml.example | 88 +++++++++++++++++++++++++++++++------- docker-compose.yml | 54 +++++++++++------------ package.json | 3 +- scripts/loadTest.ts | 39 +++++++++++++++++ 7 files changed, 146 insertions(+), 49 deletions(-) create mode 100644 scripts/loadTest.ts diff --git a/.dockerignore b/.dockerignore index 5178bb88..45808294 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,6 @@ /artwork -/config +/config/*.yaml +!/config/*.example /coverage /database /doc diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a8939b05..d517822f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,7 +11,7 @@ variables: POSTGRES_USER: 'runner' POSTGRES_PASSWORD: '' MONETDB_NAME: 'blendb_fixture' - PKG_VERSION: 'latest' + PKG_VERSION: '1.0-alpha' DOCKER_URL: 'dockerregistry.c3sl.ufpr.br:5000/c3sl/blendb:' cache: @@ -69,5 +69,5 @@ deploy: - docker - build only: - - master + - develop diff --git a/config/config.env.example b/config/config.env.example index 16b7a86b..5d330011 100644 --- a/config/config.env.example +++ b/config/config.env.example @@ -1,8 +1,8 @@ -BLENDB_DB_USER=blendb BLENDB_DB_NAME=blendb-test +BLENDB_DB_USER=blendb BLENDB_DB_PASSWORD=secret BLENDB_DB_HOST=localhost BLENDB_DB_PORT=5432 BLENDB_ADAPTER=postgres -BLENDB_SCHEMA_FILE=config/config.yaml +BLENDB_SCHEMA_FILE=config/config.yaml.example PORT=3000 diff --git a/config/config.yaml.example b/config/config.yaml.example index f97ea97d..eed9cb2b 100644 --- a/config/config.yaml.example +++ b/config/config.yaml.example @@ -1,15 +1,73 @@ -connection: - user: 'blendb' - database: 'blendb-test' - password: 'secret' - host: 'localhost' - port: 5432 - max: 10 - idleTimeoutMillis: 30000 -struct: - create: false - insert: false -schema: - views: - metrics: - dimensions: +# gitignore ignores files.yaml in this folder +# however a config file for tests in CI is required +# so this example file in fact is the CI test file +views: + links: + - config/market_views.yaml.example + obj: + - + alias: "Seller" + data: "test/postgres/fixtures/seller.json" + origin: true + dimensions: + - "dim:seller:name" + - "dim:seller:sex" + - "dim:seller:cpf" + - "dim:seller:id" + - "dim:seller:status" + metrics: + - "met:seller:avg:age" + - "met:seller:max:age" + - "met:seller:min:age" + - "met:seller:count:age" +metrics: + links: + - config/market_metrics.yaml.example + obj: + - + name: "met:seller:avg:age" + dataType: "float" + aggregation: "avg" + description: "The seller average age" +dimensions: + links: + - config/market_dimensions.yaml.example + obj: + - + name: "dim:seller:name" + dataType: "string" + description: "Name of the seller from market" +enumTypes: + links: + - config/market_enum.yaml.example + obj: + - [] +sources: + links: + - config/market_sources.yaml.example + obj: + - + name: "Seller" + description: "Market worker" + fields: + - + name: "name" + description: "Seller name" + dataType: "string" + - + name: "age" + description: "Seller age" + dataType: "integer" + - + name: "sex" + description: "Seller sex" + enumType: "enumsex" + dataType: "enumtype" + - + name: "CPF" + description: "Seller CPF" + dataType: "string" + - + name: "id" + description: "Seller id" + dataType: "integer" diff --git a/docker-compose.yml b/docker-compose.yml index d2faa322..2bc93dd4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,39 +1,37 @@ version: '3.3' services: + blendb-postgres: + image: postgres:10 + container_name: postgres + environment: + POSTGRES_PASSWORD: passwd + PGDATA: /var/lib/postgresql/docker/pgdata + ports: + - 5432:5432 + restart: unless-stopped + security_opt: + - no-new-privileges blendb: image: marula.c3sl.ufpr.br:5000/c3sl/blendb:latest build: . container_name: blendb -# depends_on: -# - db environment: - BLENDB_DB_USER: ${BLENDB_DB_USER} - BLENDB_DB_PASSWORD: ${BLENDB_DB_PASSWORD} - BLENDB_DB_NAME: ${BLENDB_DB_NAME} - BLENDB_DB_HOST: ${BLENDB_DB_HOST} - BLENDB_DB_PORT: ${BLENDB_DB_PORT} - BLENDB_ST_CREATE: ${BLENDB_ST_CREATE} - BLENDB_ST_INSERT: ${BLENDB_ST_INSERT} - BLENDB_ADAPTER: ${BLENDB_ADAPTER} - volumes: - - - type: bind - source: ./config - target: /home/node/app/config - - - type: tmpfs - target: /tmp + BLENDB_DB_USER: postgres + BLENDB_DB_PASSWORD: passwd + BLENDB_DB_NAME: postgres + BLENDB_DB_HOST: postgres + BLENDB_DB_PORT: 5432 + BLENDB_ADAPTER: postgres + BLENDB_SCHEMA_FILE: config/config.yaml.example + PORT: 3000 + ports: + - 3000:3000 + command: ["yarn","test-mode"] restart: unless-stopped read_only: 'true' security_opt: - no-new-privileges - -# db: -# image: postgres:9.6 -# container_name: db -# ports: -# - "5432" -# restart: unless-stopped -# #read_only: 'true' -# security_opt: -# - no-new-privileges + volumes: + - + type: tmpfs + target: /tmp diff --git a/package.json b/package.json index 4e1f0b91..06d65825 100644 --- a/package.json +++ b/package.json @@ -4,13 +4,14 @@ "description": "BlenDB", "main": "index.js", "scripts": { - "start": "env $(cat config/config.env) node index", + "start": "env $(cat config/config.env ) node index", "lint": "tslint -s node_modules/tslint-stylish -t stylish src/**/*.ts test/**/*.ts", "test": "env $(cat config/test.env) ts-node node_modules/istanbul/lib/cli.js cover -x \"**/*.spec.ts\" -e .ts _mocha", "show-coverage": "xdg-open coverage/lcov-report/index.html", "doc-api": "raml2html -i specs/blendb-api-v1.raml -o doc/api-v1-reference.html", "schema": "env $(cat config/config.env ) ts-node scripts/schema.ts config/config.yaml schema.sql", "service": "./scripts/service.sh", + "test-mode": "ts-node scripts/loadTest.ts && node index", "doc-code": "typedoc --mode 'file' --module 'commonjs' --target 'ES6' --ignoreCompilerErrors --exclude '**/*.spec.ts' --out 'doc/code' 'src'" }, "repository": { diff --git a/scripts/loadTest.ts b/scripts/loadTest.ts new file mode 100644 index 00000000..dfef421c --- /dev/null +++ b/scripts/loadTest.ts @@ -0,0 +1,39 @@ +#!/usr/bin/env node + +/* + * Copyright (C) 2018 Centro de Computacao Cientifica e Software Livre + * Departamento de Informatica - Universidade Federal do Parana + * + * This file is part of blendb. + * + * blendb is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * blendb is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with blendb. If not, see <http://www.gnu.org/licenses/>. + */ + + +import { Fixture as FixPostgres } from "../test/postgres/fixture"; +import { ConfigParser } from "../src/util/configParser"; + +let config: any; +let fixture; + +const configPath = process.env.BLENDB_SCHEMA_FILE; +config = ConfigParser.parse(configPath); + +fixture = new FixPostgres(config.connection); + +fixture.load(config.loadViews, (err) => { + if (err) { + throw err; + } +}) -- GitLab