Skip to content

Commit

Permalink
Merged logs into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ishevche committed May 13, 2024
2 parents 091dfaa + 1ce7282 commit 523dc1b
Show file tree
Hide file tree
Showing 56 changed files with 741 additions and 52 deletions.
Empty file removed coffee-shops/models/__init__.py
Empty file.
113 changes: 76 additions & 37 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
pull_policy: build
build:
dockerfile: Consul.Dockerfile
context: ./consul
context: src/consul
ports:
- "8500:8500"
- "8600:8600/udp"
Expand All @@ -20,55 +20,55 @@ services:
auth:
pull_policy: build
build:
context: auth
context: src/auth
scale: 3
environment:
HZ_NETWORK_RESTAPI_ENABLED: true
HZ_CLUSTERNAME: auth_hazelcast
HZ_MAP: sessions
POSTGRES_ADDR: postgres
POSTGRES_ADDR: auth-db
GIN_MODE: release
CONSUL_ADDR: consul:8500
networks:
- kavuny-net
ports:
- "8000:8080"
depends_on:
consul:
condition: service_healthy

postgres:
auth-db:
image: postgres:latest
environment:
POSTGRES_USER: auth-service
POSTGRES_PASSWORD: pass
volumes:
- ./demo_data/create.sql:/docker-entrypoint-initdb.d/create.sql
- ./demo_data/users.csv:/opt/demo_data/users.csv
- ./src/demo_data/create.sql:/docker-entrypoint-initdb.d/create.sql
- ./src/demo_data/users.csv:/opt/demo_data/users.csv
networks:
- kavuny-net

coffee-packs:
image: coffee-packs
build:
context: coffee-packs
context: src/coffee-packs
dockerfile: CoffeePacks.Dockerfile
networks:
- kavuny-net
depends_on:
packs-db:
condition: service_healthy
consul:
condition: service_healthy
environment:
CONSUL_ADDR: consul:8500

packs-db:
build:
context: coffee-packs
context: src/coffee-packs
dockerfile: Postgres.Dockerfile
environment:
POSTGRES_USER: user
POSTGRES_DB: kavuny
POSTGRES_HOST_AUTH_METHOD: trust
volumes:
- ./coffee-packs/demo_data:/opt/demo_data
- ./src/coffee-packs/demo_data:/opt/demo_data
networks:
- kavuny-net
healthcheck:
Expand All @@ -81,7 +81,7 @@ services:
coffee-shops:
image: coffee-shops
build:
context: coffee-shops
context: src/coffee-shops
dockerfile: CoffeeShops.Dockerfile
networks:
- kavuny-net
Expand All @@ -90,19 +90,20 @@ services:
condition: service_healthy
packs-db:
condition: service_healthy
consul:
condition: service_healthy
environment:
CONSUL_ADDR: consul:8500

shops-db:
build:
context: coffee-shops
context: src/coffee-shops
dockerfile: Postgres.Dockerfile
environment:
POSTGRES_USER: user
POSTGRES_DB: kavuny
POSTGRES_HOST_AUTH_METHOD: trust
volumes:
- ./coffee-shops/demo_data:/opt/demo_data
- ./src/coffee-shops/demo_data:/opt/demo_data
networks:
- kavuny-net
healthcheck:
Expand All @@ -114,22 +115,22 @@ services:

check-ins:
build:
context: check-ins
context: src/check-ins
dockerfile: CheckIns.Dockerfile
depends_on:
check-ins-db-1:
condition: service_healthy
consul:
condition: service_healthy
networks:
- kavuny-net
ports:
- "8080:8080"
environment:
CONSUL_ADDR: consul:8500


check-ins-db-1:
build:
context: check-ins
context: src/check-ins
dockerfile: Cassandra.Dockerfile
networks:
- kavuny-net
Expand All @@ -139,22 +140,60 @@ services:
timeout: 20s
retries: 3
start_period: 20s
# check-ins-db-2:
# image: cassandra:latest
# networks:
# - kavuny-net
# environment:
# - CASSANDRA_SEEDS=check-ins-db-1
# depends_on:
# check-ins-db-1:
# condition: service_healthy
# healthcheck:
# test: ["CMD-SHELL", "nodetool status | grep UN"]
# interval: 15s
# timeout: 20s
# retries: 3
# start_period: 20s

logging-service:
image: project-log:latest
pull_policy: build
build:
context: src/log
environment:
CONSUL_ADDR: consul:8500
LOG_FILE: /opt/app/logs/log.log
volumes:
- ./logs:/opt/app/logs
networks:
- kavuny-net
depends_on:
consul:
condition: service_healthy

