Skip to content

Commit

Permalink
[non-docker] Yaci Store native image / Ogmios 6.9.0 (#77)
Browse files Browse the repository at this point in the history
* Add support for downloading yaci-store as native binary

Updated DownloadCommand to accept a new component "yaci-store-jar" and adjusted DownloadService to handle downloads for both jar and native versions. Enhanced YaciStoreService to detect and handle native binaries while retaining support for jar files.

* Update Ogmios and Yaci versions; refine build script.

Bump Ogmios to v6.9.0 and Yaci store to v0.1.1-graalvm-preview1 in the configuration files. Enhance the GitHub action build script by including lowercase architecture handling, ensuring artifact naming consistency. Enabled native mode for Yaci store by default.
  • Loading branch information
satran004 authored Nov 12, 2024
1 parent 52cfd8d commit 6596e92
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 20 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/dev-release-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions applications/cli/config/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ ogmios.enabled=false
kupo.enabled=false
yaci.store.enabled=false

yaci.store.mode=native

bp.create.enabled=true

## Default ports
Expand Down
6 changes: 4 additions & 2 deletions applications/cli/config/download.properties
Original file line number Diff line number Diff line change
@@ -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=
2 changes: 1 addition & 1 deletion applications/cli/docker/download-ogmios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -380,7 +447,7 @@ private String resolveNodeDownloadPath() {
return url;
}

private String resolveYaciStoreDownloadPath() {
private String resolveYaciStoreNativeDownloadPath() {
if (!StringUtils.isEmpty(yaciStoreUrl)) {
return yaciStoreUrl;
}
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {

Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand All @@ -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 {
Expand Down

0 comments on commit 6596e92

Please sign in to comment.