diff --git a/samples/traderx/Makefile b/samples/traderx/Makefile index aaa9f98..e9c0631 100644 --- a/samples/traderx/Makefile +++ b/samples/traderx/Makefile @@ -14,7 +14,9 @@ help: .score-compose/state.yaml: score-compose init \ --no-sample \ - --provisioners https://raw.githubusercontent.com/score-spec/community-provisioners/refs/heads/main/service/score-compose/10-service.provisioners.yaml + --patch-templates ./score-patchers/compose/microcks.tpl \ + --provisioners https://raw.githubusercontent.com/score-spec/community-provisioners/refs/heads/main/service/score-compose/10-service.provisioners.yaml \ + --provisioners ./score-provisioners/compose/10-endpoint-with-microcks.provisioners.yaml 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 score-compose generate \ @@ -42,6 +44,22 @@ compose-test: compose-up sleep 5 curl $$(score-compose resources get-outputs 'dns.default#ingress.dns' --format '{{ .host }}:8080') +compose-mock.yaml: database/score.yaml ingress/score.yaml trade-feed/score.yaml trade-processor/score.yaml trade-service/score.yaml web-frontend/score.yaml .score-compose/state.yaml Makefile + score-compose generate \ + database/score.yaml \ + trade-feed/score.yaml \ + trade-processor/score.yaml \ + trade-service/score.yaml \ + web-frontend/score.yaml + score-compose generate \ + ingress/score.yaml \ + --build 'ingress={"context":"ingress/","dockerfile":"Dockerfile.mock","tags":["ingress:local"]}' + +## Generate a compose.yaml file from the score specs and launch it. +.PHONY: compose-mock-up +compose-mock-up: compose-mock.yaml + docker compose up --build -d --remove-orphans + ## Delete the containers running via compose down. .PHONY: compose-down compose-down: @@ -50,7 +68,8 @@ compose-down: .score-k8s/state.yaml: score-k8s init \ --no-sample \ - --provisioners https://raw.githubusercontent.com/score-spec/community-provisioners/refs/heads/main/service/score-k8s/10-service.provisioners.yaml + --provisioners https://raw.githubusercontent.com/score-spec/community-provisioners/refs/heads/main/service/score-k8s/10-service.provisioners.yaml \ + --provisioners ./score-provisioners/k8s/10-endpoint-with-microcks-cli.provisioners.yaml 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 score-k8s generate \ diff --git a/samples/traderx/README.md b/samples/traderx/README.md index 37e8ab3..01a02b3 100644 --- a/samples/traderx/README.md +++ b/samples/traderx/README.md @@ -21,7 +21,6 @@ flowchart TD trade-processor-->trade-feed trade-processor-->database trade-service-->account-service - trade-service-->database trade-service-->people-service trade-service-->reference-data trade-service-->trade-feed diff --git a/samples/traderx/api-mocks/position-service-examples.yaml b/samples/traderx/api-mocks/position-service-examples.yaml index 26c114b..0aaf886 100644 --- a/samples/traderx/api-mocks/position-service-examples.yaml +++ b/samples/traderx/api-mocks/position-service-examples.yaml @@ -5,15 +5,15 @@ metadata: version: 0.1.0 operations: GET /trades/{accountId}: - '52355': + '52335': request: parameters: - accountId: 52355 + accountId: 52335 response: mediaType: application/json body: - - id: TRADE-52355-AABBCC - accountId: 52355 + - id: TRADE-52335-AABBCC + accountId: 52335 security: BAC side: Sell state: Settled @@ -21,14 +21,14 @@ operations: updated: 2026-03-11T08:57:54.758+00:00 created: 2026-03-11T08:57:54.758+00:00 GET /positions/{accountId}: - '52355': + '52335': request: parameters: - accountId: 52355 + accountId: 52335 response: mediaType: application/json body: - - accountId: 52355 + - accountId: 52335 security: BAC quantity: -2400 updated: 2026-03-11T08:57:54.763+00:00 diff --git a/samples/traderx/ingress/Dockerfile.mock b/samples/traderx/ingress/Dockerfile.mock new file mode 100644 index 0000000..a97742d --- /dev/null +++ b/samples/traderx/ingress/Dockerfile.mock @@ -0,0 +1,13 @@ +FROM nginx:alpine-slim + +EXPOSE 8080 +ARG NGINX_HOST="localhost" +ENV NGINX_HOST=$NGINX_HOST + +# This is a workaround for the dollar sign in the envsubst command +ARG DOLLAR="$" +ENV DOLLAR=$DOLLAR + +COPY nginx.traderx-mock.conf.template /etc/nginx/conf.d/nginx.traderx.conf.template + +RUN envsubst < /etc/nginx/conf.d/nginx.traderx.conf.template > /etc/nginx/conf.d/default.conf \ No newline at end of file diff --git a/samples/traderx/ingress/nginx.traderx-mock.conf.template b/samples/traderx/ingress/nginx.traderx-mock.conf.template new file mode 100644 index 0000000..f972995 --- /dev/null +++ b/samples/traderx/ingress/nginx.traderx-mock.conf.template @@ -0,0 +1,59 @@ +server { + listen 8080; + server_name $NGINX_HOST; + + location /db-web/ { + proxy_pass http://database-database:18084/; + } + location /reference-data/ { + proxy_pass http://microcks:8080/rest/FINOS+TraderX+Reference+Data/1.0/; + } + + location /ng-cli-ws { + proxy_pass http://web-frontend-web-frontend:18093/ng-cli-ws; + proxy_http_version 1.1; + proxy_set_header Upgrade ${DOLLAR}http_upgrade; + proxy_set_header Connection "upgrade"; + } + + location /trade-feed/ { + proxy_set_header X-Forwarded-For ${DOLLAR}proxy_add_x_forwarded_for; + proxy_set_header Host ${DOLLAR}http_host; + + proxy_pass http://trade-feed-trade-feed:18086/; + + proxy_http_version 1.1; + proxy_set_header Upgrade ${DOLLAR}http_upgrade; + proxy_set_header Connection "upgrade"; + } + + location /socket.io/ { + proxy_set_header X-Forwarded-For ${DOLLAR}proxy_add_x_forwarded_for; + proxy_set_header Host ${DOLLAR}http_host; + + proxy_pass http://trade-feed-trade-feed:18086/socket.io/; + + proxy_http_version 1.1; + proxy_set_header Upgrade ${DOLLAR}http_upgrade; + proxy_set_header Connection "upgrade"; + } + + location /people-service/ { + proxy_pass http://microcks:8080/rest/FINOS+TraderX+People+Service/v1/; + } + location /account-service/ { + proxy_pass http://microcks:8080/rest/FINOS+TraderX+Account+Service/0.1.0/; + } + location /position-service/ { + proxy_pass http://microcks:8080/rest/FINOS+TraderX+Position+Service/0.1.0/; + } + location /trade-service/ { + proxy_pass http://trade-service-trade-service:18092/; + } + location /trade-processor/ { + proxy_pass http://trade-processor-trade-processor:18091/; + } + location / { + proxy_pass http://web-frontend-web-frontend:18093/; + } + } \ No newline at end of file diff --git a/samples/traderx/ingress/score.yaml b/samples/traderx/ingress/score.yaml index 7b14fec..b3c6f53 100644 --- a/samples/traderx/ingress/score.yaml +++ b/samples/traderx/ingress/score.yaml @@ -14,14 +14,14 @@ service: port: 8080 targetPort: 8080 resources: - people-service: - type: service + #people-service: + # type: service trade-service: type: service - account-service: - type: service - reference-data: - type: service + #account-service: + # type: service + #reference-data: + # type: service trade-feed: type: service trade-processor: diff --git a/samples/traderx/score-patchers/compose/microcks.tpl b/samples/traderx/score-patchers/compose/microcks.tpl new file mode 100644 index 0000000..c0f23b3 --- /dev/null +++ b/samples/traderx/score-patchers/compose/microcks.tpl @@ -0,0 +1,15 @@ +- op: set + path: services.microcks + value: + image: quay.io/microcks/microcks-uber:latest-native + read_only: true + user: "65532" + cap_drop: ["ALL"] + ports: + - target: 8080 + published: "9090" + volumes: + - type: tmpfs + target: /tmp + tmpfs: + size: 65536 \ No newline at end of file diff --git a/samples/traderx/score-provisioners/compose/10-endpoint-with-microcks.provisioners.yaml b/samples/traderx/score-provisioners/compose/10-endpoint-with-microcks.provisioners.yaml new file mode 100644 index 0000000..f5c02ca --- /dev/null +++ b/samples/traderx/score-provisioners/compose/10-endpoint-with-microcks.provisioners.yaml @@ -0,0 +1,55 @@ +# Custom updates for now, will need to contribute back to the community provisioners repository later on. +- uri: template://custom-provisioners/endpoint-with-microcks + type: endpoint + description: Outputs an endpoint URL for connecting to an other workload (a Microcks mock is generated if not found). + init: | + hostname: {{ splitList "." .Id | last }} + {{ $artifacts := .Params.artifacts | splitList "," }} + {{ $parsedPath := $artifacts | first | splitList "/" }} + {{ if eq (len $parsedPath) 0 }} + resourcesPath: "." + {{ else }} + resourcesPath: {{ trimSuffix (last $parsedPath) (first $artifacts) | trimSuffix "/" }} + {{ end }} + supported_params: + - port + - artifacts + - name + - version + outputs: | + {{ $w := (index .WorkloadServices .Init.hostname) }} + {{ if or (not $w) (not $w.ServiceName) }} + url: http://localhost:9090/rest/{{ .Params.name | replace " " "+" }}/{{ .Params.version }} + {{ else }} + url: http://{{ .Init.hostname }}:{{ .Params.port }} + {{ end }} + expected_outputs: + - url + services: | + {{ $w := (index .WorkloadServices .Init.hostname) }} + {{ if or (not $w) (not $w.ServiceName) }} + {{ .Init.hostname }}-mock: + image: quay.io/microcks/microcks-cli:latest + restart: on-failure + entrypoint: + - "microcks" + - "import" + - "{{ .Params.artifacts }}" + - "--microcksURL=http://microcks:8080/api" + - "--insecure-tls" + - "--keycloakClientId=foo" + - "--keycloakClientSecret=bar" + cap_drop: + - ALL + read_only: true + user: "65532" + volumes: + - type: bind + source: {{ .Init.resourcesPath }} + target: /{{ .Init.resourcesPath }} + read_only: true + depends_on: + microcks: + condition: service_started + required: true + {{ end }} \ No newline at end of file diff --git a/samples/traderx/score-provisioners/k8s/10-endpoint-with-microcks-cli.provisioners.yaml b/samples/traderx/score-provisioners/k8s/10-endpoint-with-microcks-cli.provisioners.yaml new file mode 100644 index 0000000..e37c0d3 --- /dev/null +++ b/samples/traderx/score-provisioners/k8s/10-endpoint-with-microcks-cli.provisioners.yaml @@ -0,0 +1,37 @@ +# Custom updates for now, will need to contribute back to the community provisioners repository later on. +- uri: cmd://bash#endpoint-with-microcks-cli + type: endpoint + description: Outputs an endpoint URL for connecting to an other workload (a Microcks mock is generated if not found). + supported_params: + - port + - artifacts + - name + - version + expected_outputs: + - url + args: + - -c + - | + STDIN=$(cat) + PARAM_PORT=$(echo $STDIN | yq eval -p json '.resource_params.port') + PARAM_NAME=$(echo $STDIN | yq eval -p json '.resource_params.name') + PARAM_VERSION=$(echo $STDIN | yq eval -p json '.resource_params.version') + PARAM_ARTIFACTS=$(echo $STDIN | yq eval -p json '.resource_params.artifacts') + SPEC_FILE="" + if [ "$PARAM_ARTIFACTS" != "" ]; then + SPEC_FILE=$(echo $STDIN | yq eval -p json '.resource_params.artifacts | split(",") | .[0]') + fi + WORKLOAD=$(echo $STDIN | yq eval -p json '.resource_id | split(".") | .[-1]') + WORKLOAD_EXISTS=$(echo $STDIN | WORKLOAD=${WORKLOAD} yq eval -p json '.workload_services | has(strenv(WORKLOAD))') + URL_HOSTNAME=${WORKLOAD}:${PARAM_PORT} + URL_SCHEME="http" + URL_PATH="" + if [ "$WORKLOAD_EXISTS" != "true" ]; then + URL_HOSTNAME="microcks.127.0.0.1.nip.io" + URL_SCHEME="https" + URL_PATH=/rest/$(cat $SPEC_FILE | yq eval '.info.title' | yq '. |= sub(" ", "+")') + set -eu -o pipefail + microcks import ${PARAM_ARTIFACTS} --microcksURL=https://${URL_HOSTNAME} --insecure-tls --keycloakClientId=foo --keycloakClientSecret=bar >&2 + fi + OUTPUTS='{"resource_outputs":{"url":"%s://%s%s"},"manifests":[]}' + printf "$OUTPUTS" "$URL_SCHEME" "$URL_HOSTNAME" "$URL_PATH" \ No newline at end of file diff --git a/samples/traderx/trade-service/score.yaml b/samples/traderx/trade-service/score.yaml index a0eb2d7..cfc5f66 100644 --- a/samples/traderx/trade-service/score.yaml +++ b/samples/traderx/trade-service/score.yaml @@ -7,10 +7,10 @@ containers: trade-service: image: ghcr.io/finos/traderx/trade-service:latest variables: - DATABASE_TCP_HOST: "${resources.database.name}" - PEOPLE_SERVICE_HOST: "${resources.people-service.name}" - ACCOUNT_SERVICE_HOST: "${resources.account-service.name}" - REFERENCE_DATA_HOST: "${resources.reference-data.name}" + TRADING_SERVICE_PORT: '18092' + PEOPLE_SERVICE_URL: "${resources.people-service.url}" + ACCOUNT_SERVICE_URL: "${resources.account-service.url}" + REFERENCE_DATA_SERVICE_URL: "${resources.reference-data.url}" TRADE_FEED_HOST: "${resources.trade-feed.name}" service: ports: @@ -21,22 +21,30 @@ resources: people-service: type: endpoint params: - port: 8181 - openapi_file: ../api-mocks/people-service-openapi.json - openapi_title: FINOS TraderX People Service + port: 18089 + artifacts: api-mocks/people-service-openapi.json:true,api-mocks/people-service-metadata.yaml:false,api-mocks/people-service-examples.yaml:false + name: FINOS TraderX People Service + version: v1 + position-service: + type: endpoint + params: + port: 18090 + artifacts: api-mocks/position-service-openapi.json:true,api-mocks/position-service-examples.yaml:false + name: FINOS TraderX Position Service + version: 0.1.0 trade-feed: type: service account-service: type: endpoint params: - port: 8181 - openapi_file: ../api-mocks/account-service-openapi.json - openapi_title: FINOS TraderX Account Service + port: 18088 + artifacts: api-mocks/account-service-openapi.json:true,api-mocks/account-service-examples.yaml:false + name: FINOS TraderX Account Service + version: 0.1.0 reference-data: type: endpoint params: - port: 8181 - openapi_file: ../api-mocks/reference-data-openapi.json - openapi_title: FINOS TraderX Reference Data - database: - type: service \ No newline at end of file + port: 18085 + artifacts: api-mocks/reference-data-openapi.json:true,api-mocks/reference-data-examples.yaml:false + name: FINOS TraderX Reference Data + version: '1.0' \ No newline at end of file