Skip to content

Commit c312577

Browse files
rebase cleanup
1 parent 0477581 commit c312577

File tree

4 files changed

+125
-47
lines changed

4 files changed

+125
-47
lines changed

framework/components/dockercompose/billing_platform_service/billing_platform_service.go

Lines changed: 84 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ package billing_platform_service
33
import (
44
"context"
55
"fmt"
6+
"os"
7+
"strconv"
8+
"strings"
69
"time"
710

811
"github.com/docker/docker/client"
@@ -14,6 +17,7 @@ import (
1417

1518
"github.com/smartcontractkit/chainlink-testing-framework/framework"
1619
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/dockercompose/utils"
20+
"github.com/smartcontractkit/freeport"
1721
)
1822

1923
const DefaultPostgresDSN = "postgres://postgres:postgres@postgres:5432/billing_platform"
@@ -24,23 +28,29 @@ type Output struct {
2428
}
2529

2630
type BillingPlatformServiceOutput struct {
27-
BillingGRPCInternalURL string
28-
BillingGRPCExternalURL string
29-
CreditGRPCInternalURL string
30-
CreditGRPCExternalURL string
31-
OwnershipGRPCInternalURL string
32-
OwnershipGRPCExternalURL string
31+
BillingGRPCInternalURL string
32+
BillingGRPCExternalURL string
33+
CreditGRPCInternalURL string
34+
CreditGRPCExternalURL string
3335
}
3436

3537
type PostgresOutput struct {
3638
DSN string
3739
}
3840

3941
type Input struct {
40-
ComposeFile string `toml:"compose_file"`
41-
ExtraDockerNetworks []string `toml:"extra_docker_networks"`
42-
Output *Output `toml:"output"`
43-
UseCache bool `toml:"use_cache"`
42+
ComposeFile string `toml:"compose_file"`
43+
ExtraDockerNetworks []string `toml:"extra_docker_networks"`
44+
Output *Output `toml:"output"`
45+
UseCache bool `toml:"use_cache"`
46+
ChainSelector uint64 `toml:"chain_selector"`
47+
StreamsAPIURL string `toml:"streams_api_url"`
48+
StreamsAPIKey string `toml:"streams_api_key"`
49+
StreamsAPISecret string `toml:"streams_api_secret"`
50+
RPCURL string `toml:"rpc_url"`
51+
WorkflowRegistryAddress string `toml:"workflow_registry_address"`
52+
CapabilitiesRegistryAddress string `toml:"capabilities_registry_address"`
53+
WorkflowOwners []string `toml:"workflow_owners"`
4454
}
4555

4656
func defaultBillingPlatformService(in *Input) *Input {
@@ -53,10 +63,11 @@ func defaultBillingPlatformService(in *Input) *Input {
5363
const (
5464
DEFAULT_STACK_NAME = "billing-platform-service"
5565

56-
DEFAULT_BILLING_PLATFORM_SERVICE_BILLING_GRPC_PORT = "2222"
57-
DEFAULT_BILLING_PLATFORM_SERVICE_CREDIT_GRPC_PORT = "2223"
58-
DEFAULT_BILLING_PLATFORM_SERVICE_OWNERSHIP_GRPC_PORT = "2257"
59-
DEFAULT_BILLING_PLATFORM_SERVICE_SERVICE_NAME = "billing-platform-service"
66+
DEFAULT_BILLING_PLATFORM_SERVICE_BILLING_GRPC_PORT = "2222"
67+
DEFAULT_BILLING_PLATFORM_SERVICE_CREDIT_GRPC_PORT = "2223"
68+
DEFAULT_POSTGRES_PORT = "5432"
69+
DEFAULT_BILLING_PLATFORM_SERVICE_SERVICE_NAME = "billing-platform-service"
70+
DEFAULT_POSTGRES_SERVICE_NAME = "postgres"
6071
)
6172

6273
func New(in *Input) (*Output, error) {
@@ -90,7 +101,46 @@ func New(in *Input) (*Output, error) {
90101
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
91102
defer cancel()
92103

93-
upErr := stack.Up(ctx)
104+
// Start the stackwith all environment variables from the host process
105+
// set development defaults for necessary environment variables and allow them to be overridden by the host process
106+
envVars := make(map[string]string)
107+
108+
envVars["MAINNET_WORKFLOW_REGISTRY_CHAIN_SELECTOR"] = strconv.FormatUint(in.ChainSelector, 10)
109+
envVars["MAINNET_WORKFLOW_REGISTRY_CONTRACT_ADDRESS"] = in.WorkflowRegistryAddress
110+
envVars["MAINNET_WORKFLOW_REGISTRY_RPC_URL"] = in.RPCURL
111+
envVars["MAINNET_WORKFLOW_REGISTRY_FINALITY_DEPTH"] = "0" // Instant finality on devnet
112+
envVars["KMS_PROOF_SIGNING_KEY_ID"] = "00000000-0000-0000-0000-000000000001" // provisioned via LocalStack
113+
envVars["VERIFIER_INITIAL_INTERVAL"] = "0s" // reduced to force verifier to start immediately in integration tests
114+
envVars["VERIFIER_MAXIMUM_INTERVAL"] = "1s" // reduced to force verifier to start immediately in integration tests
115+
envVars["LINKING_REQUEST_COOLDOWN"] = "0s" // reduced to force consequtive linking requests to be processed immediately in integration tests
116+
117+
envVars["MAINNET_CAPABILITIES_REGISTRY_CHAIN_SELECTOR"] = strconv.FormatUint(in.ChainSelector, 10)
118+
envVars["MAINNET_CAPABILITIES_REGISTRY_CONTRACT_ADDRESS"] = in.CapabilitiesRegistryAddress
119+
envVars["MAINNET_CAPABILITIES_REGISTRY_RPC_URL"] = in.RPCURL
120+
envVars["MAINNET_CAPABILITIES_REGISTRY_FINALITY_DEPTH"] = "10" // Arbitrary value, adjust as needed
121+
122+
envVars["TEST_OWNERS"] = strings.Join(in.WorkflowOwners, ",")
123+
envVars["STREAMS_API_URL"] = in.StreamsAPIURL
124+
envVars["STREAMS_API_KEY"] = in.StreamsAPIKey
125+
envVars["STREAMS_API_SECRET"] = in.StreamsAPISecret
126+
127+
port, err := freeport.Take(1)
128+
if err != nil {
129+
return nil, errors.Wrap(err, "failed to get free port for Billing Platform Service postgres")
130+
}
131+
132+
envVars["POSTGRES_PORT"] = strconv.FormatInt(int64(port[0]), 10)
133+
134+
for _, env := range os.Environ() {
135+
pair := strings.SplitN(env, "=", 2)
136+
if len(pair) == 2 {
137+
envVars[pair[0]] = pair[1]
138+
}
139+
}
140+
141+
upErr := stack.
142+
WithEnv(envVars).
143+
Up(ctx)
94144

95145
if upErr != nil {
96146
return nil, errors.Wrap(upErr, "failed to start stack for Billing Platform Service")
@@ -101,7 +151,6 @@ func New(in *Input) (*Output, error) {
101151
wait.ForLog("GRPC server is live").WithPollInterval(200*time.Millisecond),
102152
wait.ForListeningPort(DEFAULT_BILLING_PLATFORM_SERVICE_BILLING_GRPC_PORT),
103153
wait.ForListeningPort(DEFAULT_BILLING_PLATFORM_SERVICE_CREDIT_GRPC_PORT),
104-
wait.ForListeningPort(DEFAULT_BILLING_PLATFORM_SERVICE_OWNERSHIP_GRPC_PORT),
105154
).WithDeadline(1*time.Minute),
106155
)
107156

@@ -110,6 +159,11 @@ func New(in *Input) (*Output, error) {
110159
return nil, errors.Wrap(billingErr, "failed to get billing-platform-service container")
111160
}
112161

162+
postgresContainer, postgresErr := stack.ServiceContainer(ctx, DEFAULT_POSTGRES_SERVICE_NAME)
163+
if postgresErr != nil {
164+
return nil, errors.Wrap(postgresErr, "failed to get postgres container")
165+
}
166+
113167
cli, cliErr := client.NewClientWithOpts(
114168
client.FromEnv,
115169
client.WithAPIVersionNegotiation(),
@@ -152,16 +206,27 @@ func New(in *Input) (*Output, error) {
152206
return nil, errors.Wrap(billingExternalHostErr, "failed to get host for Billing Platform Service")
153207
}
154208

209+
// get hosts for billing platform service
210+
postgresExternalHost, postgresExternalHostErr := utils.GetContainerHost(ctx, postgresContainer)
211+
if postgresExternalHostErr != nil {
212+
return nil, errors.Wrap(postgresExternalHostErr, "failed to get host for postgres")
213+
}
214+
155215
// get mapped ports for billing platform service
156216
serviceOutput, err := getExternalPorts(ctx, billingExternalHost, billingContainer)
157217
if err != nil {
158218
return nil, errors.Wrap(err, "failed to get mapped port for Billing Platform Service")
159219
}
160220

221+
externalPostgresPort, err := utils.FindMappedPort(ctx, 20*time.Second, postgresContainer, nat.Port(DEFAULT_POSTGRES_PORT+"/tcp"))
222+
if err != nil {
223+
return nil, errors.Wrap(err, "failed to get mapped port for postgres")
224+
}
225+
161226
output := &Output{
162227
BillingPlatformService: serviceOutput,
163228
Postgres: &PostgresOutput{
164-
DSN: DefaultPostgresDSN,
229+
DSN: fmt.Sprintf("postgres://postgres:postgres@%s:%s/billing_platform", postgresExternalHost, externalPostgresPort.Port()),
165230
},
166231
}
167232

@@ -172,9 +237,8 @@ func New(in *Input) (*Output, error) {
172237

173238
func getExternalPorts(ctx context.Context, billingExternalHost string, billingContainer *testcontainers.DockerContainer) (*BillingPlatformServiceOutput, error) {
174239
ports := map[string]nat.Port{
175-
"billing": DEFAULT_BILLING_PLATFORM_SERVICE_BILLING_GRPC_PORT,
176-
"credit": DEFAULT_BILLING_PLATFORM_SERVICE_CREDIT_GRPC_PORT,
177-
"ownership": DEFAULT_BILLING_PLATFORM_SERVICE_OWNERSHIP_GRPC_PORT,
240+
"billing": DEFAULT_BILLING_PLATFORM_SERVICE_BILLING_GRPC_PORT,
241+
"credit": DEFAULT_BILLING_PLATFORM_SERVICE_CREDIT_GRPC_PORT,
178242
}
179243

180244
output := BillingPlatformServiceOutput{}
@@ -195,9 +259,6 @@ func getExternalPorts(ctx context.Context, billingExternalHost string, billingCo
195259
case "credit":
196260
output.CreditGRPCInternalURL = internal
197261
output.CreditGRPCExternalURL = external
198-
case "ownership":
199-
output.OwnershipGRPCInternalURL = internal
200-
output.OwnershipGRPCExternalURL = external
201262
}
202263
}
203264

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,40 @@
11
services:
2+
23
billing-platform-service:
3-
restart: on-failure
4-
tty: true
5-
container_name: billing-platform-service
64
image: ${BILLING_PLATFORM_SERVICE_IMAGE:-billing-platform-service:local-cre}
7-
command: ["grpc-service"]
5+
container_name: billing-platform-service
86
depends_on:
97
postgres:
108
condition: service_healthy
119
migrations:
1210
condition: service_started
13-
ports:
14-
- "2112:2112"
15-
- "2222:2222"
16-
- "2223:2223"
17-
- "2257:2257"
11+
restart: on-failure
12+
tty: true
13+
command: ["grpc", "billing", "reserve"]
1814
environment:
15+
DISABLE_AUTH: true
1916
PROMETHEUS_PORT: 2112
2017
BILLING_SERVER_PORT: 2222
2118
CREDIT_RESERVATION_SERVER_PORT: 2223
22-
WORKFLOW_OWNERSHIP_PROOF_SERVER_PORT: 2257
2319
WORKFLOW_OWNERSHIP_PROOF_SERVER_HOST: 0.0.0.0
20+
MAINNET_WORKFLOW_REGISTRY_CHAIN_SELECTOR: ${MAINNET_WORKFLOW_REGISTRY_CHAIN_SELECTOR:-}
21+
TESTNET_WORKFLOW_REGISTRY_CHAIN_SELECTOR: ${MAINNET_WORKFLOW_REGISTRY_CHAIN_SELECTOR:-}
22+
MAINNET_WORKFLOW_REGISTRY_CONTRACT_ADDRESS: ${MAINNET_WORKFLOW_REGISTRY_CONTRACT_ADDRESS:-}
23+
TESTNET_WORKFLOW_REGISTRY_CONTRACT_ADDRESS: ${MAINNET_WORKFLOW_REGISTRY_CONTRACT_ADDRESS:-}
24+
MAINNET_WORKFLOW_REGISTRY_RPC_URL: ${MAINNET_WORKFLOW_REGISTRY_RPC_URL:-}
25+
TESTNET_WORKFLOW_REGISTRY_RPC_URL: ${MAINNET_WORKFLOW_REGISTRY_RPC_URL:-}
26+
MAINNET_WORKFLOW_REGISTRY_FINALITY_DEPTH: ${MAINNET_WORKFLOW_REGISTRY_FINALITY_DEPTH:-}
27+
KMS_PROOF_SIGNING_KEY_ID: ${KMS_PROOF_SIGNING_KEY_ID:-}
28+
VERIFIER_INITIAL_INTERVAL: ${VERIFIER_INITIAL_INTERVAL:-}
29+
VERIFIER_MAXIMUM_INTERVAL: ${VERIFIER_MAXIMUM_INTERVAL:-}
30+
LINKING_REQUEST_COOLDOWN: ${LINKING_REQUEST_COOLDOWN:-}
31+
MAINNET_CAPABILITIES_REGISTRY_CHAIN_SELECTOR: ${MAINNET_CAPABILITIES_REGISTRY_CHAIN_SELECTOR:-}
32+
TESTNET_CAPABILITIES_REGISTRY_CHAIN_SELECTOR: ${MAINNET_CAPABILITIES_REGISTRY_CHAIN_SELECTOR:-}
33+
MAINNET_CAPABILITIES_REGISTRY_CONTRACT_ADDRESS: ${MAINNET_CAPABILITIES_REGISTRY_CONTRACT_ADDRESS:-}
34+
MAINNET_CAPABILITIES_REGISTRY_RPC_URL: ${MAINNET_CAPABILITIES_REGISTRY_RPC_URL:-}
35+
TESTNET_CAPABILITIES_REGISTRY_RPC_URL: ${MAINNET_CAPABILITIES_REGISTRY_RPC_URL:-}
36+
MAINNET_CAPABILITIES_REGISTRY_FINALITY_DEPTH: ${MAINNET_CAPABILITIES_REGISTRY_FINALITY_DEPTH:-}
37+
TEST_OWNERS: ${TEST_OWNERS:-}
2438
STREAMS_API_URL: ${STREAMS_API_URL:-}
2539
STREAMS_API_KEY: ${STREAMS_API_KEY:-}
2640
STREAMS_API_SECRET: ${STREAMS_API_SECRET:-}
@@ -29,6 +43,10 @@ services:
2943
DB_NAME: billing_platform
3044
DB_USERNAME: postgres
3145
DB_PASSWORD: postgres
46+
ports:
47+
- "2112:2112"
48+
- "2222:2222"
49+
- "2223:2223"
3250
healthcheck:
3351
test: ["CMD", "grpc_health_probe", "-addr=localhost:2222"]
3452
interval: 200ms
@@ -45,35 +63,31 @@ services:
4563
POSTGRES_HOST: postgres
4664
POSTGRES_USER: postgres
4765
POSTGRES_PASSWORD: postgres
66+
ports:
67+
- "${POSTGRES_PORT:-5432}:5432"
4868
healthcheck:
4969
test: ["CMD","pg_isready","-U","${POSTGRES_USER}","-d","${POSTGRES_DB}","-h","${POSTGRES_HOST}"]
5070
interval: 5s
5171
timeout: 10s
5272
retries: 3
53-
ports:
54-
- "5432:5432"
5573

5674
migrations:
5775
image: ${BILLING_PLATFORM_SERVICE_IMAGE:-billing-platform-service:local-cre}
5876
container_name: db-migrations-billing-platform
59-
restart: on-failure
60-
command: ["db", "create-and-migrate", "--url=${DATABASE_URL}"]
61-
environment:
62-
DATABASE_URL: postgres://postgres:postgres@postgres:postgres/billing_platform
63-
networks:
64-
- backend
6577
depends_on:
6678
postgres:
6779
condition: service_healthy
80+
restart: on-failure
81+
command: ["db", "create-and-migrate", "--url", "postgres://postgres:postgres@postgres:5432/billing_platform?sslmode=disable"]
6882

6983
populate_test_data:
7084
image: ${BILLING_PLATFORM_SERVICE_IMAGE:-billing-platform-service:local-cre}
71-
container_name: db-migrations-billing-platform
72-
restart: on-failure
73-
command: ["populate-db", "--environment=local"]
85+
container_name: populate-data-billing-platform
7486
depends_on:
7587
billing-platform-service:
7688
condition: service_started
77-
networks:
78-
- backend
79-
89+
restart: on-failure
90+
command: ["db", "populate-data", "--environment=local", "--billing-client-url=billing-platform-service:2222", "--simple-linking", "--dsn=postgres://postgres:postgres@postgres:5432/billing_platform?sslmode=disable"]
91+
environment:
92+
TEST_OWNERS: ${TEST_OWNERS:-}
93+
MAINNET_CAPABILITIES_REGISTRY_CHAIN_SELECTOR: ${MAINNET_CAPABILITIES_REGISTRY_CHAIN_SELECTOR:-}

framework/components/dockercompose/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ require (
1212
github.com/google/go-github/v72 v72.0.0
1313
github.com/pkg/errors v0.9.1
1414
github.com/smartcontractkit/chainlink-testing-framework/framework v0.0.0-00010101000000-000000000000
15+
github.com/smartcontractkit/freeport v0.1.2
1516
github.com/testcontainers/testcontainers-go v0.37.0
1617
github.com/testcontainers/testcontainers-go/modules/compose v0.37.0
1718
golang.org/x/oauth2 v0.25.0

framework/components/dockercompose/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,8 @@ github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ
567567
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
568568
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 h1:JIAuq3EEf9cgbU6AtGPK4CTG3Zf6CKMNqf0MHTggAUA=
569569
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog=
570+
github.com/smartcontractkit/freeport v0.1.2 h1:xMZ0UFHmjfB4MwbDANae3RS7UKt7OJ0JVqhjPSXdKVk=
571+
github.com/smartcontractkit/freeport v0.1.2/go.mod h1:T4zH9R8R8lVWKfU7tUvYz2o2jMv1OpGCdpY2j2QZXzU=
570572
github.com/spdx/tools-golang v0.5.3 h1:ialnHeEYUC4+hkm5vJm4qz2x+oEJbS0mAMFrNXdQraY=
571573
github.com/spdx/tools-golang v0.5.3/go.mod h1:/ETOahiAo96Ob0/RAIBmFZw6XN0yTnyr/uFZm2NTMhI=
572574
github.com/spf13/cast v0.0.0-20150508191742-4d07383ffe94 h1:JmfC365KywYwHB946TTiQWEb8kqPY+pybPLoGE9GgVk=

0 commit comments

Comments
 (0)