Skip to content

Commit

Permalink
configuring Docker-compose for local running web-app
Browse files Browse the repository at this point in the history
  • Loading branch information
jurabek committed Feb 25, 2024
1 parent fb99d06 commit 42b55b7
Show file tree
Hide file tree
Showing 17 changed files with 364 additions and 104 deletions.
20 changes: 10 additions & 10 deletions src/backend/docker/docker-compose.override.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3.7'
version: "3.7"

services:
order-api:
Expand All @@ -22,7 +22,7 @@ services:
- AUTH_URL=http://localhost:8080/identity
- BASE_PATH=/shoppingcart
- OTEL_EXPORTER_OTLP_ENDPOINT=otel-collector:4317

payment-api:
environment:
- ENABLE_TEST_CARDS=false
Expand All @@ -48,11 +48,11 @@ services:
- OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317
- ENV=dev

# web-app:
# environment:
# - INTERNAL_API_BASE_URL=http://traefik:80
# - NEXT_SHARP_PATH=./node_modules/sharp
# - AUTH_ISSUER=http://host.docker.internal:8080/identity
web-app:
environment:
- INTERNAL_API_BASE_URL=http://traefik:80
- NEXT_SHARP_PATH=./node_modules/sharp
- AUTH_ISSUER=http://host.docker.internal:8080/identity

identity-api:
environment:
Expand All @@ -68,7 +68,7 @@ services:
- DASHBOARD_APP_URL=http://localhost:8080/dashboard
- IDENTITY_URL_PUB=http://localhost:8080/identity

# connect:
# connect:
# pgcli 'postgresql://admin:Passw0rd!@localhost:5433/orderdb'
order-db:
environment:
Expand All @@ -77,7 +77,7 @@ services:
- PGDATA=/pg
- POSTGRES_DB=orderdb

# connect:
# connect:
# pgcli 'postgresql://admin:Passw0rd!@localhost:5435/identity_database'
identity-db:
environment:
Expand All @@ -92,4 +92,4 @@ services:
environment:
- POSTGRES_PASSWORD=Passw0rd!
- POSTGRES_USER=admin
- POSTGRES_DB=catalogdb
- POSTGRES_DB=catalogdb
6 changes: 6 additions & 0 deletions src/backend/docker/docker-compose.traefik.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ services:
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"

web-app:
labels:
- "traefik.enable=true"
- "traefik.http.routers.web.rule=PathPrefix(`/`)"
- "traefik.port=3001"

identity-api:
labels:
- "traefik.enable=true"
Expand Down
41 changes: 20 additions & 21 deletions src/backend/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
version: '3.7'
version: "3.7"

services:

identity-api:
image: restaurant/identity-api
build: ./services/identity-api
depends_on:
- identity-db
ports:
- identity-db
ports:
- "5001:80"
restart: always

Expand All @@ -25,7 +24,7 @@ services:
container_name: catalog
build: ./services/catalog-api
depends_on:
- catalog-db
- catalog-db
ports:
- 8000:8000
restart: always
Expand All @@ -40,7 +39,7 @@ services:
order-api:
image: restaurant/order-api
container_name: order
build:
build:
platforms:
- "linux/arm64"
context: ./services/order-api
Expand All @@ -50,7 +49,7 @@ services:
- payment-api
ports:
- 8082:8080

payment-api:
image: restaurant/payment-api
container_name: payment
Expand All @@ -64,24 +63,24 @@ services:
# context: ./web/web.admin/dashboard
# dockerfile: local.Dockerfile

# web-app:
# image: restaurant/web-app
# build:
# context: ./web/web.client/web-app-new
# dockerfile: Dockerfile
# ports:
# - 3001:3000
# extra_hosts:
# - "host.docker.internal:host-gateway" # run in your host machine command:
# # sudo sh -c "echo '127.0.0.1 \t host.docker.internal' >> /etc/hosts"
web-app:
image: restaurant/web-app
build:
context: ./services/web-app
dockerfile: local.Dockerfile
ports:
- 3001:3000
extra_hosts:
- "host.docker.internal:host-gateway" # run in your host machine command:
# sudo sh -c "echo '127.0.0.1 \t host.docker.internal' >> /etc/hosts"

order-db:
image: postgres:alpine
volumes:
volumes:
- database-data:/var/lib/postgresql/data
ports:
ports:
- "5433:5432"

catalog-db:
image: postgres:alpine
ports:
Expand All @@ -95,6 +94,6 @@ services:
redis:
platform: linux/arm64/v8
image: redis:alpine

volumes:
database-data:
35 changes: 31 additions & 4 deletions src/backend/docker/run.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
#!/bin/sh

set -e

trap close INT

