Skip to content

Commit 04d7735

Browse files
Merge pull request #8 from score-spec/traderx
Add traderx demo
2 parents a87a564 + a9f6971 commit 04d7735

File tree

15 files changed

+469
-1
lines changed

15 files changed

+469
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
- [Resources](./resources/)
55
- [Samples](./samples/)
66
- [OnlineBoutique](./samples/onlineboutique/)
7-
- [AKS Store Demo](./samples/aks-store-demo/)
7+
- [AKS Store Demo](./samples/aks-store-demo/)
8+
- [TraderX](./samples/traderx/)

samples/traderx/Makefile

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# Disable all the default make stuff
2+
MAKEFLAGS += --no-builtin-rules
3+
.SUFFIXES:
4+
5+
## Display a list of the documented make targets
6+
.PHONY: help
7+
help:
8+
@echo Documented Make targets:
9+
@perl -e 'undef $$/; while (<>) { while ($$_ =~ /## (.*?)(?:\n# .*)*\n.PHONY:\s+(\S+).*/mg) { printf "\033[36m%-30s\033[0m %s\n", $$2, $$1 } }' $(MAKEFILE_LIST) | sort
10+
11+
.PHONY: .FORCE
12+
.FORCE:
13+
14+
.score-compose/state.yaml:
15+
score-compose init \
16+
--no-sample \
17+
--provisioners https://raw.githubusercontent.com/score-spec/community-provisioners/refs/heads/main/service/score-compose/10-service.provisioners.yaml
18+
19+
compose.yaml: account-service/score.yaml database/score.yaml ingress/score.yaml people-service/score.yaml position-service/score.yaml reference-data/score.yaml trade-feed/score.yaml trade-processor/score.yaml trade-service/score.yaml web-frontend/score.yaml .score-compose/state.yaml Makefile
20+
score-compose generate \
21+
account-service/score.yaml \
22+
database/score.yaml \
23+
people-service/score.yaml \
24+
position-service/score.yaml \
25+
reference-data/score.yaml \
26+
trade-feed/score.yaml \
27+
trade-processor/score.yaml \
28+
trade-service/score.yaml \
29+
web-frontend/score.yaml
30+
score-compose generate \
31+
ingress/score.yaml \
32+
--build 'ingress={"context":"ingress/","tags":["ingress:local"]}'
33+
34+
## Generate a compose.yaml file from the score specs and launch it.
35+
.PHONY: compose-up
36+
compose-up: compose.yaml
37+
docker compose up --build -d --remove-orphans
38+
39+
## Generate a compose.yaml file from the score spec, launch it and test (curl) the exposed container.
40+
.PHONY: compose-test
41+
compose-test: compose-up
42+
sleep 5
43+
curl $$(score-compose resources get-outputs 'dns.default#ingress.dns' --format '{{ .host }}:8080')
44+
45+
## Delete the containers running via compose down.
46+
.PHONY: compose-down
47+
compose-down:
48+
docker compose down -v --remove-orphans || true
49+
50+
.score-k8s/state.yaml:
51+
score-k8s init \
52+
--no-sample \
53+
--provisioners https://raw.githubusercontent.com/score-spec/community-provisioners/refs/heads/main/service/score-k8s/10-service.provisioners.yaml
54+
55+
manifests.yaml: account-service/score.yaml database/score.yaml ingress/score.yaml people-service/score.yaml position-service/score.yaml reference-data/score.yaml trade-feed/score.yaml trade-processor/score.yaml trade-service/score.yaml web-frontend/score.yaml .score-k8s/state.yaml Makefile
56+
score-k8s generate \
57+
account-service/score.yaml \
58+
database/score.yaml \
59+
people-service/score.yaml \
60+
position-service/score.yaml \
61+
reference-data/score.yaml \
62+
trade-feed/score.yaml \
63+
trade-processor/score.yaml \
64+
trade-service/score.yaml \
65+
web-frontend/score.yaml
66+
score-k8s generate \
67+
ingress/score.yaml \
68+
--image ingress:local
69+
70+
## Create a local Kind cluster.
71+
.PHONY: kind-create-cluster
72+
kind-create-cluster:
73+
./scripts/setup-kind-cluster.sh
74+
75+
## Load the local container image in the current Kind cluster.
76+
.PHONY: kind-load-image
77+
kind-load-image:
78+
kind load docker-image ingress:local
79+
80+
NAMESPACE ?= default
81+
## Generate a manifests.yaml file from the score spec and apply it in Kubernetes.
82+
.PHONY: k8s-up
83+
k8s-up: manifests.yaml kind-load-image
84+
kubectl apply \
85+
-f manifests.yaml \
86+
-n ${NAMESPACE}
87+
kubectl wait deployments/ingress \
88+
-n ${NAMESPACE} \
89+
--for condition=Available \
90+
--timeout=90s
91+
kubectl wait pods \
92+
-n ${NAMESPACE} \
93+
-l app.kubernetes.io/name=ingress \
94+
--for condition=Ready \
95+
--timeout=90s
96+
97+
## Expose the container deployed in Kubernetes via port-forward.
98+
.PHONY: k8s-test
99+
k8s-test: k8s-up
100+
curl $$(score-k8s resources get-outputs dns.default#ingress.dns --format '{{ .host }}')
101+
102+
## Delete the deployment of the local container in Kubernetes.
103+
.PHONY: k8s-down
104+
k8s-down:
105+
kubectl delete \
106+
-f manifests.yaml \
107+
-n ${NAMESPACE}
108+
109+
## Generate catalog-info.yaml for Backstage.
110+
.PHONY: generate-catalog-info
111+
generate-catalog-info:
112+
score-k8s init \
113+
--no-sample \
114+
--provisioners https://raw.githubusercontent.com/score-spec/community-provisioners/refs/heads/main/service/score-k8s/10-service.provisioners.yaml \
115+
--patch-templates https://raw.githubusercontent.com/score-spec/community-patchers/refs/heads/main/score-k8s/backstage-catalog-entities.tpl
116+
score-k8s generate \
117+
--namespace traderx-demo \
118+
account-service/score.yaml \
119+
database/score.yaml \
120+
people-service/score.yaml \
121+
position-service/score.yaml \
122+
reference-data/score.yaml \
123+
trade-feed/score.yaml \
124+
trade-processor/score.yaml \
125+
trade-service/score.yaml \
126+
web-frontend/score.yaml
127+
--output catalog-info.yaml
128+
score-k8s generate \
129+
--namespace traderx-demo \
130+
--generate-namespace \
131+
ingress/score.yaml \
132+
--image ingress:local \
133+
--output catalog-info.yaml
134+
sed 's,$$GITHUB_REPO,score-spec/examples,g' -i catalog-info.yaml

samples/traderx/README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
Deploy the [finos/traderX](https://github.com/finos/traderX) with Score (`score-compose` and `score-k8s`).
2+
3+
```mermaid
4+
flowchart TD
5+
dns[DNS] --> ingress(ingress)
6+
subgraph Workloads
7+
ingress-->reference-data(reference-data)
8+
ingress-->trade-service(trade-service)
9+
ingress-->trade-feed(trade-feed)
10+
ingress-->trade-processor(trade-processor)
11+
ingress-->web-frontend(web-frontend)
12+
ingress-->position-service(position-service)
13+
ingress-->people-service(people-service)
14+
ingress-->account-service(account-service)
15+
ingress-->database[(database)]
16+
web-frontend-->trade-feed
17+
web-frontend-->database
18+
account-service-->people-service
19+
account-service-->database
20+
position-service-->database
21+
trade-processor-->trade-feed
22+
trade-processor-->database
23+
trade-service-->account-service
24+
trade-service-->database
25+
trade-service-->people-service
26+
trade-service-->reference-data
27+
trade-service-->trade-feed
28+
end
29+
```
30+
31+
## Local deployment with Docker Compose
32+
33+
You need to be in the `samples/traderx` folder to run the following commands.
34+
35+
Deploy and test locally with Docker compose:
36+
```bash
37+
make compose-up
38+
```
39+
40+
You can now browse http://localhost:8080.
41+
42+
## Local deployment with Kind cluster
43+
44+
Deploy and test locally with Kind cluster:
45+
```bash
46+
make kind-create-cluster
47+
48+
make k8s-up
49+
```
50+
51+
You can now browse http://localhost:80.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: score.dev/v1b1
2+
metadata:
3+
name: account-service
4+
annotations:
5+
tags: "java,spring"
6+
containers:
7+
account-service:
8+
image: ghcr.io/finos/traderx/account-service:latest
9+
variables:
10+
DATABASE_TCP_HOST: "${resources.database.name}"
11+
PEOPLE_SERVICE_HOST: "${resources.people-service.name}"
12+
service:
13+
ports:
14+
web:
15+
port: 18088
16+
targetPort: 18088
17+
resources:
18+
people-service:
19+
type: service
20+
database:
21+
type: service
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: score.dev/v1b1
2+
metadata:
3+
name: database
4+
annotations:
5+
tags: "java,h2"
6+
containers:
7+
database:
8+
image: ghcr.io/finos/traderx/database:latest
9+
service:
10+
ports:
11+
tcp:
12+
port: 18082
13+
targetPort: 18082
14+
pg:
15+
port: 18083
16+
targetPort: 18083
17+
web:
18+
port: 18084
19+
targetPort: 18084

samples/traderx/ingress/Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM nginx:alpine-slim
2+
3+
EXPOSE 8080
4+
ARG NGINX_HOST="localhost"
5+
ENV NGINX_HOST=$NGINX_HOST
6+
7+
# This is a workaround for the dollar sign in the envsubst command
8+
ARG DOLLAR="$"
9+
ENV DOLLAR=$DOLLAR
10+
11+
COPY nginx.traderx.conf.template /etc/nginx/conf.d/nginx.traderx.conf.template
12+
13+
RUN envsubst < /etc/nginx/conf.d/nginx.traderx.conf.template > /etc/nginx/conf.d/default.conf
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
server {
2+
listen 8080;
3+
server_name $NGINX_HOST;
4+
5+
location /db-web/ {
6+
proxy_pass http://database-database:18084/;
7+
}
8+
location /reference-data/ {
9+
proxy_pass http://reference-data-reference-data:18085/;
10+
}
11+
12+
location /ng-cli-ws {
13+
proxy_pass http://web-frontend-web-frontend:18093/ng-cli-ws;
14+
proxy_http_version 1.1;
15+
proxy_set_header Upgrade ${DOLLAR}http_upgrade;
16+
proxy_set_header Connection "upgrade";
17+
}
18+
19+
location /trade-feed/ {
20+
proxy_set_header X-Forwarded-For ${DOLLAR}proxy_add_x_forwarded_for;
21+
proxy_set_header Host ${DOLLAR}http_host;
22+
23+
proxy_pass http://trade-feed-trade-feed:18086/;
24+
25+
proxy_http_version 1.1;
26+
proxy_set_header Upgrade ${DOLLAR}http_upgrade;
27+
proxy_set_header Connection "upgrade";
28+
29+
}
30+
31+
location /socket.io/ {
32+
proxy_set_header X-Forwarded-For ${DOLLAR}proxy_add_x_forwarded_for;
33+
proxy_set_header Host ${DOLLAR}http_host;
34+
35+
proxy_pass http://trade-feed-trade-feed:18086/socket.io/;
36+
37+
proxy_http_version 1.1;
38+
proxy_set_header Upgrade ${DOLLAR}http_upgrade;
39+
proxy_set_header Connection "upgrade";
40+
41+
}
42+
43+
location /people-service/ {
44+
proxy_pass http://people-service-people-service:18089/;
45+
}
46+
location /account-service/ {
47+
proxy_pass http://account-service-account-service:18088/;
48+
}
49+
location /position-service/ {
50+
proxy_pass http://position-service-position-service:18090/;
51+
}
52+
location /trade-service/ {
53+
proxy_pass http://trade-service-trade-service:18092/;
54+
}
55+
location /trade-processor/ {
56+
proxy_pass http://trade-processor-trade-processor:18091/;
57+
}
58+
location / {
59+
proxy_pass http://web-frontend-web-frontend:18093/;
60+
}
61+
}

samples/traderx/ingress/score.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
apiVersion: score.dev/v1b1
2+
metadata:
3+
name: ingress
4+
annotations:
5+
tags: "nginx,ingress"
6+
containers:
7+
ingress:
8+
image: .
9+
variables:
10+
DATABASE_TCP_HOST: "${resources.database.name}"
11+
service:
12+
ports:
13+
web:
14+
port: 8080
15+
targetPort: 8080
16+
resources:
17+
people-service:
18+
type: service
19+
trade-service:
20+
type: service
21+
account-service:
22+
type: service
23+
reference-data:
24+
type: service
25+
trade-feed:
26+
type: service
27+
trade-processor:
28+
type: service
29+
web-frontend:
30+
type: service
31+
database:
32+
type: service
33+
dns:
34+
type: dns
35+
route:
36+
type: route
37+
params:
38+
host: ${resources.dns.host}
39+
path: /
40+
port: 8080
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: score.dev/v1b1
2+
metadata:
3+
name: people-service
4+
annotations:
5+
tags: "dotnet"
6+
containers:
7+
people-service:
8+
image: ghcr.io/finos/traderx/people-service:latest
9+
service:
10+
ports:
11+
web:
12+
port: 18089
13+
targetPort: 18089
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: score.dev/v1b1
2+
metadata:
3+
name: position-service
4+
annotations:
5+
tags: "java,spring"
6+
containers:
7+
position-service:
8+
image: ghcr.io/finos/traderx/position-service:latest
9+
variables:
10+
DATABASE_TCP_HOST: "${resources.database.name}"
11+
service:
12+
ports:
13+
web:
14+
port: 18090
15+
targetPort: 18090
16+
resources:
17+
database:
18+
type: service

0 commit comments

Comments
 (0)