Skip to content

Commit

Permalink
fix: rename runpodctl to runpod
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmerrell committed Jan 26, 2024
1 parent 270172d commit 223dd40
Show file tree
Hide file tree
Showing 45 changed files with 474 additions and 316 deletions.
29 changes: 16 additions & 13 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
id: release
with:
release-type: go
package-name: runpodctl
package-name: runpod
pull-request-title-pattern: release${component} ${version}

- uses: actions/checkout@v2
Expand All @@ -30,10 +30,10 @@ jobs:
- name: build
if: ${{ steps.release.outputs.release_created }}
run: |
env GOOS=linux GOARCH=amd64 go build -ldflags "-X 'main.Version=${{ steps.release.outputs.tag_name }}'" -o bin/runpodctl-linux-amd64 .
env GOOS=darwin GOARCH=amd64 go build -ldflags "-X 'main.Version=${{ steps.release.outputs.tag_name }}'" -o bin/runpodctl-darwin-amd64 .
env GOOS=darwin GOARCH=arm64 go build -ldflags "-X 'main.Version=${{ steps.release.outputs.tag_name }}'" -o bin/runpodctl-darwin-arm64 .
env GOOS=windows GOARCH=amd64 go build -ldflags "-X 'main.Version=${{ steps.release.outputs.tag_name }}'" -o bin/runpodctl-windows-amd64 .
env GOOS=linux GOARCH=amd64 go build -ldflags "-X 'main.Version=${{ steps.release.outputs.tag_name }}'" -o bin/runpod-linux-amd64 .
env GOOS=darwin GOARCH=amd64 go build -ldflags "-X 'main.Version=${{ steps.release.outputs.tag_name }}'" -o bin/runpod-darwin-amd64 .
env GOOS=darwin GOARCH=arm64 go build -ldflags "-X 'main.Version=${{ steps.release.outputs.tag_name }}'" -o bin/runpod-darwin-arm64 .
env GOOS=windows GOARCH=amd64 go build -ldflags "-X 'main.Version=${{ steps.release.outputs.tag_name }}'" -o bin/runpod-windows-amd64.exe .
- name: upload linux amd64 release binary
if: ${{ steps.release.outputs.release_created }}
Expand All @@ -42,36 +42,39 @@ jobs:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ steps.release.outputs.upload_url }}
asset_path: bin/runpodctl-linux-amd
asset_name: runpodctl-linux-amd
asset_path: bin/runpod-linux-amd64
asset_name: runpod-linux-amd64
asset_content_type: application/octet-stream

- name: upload darwin amd64 release binary
if: ${{ steps.release.outputs.release_created }}
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ steps.release.outputs.upload_url }}
asset_path: bin/runpodctl-darwin-amd
asset_name: runpodctl-darwin-amd
asset_path: bin/runpod-darwin-amd64
asset_name: runpod-darwin-amd64
asset_content_type: application/octet-stream

- name: upload darwin arm64 release binary
if: ${{ steps.release.outputs.release_created }}
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ steps.release.outputs.upload_url }}
asset_path: bin/runpodctl-darwin-arm
asset_name: runpodctl-darwin-arm
asset_path: bin/runpod-darwin-arm64
asset_name: runpod-darwin-arm64
asset_content_type: application/octet-stream

