mirror of
https://github.com/trezor/blockbook.git
synced 2026-03-23 16:07:24 +01:00
ci/cd: both suffix & infix archive fallback mechanism
This commit is contained in:
@@ -366,9 +366,19 @@ func lookupEnvWithArchiveFallback(prefix, alias string) (string, bool) {
|
||||
|
||||
func aliasCandidates(alias string) []string {
|
||||
candidates := []string{alias}
|
||||
if !strings.HasSuffix(alias, archiveSuffix) {
|
||||
candidates = append(candidates, alias+archiveSuffix)
|
||||
if strings.Contains(alias, archiveSuffix) {
|
||||
return candidates
|
||||
}
|
||||
|
||||
candidates = append(candidates, alias+archiveSuffix)
|
||||
|
||||
if idx := strings.Index(alias, "_"); idx != -1 {
|
||||
infix := alias[:idx] + archiveSuffix + alias[idx:]
|
||||
if infix != alias && infix != alias+archiveSuffix {
|
||||
candidates = append(candidates, infix)
|
||||
}
|
||||
}
|
||||
|
||||
return candidates
|
||||
}
|
||||
|
||||
|
||||
53
build/tools/templates_test.go
Normal file
53
build/tools/templates_test.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package build
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestLookupEnvWithArchiveFallback_PrefersExactAlias(t *testing.T) {
|
||||
const prefix = "TEST_LOOKUP_PREFIX_"
|
||||
t.Setenv(prefix+"base", "https://base")
|
||||
t.Setenv(prefix+"base_archive", "https://base-archive")
|
||||
|
||||
got, ok := lookupEnvWithArchiveFallback(prefix, "base")
|
||||
if !ok {
|
||||
t.Fatal("expected exact alias lookup to succeed")
|
||||
}
|
||||
if got != "https://base" {
|
||||
t.Fatalf("expected exact alias to win, got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLookupEnvWithArchiveFallback_UsesArchiveSuffixFallback(t *testing.T) {
|
||||
const prefix = "TEST_LOOKUP_PREFIX_"
|
||||
t.Setenv(prefix+"base_archive", "https://base-archive")
|
||||
|
||||
got, ok := lookupEnvWithArchiveFallback(prefix, "base")
|
||||
if !ok {
|
||||
t.Fatal("expected suffix archive fallback to succeed")
|
||||
}
|
||||
if got != "https://base-archive" {
|
||||
t.Fatalf("unexpected suffix fallback value %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLookupEnvWithArchiveFallback_UsesArchiveInfixFallback(t *testing.T) {
|
||||
const prefix = "TEST_LOOKUP_PREFIX_"
|
||||
t.Setenv(prefix+"polygon_archive_bor", "https://polygon-archive")
|
||||
|
||||
got, ok := lookupEnvWithArchiveFallback(prefix, "polygon_bor")
|
||||
if !ok {
|
||||
t.Fatal("expected infix archive fallback to succeed")
|
||||
}
|
||||
if got != "https://polygon-archive" {
|
||||
t.Fatalf("unexpected infix fallback value %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLookupEnvWithArchiveFallback_DoesNotDoubleArchive(t *testing.T) {
|
||||
const prefix = "TEST_LOOKUP_PREFIX_"
|
||||
t.Setenv(prefix+"polygon_archive_archive_bor", "https://invalid")
|
||||
t.Setenv(prefix+"polygon_archive_bor_archive", "https://invalid")
|
||||
|
||||
if _, ok := lookupEnvWithArchiveFallback(prefix, "polygon_archive_bor"); ok {
|
||||
t.Fatal("unexpected lookup success for duplicate archive alias variants")
|
||||
}
|
||||
}
|
||||
@@ -90,10 +90,11 @@ command: `make NO_CACHE=true all-bitcoin`.
|
||||
|
||||
`BB_RPC_URL_HTTP_<coin alias>`: Overrides `ipc.rpc_url_template` while generating package definitions so you can target
|
||||
hosted HTTP RPC endpoints without editing coin JSON. The root `Makefile` forwards any `BB_RPC_URL_HTTP_*` variables into the
|
||||
Docker build/test containers.
|
||||
Docker build/test containers. Resolution prefers the exact alias and also accepts archive variants such as `<alias>_archive`
|
||||
and, for names like Polygon, `<prefix>_archive_<suffix>`.
|
||||
|
||||
`BB_RPC_URL_WS_<coin alias>`: Overrides `ipc.rpc_url_ws_template` for WebSocket subscriptions. It should point to the
|
||||
same host as `BB_RPC_URL_HTTP_<coin alias>`.
|
||||
same host as `BB_RPC_URL_HTTP_<coin alias>` and follows the same fallback resolution.
|
||||
|
||||
Example:
|
||||
`BB_RPC_URL_HTTP_ethereum=http://backend_hostname:1234 BB_RPC_URL_WS_ethereum_archive=ws://backend_hostname:1234 make deb-ethereum_archive`.
|
||||
|
||||
@@ -21,9 +21,10 @@ Some behavior of Blockbook can be modified by environment variables. The variabl
|
||||
## Build-time variables
|
||||
|
||||
- `BB_RPC_URL_HTTP_<coin alias>` - Overrides `ipc.rpc_url_template` during package/config generation so build and
|
||||
integration-test tooling can target hosted HTTP RPC endpoints without editing coin JSON.
|
||||
integration-test tooling can target hosted HTTP RPC endpoints without editing coin JSON. Lookup prefers the exact alias
|
||||
and also accepts archive variants like `<alias>_archive` and `<prefix>_archive_<suffix>`.
|
||||
- `BB_RPC_URL_WS_<coin alias>` - Overrides `ipc.rpc_url_ws_template` for WebSocket subscriptions; should point to
|
||||
the same host as `BB_RPC_URL_HTTP_<coin alias>`.
|
||||
the same host as `BB_RPC_URL_HTTP_<coin alias>` and follows the same fallback resolution.
|
||||
- `BB_RPC_BIND_HOST_<coin alias>` - Overrides backend RPC bind host during package/config generation; when set to
|
||||
`0.0.0.0`, RPC stays restricted unless `BB_RPC_ALLOW_IP_<coin alias>` is set.
|
||||
- `BB_RPC_ALLOW_IP_<coin alias>` - Overrides backend RPC allow list for UTXO configs (e.g. `rpcallowip`), defaulting
|
||||
|
||||
Reference in New Issue
Block a user