Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release bundled binaries for MacOS, Windows, Linux | x64, aarch64 #2075

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/release-binaries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Publish release-binaries

on:
release:
types: [published]

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
release-binaries:
name: Publish release binaries
runs-on: macos-latest
env:
ERGO_RELEASE_PLATFORM: macos-x64
ERGO_RELEASE_TAG: ${{ github.event.release.tag_name }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- name: Download ergo node jar
run: |
echo $GITHUB_REF
gh release download $ERGO_RELEASE_TAG -p "ergo*"
- name: Create release binary files
run: python ci/release-binaries.py
- name: Put binary files into release
run: gh release upload $ERGO_RELEASE_TAG $(echo $(find release -name "ergo-node-*"))
Binary file added ci/ergo.icns
Binary file not shown.
227 changes: 227 additions & 0 deletions ci/release-binaries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
import os
import tarfile
import urllib.request
import zipfile
import shutil
import logging
import subprocess
from multiprocessing.pool import ThreadPool
from itertools import repeat

MICROSOFT_URL = "https://aka.ms/download-jdk/microsoft-jdk-21.0.1-"
JRE_SUBFOLDER = "jdk-21.0.1+12"
JDKS = {
"windows-x64": "windows-x64.zip",
"linux-x64": "linux-x64.tar.gz",
"macos-x64": "macos-x64.tar.gz",
"windows-aarch64": "windows-aarch64.zip",
"linux-aarch64": "linux-aarch64.tar.gz",
"macos-aarch64": "macos-aarch64.tar.gz",
}

# Specific to ergo-node .jap, collected with jdeps
JLINK_MODULES = "java.base,java.compiler,java.desktop,java.management,java.naming,java.rmi,java.sql,jdk.unsupported"

MAIN_JRE = os.environ.get("ERGO_RELEASE_PLATFORM")
VERSION = os.environ.get("ERGO_RELEASE_TAG")

JAR_FILENAME = f"ergo-{VERSION}.jar"
SCRIPT_LOGO = f"""

.-*%@#+-.
.-+#@@%*=-=*%@@#+-.
+@@#+- :=*@@+
-@@: ......... :@@-
.@@- #@@@@@@@% -@@: .@@@@@@@-:@@@@@%*. .+%@@@%+. .+%@@@%+.
%@+ .*@@*. =@@. :@@:.... :@@:..+@@ =@@=. .=*= -@@=. .=@@=
#@# .%@@= *@% :@@%%%%%.:@@+++%@# @@= .+++++ %@+ =@@
=@@. .*@@= .@@= :@@-:::: :@@+#@@- #@# .==*@@.#@# *@%
*@% =@@@*+++= %@* :@@*****::@@. =@@: .#@@*+*%@% *@@*+*%@#.
#@# +#######* *@% =======..== :== .-=++-. .-=+=-.
%@*. .+@@.
.#@@@#+-. .-+#@@%*: Node version: {VERSION}
.-+#@@@#%@@#+-.


"""
def download_jdk(url):
final_url = MICROSOFT_URL + url
logging.warning(f"Downloading {final_url}")
urllib.request.urlretrieve(final_url, url)

def unarchive_jdk(filename, directory):
logging.warning(f"Extracting {filename} into {directory}")
if filename.endswith("tar.gz"):
tar = tarfile.open(filename, "r:gz")
tar.extractall(directory)
tar.close()
elif filename.endswith("zip"):
with zipfile.ZipFile(filename, 'r') as zip_ref:
zip_ref.extractall(directory)

def create_jre(jlink, target_jre_dir, out_jre_dir):
subprocess.run([
jlink,
"--module-path",
os.path.join(target_jre_dir, "jmods"),
"--add-modules",
JLINK_MODULES,
"--strip-debug",
"--compress", "2",
"--no-header-files",
"--no-man-pages",
"--output",
out_jre_dir
], check=True)

def make_windows(target):
app_dir = f"{target}/ergo-node"
os.makedirs(app_dir, exist_ok=True)
app_script = f"""
Write-Host @"

{SCRIPT_LOGO}

"@ -ForegroundColor Red
jre/bin/java -jar -Xmx4G {JAR_FILENAME} --mainnet -c ergo.conf
"""
with open(f"{app_dir}/ergo-node.ps1", "w") as f:
f.write(app_script)

shutil.copytree(f"{target}/jre", f"{app_dir}/jre")
shutil.copyfile(JAR_FILENAME, f"{app_dir}/{JAR_FILENAME}")
shutil.copyfile("ergo.conf", f"{app_dir}/ergo.conf")
shutil.make_archive(f"release/ergo-node-{VERSION}-{target}", 'zip', app_dir)

def make_linux(target):
app_dir = f"{target}/ergo-node"
os.makedirs(app_dir, exist_ok=True)

app_script = f"""#!/bin/env sh
echo '\033[0;31m'
cat << EOF

{SCRIPT_LOGO}

EOF
echo '\033[0m'
./jre/bin/java -jar -Xmx4G {JAR_FILENAME} --mainnet -c ergo.conf
exit
"""
with open(f"{app_dir}/ergo-node.sh", "w") as f:
f.write(app_script)
os.chmod(f"{app_dir}/ergo-node.sh", 0o755)

shutil.copytree(f"{target}/jre", f"{app_dir}/jre")
shutil.copyfile(JAR_FILENAME, f"{app_dir}/{JAR_FILENAME}")
shutil.copyfile("ergo.conf", f"{app_dir}/ergo.conf")
with tarfile.open(f"release/ergo-node-{VERSION}-{target}.tar.gz", "w:gz") as tar:
tar.add(app_dir)

def make_macos(target):
app_dir = f"{target}/ErgoNode.app"
os.makedirs(app_dir, exist_ok=True)
os.makedirs(f"{app_dir}/Contents/MacOS", exist_ok=True)
os.makedirs(f"{app_dir}/Contents/Resources", exist_ok=True)

info_plist = f"""<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>start.command</string>
<key>CFBundleIdentifier</key>
<string>org.ergoplatform.ergo-node</string>
<key>CFBundleName</key>
<string>Ergo Node</string>
<key>CFBundleIconFile</key>
<string>ergo.icns</string>
<key>CFBundleVersion</key>
<string>{VERSION}</string>
</dict>
</plist>
"""
with open(f"{app_dir}/Contents/info.plist", "w") as f:
f.write(info_plist)

app_script = f"""#!/bin/zsh
SRC=$(cd "$(dirname "$0")"; pwd -P)
echo '\033[0;31m'
cat << EOF

{SCRIPT_LOGO}

EOF
echo '\033[0m'
$SRC/jre/bin/java -jar -Xmx4G $SRC/{JAR_FILENAME} --mainnet -c $SRC/ergo.conf

exit
"""
app_script_file = "ergo-node.sh"
with open(f"{app_dir}/Contents/MacOS/{app_script_file}", "w") as f:
f.write(app_script)

# Require nested script for macos Terminal app to open
start_command = f"""#!/bin/zsh
MY_PATH=$(cd "$(dirname "$0")"; pwd -P)
open -a Terminal $MY_PATH/{app_script_file}
"""
start_command_file = "start.command"
with open(f"{app_dir}/Contents/MacOS/{start_command_file}", "w") as f:
f.write(start_command)
os.chmod(f"{app_dir}/Contents/MacOS/{app_script_file}", 0o755)
os.chmod(f"{app_dir}/Contents/MacOS/{start_command_file}", 0o755)

shutil.copytree(f"{target}/jre", f"{app_dir}/Contents/MacOS/jre")
shutil.copyfile(JAR_FILENAME, f"{app_dir}/Contents/MacOS/{JAR_FILENAME}")
shutil.copyfile("ergo.conf", f"{app_dir}/Contents/MacOS/ergo.conf")
shutil.copyfile("ci/ergo.icns", f"{app_dir}/Contents/Resources/ergo.icns")

with tarfile.open(f"release/ergo-node-{VERSION}-{target}.tar.gz", "w:gz") as tar:
tar.add(app_dir)

def process_download(entry):
(os_type, filename) = entry
download_jdk(filename)
unarchive_jdk(filename, os_type)

def process_jres(os_type, main_jre):
logging.warning(f"Creating jre for {os_type}")
if (os_type.startswith("macos")):
create_jre(main_jre, os.path.join(os_type, JRE_SUBFOLDER, "Contents", "Home"), os_type + "/jre")
make_macos(os_type)
if (os_type.startswith("linux")):
create_jre(main_jre, os.path.join(os_type, JRE_SUBFOLDER), os_type + "/jre")
make_linux(os_type)
if (os_type.startswith("windows")):
create_jre(main_jre, os.path.join(os_type, JRE_SUBFOLDER), os_type + "/jre")
make_windows(os_type)

def get_main_jre(jre, subfolder) -> str:
if (jre.startswith("windows")):
return os.path.join(jre, subfolder, "bin", "jlink.exe")
elif (jre.startswith("macos")):
return os.path.join(jre, subfolder, "Contents", "Home", "bin", "jlink")
else: #linux
return os.path.join(jre, subfolder, "bin", "jlink")

logging.warning(f"Starting release binaries for ergo-node")

main_jre = get_main_jre(MAIN_JRE, JRE_SUBFOLDER)
os.makedirs("release", exist_ok=True)

ergo_conf = """
ergo {
node {
mining = false
}
}
"""
with open("ergo.conf", "w") as f:
f.write(ergo_conf)

with ThreadPool(JDKS.__len__()) as pool:
pool.map(process_download, JDKS.items())

with ThreadPool(JDKS.__len__()) as pool:
pool.starmap(process_jres, zip(JDKS.keys(), repeat(main_jre)))
Loading