Skip to content

Commit 3771a25

Browse files
committed
[DDW-1081] Publish selfnode installers for all 3 platforms
1 parent b467468 commit 3771a25

File tree

6 files changed

+98
-15
lines changed

6 files changed

+98
-15
lines changed

default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ let
264264
pushd dlls
265265
${if dummyInstaller then "touch foo" else "unzip ${self.dlls}"}
266266
popd
267-
cp -v ${self.unpackedCardano}/bin/* .
267+
cp -vr ${self.unpackedCardano}/bin/* .
268268
cp -v ${self.nsisFiles}/{*.yaml,*.json,daedalus.nsi,*.key,*.cert} .
269269
cp ${self.uninstaller}/uninstall.exe ../uninstall.exe
270270
if [ -f ${self.nsisFiles}/block-0.bin ]; then

installer-clusters.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
mainnet mainnet_flight testnet shelley_qa staging alonzo_purple
1+
mainnet mainnet_flight testnet shelley_qa staging alonzo_purple selfnode

installers/common/MacInstaller.hs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,12 +324,19 @@ makeComponentRoot Options{oBackend,oCluster} appRoot darwinConfig@DarwinConfig{d
324324
-- Executables (from daedalus-bridge)
325325
forM_ ["cardano-wallet", "cardano-node", "cardano-cli", "cardano-address" ] $ \f ->
326326
cp (bridge </> "bin" </> f) (dir </> f)
327-
forM_ ["config.yaml", "genesis.json", "genesis-byron.json", "genesis-shelley.json", "genesis-alonzo.json", "topology.yaml" ] $ \f ->
327+
forM_ ["config.yaml", "genesis.json", "topology.yaml" ] $ \f ->
328328
cp f (dataDir </> f)
329+
when (oCluster /= Selfnode) $ do
330+
forM_ ["genesis-byron.json", "genesis-shelley.json", "genesis-alonzo.json" ] $ \f ->
331+
cp f (dataDir </> f)
329332

330333
when (oCluster == Selfnode) $ do
331334
cp "signing.key" (dataDir </> "signing.key")
332335
cp "delegation.cert" (dataDir </> "delegation.cert")
336+
cp (bridge </> "bin" </> "mock-token-metadata-server") (dir </> "mock-token-metadata-server")
337+
cp (bridge </> "bin" </> "token-metadata.json") (dataDir </> "token-metadata.json")
338+
cp (bridge </> "bin" </> "local-cluster--unwrapped") (dir </> "local-cluster")
339+
cptreeL (bridge </> "bin" </> "test" </> "data") (dataDir </> "data")
333340

334341
procs "chmod" ["-R", "+w", tt dir] empty
335342

@@ -352,6 +359,9 @@ makeComponentRoot Options{oBackend,oCluster} appRoot darwinConfig@DarwinConfig{d
352359
mapM_ sortaMove [ "HID.node" ]
353360
void $ chain (encodeString dir) [ tt $ dir </> "HID.node" ]
354361

362+
when (oCluster == Selfnode) $ do
363+
void $ chain (encodeString dir) $ fmap tt [ dir </> "mock-token-metadata-server", dir </> "local-cluster" ]
364+
355365
-- Prepare launcher
356366
de <- testdir (dir </> "Frontend")
357367
unless de $ mv (dir </> (fromString $ T.unpack $ dcAppName)) (dir </> "Frontend")

installers/common/WindowsInstaller.hs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,23 @@ writeInstallerNSIS outName (Version fullVersion') InstallerConfig{installDirecto
199199
file [] "config.yaml"
200200
file [] "topology.yaml"
201201
file [] "genesis.json"
202-
file [] "genesis-byron.json"
203-
file [] "genesis-shelley.json"
204-
file [] "genesis-alonzo.json"
202+
when (clusterName /= Selfnode) $ do
203+
file [] "genesis-byron.json"
204+
file [] "genesis-shelley.json"
205+
file [] "genesis-alonzo.json"
205206
file [] "libsodium-23.dll"
206207
when (clusterName == Selfnode) $ do
207208
file [] "signing.key"
208209
file [] "delegation.cert"
210+
file [] "local-cluster.exe"
211+
file [] "libgcc_s_seh-1.dll"
212+
file [] "libgmpxx-4.dll"
213+
file [] "libstdc++-6.dll"
214+
file [] "libwinpthread-1.dll"
215+
file [] "mcfgthread-12.dll"
216+
file [] "mock-token-metadata-server.exe"
217+
file [Recursive] "test\\"
218+
file [] "token-metadata.json"
209219
file [] "cardano-launcher.exe"
210220
file [] "libffi-7.dll"
211221
file [] "libgmp-10.dll"

nix/cardano-bridge.nix

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ target, cardanoWalletPkgs, runCommandCC, cardano-wallet, cardano-node, cardano-shell, cardano-cli, cardano-address, lib, local-cluster ? null }:
1+
{ target, cardanoWalletPkgs, runCommandCC, cardano-wallet, cardano-node, cardano-shell, cardano-cli, cardano-address, lib, local-cluster ? null, mock-token-metadata-server }:
22

33
let
44
commonLib = import ../lib.nix {};
@@ -17,7 +17,30 @@ in runCommandCC "daedalus-cardano-bridge" {
1717
cp -f ${cardano-shell.haskellPackages.cardano-launcher.components.exes.cardano-launcher}/bin/cardano-launcher* .
1818
cp -f ${cardano-node}/bin/cardano-node* .
1919
cp -f ${cardano-cli}/bin/cardano-cli* .
20-
${lib.optionalString (local-cluster != null) "cp -f ${local-cluster}/bin/local-cluster* ."}
20+
${lib.optionalString (local-cluster != null) ''
21+
22+
${if target == "x86_64-windows" then ''
23+
# Recursive for selfnode shelley test data:
24+
cp -rf ${local-cluster}/bin/* .
25+
26+
'' else if target == "x86_64-linux" then ''
27+
cp -f ${local-cluster}/bin/local-cluster .
28+
29+
'' else if target == "x86_64-darwin" then ''
30+
# For nix-shell:
31+
cp -f ${local-cluster}/bin/local-cluster .
32+
33+
# For selfnode installer:
34+
cp -f ${local-cluster}/bin/.local-cluster-wrapped local-cluster--unwrapped
35+
mkdir -p test/data
36+
test_data_dir=$(cat local-cluster | grep -oP "SHELLEY_TEST_DATA='\K[^']+")
37+
cp -rf $test_data_dir test/data/
38+
39+
'' else abort "Unknown target: ${target}"}
40+
41+
cp -f ${mock-token-metadata-server}/bin/* . || true
42+
cp -f ${./../utils/cardano/selfnode}/token-metadata.json .
43+
''}
2144
${lib.optionalString (target == "x86_64-linux") ''
2245
chmod +w -R .
2346
for x in cardano-address cardano-node cardano-launcher cardano-cli cardano-wallet; do

source/main/cardano/CardanoSelfnodeLauncher.ts

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { spawn } from 'child_process';
22
import find from 'find-process';
3+
import path from 'path';
4+
import fs from 'fs';
5+
import which from 'which';
36
import tcpPortUsed from 'tcp-port-used';
47
import type { ChildProcess } from 'child_process';
58
import type { Process } from '../utils/processes';
@@ -26,12 +29,10 @@ const CARDANO_WALLET_START_TIMEOUT = 60 * 1000; // 60 seconds | unit: millisecon
2629

2730
const CARDANO_WALLET_START_CHECK_INTERVAL = 500; // 500 ms | unit: milliseconds
2831

29-
const SHELLEY_TEST_DATA = '../../utils/cardano/selfnode';
30-
const TOKEN_METADATA_REGISTRY = './utils/cardano/selfnode/token-metadata.json';
3132
const TOKEN_METADATA_SERVER_PORT = 65432;
3233
const TOKEN_METADATA_SERVER = `http://localhost:${TOKEN_METADATA_SERVER_PORT}/`;
3334
const TOKEN_METADATA_SERVER_PROCESS_NAME =
34-
platform === 'win32'
35+
environment.isWindows
3536
? 'mock-token-metadata-server.exe'
3637
: 'mock-token-metadata-server';
3738
export async function CardanoSelfnodeLauncher(
@@ -47,6 +48,17 @@ export async function CardanoSelfnodeLauncher(
4748
processName,
4849
onStop,
4950
} = selfnodeOptions;
51+
52+
const SHELLEY_TEST_DATA = (() => {
53+
const binDir = path.dirname(which.sync(selfnodeBin));
54+
return firstExisting('SHELLEY_TEST_DATA', [
55+
path.resolve(path.join(binDir, 'data', 'cardano-node-shelley')), // Windows installer
56+
path.resolve(path.join(binDir, '..', 'Resources', 'data', 'cardano-node-shelley')), // Darwin installer
57+
// Linux installer substitutes SHELLEY_TEST_DATA in the local-cluster Bash wrapper
58+
'../../utils/cardano/selfnode' // nix-shell
59+
])
60+
})();
61+
5062
setupMockTokenMetadataServer(mockTokenMetadataServerBin);
5163
// @ts-ignore ts-migrate(2322) FIXME: Type '{ pid: number; ppid?: number; uid?: number; ... Remove this comment to see the full error message
5264
const processList: Array<Process> = await find('port', CARDANO_WALLET_PORT);
@@ -86,11 +98,17 @@ export async function CardanoSelfnodeLauncher(
8698
SHELLEY_TEST_DATA,
8799
TOKEN_METADATA_SERVER,
88100
},
89-
detached: true,
101+
detached: environment.isDev, // XXX: detaching breaks Windows launching the local-cluster.exe + cardano-launcher
102+
// will not allow you to start another Daedalus when previous local-cluster.exe is running, especially awkward
103+
// on macOS without stdout/stderr logging; I’m not sure if this is ever needed in `nix-shell`, but leaving as-is
104+
// for now – @michalrus
105+
90106
// allows Daedalus to exit independently of selfnode (1/3)
91107
stdio: 'ignore', // allows Daedalus to exit independently of selfnode (2/3)
92108
});
93-
nodeProcess.unref(); // allows Daedalus to exit independently of selfnode (3/3)
109+
if (environment.isDev) {
110+
nodeProcess.unref(); // allows Daedalus to exit independently of selfnode (3/3)
111+
}
94112

95113
const node: Selfnode = setupSelfnode({
96114
processName,
@@ -118,6 +136,17 @@ export async function CardanoSelfnodeLauncher(
118136
});
119137
}
120138

139+
/**
140+
* Return the first existing file path among candidates. If none exist, return the last one, and log a warning an identifier.
141+
*/
142+
const firstExisting = (identifier: string, candidates: Array<string>): string => {
143+
const existing = candidates.filter(fs.existsSync);
144+
if (existing.length > 0) return existing[0];
145+
const fallback = candidates[candidates.length - 1];
146+
logger.warn(`${identifier} candidates don’t exist, will use fallback`, { identifier, candidates, fallback });
147+
return fallback;
148+
};
149+
121150
const setupSelfnode = ({
122151
processName,
123152
nodeProcess,
@@ -148,6 +177,15 @@ const setupSelfnode = ({
148177
const setupMockTokenMetadataServer = async (
149178
mockTokenMetadataServerBin: string
150179
) => {
180+
const TOKEN_METADATA_REGISTRY = (() => {
181+
const binDir = path.dirname(which.sync(mockTokenMetadataServerBin));
182+
return firstExisting('TOKEN_METADATA_REGISTRY', [
183+
path.resolve(path.join(binDir, 'token-metadata.json')), // Windows and Linux installers
184+
path.resolve(path.join(binDir, '..', 'Resources', 'token-metadata.json')), // Darwin installer
185+
'./utils/cardano/selfnode/token-metadata.json' // nix-shell
186+
]);
187+
})();
188+
151189
// @ts-ignore ts-migrate(2322) FIXME: Type '{ pid: number; ppid?: number; uid?: number; ... Remove this comment to see the full error message
152190
const processList: Array<Process> = await find(
153191
'port',
@@ -181,11 +219,13 @@ const setupMockTokenMetadataServer = async (
181219
],
182220
{
183221
env: { ...process.env },
184-
detached: true,
222+
detached: environment.isDev,
185223
stdio: 'ignore',
186224
}
187225
);
188-
mockTokenMetadataServerProcess.unref();
226+
if (environment.isDev) {
227+
mockTokenMetadataServerProcess.unref();
228+
}
189229
mockTokenMetadataServer = mockTokenMetadataServerProcess;
190230
}
191231
};

0 commit comments

Comments
 (0)