-
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.
Signed-off-by: aavarghese <[email protected]>
- Loading branch information
1 parent
f4b1f45
commit cff976d
Showing
7 changed files
with
203 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package skypilot | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"path" | ||
|
||
"github.com/IBM/go-sdk-core/v4/core" | ||
"github.com/IBM/vpc-go-sdk/vpcv1" | ||
) | ||
|
||
func Authenticator(apiKey string, resourceGroupID string) (*vpcv1.VpcV1, error) { | ||
vpcService, err := vpcv1.NewVpcV1(&vpcv1.VpcV1Options{ | ||
Authenticator: &core.IamAuthenticator{ | ||
ApiKey: apiKey, | ||
}, | ||
}) | ||
if err != nil { | ||
return nil, errors.New("Error creating VPC Service with apikey" + apiKey) | ||
} | ||
|
||
//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: " + resourceGroupID} | ||
|
||
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-nightly") | ||
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 | ||
} |
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,85 @@ | ||
package skypilot | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"strconv" | ||
|
||
"lunchpail.io/pkg/assembly" | ||
"lunchpail.io/pkg/be" | ||
"lunchpail.io/pkg/ir/llir" | ||
) | ||
|
||
type Action string | ||
|
||
const ( | ||
Launch Action = "launch" | ||
Stop Action = "stop" | ||
Down Action = "down" | ||
) | ||
|
||
func launchSkyCluster(name string, ir llir.LLIR, count int, zone string, profile string, imageID string) error { | ||
appYamlString, err := ir.Marshal() | ||
if err != nil { | ||
return fmt.Errorf("Failed to marshall yaml: %v", err) | ||
} | ||
|
||
f, err := os.Create("app.yaml") | ||
if err != nil { | ||
return err | ||
} | ||
defer f.Close() | ||
_, err = f.WriteString(appYamlString) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cmdStr := "env DOCKER_HOST=unix:///var/run/docker.sock docker exec sky sky launch -c " + name + " --workdir . --cloud ibm --num-nodes " + strconv.Itoa(count) + | ||
" --zone " + zone + " --image-id " + imageID + " --instance-type " + profile + " --env SKYPILOT_DEBUG=1" + | ||
" --idle-minutes-to-autostop 10 --yes \"kubectl apply -f app.yaml\"" | ||
cmd := exec.Command("/bin/bash", "-c", cmdStr) | ||
cmd.Stdout = os.Stdout | ||
cmd.Stderr = os.Stderr | ||
if err := cmd.Run(); err != nil { | ||
return fmt.Errorf("Internal Error running SkyPilot launch cmd: %v", err) | ||
} | ||
return nil | ||
} | ||
|
||
func SetAction(aopts assembly.Options, ir llir.LLIR, runname string, action Action) error { | ||
|
||
if action == Stop || action == Down { | ||
if err := stopOrDownSkyCluster(runname, action == Down); err != nil { | ||
return err | ||
} | ||
} else if action == Launch { | ||
vpcService, err := Authenticator(aopts.ApiKey, aopts.ResourceGroupID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var workerCount int32 | ||
for _, c := range ir.Components { | ||
for _, j := range c.Jobs { | ||
workerCount = *j.Spec.Parallelism | ||
} | ||
} | ||
//Compute number of VSIs to be provisioned and job parallelism for each VSI | ||
parallelism, numInstances, err := be.ComputeParallelismAndInstanceCount(vpcService, aopts.Profile, workerCount) | ||
if err != nil { | ||
return fmt.Errorf("Failed to compute number of instances and job parallelism: %v", err) | ||
} | ||
|
||
for _, c := range ir.Components { | ||
for _, j := range c.Jobs { | ||
*j.Spec.Parallelism = int32(parallelism) | ||
} | ||
} | ||
|
||
if err := launchSkyCluster(runname, ir, numInstances, aopts.Zone, aopts.Profile, aopts.ImageID); err != nil { | ||
return err | ||
} | ||
} | ||
return 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
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