- name: upload windows amd64 release binary
if: ${{ steps.release.outputs.release_created }}
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ steps.release.outputs.upload_url }}
asset_path: bin/runpodctl-win-amd
asset_name: runpodctl-win-amd
asset_path: bin/runpod-windows-amd64.exe
asset_name: runpod-windows-amd64.exe
asset_content_type: application/octet-stream
2 changes: 1 addition & 1 deletion cmd/croc/croc.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ func (c *Client) Send(filesInfo []FileInfo, emptyFoldersToTransfer []FileInfo, t
return
}
flags := &strings.Builder{}
fmt.Fprintf(os.Stderr, "Code is: %[1]s\nOn the other computer run\n\nrunpodctl receive %[2]s%[1]s\n", c.Options.SharedSecret, flags.String())
fmt.Fprintf(os.Stderr, "Code is: %[1]s\nOn the other computer run\n\nrunpod receive %[2]s%[1]s\n", c.Options.SharedSecret, flags.String())
if c.Options.Ask {
machid, _ := machineid.ID()
fmt.Fprintf(os.Stderr, "\rYour machine ID is '%s'\n", machid)
Expand Down
2 changes: 1 addition & 1 deletion cmd/project/exampleDockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# AUTOGENERATED Dockerfile using runpodctl project build
# AUTOGENERATED Dockerfile using RunPod CLI project build

# Base image -> https://github.com/runpod/containers/blob/main/official-templates/base/Dockerfile
# DockerHub -> https://hub.docker.com/r/runpod/base/tags
Expand Down
3 changes: 2 additions & 1 deletion cmd/project/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ func startProject(networkVolumeId string) error {
venvPath, remoteProjectPath, config.GetPath([]string{"runtime", "requirements_path"}).(string)),
})
//create file watcher
fmt.Println("Creating file watcher...")
go sshConn.SyncDir(cwd, projectPathUuidDev)
//run launch api server / hot reload loop
pipReqPath := path.Join(remoteProjectPath, config.GetPath([]string{"runtime", "requirements_path"}).(string))
Expand Down Expand Up @@ -397,7 +398,7 @@ func deployProject(networkVolumeId string) (endpointId string, err error) {
projectName := config.Get("name").(string)
projectPathUuid := path.Join(projectConfig.Get("volume_mount_path").(string), projectConfig.Get("uuid").(string))
projectPathUuidProd := path.Join(projectPathUuid, "prod")
remoteProjectPath := path.Join(projectPathUuidProd, projectConfig.Get("name").(string))
remoteProjectPath := path.Join(projectPathUuidProd, config.Get("name").(string))
//check for existing pod
projectPodId, err := getProjectPod(projectId)
if projectPodId == "" || err != nil {
Expand Down
6 changes: 3 additions & 3 deletions cmd/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,12 @@ var StartProjectCmd = &cobra.Command{
}
if setDefaultNetworkVolume || networkVolumeId == "" || !cachedNetVolExists {
netVolId, err := selectNetworkVolume()
networkVolumeId = netVolId
viper.Set(fmt.Sprintf("project_volumes.%s", projectId), networkVolumeId)
viper.WriteConfig()
if err != nil {
return
}
networkVolumeId = netVolId
viper.Set(fmt.Sprintf("project_volumes.%s", projectId), networkVolumeId)
viper.WriteConfig()
}
startProject(networkVolumeId)
},
Expand Down
86 changes: 43 additions & 43 deletions cmd/project/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ import (
"os/exec"
"path/filepath"
"strings"
"sync"
"time"

"github.com/dietsche/rfsnotify"
"github.com/fatih/color"
"golang.org/x/crypto/ssh"
"gopkg.in/fsnotify.v1"
)

func getPodSSHInfo(podId string) (podIp string, podPort int, err error) {
Expand Down Expand Up @@ -88,65 +85,68 @@ func (sshConn *SSHConnection) Rsync(localDir string, remoteDir string, quiet boo
return nil
}

// hasChanges checks if there are any modified files in localDir since lastSyncTime.
func hasChanges(localDir string, lastSyncTime time.Time) (bool, string) {
var hasModifications bool
var firstModifiedFile string

err := filepath.Walk(localDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
if os.IsNotExist(err) {
// Handle the case where a file has been removed
fmt.Printf("Detected a removed file at: %s\n", path)
hasModifications = true
return errors.New("change detected") // Stop walking
}
return err
}

// Check if the file was modified after the last sync time
if info.ModTime().After(lastSyncTime) {
hasModifications = true
firstModifiedFile = path
return filepath.SkipDir // Skip the rest of the directory if a change is found
}

return nil
})

if err != nil {
fmt.Printf("Error walking through directory: %v\n", err)
return false, ""
}

return hasModifications, firstModifiedFile
}

