-
Notifications
You must be signed in to change notification settings - Fork 618
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
Windows support #164
Windows support #164
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,70 @@ | ||
/* | ||
Copyright The containerd Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/containerd/containerd" | ||
"github.com/containerd/containerd/namespaces" | ||
"github.com/opencontainers/go-digest" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func newClient(clicontext *cli.Context) (*containerd.Client, context.Context, context.CancelFunc, error) { | ||
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. This does not necessarily need to be a separate file. |
||
ctx := context.Background() | ||
namespace := clicontext.String("namespace") | ||
ctx = namespaces.WithNamespace(ctx, namespace) | ||
address := clicontext.String("address") | ||
const dockerContainerdaddress = "\\\\.\\pipe\\containerd-containerd" | ||
//TODO fall back? | ||
client, err := containerd.New(address) | ||
if err != nil { | ||
return nil, nil, nil, err | ||
} | ||
var cancel context.CancelFunc | ||
ctx, cancel = context.WithCancel(ctx) | ||
return client, ctx, cancel, nil | ||
} | ||
|
||
// getDataStore returns a string like "/var/lib/nerdctl/1935db59". | ||
// "1935db9" is from `$(echo -n "/run/containerd/containerd.sock" | sha256sum | cut -c1-8)`` | ||
func getDataStore(clicontext *cli.Context) (string, error) { | ||
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. How is this different from Linux implementation? |
||
dataRoot := clicontext.String("data-root") | ||
if err := os.MkdirAll(dataRoot, 0700); err != nil { | ||
return "", err | ||
} | ||
addrHash, err := getAddrHash(clicontext.String("address")) | ||
if err != nil { | ||
return "", err | ||
} | ||
dataStore := filepath.Join(dataRoot, addrHash) | ||
if err := os.MkdirAll(dataStore, 0700); err != nil { | ||
return "", err | ||
} | ||
return dataStore, nil | ||
} | ||
|
||
func getAddrHash(addr string) (string, error) { | ||
const addrHashLen = 8 | ||
|
||
d := digest.SHA256.FromString(addr) | ||
h := d.Encoded()[0:addrHashLen] | ||
return h, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
Copyright The containerd Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/containerd/containerd/pkg/cap" | ||
"github.com/opencontainers/runtime-spec/specs-go" | ||
) | ||
|
||
func setCapabilities(pspec *specs.Process) error { | ||
if pspec.Capabilities == nil { | ||
pspec.Capabilities = &specs.LinuxCapabilities{} | ||
} | ||
allCaps, err := cap.Current() | ||
if err != nil { | ||
return err | ||
} | ||
pspec.Capabilities.Bounding = allCaps | ||
pspec.Capabilities.Permitted = pspec.Capabilities.Bounding | ||
pspec.Capabilities.Inheritable = pspec.Capabilities.Bounding | ||
pspec.Capabilities.Effective = pspec.Capabilities.Bounding | ||
|
||
return nil | ||
// https://github.com/moby/moby/pull/36466/files | ||
// > `docker exec --privileged` does not currently disable AppArmor | ||
// > profiles. Privileged configuration of the container is inherited | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
Copyright The containerd Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/opencontainers/runtime-spec/specs-go" | ||
) | ||
|
||
func setCapabilities(pspec *specs.Process) error { | ||
//no op windows | ||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
Copyright The containerd Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
"golang.org/x/crypto/ssh/terminal" | ||
"os" | ||
"syscall" | ||
) | ||
|
||
func readPassword() (string, error) { | ||
var fd int | ||
if terminal.IsTerminal(syscall.Stdin) { | ||
fd = syscall.Stdin | ||
} else { | ||
tty, err := os.Open("/dev/tty") | ||
if err != nil { | ||
return "", errors.Wrap(err, "error allocating terminal") | ||
} | ||
defer tty.Close() | ||
fd = int(tty.Fd()) | ||
} | ||
bytePassword, err := terminal.ReadPassword(fd) | ||
if err != nil { | ||
return "", errors.Wrap(err, "error reading password") | ||
} | ||
|
||
return string(bytePassword), nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
Copyright The containerd Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"bufio" | ||
"os" | ||
) | ||
|
||
func readPassword() (string, error) { | ||
reader := bufio.NewReader(os.Stdin) | ||
pwd, _ := reader.ReadString('\n') | ||
|
||
return pwd, nil | ||
} |
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.
This produces
nerdctl-$(VERSION_TRIMMED)-linux-amd64.tar.gz
, soGOOS
has to be hard-coded tolinux
here.Instead, we should add
GOOS=windows
that producesnerdctl-$(VERSION_TRIMMED)-windows-amd64.zip