Skip to content

Commit 5c83ff4

Browse files
Expose ledger API in docker compose setup (#2053)
fixes #2038 [ci] This keeps coming up every few days so rather than copy pasting the config snippet around let's just include it. Signed-off-by: Moritz Kiefer <[email protected]> Co-authored-by: Moritz Kiefer <[email protected]>
1 parent ff64743 commit 5c83ff4

File tree

9 files changed

+132
-17
lines changed

9 files changed

+132
-17
lines changed

apps/app/src/test/scala/org/lfdecentralizedtrust/splice/integration/tests/DockerComposeValidatorFrontendIntegrationTest.scala

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ class DockerComposeValidatorFrontendIntegrationTest
6767
}
6868

6969
"docker-compose based validator works" in { implicit env =>
70+
implicit val actorSystem: ActorSystem = env.actorSystem
71+
registerHttpConnectionPoolsCleanup(env)
72+
7073
val aliceTap = 123.4
7174
val adminTap = 234.5
7275

@@ -132,6 +135,37 @@ class DockerComposeValidatorFrontendIntegrationTest
132135
// Take a backup of the validator
133136
Seq("build-tools/splice-compose.sh", "backup_node", backupsDir.toString) !
134137

138+
clue("JSON ledger API is exposed") {
139+
val response =
140+
Http().singleRequest(Get("http://json-ledger-api.localhost/v2/version")).futureValue
141+
response.status should be(StatusCodes.OK)
142+
response.entity.toStrict(10.seconds).futureValue.data.utf8String should include(
143+
"\"version\":\"3." // check that it reports a version. We don't care about the exact version
144+
)
145+
}
146+
147+
clue("GRPC ledger API is exposed") {
148+
import com.digitalasset.canton.ledger.client.GrpcChannel
149+
import scala.util.Using
150+
val channelConfig = com.digitalasset.canton.ledger.client.configuration
151+
.LedgerClientChannelConfiguration(sslContext = None)
152+
implicit val releasableChannel: Using.Releasable[io.grpc.ManagedChannel] =
153+
(resource: io.grpc.ManagedChannel) => {
154+
GrpcChannel.close(resource)
155+
}
156+
Using.resource(
157+
channelConfig
158+
.builderFor("grpc-ledger-api.localhost", 80)
159+
.executor(env.executionContext)
160+
.build
161+
) { channel =>
162+
import com.daml.ledger.api.v2.version_service.*
163+
val stub = VersionServiceGrpc.stub(channel)
164+
val version = stub.getLedgerApiVersion(GetLedgerApiVersionRequest()).futureValue
165+
version.version should startWith("3.")
166+
}
167+
}
168+
135169
}
136170

137171
// Restore the node from backup
@@ -256,8 +290,6 @@ class DockerComposeValidatorFrontendIntegrationTest
256290
}
257291

