From 6042f81c35c845365209d710b9c56620c4906996 Mon Sep 17 00:00:00 2001 From: Piotr Biernat Date: Sun, 25 Dec 2022 23:21:27 +0100 Subject: [PATCH] update --- .../001_create_identity_svc_db.sql | 9 -- .../0001_create_base_tables.down.sql | 2 + .../basket-svc/0001_create_base_tables.up.sql | 34 +++++++ .../0002_add_price_to_basket_item.down.sql | 2 + .../0002_add_price_to_basket_item.up.sql | 2 + .../0001_create_base_tables.down.sql | 1 + .../0001_create_base_tables.up.sql | 16 ++++ .../0001_create_base_tables.down.sql | 1 + .../0001_create_base_tables.up.sql | 12 +++ .../0001_create_base_tables.down.sql | 2 + .../order-svc/0001_create_base_tables.up.sql | 34 +++++++ deploy/egommerce-stack.dev.yml | 38 ++++++-- deploy/egommerce-stack.yml | 93 ++++++++++++++++--- deploy/etc/consul/server.json | 14 --- 14 files changed, 219 insertions(+), 41 deletions(-) delete mode 100644 deploy/db_migrations/001_create_identity_svc_db.sql create mode 100644 deploy/db_migrations/basket-svc/0001_create_base_tables.down.sql create mode 100644 deploy/db_migrations/basket-svc/0001_create_base_tables.up.sql create mode 100644 deploy/db_migrations/basket-svc/0002_add_price_to_basket_item.down.sql create mode 100644 deploy/db_migrations/basket-svc/0002_add_price_to_basket_item.up.sql create mode 100644 deploy/db_migrations/catalog-svc/0001_create_base_tables.down.sql create mode 100644 deploy/db_migrations/catalog-svc/0001_create_base_tables.up.sql create mode 100644 deploy/db_migrations/identity-svc/0001_create_base_tables.down.sql create mode 100644 deploy/db_migrations/identity-svc/0001_create_base_tables.up.sql create mode 100644 deploy/db_migrations/order-svc/0001_create_base_tables.down.sql create mode 100644 deploy/db_migrations/order-svc/0001_create_base_tables.up.sql delete mode 100644 deploy/etc/consul/server.json diff --git a/deploy/db_migrations/001_create_identity_svc_db.sql b/deploy/db_migrations/001_create_identity_svc_db.sql deleted file mode 100644 index 7e244e1..0000000 --- a/deploy/db_migrations/001_create_identity_svc_db.sql +++ /dev/null @@ -1,9 +0,0 @@ --- TODO: Add variables for db, user name, etc... - -CREATE DATABASE svc_identity - WITH - OWNER = postgres - ENCODING = 'UTF8' - CONNECTION LIMIT = -1; - -GRANT ALL ON DATABASE svc_identity TO postgres; diff --git a/deploy/db_migrations/basket-svc/0001_create_base_tables.down.sql b/deploy/db_migrations/basket-svc/0001_create_base_tables.down.sql new file mode 100644 index 0000000..e57c530 --- /dev/null +++ b/deploy/db_migrations/basket-svc/0001_create_base_tables.down.sql @@ -0,0 +1,2 @@ +DROP TABLE IF EXISTS basket.basket_item; +DROP TABLE IF EXISTS basket.basket; diff --git a/deploy/db_migrations/basket-svc/0001_create_base_tables.up.sql b/deploy/db_migrations/basket-svc/0001_create_base_tables.up.sql new file mode 100644 index 0000000..fa67c45 --- /dev/null +++ b/deploy/db_migrations/basket-svc/0001_create_base_tables.up.sql @@ -0,0 +1,34 @@ +CREATE TABLE IF NOT EXISTS basket.basket +( + id uuid NOT NULL DEFAULT gen_random_uuid(), + state character varying NOT NULL DEFAULT 'new', + created_at timestamp without time zone NOT NULL DEFAULT now(), + updated_at timestamp without time zone, + PRIMARY KEY (id) +); + +CREATE TABLE IF NOT EXISTS basket.basket_item +( + id uuid NOT NULL DEFAULT gen_random_uuid(), + basket_id uuid NOT NULL, + product_id integer NOT NULL, + quantity integer NOT NULL DEFAULT 1, + price double precision NOT NULL DEFAULT 0.00; + created_at timestamp without time zone NOT NULL DEFAULT now(), + updated_at timestamp without time zone, + PRIMARY KEY (id) +); + +ALTER TABLE IF EXISTS basket.basket_item + ADD CONSTRAINT basket_item_basket_fkey FOREIGN KEY (basket_id) + REFERENCES basket.basket (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION + NOT VALID; + +ALTER TABLE IF EXISTS basket.basket + OWNER to postgres; + +ALTER TABLE IF EXISTS basket.basket_item + OWNER to postgres; +-- TODO ^^ PRIVILEGES... \ No newline at end of file diff --git a/deploy/db_migrations/basket-svc/0002_add_price_to_basket_item.down.sql b/deploy/db_migrations/basket-svc/0002_add_price_to_basket_item.down.sql new file mode 100644 index 0000000..0bcc200 --- /dev/null +++ b/deploy/db_migrations/basket-svc/0002_add_price_to_basket_item.down.sql @@ -0,0 +1,2 @@ +ALTER TABLE IF EXISTS basket.basket_item + DROP COLUMN price; diff --git a/deploy/db_migrations/basket-svc/0002_add_price_to_basket_item.up.sql b/deploy/db_migrations/basket-svc/0002_add_price_to_basket_item.up.sql new file mode 100644 index 0000000..5404308 --- /dev/null +++ b/deploy/db_migrations/basket-svc/0002_add_price_to_basket_item.up.sql @@ -0,0 +1,2 @@ +ALTER TABLE IF EXISTS basket.basket_item + ADD COLUMN price double precision NOT NULL DEFAULT 0.00; diff --git a/deploy/db_migrations/catalog-svc/0001_create_base_tables.down.sql b/deploy/db_migrations/catalog-svc/0001_create_base_tables.down.sql new file mode 100644 index 0000000..585c219 --- /dev/null +++ b/deploy/db_migrations/catalog-svc/0001_create_base_tables.down.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS catalog.product; diff --git a/deploy/db_migrations/catalog-svc/0001_create_base_tables.up.sql b/deploy/db_migrations/catalog-svc/0001_create_base_tables.up.sql new file mode 100644 index 0000000..527b381 --- /dev/null +++ b/deploy/db_migrations/catalog-svc/0001_create_base_tables.up.sql @@ -0,0 +1,16 @@ +CREATE TABLE catalog.product +( + id integer NOT NULL GENERATED ALWAYS AS IDENTITY, + pid character varying NOT NULL, + name character varying NOT NULL, + price double precision NOT NULL, + created_at timestamp without time zone NOT NULL DEFAULT now(), + updated_at timestamp without time zone, + PRIMARY KEY (id) +); + +ALTER TABLE IF EXISTS catalog.product + OWNER to postgres; + +COMMENT ON COLUMN catalog.product.pid + IS 'Unique product ID. EAN, UPC etc...'; diff --git a/deploy/db_migrations/identity-svc/0001_create_base_tables.down.sql b/deploy/db_migrations/identity-svc/0001_create_base_tables.down.sql new file mode 100644 index 0000000..65cad10 --- /dev/null +++ b/deploy/db_migrations/identity-svc/0001_create_base_tables.down.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS identity.users; \ No newline at end of file diff --git a/deploy/db_migrations/identity-svc/0001_create_base_tables.up.sql b/deploy/db_migrations/identity-svc/0001_create_base_tables.up.sql new file mode 100644 index 0000000..38491e2 --- /dev/null +++ b/deploy/db_migrations/identity-svc/0001_create_base_tables.up.sql @@ -0,0 +1,12 @@ +CREATE TABLE IF NOT EXISTS identity.users +( + id uuid NOT NULL DEFAULT gen_random_uuid(), + username character varying NOT NULL, + email character varying NOT NULL, + created_at timestamp without time zone NOT NULL DEFAULT now(), + updated_at timestamp without time zone, + PRIMARY KEY (id) +); + +ALTER TABLE IF EXISTS identity.users + OWNER to postgres; diff --git a/deploy/db_migrations/order-svc/0001_create_base_tables.down.sql b/deploy/db_migrations/order-svc/0001_create_base_tables.down.sql new file mode 100644 index 0000000..c08f787 --- /dev/null +++ b/deploy/db_migrations/order-svc/0001_create_base_tables.down.sql @@ -0,0 +1,2 @@ +DROP TABLE IF EXISTS ordering.order_item; +DROP TABLE IF EXISTS ordering."order"; diff --git a/deploy/db_migrations/order-svc/0001_create_base_tables.up.sql b/deploy/db_migrations/order-svc/0001_create_base_tables.up.sql new file mode 100644 index 0000000..5c58d0d --- /dev/null +++ b/deploy/db_migrations/order-svc/0001_create_base_tables.up.sql @@ -0,0 +1,34 @@ +CREATE TABLE IF NOT EXISTS ordering."order" +( + id uuid NOT NULL DEFAULT gen_random_uuid(), + state character varying NOT NULL DEFAULT 'new', + created_at timestamp without time zone NOT NULL DEFAULT now(), + updated_at timestamp without time zone, + PRIMARY KEY (id) +); + +CREATE TABLE IF NOT EXISTS ordering.order_item +( + id uuid NOT NULL DEFAULT gen_random_uuid(), + order_id uuid NOT NULL, + product_id integer NOT NULL, + quantity integer NOT NULL DEFAULT 1, + price double precision NOT NULL DEFAULT 0.00; + created_at timestamp without time zone NOT NULL DEFAULT now(), + updated_at timestamp without time zone, + PRIMARY KEY (id) +); + +ALTER TABLE IF EXISTS ordering.order_item + ADD CONSTRAINT order_item_order_fkey FOREIGN KEY (order_id) + REFERENCES "ordering"."order" (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION + NOT VALID; + +ALTER TABLE IF EXISTS "ordering"."order" + OWNER to postgres; + +ALTER TABLE IF EXISTS "ordering".order_item + OWNER to postgres; +-- TODO ^^ PRIVILEGES... \ No newline at end of file diff --git a/deploy/egommerce-stack.dev.yml b/deploy/egommerce-stack.dev.yml index 355a1a6..aae9b19 100644 --- a/deploy/egommerce-stack.dev.yml +++ b/deploy/egommerce-stack.dev.yml @@ -15,7 +15,6 @@ services: # - "traefik.http.routers.api-gateway-api.rule=PathPrefix(`/api`)" # - "traefik.http.routers.api-gateway-api.service=api@internal" # - "traefik.http.routers.api-gateway-api.middlewares=PathPrefix(`/`)" - # - "traefik.http.routers.api-gateway.tls=true" # - "traefik.http.routers.api-gateway.rule=Headers(`X-API-SERVICE`, `admin-gateway`)" # - "traefik.http.routers.api-gateway.tls=true" # - "traefik.http.routers.api-gateway.entryPoints=https" @@ -32,6 +31,7 @@ services: hostname: registry.egommerce.pbiernat.dev environment: - APP_DOMAIN=registry.egommerce.pbiernat.dev + - CONSUL_HTTP_TOKEN=devop # labels: # - "traefik.enable=true" # - "traefik.http.routers.api-registry.rule=PathPrefix(`/admin/registry`)" @@ -73,6 +73,11 @@ services: # volumes: # - ./certs/api-gateway:/certs + api-cache: + image: git.pbiernat.dev/egommerce/api-cache:dev + environment: + - PASSWORD=12345678 + api-logger: image: git.pbiernat.dev/egommerce/api-logger:dev hostname: logger.egommerce.pbiernat.dev @@ -132,6 +137,16 @@ services: volumes: - ./certs/api-gateway:/certs + pricing-svc: + image: git.pbiernat.dev/egommerce/pricing-svc:dev + environment: + - APP_DOMAIN=pricing.api.egommerce.pbiernat.dev + - DATABASE_URL=postgres://postgres:12345678@db.egommerce.pbiernat.dev:5432/egommerce + - MONGODB_URL=mongodb://mongodb:12345678@mongodb.egommerce.pbiernat.dev:27017 + - EVENTBUS_URL=amqp://guest:guest@eventbus.egommerce.pbiernat.dev:5672 + volumes: + - ./certs/api-gateway:/certs + order-svc: image: git.pbiernat.dev/egommerce/order-svc:dev environment: @@ -145,8 +160,8 @@ services: # Workers (EventBus) basket-worker: image: git.pbiernat.dev/egommerce/basket-worker:dev - deploy: - replicas: 2 + # deploy: + # replicas: 2 environment: - DATABASE_URL=postgres://postgres:12345678@db.egommerce.pbiernat.dev:5432/egommerce - MONGODB_URL=mongodb://mongodb:12345678@mongodb.egommerce.pbiernat.dev:27017 @@ -154,8 +169,17 @@ services: catalog-worker: image: git.pbiernat.dev/egommerce/catalog-worker:dev - deploy: - replicas: 2 + # deploy: + # replicas: 2 + environment: + - DATABASE_URL=postgres://postgres:12345678@db.egommerce.pbiernat.dev:5432/egommerce + - MONGODB_URL=mongodb://mongodb:12345678@mongodb.egommerce.pbiernat.dev:27017 + - EVENTBUS_URL=amqp://guest:guest@eventbus.egommerce.pbiernat.dev:5672 + + pricing-worker: + image: git.pbiernat.dev/egommerce/pricing-worker:dev + # deploy: + # replicas: 2 environment: - DATABASE_URL=postgres://postgres:12345678@db.egommerce.pbiernat.dev:5432/egommerce - MONGODB_URL=mongodb://mongodb:12345678@mongodb.egommerce.pbiernat.dev:27017 @@ -163,8 +187,8 @@ services: order-worker: image: git.pbiernat.dev/egommerce/order-worker:dev - deploy: - replicas: 2 + # deploy: + # replicas: 2 environment: - DATABASE_URL=postgres://postgres:12345678@db.egommerce.pbiernat.dev:5432/egommerce - MONGODB_URL=mongodb://mongodb:12345678@mongodb.egommerce.pbiernat.dev:27017 diff --git a/deploy/egommerce-stack.yml b/deploy/egommerce-stack.yml index aa474e5..bbef035 100644 --- a/deploy/egommerce-stack.yml +++ b/deploy/egommerce-stack.yml @@ -12,10 +12,6 @@ services: networks: - api-gateway-network # - api-logger-network # TODO - - identity-svc-network - - basket-svc-network - - catalog-svc-network - - order-svc-network volumes: - /var/run/docker.sock:/var/run/docker.sock @@ -24,19 +20,13 @@ services: environment: - APP_NAME=api-registry - APP_DOMAIN + - CONSUL_HTTP_TOKEN=VeryS3cr3tTok3N volumes: - registry_data:/consul/data networks: - api-registry-network # - api-logger-network # TODO - api-gateway-network - - identity-svc-network - - basket-svc-network - - catalog-svc-network - - order-svc-network - - basket-worker-network - - catalog-worker-network - - order-worker-network api-eventbus: image: git.pbiernat.dev/egommerce/api-eventbus:latest @@ -57,6 +47,14 @@ services: - api-eventbus-network - api-registry-network - api-logger-network + + api-cache: + image: git.pbiernat.dev/egommerce/api-cache:latest + environment: + - APP_NAME=api-cache + networks: + - api-cache-network + - api-logger-network api-logger: image: git.pbiernat.dev/egommerce/api-logger:latest @@ -107,13 +105,18 @@ services: image: git.pbiernat.dev/egommerce/identity-svc:latest environment: - APP_NAME=identity-svc + - APP_PATH_PREFIX=/identity - APP_DOMAIN - APP_KV_NAMESPACE - DATABASE_URL - MONGODB_URL - EVENTBUS_URL + volumes: + - ./db_migrations/identity-svc:/migrations networks: - identity-svc-network + - api-gateway-network + - api-registry-network - api-eventbus-network - api-logger-network - postgres-db-network @@ -123,13 +126,18 @@ services: image: git.pbiernat.dev/egommerce/basket-svc:latest environment: - APP_NAME=basket-svc + - APP_PATH_PREFIX=/basket - APP_DOMAIN - APP_KV_NAMESPACE - DATABASE_URL - MONGODB_URL - EVENTBUS_URL + volumes: + - ./db_migrations/basket-svc:/migrations networks: - basket-svc-network + - api-gateway-network + - api-registry-network - api-eventbus-network - api-logger-network - postgres-db-network @@ -139,13 +147,39 @@ services: image: git.pbiernat.dev/egommerce/catalog-svc:latest environment: - APP_NAME=catalog-svc + - APP_PATH_PREFIX=/catalog - APP_DOMAIN - APP_KV_NAMESPACE - DATABASE_URL - MONGODB_URL - EVENTBUS_URL + volumes: + - ./db_migrations/catalog-svc:/migrations networks: - catalog-svc-network + - api-gateway-network + - api-registry-network + - api-eventbus-network + - api-logger-network + - postgres-db-network + - mongodb-db-network + + pricing-svc: + image: git.pbiernat.dev/egommerce/pricing-svc:latest + environment: + - APP_NAME=pricing-svc + - APP_PATH_PREFIX=/pricing + - APP_DOMAIN + - APP_KV_NAMESPACE + - DATABASE_URL + - MONGODB_URL + - EVENTBUS_URL + volumes: + - ./db_migrations/pricing-svc:/migrations + networks: + - pricing-svc-network + - api-gateway-network + - api-registry-network - api-eventbus-network - api-logger-network - postgres-db-network @@ -155,13 +189,18 @@ services: image: git.pbiernat.dev/egommerce/order-svc:latest environment: - APP_NAME=order-svc + - APP_PATH_PREFIX=/order - APP_DOMAIN - APP_KV_NAMESPACE - DATABASE_URL - MONGODB_URL - EVENTBUS_URL + volumes: + - ./db_migrations/order-svc:/migrations networks: - order-svc-network + - api-gateway-network + - api-registry-network - api-eventbus-network - api-logger-network - postgres-db-network @@ -178,6 +217,8 @@ services: - EVENTBUS_URL networks: - basket-worker-network + - pricing-svc-network + - api-registry-network - api-eventbus-network - api-logger-network - postgres-db-network @@ -192,6 +233,22 @@ services: - EVENTBUS_URL networks: - catalog-worker-network + - api-registry-network + - api-eventbus-network + - api-logger-network + - postgres-db-network + - mongodb-db-network + + pricing-worker: + image: git.pbiernat.dev/egommerce/pricing-worker:latest + environment: + - APP_NAME=pricing-worker + - DATABASE_URL + - MONGODB_URL + - EVENTBUS_URL + networks: + - pricing-worker-network + - api-registry-network - api-eventbus-network - api-logger-network - postgres-db-network @@ -206,6 +263,8 @@ services: - EVENTBUS_URL networks: - order-worker-network + - basket-svc-network + - api-registry-network - api-eventbus-network - api-logger-network - postgres-db-network @@ -231,6 +290,10 @@ networks: driver: overlay internal: true + api-cache-network: + driver: overlay + internal: true + api-logger-network: driver: overlay internal: true @@ -256,6 +319,10 @@ networks: driver: overlay internal: true + pricing-svc-network: + driver: overlay + internal: true + order-svc-network: driver: overlay internal: true @@ -273,6 +340,10 @@ networks: driver: overlay internal: true + pricing-worker-network: + driver: overlay + internal: true + order-worker-network: driver: overlay internal: true diff --git a/deploy/etc/consul/server.json b/deploy/etc/consul/server.json deleted file mode 100644 index ba08340..0000000 --- a/deploy/etc/consul/server.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "node_name": "api-registry", - "server": true, - "bootstrap" : true, - "ui_config": { - "enabled" : true - }, - "data_dir": "/consul/data", - "addresses": { - "http" : "0.0.0.0" - }, - "bind_addr": "0.0.0.0", - "advertise_addr": "127.0.0.1" -} \ No newline at end of file