Skip to content
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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# -----------------------------------------------------------------------------

GO ?= go

GOOS := $(shell go env GOOS)

PACKAGE := github.com/containerd/nerdctl
BINDIR ?= /usr/local/bin
Expand All @@ -28,7 +28,7 @@ VERSION=$(shell git describe --match 'v[0-9]*' --dirty='.m' --always --tags)
VERSION_TRIMMED := $(VERSION:v%=%)
REVISION=$(shell git rev-parse HEAD)$(shell if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi)

export GO_BUILD=GO111MODULE=on CGO_ENABLED=0 $(GO) build -ldflags "-s -w -X $(PACKAGE)/pkg/version.Version=$(VERSION) -X $(PACKAGE)/pkg/version.Revision=$(REVISION)"
export GO_BUILD=GO111MODULE=on CGO_ENABLED=0 GOOS=$(GOOS) $(GO) build -ldflags "-s -w -X $(PACKAGE)/pkg/version.Version=$(VERSION) -X $(PACKAGE)/pkg/version.Revision=$(REVISION)"

all: binaries

Expand Down Expand Up @@ -57,19 +57,19 @@ install:
TAR_FLAGS=--transform 's/.*\///g' --owner=0 --group=0

artifacts: clean
GOOS=linux GOARCH=amd64 make -C $(CURDIR) binaries
GOOS=$(GOOS) GOARCH=amd64 make -C $(CURDIR) binaries
Copy link
Member

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, so GOOS has to be hard-coded to linux here.

Instead, we should add GOOS=windows that produces nerdctl-$(VERSION_TRIMMED)-windows-amd64.zip