func (sshConn *SSHConnection) SyncDir(localDir string, remoteDir string) {
syncFiles := func() {
fmt.Println("Syncing files...")
sshConn.Rsync(localDir, remoteDir, true)
}
// Create new watcher.
watcher, err := rfsnotify.NewWatcher()
if err != nil {
fmt.Println(err)
}
defer watcher.Close()
var mu sync.Mutex
var timer *time.Timer

// Start listening for events.
go func() {
lastSyncTime := time.Now()
for {
select {
case event, ok := <-watcher.Events:
if !ok {
return
}
//if directory modified or created, ignore
if event.Op&fsnotify.Write == fsnotify.Write || event.Op&fsnotify.Create == fsnotify.Create {
if event.Op&fsnotify.Write == fsnotify.Write {
fmt.Println("Modified file:", event.Name)
}
if event.Op&fsnotify.Create == fsnotify.Create {
fmt.Println("Created file:", event.Name)
}

mu.Lock()
if timer != nil {
timer.Stop()
}
timer = time.AfterFunc(500*time.Millisecond, syncFiles)
mu.Unlock()
}
case err, ok := <-watcher.Errors:
if !ok {
return
}
fmt.Println("error:", err)
time.Sleep(100 * time.Millisecond)
hasChanged, firstModifiedFile := hasChanges(localDir, lastSyncTime)
if hasChanged {
fmt.Printf("Detected changes in %s\n", firstModifiedFile)
syncFiles()
lastSyncTime = time.Now()
}
}
}()

// Add a path.
err = watcher.AddRecursive(localDir)
if err != nil {
fmt.Println(err)
}

// Block main goroutine forever.
<-make(chan struct{})
}

func (sshConn *SSHConnection) RunCommand(command string) error {
return sshConn.RunCommands([]string{command})
}

func (sshConn *SSHConnection) RunCommands(commands []string) error {

stdoutColor := color.New(color.FgGreen)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
# To learn more, see https://pip.pypa.io/en/stable/reference/requirements-file-format/

<<RUNPOD>>
hf_transfer
8 changes: 4 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ var version string
// rootCmd represents the base command when called without any subcommands
var RootCmd = &cobra.Command{
Use: "runpod",
Aliases: []string{"rp", "runpodctl"},
Short: "runpod for runpod.io",
Long: "runpod is a CLI tool to manage your pods for runpod.io",
Aliases: []string{"runpodctl"},
Short: "CLI for runpod.io",
Long: "CLI tool to manage your pods for runpod.io",
}

// Execute adds all child commands to the root command and sets flags appropriately.
Expand Down Expand Up @@ -73,7 +73,7 @@ func initConfig() {
fmt.Println("Runpod config location has moved from ~/.runpod.yaml to ~/.runpod/config.toml")
fmt.Println("migrating your existing config to ~/.runpod/config.toml")
} else {
fmt.Println("Runpod config file not found, please run runpodctl config to create it")
fmt.Println("Runpod config file not found, please run `runpod config` to create it")
}
viper.SetConfigType("toml")
//make .runpod folder if not exists
Expand Down
18 changes: 9 additions & 9 deletions cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,21 @@ func GetJson(url string) (*GithubApiResponse, error) {

var updateCmd = &cobra.Command{
Use: "update",
Short: "runpodctl update",
Long: "runpodctl update",
Short: "update runpod cli",
Long: "update runpod cli to the latest version",
Run: func(c *cobra.Command, args []string) {
//fetch newest github release
githubApiUrl := "https://api.github.com/repos/runpod/runpodctl/releases/latest"
apiResp, err := GetJson(githubApiUrl)
if err != nil {
fmt.Println("error fetching latest version info for runpodctl", err)
fmt.Println("error fetching latest version info for runpod cli", err)
return
}
//find download link for current platform
latestVersion := apiResp.Version
if semver.Compare("v"+version, latestVersion) == -1 {
//version < latest
newBinaryName := fmt.Sprintf("runpodctl-%s-%s", runtime.GOOS, runtime.GOARCH)
newBinaryName := fmt.Sprintf("runpod-%s-%s", runtime.GOOS, runtime.GOARCH)
foundNewBinary := false
var downloadLink string
for _, asset := range apiResp.Assets {
Expand All @@ -107,20 +107,20 @@ var updateCmd = &cobra.Command{
}
exPath := filepath.Dir(ex)
downloadPath := newBinaryName
destFilename := "runpodctl"
destFilename := "runpod"
if runtime.GOOS == "windows" {
destFilename = "runpodctl.exe"
destFilename = "runpod.exe"
}
destPath := filepath.Join(exPath, destFilename)
if runtime.GOOS == "windows" {
fmt.Println("To get the newest version, run this command:")
fmt.Printf("wget https://github.com/runpod/runpodctl/releases/download/%s/%s -O runpodctl.exe\n", latestVersion, newBinaryName)
fmt.Printf("wget https://github.com/runpod/runpodctl/releases/download/%s/%s -O runpod.exe\n", latestVersion, newBinaryName)
}
fmt.Printf("downloading runpodctl %s to %s\n", latestVersion, downloadPath)
fmt.Printf("downloading runpod %s to %s\n", latestVersion, downloadPath)
file, err := DownloadFile(downloadLink, downloadPath)
defer file.Close()
if err != nil {
fmt.Println("error fetching the latest version of runpodctl", err)
fmt.Println("error fetching the latest version of runpod cli", err)
return
}
//chmod +x
Expand Down
6 changes: 3 additions & 3 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (

var versionCmd = &cobra.Command{
Use: "version",
Short: "runpodctl version",
Long: "runpodctl version",
Short: "runpod cli version",
Long: "runpod cli version",
Run: func(c *cobra.Command, args []string) {
fmt.Println("runpodctl " + version)
fmt.Println("runpod " + version)
},
}
29 changes: 29 additions & 0 deletions doc/runpod.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## runpod

CLI for runpod.io

### Synopsis

CLI tool to manage your pods for runpod.io

### Options

```
-h, --help help for runpod
```

### SEE ALSO

* [runpod config](runpod_config.md) - CLI Config
* [runpod create](runpod_create.md) - create a resource
* [runpod get](runpod_get.md) - get resource
* [runpod project](runpod_project.md) - manage projects
* [runpod receive](runpod_receive.md) - receive file(s), or folder
* [runpod remove](runpod_remove.md) - remove a resource
* [runpod send](runpod_send.md) - send file(s), or folder
* [runpod start](runpod_start.md) - start a resource
* [runpod stop](runpod_stop.md) - stop a resource
* [runpod update](runpod_update.md) - update runpod cli
* [runpod version](runpod_version.md) - runpod cli version

###### Auto generated by spf13/cobra on 26-Jan-2024
8 changes: 4 additions & 4 deletions doc/runpodctl_config.md → doc/runpod_config.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## runpodctl config
## runpod config

CLI Config

Expand All @@ -7,7 +7,7 @@ CLI Config
RunPod CLI Config Settings

```
runpodctl config [flags]
runpod config [flags]
```

### Options
Expand All @@ -20,6 +20,6 @@ runpodctl config [flags]

### SEE ALSO

* [runpodctl](runpodctl.md) - runpodctl for runpod.io
* [runpod](runpod.md) - CLI for runpod.io

###### Auto generated by spf13/cobra on 8-Apr-2023
###### Auto generated by spf13/cobra on 26-Jan-2024
Loading

0 comments on commit 223dd40

Please sign in to comment.