Skip to content

Commit 1cc7134

Browse files
authored
[LW-10042] chore: accept older minor/patch versions in routes (#1146)
* chore: accept older minor/patch versions in routes LW-10042 chore: reuse only the same major versions in supportedVersions.json chore: syntax errors, whitespace chore: cardano-services-client build in the Dockerfile (?) chore: revive `createVersionSource.js --check` * ci: try setting `max_old_space_size = 8192` … but it doesn’t make sense, since the build works on my machine?
1 parent 19a8cf7 commit 1cc7134

File tree

7 files changed

+78
-35
lines changed

7 files changed

+78
-35
lines changed

nix/cardano-services/deployments/backend-ingress.nix

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
++ lib.optionals config.providers.stake-pool-provider.enabled [
6969
{
7070
pathType = "Prefix";
71-
path = "/v${values.cardano-services.versions.stakePool}/stake-pool";
71+
path = "/v${lib.last (lib.sort lib.versionOlder values.cardano-services.versions.stakePool)}/stake-pool";
7272
backend.service = {
7373
name = "${chart.name}-stake-pool-provider";
7474
port.name = "http";
@@ -78,7 +78,7 @@
7878
++ lib.optionals config.providers.handle-provider.enabled [
7979
{
8080
pathType = "Prefix";
81-
path = "/v${values.cardano-services.versions.handle}/handle";
81+
path = "/v${lib.last (lib.sort lib.versionOlder values.cardano-services.versions.handle)}/handle";
8282
backend.service = {
8383
name = "${chart.name}-handle-provider";
8484
port.name = "http";
@@ -88,7 +88,7 @@
8888
++ lib.optionals config.providers.asset-provider.enabled [
8989
{
9090
pathType = "Prefix";
91-
path = "/v${values.cardano-services.versions.handle}/asset";
91+
path = "/v${lib.last (lib.sort lib.versionOlder values.cardano-services.versions.handle)}/asset";
9292
backend.service = {
9393
name = "${chart.name}-asset-provider";
9494
port.name = "http";

nix/cardano-services/deployments/default.nix

+14-13
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ in
8383
image = oci.image.name;
8484
buildInfo = oci.meta.buildInfo;
8585
versions = oci.meta.versions;
86-
httpPrefix = "/v${oci.meta.versions.root}";
86+
httpPrefix = "/v${lib.last (lib.sort lib.versionOlder oci.meta.versions.root)}";
8787

8888
loggingLevel = "debug";
8989
tokenMetadataServerUrl = "http://${final.namespace}-cardano-stack-metadata.${final.namespace}.svc.cluster.local";
@@ -131,18 +131,19 @@ in
131131
};
132132
routes = let
133133
inherit (oci.meta) versions;
134-
in [
135-
"/v${versions.root}/health"
136-
"/v${versions.root}/live"
137-
"/v${versions.root}/meta"
138-
"/v${versions.root}/ready"
139-
"/v${versions.assetInfo}/asset"
140-
"/v${versions.chainHistory}/chain-history"
141-
"/v${versions.networkInfo}/network-info"
142-
"/v${versions.rewards}/rewards"
143-
"/v${versions.txSubmit}/tx-submit"
144-
"/v${versions.utxo}/utxo"
145-
];
134+
in
135+
lib.concatLists [
136+
(map (v: "/v${v}/health") versions.root)
137+
(map (v: "/v${v}/live") versions.root)
138+
(map (v: "/v${v}/meta") versions.root)
139+
(map (v: "/v${v}/ready") versions.root)
140+
(map (v: "/v${v}/asset") versions.assetInfo)
141+
(map (v: "/v${v}/chain-history") versions.chainHistory)
142+
(map (v: "/v${v}/network-info") versions.networkInfo)
143+
(map (v: "/v${v}/rewards") versions.rewards)
144+
(map (v: "/v${v}/tx-submit") versions.txSubmit)
145+
(map (v: "/v${v}/utxo") versions.utxo)
146+
];
146147
};
147148
};
148149
imports = [

nix/cardano-services/oci-images.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ in {
1616
name = "926093910549.dkr.ecr.us-east-1.amazonaws.com/cardano-services";
1717
operable = cell.operables.cardano-services;
1818
meta.description = "Minimal Cardano Services OCI Image";
19-
meta.versions = builtins.fromJSON (builtins.readFile (self + /packages/cardano-services-client/version.json));
19+
meta.versions = builtins.fromJSON (builtins.readFile (self + /packages/cardano-services-client/supportedVersions.json));
2020
meta.buildInfo = buildInfo;
2121
};
2222
}

nix/cardano-services/packages.nix

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ in {
2828
oldAttrs.configurePhase;
2929
# A bunch of deps build binaries using node-gyp that requires Python
3030
PYTHON = "${nixpkgs.python3}/bin/python3";
31+
NODE_OPTIONS = "--max_old_space_size=8192";
3132
# node-hid uses pkg-config to find sources
3233
buildInputs = oldAttrs.buildInputs ++ [nixpkgs.pkg-config nixpkgs.libusb1];
3334

@@ -46,6 +47,7 @@ in {
4647
project.overrideAttrs (oldAttrs: {
4748
# A bunch of deps build binaries using node-gyp that requires Python
4849
PYTHON = "${nixpkgs.python3}/bin/python3";
50+
NODE_OPTIONS = "--max_old_space_size=8192";
4951
# playwright build fixes
5052
PLAYWRIGHT_BROWSERS_PATH = nixpkgs.playwright-driver.browsers;
5153
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD = 1;

packages/cardano-services-client/scripts/createVersionSource.js

+28-7
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,42 @@ const apiVersion = Object.fromEntries(
2222
])
2323
);
2424

25-
const versionFile = path.join(__dirname, '../version.json');
25+
const supportedVersionsFile = path.join(__dirname, '../supportedVersions.json');
26+
const sameMajorVersion = (a) => (b) => {
27+
const [majorA] = a.split('.');
28+
const [majorB] = b.split('.');
29+
return majorA === majorB;
30+
};
31+
const supportedVersions = (() => {
32+
let rv = {};
33+
if (fs.existsSync(supportedVersionsFile)) {
34+
const data = fs.readFileSync(supportedVersionsFile, { encoding: 'utf8' });
35+
rv = JSON.parse(data);
36+
}
37+
for (const [api, version] of Object.entries(apiVersion)) {
38+
const previouslySupported = rv[api] ?? [];
39+
rv[api] = previouslySupported.includes(apiVersion[api])
40+
? previouslySupported
41+
: [...previouslySupported.filter(sameMajorVersion(version)), version];
42+
}
43+
return rv;
44+
})();
45+
2646
const create = () => {
27-
const version = JSON.stringify(apiVersion, null, 2);
47+
fs.writeFileSync(supportedVersionsFile, `${JSON.stringify(supportedVersions, null, 2)}\n`, {
48+
encoding: 'utf8',
49+
flag: 'w'
50+
});
2851
const contents = `// auto-generated using ../scripts/createVersionSource.js
29-
export const apiVersion = ${version};
30-
`;
31-
52+
export const apiVersion = ${JSON.stringify(apiVersion, null, 2)};
53+
`;
3254
fs.writeFileSync(path.join(__dirname, '../src/version.ts'), contents, { encoding: 'utf8', flag: 'w' });
33-
fs.writeFileSync(versionFile, `${version}\n`, { encoding: 'utf8', flag: 'w' });
3455
};
3556

3657
switch (argv[2]) {
3758
case '--check':
3859
try {
39-
deepEqual(JSON.parse(fs.readFileSync(versionFile, { encoding: 'utf8' })), apiVersion);
60+
deepEqual(JSON.parse(fs.readFileSync(supportedVersionsFile, { encoding: 'utf8' })), supportedVersions);
4061
exit(1);
4162
} catch {
4263
exit(0);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"assetInfo": [
3+
"1.0.0"
4+
],
5+
"chainHistory": [
6+
"3.0.0",
7+
"3.0.1"
8+
],
9+
"handle": [
10+
"1.0.0"
11+
],
12+
"networkInfo": [
13+
"1.0.0"
14+
],
15+
"rewards": [
16+
"1.0.0"
17+
],
18+
"root": [
19+
"1.0.0"
20+
],
21+
"stakePool": [
22+
"1.1.0"
23+
],
24+
"txSubmit": [
25+
"2.0.0"
26+
],
27+
"utxo": [
28+
"2.0.0"
29+
]
30+
}

packages/cardano-services-client/version.json

-11
This file was deleted.

0 commit comments

Comments
 (0)