From e9abfd52bfc36117a1345b74cde5c4821e55114a Mon Sep 17 00:00:00 2001 From: Kamil Samigullin Date: Wed, 24 Oct 2018 23:26:42 +0300 Subject: [PATCH] implement mvp, run smoke tests, update demo example --- README.md | 23 +++++++------ env/client/grpc/install.sh | 33 ++++++++++--------- env/client/grpc/license.update.yml | 4 +-- env/docker/compose/docker-compose.base.yml | 17 ++++++++++ env/docker/compose/docker-compose.ci.yml | 12 +------ env/docker/compose/docker-compose.demo.yml | 6 ---- env/docker/compose/docker-compose.dev.yml | 21 ------------ env/docker/server/context/conf.d/default.conf | 2 +- env/docker/service/Dockerfile | 8 ++--- 9 files changed, 54 insertions(+), 72 deletions(-) diff --git a/README.md b/README.md index c9a980d..4e63a77 100644 --- a/README.md +++ b/README.md @@ -25,18 +25,17 @@ Requirements: - GNU Make 3.81 or above ```bash -$ make demo up start-migration status - - Name Command State Ports ------------------------------------------------------------------------------------------------------------- -guard_db_1 docker-entrypoint.sh postgres Up 5432/tcp -guard_legacy_1 docker-php-entrypoint php-fpm Up 9000/tcp -guard_migration_1 service migrate Exit 0 -guard_server_1 nginx -g daemon off; Up 0.0.0.0:443->443/tcp, 0.0.0.0:80->80/tcp -guard_service_1 service run --with-profili ... Up 80/tcp, 8090/tcp, 8091/tcp, 8092/tcp, 8093/tcp -guard_spec_1 sh /usr/share/nginx/docker ... Up 80/tcp, 8080/tcp - -$ ./env/client/grpc/install.sh +$ make demo up clean status + + Name Command State Ports +----------------------------------------------------------------------------------------------------------- +guard_db_1 docker-entrypoint.sh postgres Up 5432/tcp +guard_legacy_1 docker-php-entrypoint php-fpm Up 9000/tcp +guard_server_1 nginx -g daemon off; Up 0.0.0.0:443->443/tcp, 0.0.0.0:80->80/tcp +guard_service_1 service run --with-profili ... Up 8080/tcp, 8090/tcp, 8091/tcp, 8092/tcp, 8093/tcp +guard_spec_1 sh /usr/share/nginx/docker ... Up 80/tcp, 8080/tcp + +$ ./env/client/grpc/install.sh localhost:443 $ open http://spec.127.0.0.1.xip.io/ diff --git a/env/client/grpc/install.sh b/env/client/grpc/install.sh index 51ab201..c3ad07d 100755 --- a/env/client/grpc/install.sh +++ b/env/client/grpc/install.sh @@ -2,23 +2,26 @@ set -euo pipefail -export GUARD_TOKEN=10000000-2000-4000-8000-160000000003 +HOST=${1:-127.0.0.1:8092} +GUARD_TOKEN=10000000-2000-4000-8000-160000000003 -guardctl install -f env/client/grpc/install.yml +guardctl install -f env/client/grpc/install.yml --grpc-host=${HOST} -guardctl license register -f env/client/grpc/license.register.yml -guardctl license update -f env/client/grpc/license.update.yml -guardctl license delete -f env/client/grpc/license.delete.yml -guardctl license restore -f env/client/grpc/license.restore.yml -guardctl license read -f env/client/grpc/license.read.yml +guardctl license register -f env/client/grpc/license.register.yml --grpc-host=${HOST} +guardctl license update -f env/client/grpc/license.update.yml --grpc-host=${HOST} +guardctl license delete -f env/client/grpc/license.delete.yml --grpc-host=${HOST} +guardctl license restore -f env/client/grpc/license.restore.yml --grpc-host=${HOST} +guardctl license read -f env/client/grpc/license.read.yml --grpc-host=${HOST} -guardctl license employee add -f env/client/grpc/license.employee.yml -guardctl license employee delete -f env/client/grpc/license.employee.yml +guardctl license employee add -f env/client/grpc/license.employee.yml --grpc-host=${HOST} +guardctl license employee delete -f env/client/grpc/license.employee.yml --grpc-host=${HOST} +guardctl license employee add -f env/client/grpc/license.employee.yml --grpc-host=${HOST} -guardctl license workplace add -f env/client/grpc/license.workplace.yml -guardctl license workplace push -f env/client/grpc/license.workplace.yml -guardctl license workplace delete -f env/client/grpc/license.workplace.yml +guardctl license workplace add -f env/client/grpc/license.workplace.yml --grpc-host=${HOST} +guardctl license workplace push -f env/client/grpc/license.workplace.yml --grpc-host=${HOST} +guardctl license workplace delete -f env/client/grpc/license.workplace.yml --grpc-host=${HOST} +guardctl license workplace add -f env/client/grpc/license.workplace.yml --grpc-host=${HOST} -guardctl license create -f env/client/grpc/license.create.yml | \ -guardctl license delete | \ -guardctl license read +guardctl license create -f env/client/grpc/license.create.yml --grpc-host=${HOST} | \ +guardctl license delete --grpc-host=${HOST} | \ +guardctl license read --grpc-host=${HOST} diff --git a/env/client/grpc/license.update.yml b/env/client/grpc/license.update.yml index 4db99d9..fbd2527 100644 --- a/env/client/grpc/license.update.yml +++ b/env/client/grpc/license.update.yml @@ -3,5 +3,5 @@ contract: since: 2018-09-29T17:11:43.264Z until: ~ rate: { value: 10, unit: rpd } - requests: 1000 - workplaces: 10 + requests: 5 + workplaces: 1 diff --git a/env/docker/compose/docker-compose.base.yml b/env/docker/compose/docker-compose.base.yml index f1f1465..49b6b78 100644 --- a/env/docker/compose/docker-compose.base.yml +++ b/env/docker/compose/docker-compose.base.yml @@ -4,14 +4,24 @@ services: db: image: guard-db:latest + build: + context: ../db/context + dockerfile: ../Dockerfile env_file: ../db/.env legacy: image: guard-legacy:latest + build: + context: ../legacy/context + dockerfile: ../Dockerfile env_file: ../legacy/.env migration: image: guard-service:latest + build: + args: { PACKAGE: "${PACKAGE}" } + context: ../../../. + dockerfile: ./env/docker/service/Dockerfile command: [ "migrate" ] depends_on: - db @@ -20,6 +30,10 @@ services: service: image: guard-service:latest + build: + args: { PACKAGE: "${PACKAGE}" } + context: ../../../. + dockerfile: ./env/docker/service/Dockerfile command: [ "run", "--with-profiling", "--with-monitoring", "--with-grpc-gateway" ] depends_on: - migration @@ -27,6 +41,9 @@ services: server: image: guard-server:latest + build: + context: ../server/context + dockerfile: ../Dockerfile depends_on: - legacy - service diff --git a/env/docker/compose/docker-compose.ci.yml b/env/docker/compose/docker-compose.ci.yml index b36c8c3..007d200 100644 --- a/env/docker/compose/docker-compose.ci.yml +++ b/env/docker/compose/docker-compose.ci.yml @@ -1,13 +1,3 @@ version: "3" -services: - - db: {} - - legacy: {} - - migration: {} - - service: {} - - server: {} +services: {} diff --git a/env/docker/compose/docker-compose.demo.yml b/env/docker/compose/docker-compose.demo.yml index 3e45a4a..3346a8b 100644 --- a/env/docker/compose/docker-compose.demo.yml +++ b/env/docker/compose/docker-compose.demo.yml @@ -6,12 +6,6 @@ services: volumes: - pgdata:${PGDATA} - legacy: {} - - migration: {} - - service: {} - server: depends_on: - spec diff --git a/env/docker/compose/docker-compose.dev.yml b/env/docker/compose/docker-compose.dev.yml index 46ee3af..7b8178d 100644 --- a/env/docker/compose/docker-compose.dev.yml +++ b/env/docker/compose/docker-compose.dev.yml @@ -3,30 +3,12 @@ version: "3" services: db: - build: - context: ../db/context - dockerfile: ../Dockerfile ports: - ${LOCAL_DB_PORT}:5432 volumes: - pgdata:${PGDATA} - legacy: - build: - context: ../legacy/context - dockerfile: ../Dockerfile - - migration: - build: - args: { PACKAGE: "${PACKAGE}" } - context: ../../../. - dockerfile: ./env/docker/service/Dockerfile - service: - build: - args: { PACKAGE: "${PACKAGE}" } - context: ../../../. - dockerfile: ./env/docker/service/Dockerfile ports: - ${LOCAL_SERVICE_HTTP_PORT}:8080 - ${LOCAL_SERVICE_PROFILING_PORT}:8090 @@ -35,9 +17,6 @@ services: - ${LOCAL_SERVICE_GRPC_GATEWAY_PORT}:8093 server: - build: - context: ../server/context - dockerfile: ../Dockerfile ports: - ${LOCAL_SERVER_HTTP_PORT}:80 - ${LOCAL_SERVER_HTTPS_PORT}:443 diff --git a/env/docker/server/context/conf.d/default.conf b/env/docker/server/context/conf.d/default.conf index e4135cf..b0a6924 100644 --- a/env/docker/server/context/conf.d/default.conf +++ b/env/docker/server/context/conf.d/default.conf @@ -61,7 +61,7 @@ server { # documentation # - https://www.nginx.com/blog/nginx-1-13-10-grpc/ # - https://nginx.org/en/docs/http/ngx_http_grpc_module.html - location /grpc { grpc_pass grpc://service_grpc; } + location /protobuf { grpc_pass grpc://service_grpc; } location /guard/api/ { rewrite ^/guard/api/(.*) /api/$1 break; diff --git a/env/docker/service/Dockerfile b/env/docker/service/Dockerfile index 22b31dc..75aca23 100644 --- a/env/docker/service/Dockerfile +++ b/env/docker/service/Dockerfile @@ -11,11 +11,11 @@ ENV GOARCH amd64 ENV CGO_ENABLED 0 RUN echo "os: ${GOOS}" "arch: ${GOARCH}" "cgo: ${CGO_ENABLED}" \ - && export _commit="-X ${PACKAGE}/cmd.commit=$(git rev-parse --short HEAD || echo 'none')" \ - && export _date="-X ${PACKAGE}/cmd.date=$(date -u +%FT%X%Z || echo 'unknown')" \ - && export _version="-X ${PACKAGE}/cmd.version=$(git describe --tags 2>&- || echo 'dev' | cut -d - -f 1)" \ + && export _commit="-X ${PACKAGE}/pkg/cmd.commit=$(git rev-parse --short HEAD || echo 'none')" \ + && export _date="-X ${PACKAGE}/pkg/cmd.date=$(date -u +%FT%X%Z || echo 'unknown')" \ + && export _version="-X ${PACKAGE}/pkg/cmd.version=$(git describe --tags 2>&- || echo 'dev' | cut -d - -f 1)" \ && go build -o /go/bin/service \ - -ldflags "-s -w ${_commit} ${_date} ${_version}" . + -ldflags "-s -w ${_commit} ${_date} ${_version}" ./cmd/guard FROM alpine:latest AS service