zookeeper:
image: bitnami/zookeeper:latest
environment:
ALLOW_ANONYMOUS_LOGIN: yes
networks:
- kavuny-net
healthcheck:
test: echo srvr | nc zookeeper 2181 || exit 1
timeout: 5s
retries: 3
interval: 30s
kafka:
image: bitnami/kafka:latest
environment:
KAFKA_CFG_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE: true
networks:
- kavuny-net
depends_on:
- zookeeper

networks:
kavuny-net:
driver: bridge
driver: bridge

# check-ins-db-2:
# image: cassandra:latest
# networks:
# - kavuny-net
# environment:
# - CASSANDRA_SEEDS=check-ins-db-1
# depends_on:
# check-ins-db-1:
# condition: service_healthy
# healthcheck:
# test: ["CMD-SHELL", "nodetool status | grep UN"]
# interval: 15s
# timeout: 20s
# retries: 3
# start_period: 20s
2 changes: 0 additions & 2 deletions auth/Dockerfile → src/auth/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,4 @@ FROM hazelcast/hazelcast:latest AS build-release-stage

COPY --from=build-stage /auth_service /auth_service

EXPOSE 8080

CMD /auth_service
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions auth/go.mod → src/auth/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ require (
github.com/hashicorp/serf v0.10.1 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
Expand All @@ -44,6 +45,7 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/rogpeppe/go-internal v1.8.0 // indirect
github.com/shirou/gopsutil/v3 v3.21.5 // indirect
github.com/tklauser/go-sysconf v0.3.4 // indirect
github.com/tklauser/numcpus v0.2.1 // indirect
Expand Down
10 changes: 9 additions & 1 deletion auth/go.sum → src/auth/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/
github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
Expand Down Expand Up @@ -131,8 +132,9 @@ github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZY
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
Expand Down Expand Up @@ -179,6 +181,7 @@ github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0Mw
github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand All @@ -199,6 +202,9 @@ github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8b
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
Expand Down Expand Up @@ -305,8 +311,10 @@ google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFW
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
39 changes: 27 additions & 12 deletions auth/main.go → src/auth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ import (
)

func startHazelcast() <-chan error {
err := exec.Command("hz", "start").Start()
if err != nil {
return nil
}
go func() {
output, _ := exec.Command("hz", "start").Output()
fmt.Println(output)
}()
//if err != nil {
// return nil
//}
hzStarted := make(chan error)
go func() {
var err error
Expand All @@ -29,6 +32,8 @@ func startHazelcast() <-chan error {
_, err = http.Get("http://localhost:5701/hazelcast/health")
if err == nil {
hzStarted <- nil

<-time.After(10 * time.Second)
close(hzStarted)
return
}
Expand Down Expand Up @@ -74,20 +79,20 @@ func externalIP() (string, error) {
return "", errors.New("failed to find an external IP address")
}

func registerInConsul(consulAddr string) (string, error) {
func registerInConsul(consulAddr string) (string, string, string, error) {
cfg := capi.DefaultConfig()
cfg.Address = consulAddr
client, err := capi.NewClient(cfg)
if err != nil {
return "", err
return "", "", "", err
}
host, err := externalIP()
if err != nil {
return "", err
return "", "", "", err
}
serviceID, err := uuid.NewUUID()
if err != nil {
return "", err
return "", "", "", err
}
err = client.Agent().ServiceRegister(&capi.AgentServiceRegistration{
ID: serviceID.String(),
Expand All @@ -101,9 +106,20 @@ func registerInConsul(consulAddr string) (string, error) {
},
})
if err != nil {
return "", err
return "", "", "", err
}
keyValuePairs := client.KV()
kafkaAddrKV, _, err := keyValuePairs.Get("kafka_address", &capi.QueryOptions{})
if err != nil {
return "", "", "", err
}
kafkaTopicKV, _, err := keyValuePairs.Get("kafka_topic", &capi.QueryOptions{})
if err != nil {
return "", "", "", err
}
return serviceID.String(), nil
kafkaAddr := string(kafkaAddrKV.Value)
kafkaTopic := string(kafkaTopicKV.Value)
return serviceID.String(), kafkaAddr, kafkaTopic, nil
}

func unregisterConsul(consulAddr string, serviceID string) {
Expand All @@ -112,7 +128,6 @@ func unregisterConsul(consulAddr string, serviceID string) {
client, err := capi.NewClient(cfg)
check(err)
check(client.Agent().ServiceDeregister(serviceID))
fmt.Println("Unregistered service:", serviceID)
}

func check(err error) {
Expand All @@ -138,7 +153,7 @@ func main() {

consulAddr, err := getArgs()
check(err)
serviceID, err := registerInConsul(consulAddr)
serviceID, _, _, err := registerInConsul(consulAddr)
check(err)
defer unregisterConsul(consulAddr, serviceID)

Expand Down
Loading

0 comments on commit 523dc1b

Please sign in to comment.