diff --git a/.github/workflows/dev-release-cli.yml b/.github/workflows/dev-release-cli.yml index 9072d6b..2147b78 100644 --- a/.github/workflows/dev-release-cli.yml +++ b/.github/workflows/dev-release-cli.yml @@ -40,13 +40,15 @@ jobs: if: runner.os == 'macOS' run: | echo "os_prefix=macos" >> $GITHUB_ENV + - name: Set lowercase architecture + run: echo "arch=$(echo ${{ runner.arch }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV - name: Build with Gradle working-directory: applications/cli run: ./gradlew --no-daemon -i -Pversion=${{ env.TAG }} clean build nativeCompile cliZip - name: Copy artifacts working-directory: applications/cli - run: mv build/yaci-cli-${{ env.TAG }}.zip build/yaci-cli-${{ env.TAG }}-${{ env.os_prefix }}-${{ runner.arch }}.zip + run: mv build/yaci-cli-${{ env.TAG }}.zip build/yaci-cli-${{ env.TAG }}-${{ env.os_prefix }}-${{ env.arch }}.zip - uses: actions/upload-artifact@v4 with: - name: yaci-cli-${{ env.TAG }}-${{ env.os_prefix }}-${{ runner.arch }} - path: ./applications/cli/build/yaci-cli-${{ env.TAG }}-${{ env.os_prefix }}-${{ runner.arch }}.zip + name: yaci-cli-${{ env.TAG }}-${{ env.os_prefix }}-${{ env.arch }} + path: ./applications/cli/build/yaci-cli-${{ env.TAG }}-${{ env.os_prefix }}-${{ env.arch }}.zip diff --git a/applications/cli/config/application.properties b/applications/cli/config/application.properties index 02ec845..15f2460 100644 --- a/applications/cli/config/application.properties +++ b/applications/cli/config/application.properties @@ -11,6 +11,8 @@ ogmios.enabled=false kupo.enabled=false yaci.store.enabled=false +yaci.store.mode=native + bp.create.enabled=true ## Default ports diff --git a/applications/cli/config/download.properties b/applications/cli/config/download.properties index febea50..aa40db0 100644 --- a/applications/cli/config/download.properties +++ b/applications/cli/config/download.properties @@ -1,10 +1,12 @@ #Please specify either the version or the full url for the following components node.version=10.1.2 -ogmios.version=6.8.0 +ogmios.version=6.9.0 kupo.version=2.9.0 -yaci.store.version=0.1.0 +yaci.store.version=0.1.1-graalvm-preview1 +yaci.store.jar.version=0.1.0 #node.url= #ogmios.url= #kupo.url= #yaci.store.url= +#yaci.store.jar.url= diff --git a/applications/cli/docker/download-ogmios.sh b/applications/cli/docker/download-ogmios.sh index 34eabec..36faebc 100644 --- a/applications/cli/docker/download-ogmios.sh +++ b/applications/cli/docker/download-ogmios.sh @@ -15,7 +15,7 @@ case $1 in esac -version=v6.8.0 +version=v6.9.0 file=ogmios-${version}-${SUFFIX}-linux.zip wget https://github.com/CardanoSolutions/ogmios/releases/download/${version}/$file diff --git a/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/commands/common/DownloadService.java b/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/commands/common/DownloadService.java index ba284ef..db8af8f 100644 --- a/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/commands/common/DownloadService.java +++ b/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/commands/common/DownloadService.java @@ -42,9 +42,15 @@ public class DownloadService { @Value("${yaci.store.version:#{null}}") private String yaciStoreVersion; + @Value("${yaci.store.jar.version:#{null}}") + private String yaciStoreJarVersion; + @Value("${yaci.store.url:#{null}}") private String yaciStoreUrl; + @Value("${yaci.store.jar.url:#{null}}") + private String yaciStoreJarUrl; + @Value("${ogmios.version:#{null}}") private String ogmiosVersion; @@ -98,13 +104,74 @@ public boolean downloadNode(boolean overwrite) { return false; } - public boolean downloadYaciStore(boolean overwrite) { + public boolean downloadYaciStoreNative(boolean overwrite) { + String downloadPath = resolveYaciStoreNativeDownloadPath(); + + if ( downloadPath == null) { + writeLn(error("Download URL for yaci-store is not set. Please set the download URL in application.properties")); + return false; + } + + Path yaciStoreExec = Path.of(clusterConfig.getYaciStoreBinPath(), "yaci-store"); + + if (yaciStoreExec.toFile().exists()) { + if (!overwrite) { + writeLn(info("yaci-store already exists in %s", yaciStoreExec.toFile().getAbsolutePath())); + writeLn(info("Use --overwrite to overwrite the existing yaci-store")); + return false; + } else { + deleteExistingDir("store", clusterConfig.getYaciStoreBinPath()); + } + } + + String targetDir = clusterConfig.getYaciStoreBinPath(); + var downloadedFile = download("yaci-store", downloadPath, targetDir, "yaci-store.zip"); + if (downloadedFile != null) { + try { + var tmpFolder = Paths.get(clusterConfig.getYaciStoreBinPath(), "tmp"); + extractZip(downloadedFile.toFile().getAbsolutePath(), tmpFolder.toFile().getAbsolutePath()); + + File[] files = tmpFolder.toFile().listFiles(); + if(files != null && files.length > 0) { + File extractedFolder = files[0]; + if (extractedFolder.getName().startsWith("yaci-store")) { + extractedFolder.renameTo(Paths.get(tmpFolder.toFile().getAbsolutePath(), "yaci-store-files").toFile()); + } + } + + //Move the file yaci-store inside yaci-store folder to yaciStoreBinPath. Then remove the tmpFolder + Path yaciStoreBinFile = Paths.get(tmpFolder.toFile().getAbsolutePath(), "yaci-store-files", "yaci-store"); + + if(yaciStoreBinFile.toFile().exists()) { + writeLn(info("Copying yaci-store binary to " + yaciStoreExec.toFile().getAbsolutePath())); + Files.copy(yaciStoreBinFile, yaciStoreExec.toFile().toPath()); + writeLn(success("Copied")); + } else { + writeLn(error("yaci-store binary not found in the extracted folder : " + yaciStoreBinFile.toFile().getAbsolutePath())); + } + + setExecutablePermission(yaciStoreExec.toFile().getAbsolutePath()); + + FileUtils.deleteDirectory(tmpFolder.toFile()); + return true; + } catch (IOException e) { + e.printStackTrace(); + writeLn(error("Error extracting yaci-store" + e.getMessage())); + } + } else { + writeLn(error("Download failed for yaci-store native binary")); + } + + return false; + } + + public boolean downloadYaciStoreJar(boolean overwrite) { downloadJre(overwrite); //Download JRE first (if not already downloaded - String downloadPath = resolveYaciStoreDownloadPath(); + String downloadPath = resolveYaciStoreJarDownloadPath(); if ( downloadPath == null) { - writeLn(error("Download URL for yaci-store is not set. Please set the download URL in application.properties")); + writeLn(error("Download URL for yaci-store-jar is not set. Please set the download URL in application.properties")); return false; } @@ -380,7 +447,7 @@ private String resolveNodeDownloadPath() { return url; } - private String resolveYaciStoreDownloadPath() { + private String resolveYaciStoreNativeDownloadPath() { if (!StringUtils.isEmpty(yaciStoreUrl)) { return yaciStoreUrl; } @@ -390,7 +457,39 @@ private String resolveYaciStoreDownloadPath() { return null; } - String url = YACI_STORE_DOWNLOAD_URL + "/v" + yaciStoreVersion + "/yaci-store-all-" + yaciStoreVersion +".jar"; + String osPrefix = null; + if (SystemUtils.IS_OS_MAC) { + osPrefix = "macos"; + } else if (SystemUtils.IS_OS_LINUX) { + osPrefix = "linux"; + } else { + writeLn(error("Unsupported OS : " + System.getProperty("os.name"))); + } + + String arch = System.getProperty("os.arch"); + String cpuArch = null; + if (arch.startsWith("aarch") || arch.startsWith("arm")) { + cpuArch = "arm64"; + } else{ + cpuArch = "x64"; + } + + + String url = YACI_STORE_DOWNLOAD_URL + "/rel-graal-" + yaciStoreVersion + "/yaci-store-" + yaciStoreVersion + "-" + osPrefix + "-" + cpuArch +"-n2c.zip"; + return url; + } + + private String resolveYaciStoreJarDownloadPath() { + if (!StringUtils.isEmpty(yaciStoreJarUrl)) { + return yaciStoreJarUrl; + } + + if (StringUtils.isEmpty(yaciStoreJarVersion)) { + writeLn(error("YaciStore Jar version is not set. Please set the yaci-store version (yaci.store.jar.version) or yaci-store download url (yaci.store.jar.url) in application.properties")); + return null; + } + + String url = YACI_STORE_DOWNLOAD_URL + "/v" + yaciStoreJarVersion + "/yaci-store-all-" + yaciStoreJarVersion +".jar"; return url; } diff --git a/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/commands/general/DownloadCommand.java b/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/commands/general/DownloadCommand.java index f0e77e3..a903e8e 100644 --- a/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/commands/general/DownloadCommand.java +++ b/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/commands/general/DownloadCommand.java @@ -17,7 +17,7 @@ public class DownloadCommand { @ShellMethod(value = "Download", key = "download") @ShellMethodAvailability("generalCmdAvailability") public void download( - @ShellOption(value = {"--component", "-c"}, defaultValue = "all", help = "node,ogmios,kupo,yaci-store") String component, + @ShellOption(value = {"--component", "-c"}, defaultValue = "all", help = "node,ogmios,kupo,yaci-store,yaci-store-jar") String component, @ShellOption(value = {"-o", "--overwrite"}, defaultValue = "false", help = "Overwrite existing installation. default: false") boolean overwrite ) { @@ -31,14 +31,16 @@ public void download( if (component.equals("node")) { downloadService.downloadNode(overwrite); } else if (component.equals("yaci-store")) { - downloadService.downloadYaciStore(overwrite); + downloadService.downloadYaciStoreNative(overwrite); + } else if (component.equals("yaci-store-jar")) { + downloadService.downloadYaciStoreJar(overwrite); } else if (component.equals("ogmios")) { downloadService.downloadOgmios(overwrite); } else if (component.equals("kupo")) { downloadService.downloadKupo(overwrite); } else if (component.equals("all")) { downloadService.downloadNode(overwrite); - downloadService.downloadYaciStore(overwrite); + downloadService.downloadYaciStoreNative(overwrite); downloadService.downloadOgmios(overwrite); downloadService.downloadKupo(overwrite); } else { diff --git a/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/localcluster/yacistore/YaciStoreService.java b/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/localcluster/yacistore/YaciStoreService.java index 6cd0d4f..5d61cb4 100644 --- a/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/localcluster/yacistore/YaciStoreService.java +++ b/applications/cli/src/main/java/com/bloxbean/cardano/yacicli/localcluster/yacistore/YaciStoreService.java @@ -100,18 +100,24 @@ private Process startStoreApp(ClusterInfo clusterInfo, Era era) throws IOExcepti ProcessBuilder builder = new ProcessBuilder(); builder.directory(new File(clusterConfig.getYaciStoreBinPath())); - Path yaciStoreJar = Path.of(clusterConfig.getYaciStoreBinPath(), "yaci-store.jar"); - if (!yaciStoreJar.toFile().exists()) { - writeLn(error("yaci-store.jar is not found at " + clusterConfig.getYaciStoreBinPath())); - return null; + if (yaciStoreMode == null || yaciStoreMode.equals("java")) { + Path yaciStoreJar = Path.of(clusterConfig.getYaciStoreBinPath(), "yaci-store.jar"); + if (!yaciStoreJar.toFile().exists()) { + writeLn(error("yaci-store.jar is not found at " + clusterConfig.getYaciStoreBinPath())); + return null; + } + } else if (yaciStoreMode != null && yaciStoreMode.equals("native")) { + Path yaciStoreBin = Path.of(clusterConfig.getYaciStoreBinPath(), "yaci-store"); + if (!yaciStoreBin.toFile().exists()) { + writeLn(error("yaci-store binary is not found at " + clusterConfig.getYaciStoreBinPath())); + return null; + } } if (!isDocker) { yaciStoreConfigBuilder.build(clusterInfo); } - String javaExecPath = jreResolver.getJavaCommand(); - if (yaciStoreMode != null && yaciStoreMode.equals("native")) { builder.environment().put("STORE_CARDANO_N2C_ERA", era.name()); builder.environment().put("STORE_CARDANO_PROTOCOL_MAGIC", String.valueOf(clusterInfo.getProtocolMagic())); @@ -121,6 +127,8 @@ private Process startStoreApp(ClusterInfo clusterInfo, Era era) throws IOExcepti builder.command(clusterConfig.getYaciStoreBinPath() + File.separator + "yaci-store"); } } else { + String javaExecPath = jreResolver.getJavaCommand(); + if (OSUtil.getOperatingSystem() == OSUtil.OS.WINDOWS) { builder.command(javaExecPath, "-Dstore.cardano.n2c-era=" + era.name(), "-Dstore.cardano.protocol-magic=" + clusterInfo.getProtocolMagic(), "-jar", clusterConfig.getYaciStoreBinPath() + File.separator + "yaci-store.jar"); } else {