-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding SkyPilot as another target option
Signed-off-by: aavarghese <[email protected]>
- Loading branch information
1 parent
d3e8eb1
commit 9833f13
Showing
19 changed files
with
389 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package skypilot | ||
|
||
import ( | ||
"github.com/IBM/vpc-go-sdk/vpcv1" | ||
"lunchpail.io/pkg/be/platform" | ||
) | ||
|
||
type Backend struct { | ||
config platform.IbmConfig | ||
vpcService *vpcv1.VpcV1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package skypilot | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"path" | ||
|
||
"github.com/IBM/go-sdk-core/v5/core" | ||
"github.com/IBM/vpc-go-sdk/vpcv1" | ||
"lunchpail.io/pkg/be/platform" | ||
) | ||
|
||
func Authenticator(apiKey string, config platform.IbmConfig) (*vpcv1.VpcV1, error) { | ||
var auth core.Authenticator | ||
var method = "apikey" | ||
if apiKey == "" && config.IAMToken != "" { | ||
bearerAuth, err := core.NewBearerTokenAuthenticator(config.IAMToken) | ||
if err != nil { | ||
return nil, err | ||
} | ||
method = "bearer token" | ||
auth = bearerAuth | ||
} else if apiKey != "" { | ||
auth = &core.IamAuthenticator{ | ||
ApiKey: apiKey, | ||
} | ||
|
||
} else { | ||
return nil, fmt.Errorf("Either use 'ibmcloud login' or rerun with an '--api-key' option") | ||
} | ||
|
||
// Instantiate the service with an API key based IAM authenticator | ||
vpcService, err := vpcv1.NewVpcV1(&vpcv1.VpcV1Options{ | ||
Authenticator: auth, | ||
}) | ||
if err != nil { | ||
return nil, errors.New("Error creating VPC Service with apikey" + apiKey) | ||
} | ||
fmt.Printf("Accessing the VPC service via %s\n", method) | ||
|
||
//To access IBM’s VPC service, store the apikey and resource group in $HOME/.ibm/credentials.yaml | ||
credsPath := os.Getenv("HOME") + "/.ibm/credentials.yaml" | ||
err = os.MkdirAll(path.Dir(credsPath), 0755) | ||
if err != nil { | ||
return nil, err | ||
} | ||
f, err := os.Create(credsPath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
defer f.Close() | ||
d := []string{"iam_api_key: " + apiKey, "resource_group_id: " + config.ResourceGroup.GUID} | ||
|
||
for _, v := range d { | ||
_, err = fmt.Fprintln(f, v) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
cmd := exec.Command("/bin/bash", "-c", "env DOCKER_HOST=unix:///var/run/docker.sock docker run -td --rm --name sky -v ${HOME}/.sky:/root/.sky:rw -v $HOME/.ibm:/root/.ibm:rw berkeleyskypilot/skypilot") | ||
cmd.Stdout = os.Stdout | ||
cmd.Stderr = os.Stderr | ||
if err := cmd.Run(); err != nil { | ||
return nil, fmt.Errorf("internal Error starting docker container: %v", err) | ||
} | ||
return vpcService, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package skypilot | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
) | ||
|
||
func stopOrDownSkyCluster(name string, down bool) error { | ||
cmd := exec.Command("/bin/bash", "-c", "env DOCKER_HOST=unix:///var/run/docker.sock docker exec sky sky stop --yes "+name) | ||
cmd.Stdout = os.Stdout | ||
cmd.Stderr = os.Stderr | ||
if err := cmd.Run(); err != nil { | ||
return fmt.Errorf("Internal Error running SkyPilot stop cmd: %v", err) | ||
} | ||
|
||
if down { | ||
cmd = exec.Command("/bin/bash", "-c", "env DOCKER_HOST=unix:///var/run/docker.sock docker exec sky sky down --yes "+name+" ; docker stop sky") | ||
cmd.Stdout = os.Stdout | ||
cmd.Stderr = os.Stderr | ||
if err := cmd.Run(); err != nil { | ||
return fmt.Errorf("Internal Error running SkyPilot down cmd: %v", err) | ||
} | ||
} | ||
return nil | ||
} |
Oops, something went wrong.