From 5feb115f627befbcf41df3247392e05e0c0e6646 Mon Sep 17 00:00:00 2001 From: Piotr Biernat Date: Thu, 5 Dec 2024 16:57:56 +0100 Subject: [PATCH] Update --- .app.config | 12 +++++++++++- .env.dist | 2 +- Dockerfile.builder | 5 +++-- Dockerfile.target | 1 + bin/entrypoint.sh | 15 ++++++++++----- deploy/image-build.sh | 2 +- deploy/image-push.sh | 2 +- src/cmd/health/main.go | 2 +- src/cmd/server/main.go | 2 +- src/go.mod | 2 +- src/go.sum | 4 ++-- src/internal/app/plugins.go | 13 +++++++------ src/internal/server/config.go | 2 +- src/internal/server/middleware.go | 10 ++++------ src/internal/server/server.go | 2 +- src/internal/worker/worker.go | 6 +++--- 16 files changed, 49 insertions(+), 33 deletions(-) diff --git a/.app.config b/.app.config index 1380275..d0c5239 100644 --- a/.app.config +++ b/.app.config @@ -5,10 +5,20 @@ "Tags": ["catalog-svc", "catalog", "https", "service"], "Port": 443, "Connect": { - "Native": true + "Native": true, + "SidecarService": { + "Port": 20000, + "Check": { + "Name": "Connect Envoy Sidecar", + "TCP": "127.0.0.1:20000", + "Interval": "5s" + } + } }, "Check": { "TCP": "__IP__:443", + "Interval": "5s", + "Timeout": "1s", "DeregisterCriticalServiceAfter": "10s" } } \ No newline at end of file diff --git a/.env.dist b/.env.dist index 24c4ecb..a4d1a98 100644 --- a/.env.dist +++ b/.env.dist @@ -7,7 +7,7 @@ APP_PATH_PREFIX=/catalog APP_KV_NAMESPACE=dev.egommerce/service/catalog-svc LOGGER_ADDR=api-logger:24224 -REGISTRY_ADDR=api-registry:8500 +REGISTRY_ADDR=api-registry:8501 DATABASE_URL=postgres://postgres:12345678@postgres-db:5432/egommerce CACHE_ADDR=api-cache:6379 CACHE_PASSWORD=12345678 diff --git a/Dockerfile.builder b/Dockerfile.builder index 9524430..1ff34d4 100644 --- a/Dockerfile.builder +++ b/Dockerfile.builder @@ -1,14 +1,15 @@ # Builder FROM golang:alpine +WORKDIR /go/src/app +COPY src ./ + ARG BIN_OUTPUT=/go/bin ARG GO_SERVER=cmd/server/main.go ARG GO_MIGRATE=cmd/migrate/main.go ARG GO_WORKER=cmd/worker/main.go ARG GO_HEALTH=cmd/health/main.go -WORKDIR /go/src/app -COPY src ./ RUN export CGO_ENABLED=0 ; export GOOS=linux ; export GOARCH=amd64 && \ go build -ldflags="-w -s" -o "$BIN_OUTPUT/server" $GO_SERVER && \ diff --git a/Dockerfile.target b/Dockerfile.target index 1f0475d..e6a5ba3 100644 --- a/Dockerfile.target +++ b/Dockerfile.target @@ -27,6 +27,7 @@ COPY ./bin /bin RUN chmod 755 /bin/entrypoint.sh /bin/migrate.sh RUN apk add curl +# is required / ^^ EXPOSE 443 diff --git a/bin/entrypoint.sh b/bin/entrypoint.sh index 24728ae..c7c25d6 100755 --- a/bin/entrypoint.sh +++ b/bin/entrypoint.sh @@ -14,13 +14,18 @@ waitForService() done } -update-resolv # provided by stack - better approach - single copy +update-resolv update-ca-certificates -waitForService "postgres-db:5432" -waitForService "api-eventbus:5672" -waitForService "api-logger:24224" -waitForService "api-registry:8500" +waitForService "api-registry:8501" +waitForService "esb.service.ego.io:5672" +waitForService "logger.service.ego.io:24224" +waitForService "postgresdb.service.ego.io:5432" +# waitForService "api-eventbus:5672" +# waitForService "api-logger:24224" +# waitForService "db-postgres:5432" + +register-service # run migrations migrate.sh diff --git a/deploy/image-build.sh b/deploy/image-build.sh index 8637335..ff6cb3d 100755 --- a/deploy/image-build.sh +++ b/deploy/image-build.sh @@ -1,7 +1,7 @@ #!/bin/sh # RUN IN REPO ROOT DIR !! -export IMAGE_PREFIX="git.pbiernat.io/egommerce/catalog" +export IMAGE_PREFIX="git.ego.cloudns.be/egommerce/catalog" export BUILDER_IMAGE="egommerce-builder:catalog" export BUILD_TIME=$(date +"%Y%m%d%H%M%S") export SERVER_IMAGE="$IMAGE_PREFIX-svc" diff --git a/deploy/image-push.sh b/deploy/image-push.sh index d1a32cd..3774875 100755 --- a/deploy/image-push.sh +++ b/deploy/image-push.sh @@ -1,7 +1,7 @@ #!/bin/sh # RUN IN REPO ROOT DIR !! -export IMAGE_BASE="git.pbiernat.io/egommerce/catalog" +export IMAGE_BASE="git.ego.cloudns.be/egommerce/catalog" export SERVER_IMAGE="$IMAGE_BASE-svc" export WORKER_IMAGE="$IMAGE_BASE-worker" diff --git a/src/cmd/health/main.go b/src/cmd/health/main.go index c27f125..4c4420e 100644 --- a/src/cmd/health/main.go +++ b/src/cmd/health/main.go @@ -29,7 +29,7 @@ func main() { } func healthCheck() bool { - run, err := os.Open("/app.run") + run, err := os.Open("./app.run") if err != nil { return false } diff --git a/src/cmd/server/main.go b/src/cmd/server/main.go index 9c87bf8..4f6b53e 100644 --- a/src/cmd/server/main.go +++ b/src/cmd/server/main.go @@ -25,7 +25,7 @@ func main() { a.RegisterPlugin(app.CachePlugin(cArr)) a.RegisterPlugin(app.DatabasePlugin(cArr)) a.RegisterPlugin(app.EventbusPlugin(cArr)) - a.RegisterPlugin(app.RegistryPlugin(cArr)) + // a.RegisterPlugin(app.RegistryPlugin(cArr)) while := make(chan struct{}) err := a.Start(while) diff --git a/src/go.mod b/src/go.mod index 9da9103..d1193a5 100644 --- a/src/go.mod +++ b/src/go.mod @@ -4,7 +4,7 @@ go 1.18 require ( git.pbiernat.io/egommerce/api-entities v0.2.3 - git.pbiernat.io/egommerce/go-api-pkg v0.3.18 + git.pbiernat.io/egommerce/go-api-pkg v0.3.28 github.com/georgysavva/scany/v2 v2.0.0 github.com/go-pg/migrations/v8 v8.1.0 github.com/go-pg/pg/v10 v10.11.1 diff --git a/src/go.sum b/src/go.sum index 829d9e7..1cd5814 100644 --- a/src/go.sum +++ b/src/go.sum @@ -37,8 +37,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9 dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= git.pbiernat.io/egommerce/api-entities v0.2.3 h1:mR6EYfZkAzh4teydb7KXDBWoxwVW3qasnmmH5J3mnas= git.pbiernat.io/egommerce/api-entities v0.2.3/go.mod h1:INXAG5x4+i+vNwg1NpfPHiDW8nY1kn1K7pgLOtX+/I0= -git.pbiernat.io/egommerce/go-api-pkg v0.3.18 h1:0+C9BMsllrNvRbh4kb7dJ5lrzP1Lc7J4pb+KV76YrXk= -git.pbiernat.io/egommerce/go-api-pkg v0.3.18/go.mod h1:XIy2mmvRNIzQmYIUAcDZafhRPxTQFS2HDmsK7ZQ6980= +git.pbiernat.io/egommerce/go-api-pkg v0.3.28 h1:PiqwprMSJxtK/nLUiidfBQUHz2n6XIpWZysWNfby4kw= +git.pbiernat.io/egommerce/go-api-pkg v0.3.28/go.mod h1:XIy2mmvRNIzQmYIUAcDZafhRPxTQFS2HDmsK7ZQ6980= github.com/Azure/azure-sdk-for-go v44.0.0+incompatible h1:e82Yv2HNpS0kuyeCrV29OPKvEiqfs2/uJHic3/3iKdg= github.com/Azure/go-autorest v14.2.0+incompatible h1:V5VMDjClD3GiElqLWO7mz2MxNAK/vTfRHdAubSIPRgs= github.com/Azure/go-autorest/autorest v0.11.18 h1:90Y4srNYrwOtAgVo3ndrQkTYn6kf1Eg/AjTFJ8Is2aM= diff --git a/src/internal/app/plugins.go b/src/internal/app/plugins.go index d3c3e2c..9fe3c45 100644 --- a/src/internal/app/plugins.go +++ b/src/internal/app/plugins.go @@ -1,6 +1,7 @@ package app import ( + "fmt" "log" "os" "strconv" @@ -104,6 +105,12 @@ func RegistryPlugin(cArr map[string]string) Plugin { os.Exit(1) // TODO: retry in background... } + svc, _ := registry.Connect() + tlsCnf := svc.ServerTLSConfig() + // s.Base.App.Server().TLSConfig = tlsCnf + fmt.Println("Podmiana configa TLS", tlsCnf) + // defer svc.Close() + err = registry.Register() if err != nil { log.Fatalf("Failed to register in the Consul service. Err: %v", err) @@ -115,12 +122,6 @@ func RegistryPlugin(cArr map[string]string) Plugin { return registry - // svc, _ := registry.Connect() - // tlsCnf := svc.ServerTLSConfig() - // s.Base.App.Server().TLSConfig = tlsCnf - // fmt.Println("Podmiana configa TLS") - // defer svc.Close() - // go func() { // Consul KV updater // ticker := time.NewTicker(time.Second * 15) // for range ticker.C { diff --git a/src/internal/server/config.go b/src/internal/server/config.go index f8e927b..f1d5c9c 100644 --- a/src/internal/server/config.go +++ b/src/internal/server/config.go @@ -21,7 +21,7 @@ const ( defNetAddr = ":443" defMongoDbURL = "mongodb://mongodb:12345678@mongo-db:27017" defPathPrefix = "/catalog" - defRegistryAddr = "api-registry:8500" + defRegistryAddr = "api-registry:8501" defEbEventsExchange = "api-events" defEbEventsQueue = "catalog-svc" ) diff --git a/src/internal/server/middleware.go b/src/internal/server/middleware.go index 32328d9..8c7a36c 100644 --- a/src/internal/server/middleware.go +++ b/src/internal/server/middleware.go @@ -1,8 +1,6 @@ package server import ( - "strings" - "github.com/gofiber/fiber/v2" "git.pbiernat.io/egommerce/go-api-pkg/fluentd" @@ -17,10 +15,10 @@ func SetupMiddleware(s *Server) { func LoggingMiddleware(log *fluentd.Logger) func(c *fiber.Ctx) error { return func(c *fiber.Ctx) error { - path := string(c.Request().URI().Path()) - if strings.Contains(path, "/health") { - return c.Next() - } + // path := string(c.Request().URI().Path()) + // if strings.Contains(path, "/health") { + // return c.Next() + // } log.Log("Request: %s, remote: %s, via: %s", c.Request().URI().String(), diff --git a/src/internal/server/server.go b/src/internal/server/server.go index 3e5d21a..b9cbaf4 100644 --- a/src/internal/server/server.go +++ b/src/internal/server/server.go @@ -69,7 +69,7 @@ func (s *Server) RegisterHandler(name string, fn func() any) { func (s *Server) OnShutdown() { // s.GetLogger().Log("Server %s is going down...", s.ID) - s.GetRegistry().Unregister() + // s.GetRegistry().Unregister() // a.clearMetadataCache() s.GetEventBus().Close() s.GetDatabase().Close() diff --git a/src/internal/worker/worker.go b/src/internal/worker/worker.go index c1dc946..8a647b3 100644 --- a/src/internal/worker/worker.go +++ b/src/internal/worker/worker.go @@ -89,7 +89,7 @@ func (w *Worker) GetCache() *redis.Client { return (w.handlers["cache"]).(*redis.Client) } -func (w *Worker) GetDatabase() *pgxpool.Pool { // FIXME hardcoded index issue +func (w *Worker) GetDatabase() *pgxpool.Pool { return (w.handlers["database"]).(*pgxpool.Pool) } @@ -158,8 +158,8 @@ func (w *Worker) processMsg(cSrv *service.CatalogService, d amqp.Delivery) { w.GetLogger().Log("Event: %s", event.EVENT_WAREHOUSE_STOCK_UPDATED) } - rnr := NewCommandRunner(data, cSrv) - ok, _ = rnr.run(data) + r := NewCommandRunner(data, cSrv) + ok, _ = r.run(data) if ok { w.GetLogger().Log("Successful executed message \"%s\"\n", name) fmt.Printf("Successful executed message \"%s\"\n", name)