dockerhost="127.0.0.1 host.docker.internal"
hostfile="/etc/hosts"

if [ "$EUID" -ne 0 ]; then
if ! grep -q "^$dockerhost" "$hostfile"; then
tput setaf 1
tput bold
echo "-----------------------------------------------------------------------------------------------------------"
echo "Note this script needs sudo permission, to append '127.0.0.1 host.docker.internal' into /etc/hosts"
echo "-----------------------------------------------------------------------------------------------------------"
tput sgr 0
exit
fi
fi

docker-compose --env-file docker/.env -f docker/docker-compose.yml -f docker/docker-compose.override.yml \
-f docker/docker-compose.traefik.yml \
-f docker/docker-compose.kafka.yml \
-f docker/docker-compose.grafana.yaml \
-f docker/docker-compose.otel.yml --project-directory . up -d --build
-f docker/docker-compose.traefik.yml \
-f docker/docker-compose.kafka.yml \
-f docker/docker-compose.grafana.yaml \
-f docker/docker-compose.otel.yml --project-directory . up -d --build

tput bold
tput setaf 3 # yellow

if ! grep -q "^$dockerhost" "$hostfile"; then
echo "- Adding entry '$dockerhost"
echo "$dockerhost" >>"$hostfile"
fi
2 changes: 2 additions & 0 deletions src/backend/docker/tempo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ server:
http_listen_port: 3200

distributor:
# extraArgs:
# "distributor.log-received-traces": true
receivers: # this configuration will listen on all ports and protocols that tempo is capable of.
jaeger: # the receives all come from the OpenTelemetry collector. more configuration information can
protocols: # be found there: https://github.com/open-telemetry/opentelemetry-collector/tree/main/receiver
Expand Down
1 change: 1 addition & 0 deletions src/backend/load-tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM grafana/k6
6 changes: 2 additions & 4 deletions src/backend/load-tests/checkout.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import http, { get } from "k6/http";
import http from "k6/http";
import { check, sleep } from "k6";
import faker from "k6/x/faker";

Expand Down Expand Up @@ -28,7 +28,7 @@ export default function () {

const foods = getFoods.json();
const food = foods[Math.floor(Math.random() * foods.length)];

const user_id = faker.uuid();
// create new cart
const createCart = http.post(
Expand Down Expand Up @@ -87,7 +87,5 @@ export default function () {
"checkout was 200": (r) => r.status == 200,
});

console.log(checkout.json());

sleep(1);
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ public static IEnumerable<Client> GetClients(IDictionary<string, string> clientU
AllowedGrantTypes = GrantTypes.CodeAndClientCredentials,
RequireConsent = false,
ClientSecrets = {new Secret("secret".Sha256())},
RedirectUris = {"http://localhost:3001/api/auth/callback/web-app"},
RedirectUris = {
"http://localhost:3001/api/auth/callback/web-app",
"http://localhost:8080/api/auth/callback/web-app",
"http://localhost:80/api/auth/callback/web-app"
},
PostLogoutRedirectUris = {"http://localhost:5002/signout-callback-oidc"},
AllowedScopes =
{
Expand Down
3 changes: 3 additions & 0 deletions src/backend/services/payment-api/grpc/payment_service_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ func NewPaymentServiceGrpc(enableTestCards bool) *PaymentServiceGrpc {
var ErrUnsupportedCardType = errors.New("card type unsupported")
var ErrInvalidCardInfo = errors.New("invalid card information")

func (p *PaymentServiceGrpc) GetPaymentMethods(context.Context, *pbv1.GetPaymentMethodsRequest) (*pbv1.GetPaymentMethodsResponse, error) {
return nil, nil
}
// Payment implements v1.PaymentServiceServer
func (p *PaymentServiceGrpc) Payment(ctx context.Context, req *pbv1.PaymentRequest) (res *pbv1.PaymentResponse, err error) {
var tracer = otel.Tracer("payment-api/grpc")
Expand Down
6 changes: 5 additions & 1 deletion src/backend/services/payment-api/pb/payments.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ option java_package = "org.jurabek.payment";

service PaymentService {
rpc Payment(PaymentRequest) returns (PaymentResponse) {}
rpc GetPaymentMethods(GetPaymentMethodsRequest) returns (GetPaymentMethodsResponse) {}
}

message GetPaymentMethodsRequest {}
message GetPaymentMethodsResponse {}

message CreditCardInfo {
string credit_card_number = 1;
int32 credit_card_cvv = 2;
Expand All @@ -28,4 +32,4 @@ message PaymentRequest {

message PaymentResponse {
string transaction_id = 1;
}
}
Loading

0 comments on commit 42b55b7

Please sign in to comment.