Skip to content

Commit 8d11e0d

Browse files
authored
feat: cre local env setup validation (#18174)
script
1 parent 8e4abfc commit 8d11e0d

File tree

4 files changed

+656
-74
lines changed

4 files changed

+656
-74
lines changed

core/scripts/cre/environment/docs.md

Lines changed: 82 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Local CRE environment
22

3+
## Contact Us
4+
Slack: #topic-local-dev-environments
5+
36
## Table of content
47

58
1. [Using the CLI](#using-the-cli)
@@ -16,83 +19,32 @@
1619

1720
The CLI manages CRE test environments. It is located in `core/scripts/cre/environment`.
1821

22+
23+
1924
## Prerequisites (for Docker) ###
2025
1. **Docker installed and running**
2126
- with usage of default Docker socket **enabled**
2227
- with Apple Virtualization framework **enabled**
2328
- with VirtioFS **enabled**
2429
- with use of containerd for pulling and storing images **disabled**
25-
2. **Job Distributor Docker image available**
26-
- Either build it locally as described in [this section](#job-distributor-image)
27-
- or download it from the PROD ECR (if you have access) and tag as `job-distributor:0.9.0`
28-
29-
If you want to run an example workflow you also need to:
30-
31-
1. **Download CRE CLI v0.2.0**
32-
- download it either from [smartcontract/dev-platform](https://github.com/smartcontractkit/dev-platform/releases/tag/v0.2.0)
33-
- or using GH CLI by running: `gh release download v0.2.0 --repo smartcontractkit/dev-platform --pattern 'cre_v0.2.0_darwin_arm64.tar.gz'`
34-
- once you have the archive downloaded run:
35-
```bash
36-
tar -xf cre_v0.2.0_darwin_arm64.tar.gz
37-
rm cre_v0.2.0_darwin_arm64.tar.gz
38-
# do not worry about potential 'No such xattr: com.apple.quarantine' error
39-
xattr -d com.apple.quarantine cre_v0.2.0_darwin_arm64
40-
export "PATH=$(pwd):$PATH"
41-
```
42-
43-
> Minimum required version of the `GH CLI` is `v2.50.0`
44-
45-
Optionally:
46-
1. **Choose the Right Topology**
47-
- For a single DON with all capabilities: `configs/single-don.toml` (default)
48-
- For a full topology (workflow DON + capabilities DON + gateway DON): `configs/workflow-capabilities-don.toml`
49-
2. **Download or Build Capability Binaries**
50-
- Some capabilities like `cron`, `log-event-trigger`, or `read-contract` are not embedded in all Chainlink images.
51-
- If your use case requires them, you can either:
52-
- Download binaries from [smartcontractkit/capabilities](https://github.com/smartcontractkit/capabilities/releases/tag/v1.0.2-alpha) release page or
53-
- Use GH CLI to download them, e.g. `gh release download v1.0.2-alpha --repo smartcontractkit/capabilities --pattern 'amd64_cron' && mv amd64_cron cron`
54-
Make sure they are built for `linux/amd64`!
55-
56-
Once that is done reference them in your TOML like:
57-
```toml
58-
[extra_capabilities]
59-
cron_capability_binary_path = "./cron" # remember to adjust binary name and path
60-
# log even trigger and read-contract binaries go here
61-
# they are all commented out by default
62-
```
63-
Do make sure that the path to the binary is either relative to the `environment` folder or absolute. Then the binary will be copied to the Docker image.
64-
- If the capability is already baked into your CL image (check the Dockerfile), comment out the TOML path line to skip copying. (they will be commented out by default)
65-
3. **Decide whether to build or reuse Chainlink Docker Image**
66-
- By default, the config builds the Docker image from your local branch. To use an existing image change to:
67-
```toml
68-
[nodesets.node_specs.node]
69-
image = "<your-Docker-image>:<your-tag>"
70-
```
71-
- Make these changes for **all** nodes in the nodeset in the TOML config.
72-
- If you decide to reuse a Chainlink Docker Image using the `--with-plugins-docker-image` flag, please notice that this will not copy any capability binaries to the image.
73-
You will need to make sure that all the capabilities you need are baked in the image you are using.
30+
2. **AWS SSO access to SDLC**
31+
- REQUIRED: `sdlc` profile
32+
3. **gh cli**
33+
- To pull the `cre` cli. Minimum version `v.2.50.0`
7434

75-
4. **Decide whether to use Docker or k8s**
76-
- Read [Docker vs Kubernetes in guidelines.md](../../../../system-tests/tests/smoke/cre/guidelines.md) to learn how to switch between Docker and Kubernetes
77-
5. **Start Observability Stack (Docker-only)**
78-
```bash
79-
# to start Loki, Grafana and Prometheus run:
80-
ctf obs up
8135

82-
# to start Blockscout block explorer run:
83-
ctf bs u
84-
```
85-
- To download the `ctf` binary follow the steps described [here](https://smartcontractkit.github.io/chainlink-testing-framework/framework/getting_started.html)
86-
87-
Optional environment variables used by the CLI:
88-
- `CTF_CONFIGS`: TOML config paths. Defaults to [./configs/single-don.toml](./configs/single-don.toml)
89-
- `PRIVATE_KEY`: Plaintext private key that will be used for all deployments (needs to be funded). Defaults to `ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80`
90-
- `TESTCONTAINERS_RYUK_DISABLED`: Set to "true" to disable cleanup. Defaults to `false`
36+
[See more for configuring AWS in CLL](https://smartcontract-it.atlassian.net/wiki/spaces/INFRA/pages/1045495923/Configure+the+AWS+CLI)
9137

92-
When starting the environment in AWS-managed Kubernetes make sure to source `.env` environment from the `crib/deployments/cre` folder specific for AWS. Remember, that it must include ingress domain settings.
9338

94-
---
39+
# QUICKSTART
40+
```
41+
go run main.go env setup --config single-don.toml
42+
go run main.go env start
43+
```
9544

45+
The script will ensure all pre-requisites are configured and installed for the `single-don.toml` profile.
46+
If you are missing requirements, you may need to fix the errors and re-run.
47+
Use `#topic-local-dev-environments` for help
9648
## Start Environment
9749
```bash
9850
# while in core/scripts/cre/environment
@@ -154,6 +106,60 @@ Remember that the CRE CLI version needs to match your CPU architecture and opera
154106

155107
---
156108

109+
110+
### Advanced Usage:
111+
1. **Choose the Right Topology**
112+
- For a single DON with all capabilities: `configs/single-don.toml` (default)
113+
- For a full topology (workflow DON + capabilities DON + gateway DON): `configs/workflow-capabilities-don.toml`
114+
2. **Download or Build Capability Binaries**
115+
- Some capabilities like `cron`, `log-event-trigger`, or `read-contract` are not embedded in all Chainlink images.
116+
- If your use case requires them, you can either:
117+
- Download binaries from [smartcontractkit/capabilities](https://github.com/smartcontractkit/capabilities/releases/tag/v1.0.2-alpha) release page or
118+
- Use GH CLI to download them, e.g. `gh release download v1.0.2-alpha --repo smartcontractkit/capabilities --pattern 'amd64_cron' && mv amd64_cron cron`
119+
Make sure they are built for `linux/amd64`!
120+
121+
Once that is done reference them in your TOML like:
122+
```toml
123+
[extra_capabilities]
124+
cron_capability_binary_path = "./cron" # remember to adjust binary name and path
125+
# log even trigger and read-contract binaries go here
126+
# they are all commented out by default
127+
```
128+
Do make sure that the path to the binary is either relative to the `environment` folder or absolute. Then the binary will be copied to the Docker image.
129+
- If the capability is already baked into your CL image (check the Dockerfile), comment out the TOML path line to skip copying. (they will be commented out by default)
130+
3. **Decide whether to build or reuse Chainlink Docker Image**
131+
- By default, the config builds the Docker image from your local branch. To use an existing image change to:
132+
```toml
133+
[nodesets.node_specs.node]
134+
image = "<your-Docker-image>:<your-tag>"
135+
```
136+
- Make these changes for **all** nodes in the nodeset in the TOML config.
137+
- If you decide to reuse a Chainlink Docker Image using the `--with-plugins-docker-image` flag, please notice that this will not copy any capability binaries to the image.
138+
You will need to make sure that all the capabilities you need are baked in the image you are using.
139+
140+
4. **Decide whether to use Docker or k8s**
141+
- Read [Docker vs Kubernetes in guidelines.md](../../../../system-tests/tests/smoke/cre/guidelines.md) to learn how to switch between Docker and Kubernetes
142+
5. **Start Observability Stack (Docker-only)**
143+
```bash
144+
# to start Loki, Grafana and Prometheus run:
145+
ctf obs up
146+
147+
# to start Blockscout block explorer run:
148+
ctf bs u
149+
```
150+
- To download the `ctf` binary follow the steps described [here](https://smartcontractkit.github.io/chainlink-testing-framework/framework/getting_started.html)
151+
152+
Optional environment variables used by the CLI:
153+
- `CTF_CONFIGS`: TOML config paths. Defaults to [./configs/single-don.toml](./configs/single-don.toml)
154+
- `PRIVATE_KEY`: Plaintext private key that will be used for all deployments (needs to be funded). Defaults to `ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80`
155+
- `TESTCONTAINERS_RYUK_DISABLED`: Set to "true" to disable cleanup. Defaults to `false`
156+
157+
When starting the environment in AWS-managed Kubernetes make sure to source `.env` environment from the `crib/deployments/cre` folder specific for AWS. Remember, that it must include ingress domain settings.
158+
159+
---
160+
161+
162+
157163
## DX Tracing
158164

159165
To track environment usage and quality metrics (success/failure rate, startup time) local CRE environment is integrated with DX. If you have `gh cli` configured and authenticated on your local machine it will be used to automatically setup DX integration in the background. If you don't, tracing data will be stored locally in `~/.dx/` and uploaded once either `gh cli` is available or valid `~/.dx/config.json` file appears.
@@ -228,6 +234,16 @@ You might see multiple attempts to trigger and verify that workflow, when runnin
228234
### Docker fails to download public images
229235
Make sure you are logged in to Docker. Run: `docker login`
230236

237+
```
238+
Error: failed to setup test environment: failed to create blockchains: failed to deploy blockchain: create container: Error response from daemon: Head "https://ghcr.io/v2/foundry-rs/foundry/manifests/stable": denied: denied
239+
```
240+
your ghcr token is stale. do
241+
```
242+
docker logout ghcr.io
243+
docker pull ghcr.io/foundry-rs/foundry
244+
```
245+
and try starting the environment
246+
231247
### GH CLI is not installed
232248
Either download from [cli.github.com](https://cli.github.com) or install with Homebrew with:
233249
```bash

core/scripts/cre/environment/environment/environment.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package environment
33
import (
44
"context"
55
"crypto/ecdsa"
6+
"crypto/rand"
7+
"encoding/hex"
68
"encoding/json"
79
"fmt"
810
"os"
@@ -152,11 +154,12 @@ var (
152154
var StartCmdPreRunFunc = func(cmd *cobra.Command, args []string) {
153155
provisioningStartTime = time.Now()
154156

155-
var dxErr error
156-
dxTracker, dxErr = tracking.NewDxTracker()
157-
if dxErr != nil {
158-
fmt.Fprintf(os.Stderr, "failed to create DX tracker: %s\n", dxErr)
159-
dxTracker = &tracking.NoOpTracker{}
157+
// ensure non-nil dxTracker by default
158+
dxTracker = new(tracking.DxTracker)
159+
if t, err := tracking.NewDxTracker(); err != nil {
160+
fmt.Fprintf(os.Stderr, "failed to create DX tracker: %s\n", err)
161+
} else {
162+
dxTracker = t
160163
}
161164

162165
// remove all containers before starting the environment, just in case
@@ -222,7 +225,7 @@ var StartCmdGenerateSettingsFile = func(homeChainOut *creenv.BlockchainOutput, o
222225
creCLISettingsFile, settingsErr := crecli.PrepareCRECLISettingsFile(
223226
crecli.CRECLIProfile,
224227
homeChainOut.SethClient.MustGetRootKeyAddress(),
225-
output.CldEnvironment.ExistingAddresses, //nolint:staticcheck // won't migrate now
228+
output.CldEnvironment.ExistingAddresses, //nolint:staticcheck // ignore SA1019 as ExistingAddresses is deprecated but still used
226229
output.DonTopology.WorkflowDonID,
227230
homeChainOut.ChainSelector,
228231
rpcs,
@@ -628,6 +631,15 @@ func StartCLIEnvironment(
628631
))
629632
}
630633

634+
if in.JD.CSAEncryptionKey == "" {
635+
// generate a new key
636+
key, keyErr := ecdsa.GenerateKey(crypto.S256(), rand.Reader)
637+
if keyErr != nil {
638+
return nil, fmt.Errorf("failed to generate CSA encryption key: %w", keyErr)
639+
}
640+
in.JD.CSAEncryptionKey = hex.EncodeToString(crypto.FromECDSA(key)[:32])
641+
fmt.Printf("Generated new CSA encryption key for JD: %s\n", in.JD.CSAEncryptionKey)
642+
}
631643
universalSetupInput := creenv.SetupInput{
632644
CapabilitiesAwareNodeSets: capabilitiesAwareNodeSets,
633645
CapabilitiesContractFactoryFunctions: capabilityFactoryFns,

0 commit comments

Comments
 (0)