258292
clue("validator and participant metrics work") {
259-
implicit val sys: ActorSystem = env.actorSystem
260-
registerHttpConnectionPoolsCleanup(env)
261293

262294
def metricsAreAvailableFor(node: String) = {
263295
val result = Http()

build-tools/splice-compose.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function _do_start_validator {
5757
"$@" \
5858
| tee -a "${SPLICE_ROOT}/log/compose.log" 2>&1 || _error "Failed to start validator, please check ${SPLICE_ROOT}/log/compose.log for details"
5959

60-
for c in validator participant; do
60+
for c in validator participant nginx; do
6161
docker logs -f splice-validator-${c}-1 >> "${SPLICE_ROOT}/log/compose-${c}.clog" 2>&1 &
6262
done
6363

cluster/compose/localnet/conf/nginx/app-provider.conf

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,34 @@ server {
1010
}
1111
}
1212

13+
# Deprecated, use json-ledger-api.localhost instead
1314
server {
1415
listen ${APP_PROVIDER_UI_PORT};
1516
server_name canton.localhost;
16-
location /docs/openapi {
17-
proxy_pass http://canton:3${PARTICIPANT_JSON_API_PORT_SUFFIX}/docs/openapi;
18-
include /etc/nginx/includes/cors-headers.conf;
17+
location / {
18+
proxy_pass http://canton:3${PARTICIPANT_JSON_API_PORT_SUFFIX};
19+
include /etc/nginx/includes/cors-headers.conf;
1920
}
21+
}
2022

21-
location /v2 {
22-
include /etc/nginx/includes/cors-options-headers.conf;
23-
proxy_pass http://canton:3${PARTICIPANT_JSON_API_PORT_SUFFIX}/v2;
24-
include /etc/nginx/includes/cors-headers.conf;
23+
server {
24+
listen ${APP_PROVIDER_UI_PORT};
25+
server_name json-ledger-api.localhost;
26+
location / {
27+
proxy_pass http://canton:3${PARTICIPANT_JSON_API_PORT_SUFFIX};
28+
include /etc/nginx/includes/cors-headers.conf;
2529
}
2630
}
2731

32+
server {
33+
listen ${APP_PROVIDER_UI_PORT} http2;
34+
server_name grpc-ledger-api.localhost;
35+
location / {
36+
grpc_pass grpc://canton:3${PARTICIPANT_LEDGER_API_PORT_SUFFIX};
37+
}
38+
}
39+
40+
2841
server {
2942
listen ${APP_PROVIDER_UI_PORT};
3043
server_name wallet.localhost;

cluster/compose/localnet/conf/nginx/app-user.conf

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,30 @@ server {
1010
}
1111
}
1212

13+
# Deprecated, use json-ledger-api.localhost instead
1314
server {
1415
listen ${APP_USER_UI_PORT};
1516
server_name canton.localhost;
16-
location /docs/openapi {
17-
proxy_pass http://canton:2${PARTICIPANT_JSON_API_PORT_SUFFIX}/docs/openapi;
18-
include /etc/nginx/includes/cors-headers.conf;
17+
location / {
18+
proxy_pass http://canton:2${PARTICIPANT_JSON_API_PORT_SUFFIX};
19+
include /etc/nginx/includes/cors-headers.conf;
20+
}
21+
}
22+
23+
server {
24+
listen ${APP_USER_UI_PORT};
25+
server_name json-ledger-api.localhost;
26+
location / {
27+
proxy_pass http://canton:2${PARTICIPANT_JSON_API_PORT_SUFFIX};
28+
include /etc/nginx/includes/cors-headers.conf;
1929
}
30+
}
2031

21-
location /v2 {
22-
include /etc/nginx/includes/cors-options-headers.conf;
23-
proxy_pass http://canton:2${PARTICIPANT_JSON_API_PORT_SUFFIX}/v2;
24-
include /etc/nginx/includes/cors-headers.conf;
32+
server {
33+
listen ${APP_USER_UI_PORT} http2;
34+
server_name grpc-ledger-api.localhost;
35+
location / {
36+
grpc_pass grpc://canton:2${PARTICIPANT_LEDGER_API_PORT_SUFFIX};
2537
}
2638
}
2739

cluster/compose/validator/compose.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ services:
150150
image: "nginx:${NGINX_VERSION}"
151151
volumes:
152152
- ./nginx.conf:/etc/nginx/nginx.conf
153+
- ./nginx:/etc/nginx/includes
153154
ports:
154155
- 80:80
155156
depends_on:

cluster/compose/validator/nginx.conf

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,33 @@ http {
4242
proxy_pass http://participant:10013/metrics;
4343
}
4444
}
45+
46+
server {
47+
listen 80;
48+
server_name json-ledger-api.localhost;
49+
location / {
50+
proxy_pass http://participant:7575;
51+
include /etc/nginx/includes/cors-headers.conf;
52+
}
53+
}
54+
55+
server {
56+
listen 80 http2;
57+
server_name grpc-ledger-api.localhost;
58+
location / {
59+
grpc_pass grpc://participant:5001;
60+
}
61+
}
62+
63+
# Note: There is no auth at the admin API at this point so this is not exposed
64+
# exposed by default. If you need it during development, you can enable this section.
65+
# If you need access in prod, make sure to protect access otherwise, e.g., through network restrictions.
66+
# server {
67+
# listen 80;
68+
# http2 on;
69+
# server_name grpc-admin-api.localhost;
70+
# location / {
71+
# grpc_pass grpc://participant:5002;
72+
# }
73+
# }
4574
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
add_header Access-Control-Allow-Origin *;
2+
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
3+
add_header Access-Control-Allow-Headers 'Origin, Content-Type, Accept';

docs/src/release_notes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ Upcoming
4545
- Canton/Sequencer Messages dashboard now includes hourly totals, and a pie chart of the
4646
distribution of message types over the last 24 hours.
4747

48+
- Validator Compose Deployment
49+
50+
- Expose Canton ledger API by default. Reference the :ref:`docs <compose_canton_apis>` for details.
51+
4852
- Daml
4953

5054
- Fix a bug where activity record expiration had a reference to the ``AmuletRules`` contract which resulted in transactions

docs/src/validator_operator/validator_compose.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,27 @@ You can open your browser at http://ans.localhost (note that this is currently b
138138
`ans` and not `cns`), and login using the same administrator user, or any other user that has been onboarded
139139
via the wallet, in order to purchase a CNS entry for that user.
140140

141+
.. _compose_canton_apis:
142+
143+
Accessing the Canton Participant APIs
144+
-------------------------------------
145+
146+
The `JSON Ledger API <https://docs.digitalasset.com/build/3.3/tutorials/json-api/canton_and_the_json_ledger_api.html>`_
147+
is exposed under ``json-ledger-api.localhost:80``. Note that for some
148+
clients you may explicitly need to set the ``Host:
149+
json-ledger-api.localhost`` header for this to get resolved correctly.
150+
151+
The `gRPC Ledger API
152+
<https://docs.digitalasset.com/build/3.3/explanations/ledger-api-services.html>`_
153+
is exposed under ``grpc-ledger-api.localhost:80``. Note that for some
154+
clients you may explicitly need to set the ``:authority:
155+
json-ledger-api.localhost`` pseudo-header for this to get resolved correctly.
156+
157+
The Canton Admin API is not exposed by default as it does not yet
158+
support auth. There is a commented out section in ``nginx.conf`` that
159+
you can enable to expose it if you ensure that it is not exposed
160+
publicly, e.g., through network restrictions.
161+
141162

142163
.. _compose_validator_auth:
143164

0 commit comments

Comments
 (0)