tar $(TAR_FLAGS) -czvf $(CURDIR)/_output/nerdctl-$(VERSION_TRIMMED)-linux-amd64.tar.gz _output/nerdctl extras/rootless/*

GOOS=linux GOARCH=arm64 make -C $(CURDIR) binaries
GOOS=$(GOOS) GOARCH=arm64 make -C $(CURDIR) binaries
tar $(TAR_FLAGS) -czvf $(CURDIR)/_output/nerdctl-$(VERSION_TRIMMED)-linux-arm64.tar.gz _output/nerdctl extras/rootless/*

GOOS=linux GOARCH=arm GOARM=7 make -C $(CURDIR) binaries
GOOS=$(GOOS) GOARCH=arm GOARM=7 make -C $(CURDIR) binaries
tar $(TAR_FLAGS) -czvf $(CURDIR)/_output/nerdctl-$(VERSION_TRIMMED)-linux-arm-v7.tar.gz _output/nerdctl extras/rootless/*

GOOS=linux GOARCH=ppc64le make -C $(CURDIR) binaries
GOOS=$(GOOS) GOARCH=ppc64le make -C $(CURDIR) binaries
tar $(TAR_FLAGS) -czvf $(CURDIR)/_output/nerdctl-$(VERSION_TRIMMED)-linux-ppc64le.tar.gz _output/nerdctl extras/rootless/*

GOOS=linux GOARCH=s390x make -C $(CURDIR) binaries
GOOS=$(GOOS) GOARCH=s390x make -C $(CURDIR) binaries
tar $(TAR_FLAGS) -czvf $(CURDIR)/_output/nerdctl-$(VERSION_TRIMMED)-linux-s390x.tar.gz _output/nerdctl extras/rootless/*

rm -f $(CURDIR)/_output/nerdctl
Expand Down
File renamed without changes.
70 changes: 70 additions & 0 deletions client_windows.go
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not necessarily need to be a separate file.
The containerd address can be changed with if runtime.GOOS == "windows"{}.

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) {
Copy link
Member

Choose a reason for hiding this comment

The 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
}
4 changes: 4 additions & 0 deletions container_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ type containerInspector struct {
entries []interface{}
}

type Inspector interface {
Inspect(context.Context, containerwalker.ContainerWalker)
}

func (x *containerInspector) Handler(ctx context.Context, found containerwalker.Found) error {
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
Expand Down
14 changes: 1 addition & 13 deletions exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/containerd/containerd/cio"
"github.com/containerd/containerd/cmd/ctr/commands"
"github.com/containerd/containerd/cmd/ctr/commands/tasks"
"github.com/containerd/containerd/pkg/cap"
"github.com/containerd/nerdctl/pkg/idgen"
"github.com/containerd/nerdctl/pkg/idutil/containerwalker"
"github.com/containerd/nerdctl/pkg/strutil"
Expand Down Expand Up @@ -224,21 +223,10 @@ func generateExecProcessSpec(ctx context.Context, clicontext *cli.Context, conta
}

if clicontext.Bool("privileged") {
if pspec.Capabilities == nil {
pspec.Capabilities = &specs.LinuxCapabilities{}
}
allCaps, err := cap.Current()
err = setCapabilities(pspec)
if err != nil {
return nil, err
}
pspec.Capabilities.Bounding = allCaps
pspec.Capabilities.Permitted = pspec.Capabilities.Bounding
pspec.Capabilities.Inheritable = pspec.Capabilities.Bounding
pspec.Capabilities.Effective = pspec.Capabilities.Bounding

// https://github.com/moby/moby/pull/36466/files
// > `docker exec --privileged` does not currently disable AppArmor
// > profiles. Privileged configuration of the container is inherited
}

return pspec, nil
Expand Down
41 changes: 41 additions & 0 deletions exec_linux.go
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
}
26 changes: 26 additions & 0 deletions exec_windows.go
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
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/containerd/nerdctl
go 1.16

require (
github.com/Microsoft/hcsshim v0.8.16
github.com/containerd/cgroups v0.0.0-20210114181951-8a68de567b68
github.com/containerd/console v1.0.1
github.com/containerd/containerd v1.5.0-beta.4
Expand Down Expand Up @@ -30,6 +31,6 @@ require (
github.com/urfave/cli/v2 v2.3.0
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a
golang.org/x/sys v0.0.0-20210228012217-479acdf4ea46
golang.org/x/sys v0.0.0-20210324051608-47abb6519492
gotest.tools/v3 v3.0.3
)
7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ github.com/Microsoft/hcsshim v0.8.7-0.20190325164909-8abdbb8205e4/go.mod h1:Op3h
github.com/Microsoft/hcsshim v0.8.7/go.mod h1:OHd7sQqRFrYd3RmSgbgji+ctCwkbq2wbEYNSzOYtcBQ=
github.com/Microsoft/hcsshim v0.8.9/go.mod h1:5692vkUqntj1idxauYlpoINNKeqCiG6Sg38RRsjT5y8=
github.com/Microsoft/hcsshim v0.8.14/go.mod h1:NtVKoYxQuTLx6gEq0L96c9Ju4JbRJ4nY2ow3VK6a9Lg=
github.com/Microsoft/hcsshim v0.8.15 h1:Aof83YILRs2Vx3GhHqlvvfyx1asRJKMFIMeVlHsZKtI=
github.com/Microsoft/hcsshim v0.8.15/go.mod h1:x38A4YbHbdxJtc0sF6oIz+RG0npwSCAvn69iY6URG00=
github.com/Microsoft/hcsshim v0.8.16 h1:8/auA4LFIZFTGrqfKhGBSXwM6/4X1fHa/xniyEHu8ac=
github.com/Microsoft/hcsshim v0.8.16/go.mod h1:o5/SZqmR7x9JNKsW3pu+nqHm0MF8vbA+VxGOoXdC600=
github.com/Microsoft/hcsshim/test v0.0.0-20201218223536-d3e5debf77da/go.mod h1:5hlzMzRKMLyo42nCZ9oml8AdTlq/0cvIaBv6tK1RehU=
github.com/Microsoft/hcsshim/test v0.0.0-20210227013316-43a75bb4edd3/go.mod h1:mw7qgWloBUl75W/gVH3cQszUg1+gUITj7D6NY7ywVnY=
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
Expand Down Expand Up @@ -790,8 +791,8 @@ golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20201202213521-69691e467435/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210228012217-479acdf4ea46 h1:V066+OYJ66oTjnhm4Yrn7SXIwSCiDQJxpBxmvqb1N1c=
golang.org/x/sys v0.0.0-20210228012217-479acdf4ea46/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210324051608-47abb6519492 h1:Paq34FxTluEPvVyayQqMPgHm+vTOrIifmcYxFBx9TLg=
golang.org/x/sys v0.0.0-20210324051608-47abb6519492/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Expand Down
20 changes: 3 additions & 17 deletions login.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ import (
"context"
"fmt"
"io/ioutil"
"os"
"runtime"
"strings"
"syscall"

"github.com/containerd/nerdctl/pkg/version"
dockercliconfig "github.com/docker/cli/cli/config"
Expand All @@ -35,7 +33,6 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
"golang.org/x/crypto/ssh/terminal"
)

type loginOptions struct {
Expand Down Expand Up @@ -210,22 +207,11 @@ func ConfigureAuthentification(clicontext *cli.Context, authConfig *types.AuthCo
if options.password == "" {

fmt.Print("Enter Password: ")
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)
pwd, err := readPassword()
if err != nil {
return errors.Wrap(err, "error reading password")
return err
}
options.password = string(bytePassword)
options.password = pwd
}

if options.password == "" {
Expand Down
44 changes: 44 additions & 0 deletions login_linux.go
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
}
29 changes: 29 additions & 0 deletions login_windows.go
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
}
Loading