-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
s2i: Add img support #33
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package config | ||
|
||
const ( | ||
KubeConfig = "kubeconfig" | ||
S2I = "s2i" | ||
S2IProvider = "provider" | ||
S2IProviderS2I = "s2i" | ||
S2IProviderImg = "img" | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package img | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
|
||
"github.com/caicloud/ciao/pkg/types" | ||
) | ||
|
||
const ( | ||
prefix = "kubeflow-kernel-code." | ||
codeFile = "code.py" | ||
dockerFile = "Dockerfile" | ||
imageOwner = "gaocegege" | ||
) | ||
|
||
// Client is the type for using img. | ||
type Client struct { | ||
} | ||
|
||
// New creates a new Client. | ||
func New() *Client { | ||
return &Client{} | ||
} | ||
|
||
// SourceToImage converts the code to the image. | ||
func (c Client) SourceToImage(code string, parameter *types.Parameter) (string, error) { | ||
// This is a hack to let kubernetes do not pull from docker registry. | ||
imageName := fmt.Sprintf("%s:v1", filepath.Join(imageOwner, parameter.GenerateName)) | ||
|
||
dir, err := ioutil.TempDir(os.TempDir(), prefix) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
err = ioutil.WriteFile(filepath.Join(dir, codeFile), []byte(code), 0666) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
if err = c.writeDockerfile(dir, parameter); err != nil { | ||
return "", err | ||
} | ||
|
||
cmd := exec.Command("img", "build", "-t", imageName, dir) | ||
output, err := cmd.Output() | ||
if err != nil { | ||
fmt.Printf("[kubeflow] Failed to build the image: %s", string(output)) | ||
return "", err | ||
} | ||
|
||
fmt.Printf("[kubeflow] Pushing the image...\n") | ||
cmd = exec.Command("img", "push", imageName) | ||
output, err = cmd.Output() | ||
if err != nil { | ||
fmt.Printf("[kubeflow] Failed to push the image: %s", string(output)) | ||
return "", err | ||
} | ||
return imageName, nil | ||
} | ||
|
||
func (c Client) writeDockerfile(dir string, parameter *types.Parameter) error { | ||
var template string | ||
switch parameter.Framework { | ||
case types.FrameworkTypeTensorFlow: | ||
template = tensorflowTemplate | ||
case types.FrameworkTypePyTorch: | ||
template = pytorchTemplate | ||
} | ||
return ioutil.WriteFile(filepath.Join(dir, dockerFile), []byte(template), 0666) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package img | ||
|
||
const ( | ||
tensorflowTemplate = `FROM tensorflow/tensorflow:1.10.1-py3 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'm not sure it will always work; most of the time, we need a lot libraries other than tensorflow. Do you have any solution in mind? I think this is not specific to ciao, but a general question. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the current stage, I prefer all-in-one support. In the future, I think we should support adding new layers in the image to add dependencies while I have no detailed design for it since it is out of the scope of ciao now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rough approaches:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I created an issue for it. #35 |
||
LABEL maintainer="Kubeflow" | ||
COPY ./code.py / | ||
ENTRYPOINT ["python", "/app/code.py"]` | ||
|
||
pytorchTemplate = `FROM pytorch/pytorch:v0.2 | ||
LABEL maintainer="Kubeflow" | ||
COPY ./code.py / | ||
ENTRYPOINT ["python", "/code.py"]` | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM pytorch/pytorch:0.4_cuda9_cudnn7 | ||
FROM pytorch/pytorch:v0.2 | ||
|
||
LABEL maintainer="Kubeflow" | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here we need to pre-install
img
? what if notebook itself is running in a pod?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then img should be added into the image, with runc and some other deps.