Skip to content

Commit

Permalink
Merge branch 'workflow-child' of https://github.com/packethost/rover
Browse files Browse the repository at this point in the history
…into workflow-child
  • Loading branch information
parauliya committed Nov 4, 2019
2 parents f69b7b8 + 0c3e2be commit 2a8c298
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion grpc-server/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func (s *server) CreateWorkflow(ctx context.Context, in *workflow.CreateRequest)
labels["op"] = "createworkflow"
msg = "creating a new workflow"
id := uuid.NewV4()
//var data string
fn := func() error {
wf := db.Workflow{
ID: id.String(),
Expand All @@ -52,7 +53,6 @@ func (s *server) CreateWorkflow(ctx context.Context, in *workflow.CreateRequest)
if err != nil {
return err
}

return nil
}

Expand Down
31 changes: 30 additions & 1 deletion worker/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"log"
"os"

Expand All @@ -19,6 +20,11 @@ var (
)

func executeAction(ctx context.Context, action *pb.WorkflowAction) error {
err := pullActionImage(ctx, action.GetImage())
if err != nil {
log.Fatalln("Action: ", action.Name, "Failed for error: ", err)
return err
}
id, err := createContainer(ctx, action)
if err != nil {
log.Fatalln("Action: ", action.Name, "Failed for error: ", err)
Expand All @@ -31,17 +37,40 @@ func executeAction(ctx context.Context, action *pb.WorkflowAction) error {
log.Fatalln("Action: ", action.Name, "Failed for error: ", err)
return err
}
// TODO: use "github.com/docker/docker/pkg/stdcopy"

io.Copy(os.Stdout, out)
return nil
}

func pullActionImage(ctx context.Context, image string) error {
f, err := os.Open("/" + registry + "/ca.crt")
defer f.Close()
if err != nil {
log.Fatalln("Failed to LOAD the certificate for registry:", registry)
return err
}
auth, err := ioutil.ReadAll(f)
if err != nil {
log.Fatalln("Failed to READ the certificate for registry:", registry)
return err
}

rw, err := cli.ImagePull(ctx, registry+"/"+image, types.ImagePullOptions{RegistryAuth: string(auth)})
defer rw.Close()
if err != nil {
log.Fatalln("Failed to pull Docker image", err)
return err
}
return nil
}

func createContainer(ctx context.Context, action *pb.WorkflowAction) (string, error) {
config := &container.Config{
Image: registry + "/" + action.GetImage(),
AttachStdout: true,
AttachStderr: true,
}

resp, err := cli.ContainerCreate(ctx, config, nil, nil, action.GetName())
if err != nil {
log.Fatalln(err)
Expand Down

0 comments on commit 2a8c298

Please sign in to comment.