Skip to content

Commit

Permalink
add --compute-dev-version flag for running dev releases
Browse files Browse the repository at this point in the history
  • Loading branch information
selimseker committed Sep 24, 2024
1 parent 9793ae9 commit 85e7444
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func main() {
trace := flag.Bool("trace", false, "Sets the logging level to trace (default: false)")
dkn_admin_pkey_flag := flag.String("dkn-admin-public-key", DKN_ADMIN_PUBLIC_KEY, "DKN Admin Node Public Key, usually dont need this since it's given by default")
pick_model := flag.Bool("pick-models", false, "Pick the models using cli, supprases the -m flags (default: false)")
use_compute_dev_version := flag.Bool("compute-dev-version", false, "For using the latest dev version of dkn-compute node (optional, only for development purposes)")
flag.Parse()

// Display help and exit if -h or --help is provided
Expand Down Expand Up @@ -162,7 +163,7 @@ func main() {
}

// get latest dkn_compute binary version
latestVersion, err := utils.GetComputeLatestTag()
latestVersion, err := utils.GetComputeLatestTag(*use_compute_dev_version)
if err != nil {
fmt.Println("Couldn't get the latest dkn-compute version")
utils.ExitWithDelay(1)
Expand All @@ -174,7 +175,7 @@ func main() {
// compare current and latest versions
if latestVersion != envvars["DKN_COMPUTE_VERSION"] {
fmt.Printf("New dkn-compute version detected (%s), downloading it...\n", latestVersion)
if err := utils.DownloadLatestComputeBinary(working_dir, dkn_compute_binary); err != nil {
if err := utils.DownloadLatestComputeBinary(latestVersion, working_dir, dkn_compute_binary); err != nil {
fmt.Printf("Error during downloading the latest dkn-compute binary %s\n", err)
utils.ExitWithDelay(1)
}
Expand All @@ -185,7 +186,7 @@ func main() {
} else {
// couldn't find the dkn-compute binary, download it
fmt.Printf("Downloading the latest dkn-compute binary (%s)\n", latestVersion)
if err := utils.DownloadLatestComputeBinary(working_dir, dkn_compute_binary); err != nil {
if err := utils.DownloadLatestComputeBinary(latestVersion, working_dir, dkn_compute_binary); err != nil {
fmt.Printf("Error during downloading the latest dkn-compute binary %s\n", err)
utils.ExitWithDelay(1)
}
Expand Down
40 changes: 31 additions & 9 deletions utils/compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@ import (
"net/http"
"path/filepath"
"runtime"
"strings"
)

// GetComputeLatestTag fetches the latest tag from the DKN Compute Node repository on GitHub.
// This tag represents the latest version of the compute node.
//
// Parameters:
// - dev: A boolean parameter. If true, it returns the latest tag with the '-dev' suffix.
// If false, it returns the latest tag without the '-dev' suffix.
//
// Returns:
// - string: The latest tag (version) as a string.
// - error: An error if the request fails or the response cannot be parsed.
func GetComputeLatestTag() (string, error) {
// - string: The latest tag (version) as a string, filtered by the '-dev' suffix based on the dev parameter.
// - error: An error if the request fails, the response cannot be parsed, or no valid tags are found.
func GetComputeLatestTag(dev bool) (string, error) {
url := "https://api.github.com/repos/firstbatchxyz/dkn-compute-node/tags"

// get and parse the tags
Expand All @@ -40,12 +45,28 @@ func GetComputeLatestTag() (string, error) {
if len(tags) == 0 {
return "", fmt.Errorf("no tags found")
}
latestTag, ok := tags[0]["name"].(string)
if !ok {
return "", fmt.Errorf("failed to extract tag name")

// Iterate through the tags and return the first one based on the 'dev' parameter
for _, tag := range tags {
tagName, ok := tag["name"].(string)
if !ok {
return "", fmt.Errorf("failed to extract tag name")
}

if dev {
// Return the first tag with '-dev' suffix if dev is true
if strings.HasSuffix(tagName, "-dev") {
return tagName, nil
}
} else {
// Return the first tag without '-dev' suffix if dev is false
if !strings.HasSuffix(tagName, "-dev") {
return tagName, nil
}
}
}

return latestTag, nil
return "", fmt.Errorf("no valid tags found")
}

// DownloadLatestComputeBinary downloads the latest compute binary for the current operating system and architecture
Expand All @@ -57,14 +78,15 @@ func GetComputeLatestTag() (string, error) {
//
// Returns:
// - error: An error if the download or file preparation fails.
func DownloadLatestComputeBinary(workingDir, file string) error {
func DownloadLatestComputeBinary(version, workingDir, file string) error {
os, arch := GetOSAndArch()
extension := ""
if os == "windows" {
extension = ".exe"
}
asset_name := fmt.Sprintf("dkn-compute-binary-%s-%s%s", os, arch, extension)
url := fmt.Sprintf("https://github.com/firstbatchxyz/dkn-compute-node/releases/latest/download/%s", asset_name)
// releases/download/v0.2.4-dev
url := fmt.Sprintf("https://github.com/firstbatchxyz/dkn-compute-node/releases/download/%s/%s", version, asset_name)
destPath := filepath.Join(workingDir, file)
if err := DownloadFile(url, destPath); err != nil {
return err
Expand Down

0 comments on commit 85e7444

Please sign in to comment.