Windows: Updates Windows Vendoring
Updates windows dependent libraries for vendoing.
This commit is contained in:
191
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/LICENSE
generated
vendored
Normal file
191
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/LICENSE
generated
vendored
Normal file
@ -0,0 +1,191 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
Copyright 2014 Docker, Inc.
|
||||
|
||||
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.
|
22
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/NOTICE
generated
vendored
Normal file
22
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/NOTICE
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
runhcs is a fork of runc.
|
||||
|
||||
The following is runc's legal notice.
|
||||
|
||||
---
|
||||
|
||||
runc
|
||||
|
||||
Copyright 2012-2015 Docker, Inc.
|
||||
|
||||
This product includes software developed at Docker, Inc. (http://www.docker.com).
|
||||
|
||||
The following is courtesy of our legal counsel:
|
||||
|
||||
Use and transfer of Docker may be subject to certain restrictions by the
|
||||
United States and other governments.
|
||||
It is your responsibility to ensure that your use and/or transfer does not
|
||||
violate applicable laws.
|
||||
|
||||
For more information, please see http://www.bis.doc.gov
|
||||
|
||||
See also http://www.apache.org/dev/crypto.html and/or seek legal counsel.
|
848
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/container.go
generated
vendored
Normal file
848
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/container.go
generated
vendored
Normal file
@ -0,0 +1,848 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
winio "github.com/Microsoft/go-winio"
|
||||
"github.com/Microsoft/hcsshim/internal/cni"
|
||||
"github.com/Microsoft/hcsshim/internal/guid"
|
||||
"github.com/Microsoft/hcsshim/internal/hcs"
|
||||
"github.com/Microsoft/hcsshim/internal/hcsoci"
|
||||
"github.com/Microsoft/hcsshim/internal/logfields"
|
||||
"github.com/Microsoft/hcsshim/internal/regstate"
|
||||
"github.com/Microsoft/hcsshim/internal/runhcs"
|
||||
"github.com/Microsoft/hcsshim/internal/uvm"
|
||||
"github.com/Microsoft/hcsshim/osversion"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/sirupsen/logrus"
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
var errContainerStopped = errors.New("container is stopped")
|
||||
|
||||
type persistedState struct {
|
||||
// ID is the id of this container/UVM.
|
||||
ID string `json:",omitempty"`
|
||||
// Owner is the owner value passed into the runhcs command and may be `""`.
|
||||
Owner string `json:",omitempty"`
|
||||
// SandboxID is the sandbox identifer passed in via OCI specifications. This
|
||||
// can either be the sandbox itself or the sandbox this container should run
|
||||
// in. See `parseSandboxAnnotations`.
|
||||
SandboxID string `json:",omitempty"`
|
||||
// HostID will be VM ID hosting this container. If a sandbox is used it will
|
||||
// match the `SandboxID`.
|
||||
HostID string `json:",omitempty"`
|
||||
// Bundle is the folder path on disk where the container state and spec files
|
||||
// reside.
|
||||
Bundle string `json:",omitempty"`
|
||||
Created time.Time `json:",omitempty"`
|
||||
Rootfs string `json:",omitempty"`
|
||||
// Spec is the in memory deserialized values found on `Bundle\config.json`.
|
||||
Spec *specs.Spec `json:",omitempty"`
|
||||
RequestedNetNS string `json:",omitempty"`
|
||||
// IsHost is `true` when this is a VM isolated config.
|
||||
IsHost bool `json:",omitempty"`
|
||||
// UniqueID is a unique ID generated per container config.
|
||||
UniqueID guid.GUID `json:",omitempty"`
|
||||
// HostUniqueID is the unique ID of the hosting VM if this container is
|
||||
// hosted.
|
||||
HostUniqueID guid.GUID `json:",omitempty"`
|
||||
}
|
||||
|
||||
type containerStatus string
|
||||
|
||||
const (
|
||||
containerRunning containerStatus = "running"
|
||||
containerStopped containerStatus = "stopped"
|
||||
containerCreated containerStatus = "created"
|
||||
containerPaused containerStatus = "paused"
|
||||
containerUnknown containerStatus = "unknown"
|
||||
|
||||
keyState = "state"
|
||||
keyResources = "resources"
|
||||
keyShimPid = "shim"
|
||||
keyInitPid = "pid"
|
||||
keyNetNS = "netns"
|
||||
// keyPidMapFmt is the format to use when mapping a host OS pid to a guest
|
||||
// pid.
|
||||
keyPidMapFmt = "pid-%d"
|
||||
)
|
||||
|
||||
type container struct {
|
||||
persistedState
|
||||
ShimPid int
|
||||
hc *hcs.System
|
||||
resources *hcsoci.Resources
|
||||
}
|
||||
|
||||
func startProcessShim(id, pidFile, logFile string, spec *specs.Process) (_ *os.Process, err error) {
|
||||
// Ensure the stdio handles inherit to the child process. This isn't undone
|
||||
// after the StartProcess call because the caller never launches another
|
||||
// process before exiting.
|
||||
for _, f := range []*os.File{os.Stdin, os.Stdout, os.Stderr} {
|
||||
err = windows.SetHandleInformation(windows.Handle(f.Fd()), windows.HANDLE_FLAG_INHERIT, windows.HANDLE_FLAG_INHERIT)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
args := []string{
|
||||
"--stdin", strconv.Itoa(int(os.Stdin.Fd())),
|
||||
"--stdout", strconv.Itoa(int(os.Stdout.Fd())),
|
||||
"--stderr", strconv.Itoa(int(os.Stderr.Fd())),
|
||||
}
|
||||
if spec != nil {
|
||||
args = append(args, "--exec")
|
||||
}
|
||||
if strings.HasPrefix(logFile, runhcs.SafePipePrefix) {
|
||||
args = append(args, "--log-pipe", logFile)
|
||||
}
|
||||
args = append(args, id)
|
||||
return launchShim("shim", pidFile, logFile, args, spec)
|
||||
}
|
||||
|
||||
func launchShim(cmd, pidFile, logFile string, args []string, data interface{}) (_ *os.Process, err error) {
|
||||
executable, err := os.Executable()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Create a pipe to use as stderr for the shim process. This is used to
|
||||
// retrieve early error information, up to the point that the shim is ready
|
||||
// to launch a process in the container.
|
||||
rp, wp, err := os.Pipe()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rp.Close()
|
||||
defer wp.Close()
|
||||
|
||||
// Create a pipe to send the data, if one is provided.
|
||||
var rdatap, wdatap *os.File
|
||||
if data != nil {
|
||||
rdatap, wdatap, err = os.Pipe()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rdatap.Close()
|
||||
defer wdatap.Close()
|
||||
}
|
||||
|
||||
var log *os.File
|
||||
fullargs := []string{os.Args[0]}
|
||||
if logFile != "" {
|
||||
if !strings.HasPrefix(logFile, runhcs.SafePipePrefix) {
|
||||
log, err = os.OpenFile(logFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND|os.O_SYNC, 0666)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer log.Close()
|
||||
}
|
||||
|
||||
fullargs = append(fullargs, "--log-format", logFormat)
|
||||
if logrus.GetLevel() == logrus.DebugLevel {
|
||||
fullargs = append(fullargs, "--debug")
|
||||
}
|
||||
}
|
||||
fullargs = append(fullargs, cmd)
|
||||
fullargs = append(fullargs, args...)
|
||||
attr := &os.ProcAttr{
|
||||
Files: []*os.File{rdatap, wp, log},
|
||||
}
|
||||
p, err := os.StartProcess(executable, fullargs, attr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
p.Kill()
|
||||
}
|
||||
}()
|
||||
|
||||
wp.Close()
|
||||
|
||||
// Write the data if provided.
|
||||
if data != nil {
|
||||
rdatap.Close()
|
||||
dataj, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, err = wdatap.Write(dataj)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
wdatap.Close()
|
||||
}
|
||||
|
||||
err = runhcs.GetErrorFromPipe(rp, p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if pidFile != "" {
|
||||
if err = createPidFile(pidFile, p.Pid); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return p, nil
|
||||
}
|
||||
|
||||
// parseSandboxAnnotations searches `a` for various annotations used by
|
||||
// different runtimes to represent a sandbox ID, and sandbox type.
|
||||
//
|
||||
// If found returns the tuple `(sandboxID, isSandbox)` where `isSandbox == true`
|
||||
// indicates the identifer is the sandbox itself; `isSandbox == false` indicates
|
||||
// the identifer is the sandbox in which to place this container. Otherwise
|
||||
// returns `("", false)`.
|
||||
func parseSandboxAnnotations(a map[string]string) (string, bool) {
|
||||
var t, id string
|
||||
if t = a["io.kubernetes.cri.container-type"]; t != "" {
|
||||
id = a["io.kubernetes.cri.sandbox-id"]
|
||||
} else if t = a["io.kubernetes.cri-o.ContainerType"]; t != "" {
|
||||
id = a["io.kubernetes.cri-o.SandboxID"]
|
||||
} else if t = a["io.kubernetes.docker.type"]; t != "" {
|
||||
id = a["io.kubernetes.sandbox.id"]
|
||||
if t == "podsandbox" {
|
||||
t = "sandbox"
|
||||
}
|
||||
}
|
||||
if t == "container" {
|
||||
return id, false
|
||||
}
|
||||
if t == "sandbox" {
|
||||
return id, true
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
||||
// parseAnnotationsBool searches `a` for `key` and if found verifies that the
|
||||
// value is `true` or `false` in any case. If `key` is not found returns `def`.
|
||||
func parseAnnotationsBool(a map[string]string, key string, def bool) bool {
|
||||
if v, ok := a[key]; ok {
|
||||
switch strings.ToLower(v) {
|
||||
case "true":
|
||||
return true
|
||||
case "false":
|
||||
return false
|
||||
default:
|
||||
logrus.WithFields(logrus.Fields{
|
||||
logfields.OCIAnnotation: key,
|
||||
logfields.Value: v,
|
||||
logfields.ExpectedType: logfields.Bool,
|
||||
}).Warning("annotation could not be parsed")
|
||||
}
|
||||
}
|
||||
return def
|
||||
}
|
||||
|
||||
// parseAnnotationsCPU searches `s.Annotations` for the CPU annotation. If
|
||||
// not found searches `s` for the Windows CPU section. If neither are found
|
||||
// returns `def`.
|
||||
func parseAnnotationsCPU(s *specs.Spec, annotation string, def int32) int32 {
|
||||
if m := parseAnnotationsUint64(s.Annotations, annotation, 0); m != 0 {
|
||||
return int32(m)
|
||||
}
|
||||
if s.Windows != nil &&
|
||||
s.Windows.Resources != nil &&
|
||||
s.Windows.Resources.CPU != nil &&
|
||||
s.Windows.Resources.CPU.Count != nil &&
|
||||
*s.Windows.Resources.CPU.Count > 0 {
|
||||
return int32(*s.Windows.Resources.CPU.Count)
|
||||
}
|
||||
return def
|
||||
}
|
||||
|
||||
// parseAnnotationsMemory searches `s.Annotations` for the memory annotation. If
|
||||
// not found searches `s` for the Windows memory section. If neither are found
|
||||
// returns `def`.
|
||||
func parseAnnotationsMemory(s *specs.Spec, annotation string, def int32) int32 {
|
||||
if m := parseAnnotationsUint64(s.Annotations, annotation, 0); m != 0 {
|
||||
return int32(m)
|
||||
}
|
||||
if s.Windows != nil &&
|
||||
s.Windows.Resources != nil &&
|
||||
s.Windows.Resources.Memory != nil &&
|
||||
s.Windows.Resources.Memory.Limit != nil &&
|
||||
*s.Windows.Resources.Memory.Limit > 0 {
|
||||
return int32(*s.Windows.Resources.Memory.Limit)
|
||||
}
|
||||
return def
|
||||
}
|
||||
|
||||
// parseAnnotationsPreferredRootFSType searches `a` for `key` and verifies that the
|
||||
// value is in the set of allowed values. If `key` is not found returns `def`.
|
||||
func parseAnnotationsPreferredRootFSType(a map[string]string, key string, def uvm.PreferredRootFSType) uvm.PreferredRootFSType {
|
||||
if v, ok := a[key]; ok {
|
||||
switch v {
|
||||
case "initrd":
|
||||
return uvm.PreferredRootFSTypeInitRd
|
||||
case "vhd":
|
||||
return uvm.PreferredRootFSTypeVHD
|
||||
default:
|
||||
logrus.Warningf("annotation: '%s', with value: '%s' must be 'initrd' or 'vhd'", key, v)
|
||||
}
|
||||
}
|
||||
return def
|
||||
}
|
||||
|
||||
// parseAnnotationsUint32 searches `a` for `key` and if found verifies that the
|
||||
// value is a 32 bit unsigned integer. If `key` is not found returns `def`.
|
||||
func parseAnnotationsUint32(a map[string]string, key string, def uint32) uint32 {
|
||||
if v, ok := a[key]; ok {
|
||||
countu, err := strconv.ParseUint(v, 10, 32)
|
||||
if err == nil {
|
||||
v := uint32(countu)
|
||||
return v
|
||||
}
|
||||
logrus.WithFields(logrus.Fields{
|
||||
logfields.OCIAnnotation: key,
|
||||
logfields.Value: v,
|
||||
logfields.ExpectedType: logfields.Uint32,
|
||||
logrus.ErrorKey: err,
|
||||
}).Warning("annotation could not be parsed")
|
||||
}
|
||||
return def
|
||||
}
|
||||
|
||||
// parseAnnotationsUint64 searches `a` for `key` and if found verifies that the
|
||||
// value is a 64 bit unsigned integer. If `key` is not found returns `def`.
|
||||
func parseAnnotationsUint64(a map[string]string, key string, def uint64) uint64 {
|
||||
if v, ok := a[key]; ok {
|
||||
countu, err := strconv.ParseUint(v, 10, 64)
|
||||
if err == nil {
|
||||
return countu
|
||||
}
|
||||
logrus.WithFields(logrus.Fields{
|
||||
logfields.OCIAnnotation: key,
|
||||
logfields.Value: v,
|
||||
logfields.ExpectedType: logfields.Uint64,
|
||||
logrus.ErrorKey: err,
|
||||
}).Warning("annotation could not be parsed")
|
||||
}
|
||||
return def
|
||||
}
|
||||
|
||||
// startVMShim starts a vm-shim command with the specified `opts`. `opts` can be `uvm.OptionsWCOW` or `uvm.OptionsLCOW`
|
||||
func (c *container) startVMShim(logFile string, opts interface{}) (*os.Process, error) {
|
||||
var os string
|
||||
if _, ok := opts.(*uvm.OptionsLCOW); ok {
|
||||
os = "linux"
|
||||
} else {
|
||||
os = "windows"
|
||||
}
|
||||
args := []string{"--os", os}
|
||||
if strings.HasPrefix(logFile, runhcs.SafePipePrefix) {
|
||||
args = append(args, "--log-pipe", logFile)
|
||||
}
|
||||
args = append(args, c.VMPipePath())
|
||||
return launchShim("vmshim", "", logFile, args, opts)
|
||||
}
|
||||
|
||||
type containerConfig struct {
|
||||
ID string
|
||||
Owner string
|
||||
HostID string
|
||||
PidFile string
|
||||
ShimLogFile, VMLogFile string
|
||||
Spec *specs.Spec
|
||||
VMConsolePipe string
|
||||
}
|
||||
|
||||
func createContainer(cfg *containerConfig) (_ *container, err error) {
|
||||
// Store the container information in a volatile registry key.
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
vmisolated := cfg.Spec.Linux != nil || (cfg.Spec.Windows != nil && cfg.Spec.Windows.HyperV != nil)
|
||||
|
||||
sandboxID, isSandbox := parseSandboxAnnotations(cfg.Spec.Annotations)
|
||||
hostID := cfg.HostID
|
||||
if isSandbox {
|
||||
if sandboxID != cfg.ID {
|
||||
return nil, errors.New("sandbox ID must match ID")
|
||||
}
|
||||
} else if sandboxID != "" {
|
||||
// Validate that the sandbox container exists.
|
||||
sandbox, err := getContainer(sandboxID, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer sandbox.Close()
|
||||
if sandbox.SandboxID != sandboxID {
|
||||
return nil, fmt.Errorf("container %s is not a sandbox", sandboxID)
|
||||
}
|
||||
if hostID == "" {
|
||||
// Use the sandbox's host.
|
||||
hostID = sandbox.HostID
|
||||
} else if sandbox.HostID == "" {
|
||||
return nil, fmt.Errorf("sandbox container %s is not running in a VM host, but host %s was specified", sandboxID, hostID)
|
||||
} else if hostID != sandbox.HostID {
|
||||
return nil, fmt.Errorf("sandbox container %s has a different host %s from the requested host %s", sandboxID, sandbox.HostID, hostID)
|
||||
}
|
||||
if vmisolated && hostID == "" {
|
||||
return nil, fmt.Errorf("container %s is not a VM isolated sandbox", sandboxID)
|
||||
}
|
||||
}
|
||||
|
||||
uniqueID := guid.New()
|
||||
|
||||
newvm := false
|
||||
var hostUniqueID guid.GUID
|
||||
if hostID != "" {
|
||||
host, err := getContainer(hostID, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer host.Close()
|
||||
if !host.IsHost {
|
||||
return nil, fmt.Errorf("host container %s is not a VM host", hostID)
|
||||
}
|
||||
hostUniqueID = host.UniqueID
|
||||
} else if vmisolated && (isSandbox || cfg.Spec.Linux != nil || osversion.Get().Build >= osversion.RS5) {
|
||||
// This handles all LCOW, Pod Sandbox, and (Windows Xenon V2 for RS5+)
|
||||
hostID = cfg.ID
|
||||
newvm = true
|
||||
hostUniqueID = uniqueID
|
||||
}
|
||||
|
||||
// Make absolute the paths in Root.Path and Windows.LayerFolders.
|
||||
rootfs := ""
|
||||
if cfg.Spec.Root != nil {
|
||||
rootfs = cfg.Spec.Root.Path
|
||||
if rootfs != "" && !filepath.IsAbs(rootfs) && !strings.HasPrefix(rootfs, `\\?\`) {
|
||||
rootfs = filepath.Join(cwd, rootfs)
|
||||
cfg.Spec.Root.Path = rootfs
|
||||
}
|
||||
}
|
||||
|
||||
netNS := ""
|
||||
if cfg.Spec.Windows != nil {
|
||||
for i, f := range cfg.Spec.Windows.LayerFolders {
|
||||
if !filepath.IsAbs(f) && !strings.HasPrefix(rootfs, `\\?\`) {
|
||||
cfg.Spec.Windows.LayerFolders[i] = filepath.Join(cwd, f)
|
||||
}
|
||||
}
|
||||
|
||||
// Determine the network namespace to use.
|
||||
if cfg.Spec.Windows.Network != nil {
|
||||
if cfg.Spec.Windows.Network.NetworkSharedContainerName != "" {
|
||||
// RS4 case
|
||||
err = stateKey.Get(cfg.Spec.Windows.Network.NetworkSharedContainerName, keyNetNS, &netNS)
|
||||
if err != nil {
|
||||
if _, ok := err.(*regstate.NoStateError); !ok {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
} else if cfg.Spec.Windows.Network.NetworkNamespace != "" {
|
||||
// RS5 case
|
||||
netNS = cfg.Spec.Windows.Network.NetworkNamespace
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Store the initial container state in the registry so that the delete
|
||||
// command can clean everything up if something goes wrong.
|
||||
c := &container{
|
||||
persistedState: persistedState{
|
||||
ID: cfg.ID,
|
||||
Owner: cfg.Owner,
|
||||
Bundle: cwd,
|
||||
Rootfs: rootfs,
|
||||
Created: time.Now(),
|
||||
Spec: cfg.Spec,
|
||||
SandboxID: sandboxID,
|
||||
HostID: hostID,
|
||||
IsHost: newvm,
|
||||
RequestedNetNS: netNS,
|
||||
UniqueID: uniqueID,
|
||||
HostUniqueID: hostUniqueID,
|
||||
},
|
||||
}
|
||||
err = stateKey.Create(cfg.ID, keyState, &c.persistedState)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
c.Remove()
|
||||
}
|
||||
}()
|
||||
if isSandbox && vmisolated {
|
||||
cnicfg := cni.NewPersistedNamespaceConfig(netNS, cfg.ID, hostUniqueID)
|
||||
err = cnicfg.Store()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
cnicfg.Remove()
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// Start a VM if necessary.
|
||||
if newvm {
|
||||
var opts interface{}
|
||||
|
||||
const (
|
||||
annotationAllowOvercommit = "io.microsoft.virtualmachine.computetopology.memory.allowovercommit"
|
||||
annotationEnableDeferredCommit = "io.microsoft.virtualmachine.computetopology.memory.enabledeferredcommit"
|
||||
annotationMemorySizeInMB = "io.microsoft.virtualmachine.computetopology.memory.sizeinmb"
|
||||
annotationProcessorCount = "io.microsoft.virtualmachine.computetopology.processor.count"
|
||||
annotationVPMemCount = "io.microsoft.virtualmachine.devices.virtualpmem.maximumcount"
|
||||
annotationVPMemSize = "io.microsoft.virtualmachine.devices.virtualpmem.maximumsizebytes"
|
||||
annotationPreferredRootFSType = "io.microsoft.virtualmachine.lcow.preferredrootfstype"
|
||||
)
|
||||
|
||||
if cfg.Spec.Linux != nil {
|
||||
lopts := uvm.NewDefaultOptionsLCOW(vmID(c.ID), cfg.Owner)
|
||||
lopts.MemorySizeInMB = parseAnnotationsMemory(cfg.Spec, annotationMemorySizeInMB, lopts.MemorySizeInMB)
|
||||
lopts.AllowOvercommit = parseAnnotationsBool(cfg.Spec.Annotations, annotationAllowOvercommit, lopts.AllowOvercommit)
|
||||
lopts.EnableDeferredCommit = parseAnnotationsBool(cfg.Spec.Annotations, annotationEnableDeferredCommit, lopts.EnableDeferredCommit)
|
||||
lopts.ProcessorCount = parseAnnotationsCPU(cfg.Spec, annotationProcessorCount, lopts.ProcessorCount)
|
||||
lopts.ConsolePipe = cfg.VMConsolePipe
|
||||
lopts.VPMemDeviceCount = parseAnnotationsUint32(cfg.Spec.Annotations, annotationVPMemCount, lopts.VPMemDeviceCount)
|
||||
lopts.VPMemSizeBytes = parseAnnotationsUint64(cfg.Spec.Annotations, annotationVPMemSize, lopts.VPMemSizeBytes)
|
||||
lopts.PreferredRootFSType = parseAnnotationsPreferredRootFSType(cfg.Spec.Annotations, annotationPreferredRootFSType, lopts.PreferredRootFSType)
|
||||
switch lopts.PreferredRootFSType {
|
||||
case uvm.PreferredRootFSTypeInitRd:
|
||||
lopts.RootFSFile = uvm.InitrdFile
|
||||
case uvm.PreferredRootFSTypeVHD:
|
||||
lopts.RootFSFile = uvm.VhdFile
|
||||
}
|
||||
opts = lopts
|
||||
} else {
|
||||
wopts := uvm.NewDefaultOptionsWCOW(vmID(c.ID), cfg.Owner)
|
||||
wopts.MemorySizeInMB = parseAnnotationsMemory(cfg.Spec, annotationMemorySizeInMB, wopts.MemorySizeInMB)
|
||||
wopts.AllowOvercommit = parseAnnotationsBool(cfg.Spec.Annotations, annotationAllowOvercommit, wopts.AllowOvercommit)
|
||||
wopts.EnableDeferredCommit = parseAnnotationsBool(cfg.Spec.Annotations, annotationEnableDeferredCommit, wopts.EnableDeferredCommit)
|
||||
wopts.ProcessorCount = parseAnnotationsCPU(cfg.Spec, annotationProcessorCount, wopts.ProcessorCount)
|
||||
|
||||
// In order for the UVM sandbox.vhdx not to collide with the actual
|
||||
// nested Argon sandbox.vhdx we append the \vm folder to the last entry
|
||||
// in the list.
|
||||
layersLen := len(cfg.Spec.Windows.LayerFolders)
|
||||
layers := make([]string, layersLen)
|
||||
copy(layers, cfg.Spec.Windows.LayerFolders)
|
||||
|
||||
vmPath := filepath.Join(layers[layersLen-1], "vm")
|
||||
err := os.MkdirAll(vmPath, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
layers[layersLen-1] = vmPath
|
||||
|
||||
wopts.LayerFolders = layers
|
||||
opts = wopts
|
||||
}
|
||||
|
||||
shim, err := c.startVMShim(cfg.VMLogFile, opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
shim.Release()
|
||||
}
|
||||
|
||||
if c.HostID != "" {
|
||||
// Call to the VM shim process to create the container. This is done so
|
||||
// that the VM process can keep track of the VM's virtual hardware
|
||||
// resource use.
|
||||
err = c.issueVMRequest(runhcs.OpCreateContainer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.hc, err = hcs.OpenComputeSystem(cfg.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
// Create the container directly from this process.
|
||||
err = createContainerInHost(c, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// Create the shim process for the container.
|
||||
err = startContainerShim(c, cfg.PidFile, cfg.ShimLogFile)
|
||||
if err != nil {
|
||||
if e := c.Kill(); e == nil {
|
||||
c.Remove()
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func (c *container) ShimPipePath() string {
|
||||
return runhcs.SafePipePath("runhcs-shim-" + c.UniqueID.String())
|
||||
}
|
||||
|
||||
func (c *container) VMPipePath() string {
|
||||
return runhcs.VMPipePath(c.HostUniqueID)
|
||||
}
|
||||
|
||||
func (c *container) VMIsolated() bool {
|
||||
return c.HostID != ""
|
||||
}
|
||||
|
||||
func (c *container) unmountInHost(vm *uvm.UtilityVM, all bool) error {
|
||||
resources := &hcsoci.Resources{}
|
||||
err := stateKey.Get(c.ID, keyResources, resources)
|
||||
if _, ok := err.(*regstate.NoStateError); ok {
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = hcsoci.ReleaseResources(resources, vm, all)
|
||||
if err != nil {
|
||||
stateKey.Set(c.ID, keyResources, resources)
|
||||
return err
|
||||
}
|
||||
|
||||
err = stateKey.Clear(c.ID, keyResources)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *container) Unmount(all bool) error {
|
||||
if c.VMIsolated() {
|
||||
op := runhcs.OpUnmountContainerDiskOnly
|
||||
if all {
|
||||
op = runhcs.OpUnmountContainer
|
||||
}
|
||||
err := c.issueVMRequest(op)
|
||||
if err != nil {
|
||||
if _, ok := err.(*noVMError); ok {
|
||||
logrus.WithFields(logrus.Fields{
|
||||
logfields.ContainerID: c.ID,
|
||||
logfields.UVMID: c.HostID,
|
||||
logrus.ErrorKey: errors.New("failed to unmount container resources"),
|
||||
}).Warning("VM shim could not be contacted")
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
c.unmountInHost(nil, false)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func createContainerInHost(c *container, vm *uvm.UtilityVM) (err error) {
|
||||
if c.hc != nil {
|
||||
return errors.New("container already created")
|
||||
}
|
||||
|
||||
// Create the container without starting it.
|
||||
opts := &hcsoci.CreateOptions{
|
||||
ID: c.ID,
|
||||
Owner: c.Owner,
|
||||
Spec: c.Spec,
|
||||
HostingSystem: vm,
|
||||
NetworkNamespace: c.RequestedNetNS,
|
||||
}
|
||||
vmid := ""
|
||||
if vm != nil {
|
||||
vmid = vm.ID()
|
||||
}
|
||||
logrus.WithFields(logrus.Fields{
|
||||
logfields.ContainerID: c.ID,
|
||||
logfields.UVMID: vmid,
|
||||
}).Info("creating container in UVM")
|
||||
hc, resources, err := hcsoci.CreateContainer(opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
hc.Terminate()
|
||||
hc.Wait()
|
||||
hcsoci.ReleaseResources(resources, vm, true)
|
||||
}
|
||||
}()
|
||||
|
||||
// Record the network namespace to support namespace sharing by container ID.
|
||||
if resources.NetNS() != "" {
|
||||
err = stateKey.Set(c.ID, keyNetNS, resources.NetNS())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
err = stateKey.Set(c.ID, keyResources, resources)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.hc = hc
|
||||
return nil
|
||||
}
|
||||
|
||||
func startContainerShim(c *container, pidFile, logFile string) error {
|
||||
// Launch a shim process to later execute a process in the container.
|
||||
shim, err := startProcessShim(c.ID, pidFile, logFile, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer shim.Release()
|
||||
defer func() {
|
||||
if err != nil {
|
||||
shim.Kill()
|
||||
}
|
||||
}()
|
||||
|
||||
c.ShimPid = shim.Pid
|
||||
err = stateKey.Set(c.ID, keyShimPid, shim.Pid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if pidFile != "" {
|
||||
if err = createPidFile(pidFile, shim.Pid); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *container) Close() error {
|
||||
if c.hc == nil {
|
||||
return nil
|
||||
}
|
||||
return c.hc.Close()
|
||||
}
|
||||
|
||||
func (c *container) Exec() error {
|
||||
err := c.hc.Start()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if c.Spec.Process == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Alert the shim that the container is ready.
|
||||
pipe, err := winio.DialPipe(c.ShimPipePath(), nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer pipe.Close()
|
||||
|
||||
shim, err := os.FindProcess(c.ShimPid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer shim.Release()
|
||||
|
||||
err = runhcs.GetErrorFromPipe(pipe, shim)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func getContainer(id string, notStopped bool) (*container, error) {
|
||||
var c container
|
||||
err := stateKey.Get(id, keyState, &c.persistedState)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = stateKey.Get(id, keyShimPid, &c.ShimPid)
|
||||
if err != nil {
|
||||
if _, ok := err.(*regstate.NoStateError); !ok {
|
||||
return nil, err
|
||||
}
|
||||
c.ShimPid = -1
|
||||
}
|
||||
if notStopped && c.ShimPid == 0 {
|
||||
return nil, errContainerStopped
|
||||
}
|
||||
|
||||
hc, err := hcs.OpenComputeSystem(c.ID)
|
||||
if err == nil {
|
||||
c.hc = hc
|
||||
} else if !hcs.IsNotExist(err) {
|
||||
return nil, err
|
||||
} else if notStopped {
|
||||
return nil, errContainerStopped
|
||||
}
|
||||
|
||||
return &c, nil
|
||||
}
|
||||
|
||||
func (c *container) Remove() error {
|
||||
// Unmount any layers or mapped volumes.
|
||||
err := c.Unmount(!c.IsHost)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Follow kata's example and delay tearing down the VM until the owning
|
||||
// container is removed.
|
||||
if c.IsHost {
|
||||
vm, err := hcs.OpenComputeSystem(vmID(c.ID))
|
||||
if err == nil {
|
||||
if err := vm.Terminate(); hcs.IsPending(err) {
|
||||
vm.Wait()
|
||||
}
|
||||
}
|
||||
}
|
||||
return stateKey.Remove(c.ID)
|
||||
}
|
||||
|
||||
func (c *container) Kill() error {
|
||||
if c.hc == nil {
|
||||
return nil
|
||||
}
|
||||
err := c.hc.Terminate()
|
||||
if hcs.IsPending(err) {
|
||||
err = c.hc.Wait()
|
||||
}
|
||||
if hcs.IsAlreadyStopped(err) {
|
||||
err = nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *container) Status() (containerStatus, error) {
|
||||
if c.hc == nil || c.ShimPid == 0 {
|
||||
return containerStopped, nil
|
||||
}
|
||||
props, err := c.hc.Properties()
|
||||
if err != nil {
|
||||
if !strings.Contains(err.Error(), "operation is not valid in the current state") {
|
||||
return "", err
|
||||
}
|
||||
return containerUnknown, nil
|
||||
}
|
||||
state := containerUnknown
|
||||
switch props.State {
|
||||
case "", "Created":
|
||||
state = containerCreated
|
||||
case "Running":
|
||||
state = containerRunning
|
||||
case "Paused":
|
||||
state = containerPaused
|
||||
case "Stopped":
|
||||
state = containerStopped
|
||||
}
|
||||
return state, nil
|
||||
}
|
71
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/create-scratch.go
generated
vendored
Normal file
71
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/create-scratch.go
generated
vendored
Normal file
@ -0,0 +1,71 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/Microsoft/hcsshim/internal/appargs"
|
||||
"github.com/Microsoft/hcsshim/internal/lcow"
|
||||
"github.com/Microsoft/hcsshim/internal/uvm"
|
||||
"github.com/Microsoft/hcsshim/osversion"
|
||||
gcsclient "github.com/Microsoft/opengcs/client"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var createScratchCommand = cli.Command{
|
||||
Name: "create-scratch",
|
||||
Usage: "creates a scratch vhdx at 'destpath' that is ext4 formatted",
|
||||
Description: "Creates a scratch vhdx at 'destpath' that is ext4 formatted",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "destpath",
|
||||
Usage: "Required: describes the destination vhd path",
|
||||
},
|
||||
},
|
||||
Before: appargs.Validate(),
|
||||
Action: func(context *cli.Context) error {
|
||||
dest := context.String("destpath")
|
||||
if dest == "" {
|
||||
return errors.New("'destpath' is required")
|
||||
}
|
||||
|
||||
// If we only have v1 lcow support do it the old way.
|
||||
if osversion.Get().Build < osversion.RS5 {
|
||||
cfg := gcsclient.Config{
|
||||
Options: gcsclient.Options{
|
||||
KirdPath: filepath.Join(os.Getenv("ProgramFiles"), "Linux Containers"),
|
||||
KernelFile: "kernel",
|
||||
InitrdFile: uvm.InitrdFile,
|
||||
},
|
||||
Name: "createscratch-uvm",
|
||||
UvmTimeoutSeconds: 5 * 60, // 5 Min
|
||||
}
|
||||
|
||||
if err := cfg.StartUtilityVM(); err != nil {
|
||||
return errors.Wrapf(err, "failed to start '%s'", cfg.Name)
|
||||
}
|
||||
defer cfg.Uvm.Terminate()
|
||||
|
||||
if err := cfg.CreateExt4Vhdx(dest, lcow.DefaultScratchSizeGB, ""); err != nil {
|
||||
return errors.Wrapf(err, "failed to create ext4vhdx for '%s'", cfg.Name)
|
||||
}
|
||||
} else {
|
||||
opts := uvm.NewDefaultOptionsLCOW("createscratch-uvm", context.GlobalString("owner"))
|
||||
convertUVM, err := uvm.CreateLCOW(opts)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to create '%s'", opts.ID)
|
||||
}
|
||||
defer convertUVM.Close()
|
||||
if err := convertUVM.Start(); err != nil {
|
||||
return errors.Wrapf(err, "failed to start '%s'", opts.ID)
|
||||
}
|
||||
|
||||
if err := lcow.CreateScratch(convertUVM, dest, lcow.DefaultScratchSizeGB, "", ""); err != nil {
|
||||
return errors.Wrapf(err, "failed to create ext4vhdx for '%s'", opts.ID)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
100
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/create.go
generated
vendored
Normal file
100
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/create.go
generated
vendored
Normal file
@ -0,0 +1,100 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/Microsoft/hcsshim/internal/appargs"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var createRunFlags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "bundle, b",
|
||||
Value: "",
|
||||
Usage: `path to the root of the bundle directory, defaults to the current directory`,
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "pid-file",
|
||||
Value: "",
|
||||
Usage: "specify the file to write the process id to",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "shim-log",
|
||||
Value: "",
|
||||
Usage: `path to the log file or named pipe (e.g. \\.\pipe\ProtectedPrefix\Administrators\runhcs-<container-id>-shim-log) for the launched shim process`,
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "vm-log",
|
||||
Value: "",
|
||||
Usage: `path to the log file or named pipe (e.g. \\.\pipe\ProtectedPrefix\Administrators\runhcs-<container-id>-vm-log) for the launched VM shim process`,
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "vm-console",
|
||||
Value: "",
|
||||
Usage: `path to the pipe for the VM's console (e.g. \\.\pipe\debugpipe)`,
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "host",
|
||||
Value: "",
|
||||
Usage: "host container whose VM this container should run in",
|
||||
},
|
||||
}
|
||||
|
||||
var createCommand = cli.Command{
|
||||
Name: "create",
|
||||
Usage: "create a container",
|
||||
ArgsUsage: `<container-id>
|
||||
|
||||
Where "<container-id>" is your name for the instance of the container that you
|
||||
are starting. The name you provide for the container instance must be unique on
|
||||
your host.`,
|
||||
Description: `The create command creates an instance of a container for a bundle. The bundle
|
||||
is a directory with a specification file named "` + specConfig + `" and a root
|
||||
filesystem.
|
||||
|
||||
The specification file includes an args parameter. The args parameter is used
|
||||
to specify command(s) that get run when the container is started. To change the
|
||||
command(s) that get executed on start, edit the args parameter of the spec. See
|
||||
"runc spec --help" for more explanation.`,
|
||||
Flags: append(createRunFlags),
|
||||
Before: appargs.Validate(argID),
|
||||
Action: func(context *cli.Context) error {
|
||||
cfg, err := containerConfigFromContext(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = createContainer(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func containerConfigFromContext(context *cli.Context) (*containerConfig, error) {
|
||||
id := context.Args().First()
|
||||
pidFile, err := absPathOrEmpty(context.String("pid-file"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
shimLog, err := absPathOrEmpty(context.String("shim-log"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
vmLog, err := absPathOrEmpty(context.String("vm-log"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
spec, err := setupSpec(context)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &containerConfig{
|
||||
ID: id,
|
||||
Owner: context.GlobalString("owner"),
|
||||
PidFile: pidFile,
|
||||
ShimLogFile: shimLog,
|
||||
VMLogFile: vmLog,
|
||||
VMConsolePipe: context.String("vm-console"),
|
||||
Spec: spec,
|
||||
HostID: context.String("host"),
|
||||
}, nil
|
||||
}
|
73
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/delete.go
generated
vendored
Normal file
73
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/delete.go
generated
vendored
Normal file
@ -0,0 +1,73 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/Microsoft/hcsshim/internal/appargs"
|
||||
"github.com/Microsoft/hcsshim/internal/regstate"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var deleteCommand = cli.Command{
|
||||
Name: "delete",
|
||||
Usage: "delete any resources held by the container often used with detached container",
|
||||
ArgsUsage: `<container-id>
|
||||
|
||||
Where "<container-id>" is the name for the instance of the container.
|
||||
|
||||
EXAMPLE:
|
||||
For example, if the container id is "ubuntu01" and runhcs list currently shows the
|
||||
status of "ubuntu01" as "stopped" the following will delete resources held for
|
||||
"ubuntu01" removing "ubuntu01" from the runhcs list of containers:
|
||||
|
||||
# runhcs delete ubuntu01`,
|
||||
Flags: []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "force, f",
|
||||
Usage: "Forcibly deletes the container if it is still running (uses SIGKILL)",
|
||||
},
|
||||
},
|
||||
Before: appargs.Validate(argID),
|
||||
Action: func(context *cli.Context) error {
|
||||
id := context.Args().First()
|
||||
force := context.Bool("force")
|
||||
container, err := getContainer(id, false)
|
||||
if err != nil {
|
||||
if _, ok := err.(*regstate.NoStateError); ok {
|
||||
if e := stateKey.Remove(id); e != nil {
|
||||
fmt.Fprintf(os.Stderr, "remove %s: %v\n", id, e)
|
||||
}
|
||||
if force {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
defer container.Close()
|
||||
s, err := container.Status()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
kill := false
|
||||
switch s {
|
||||
case containerStopped:
|
||||
case containerCreated:
|
||||
kill = true
|
||||
default:
|
||||
if !force {
|
||||
return fmt.Errorf("cannot delete container %s that is not stopped: %s\n", id, s)
|
||||
}
|
||||
kill = true
|
||||
}
|
||||
|
||||
if kill {
|
||||
err = container.Kill()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return container.Remove()
|
||||
},
|
||||
}
|
160
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/exec.go
generated
vendored
Normal file
160
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/exec.go
generated
vendored
Normal file
@ -0,0 +1,160 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/Microsoft/hcsshim/internal/appargs"
|
||||
"github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var execCommand = cli.Command{
|
||||
Name: "exec",
|
||||
Usage: "execute new process inside the container",
|
||||
ArgsUsage: `<container-id> <command> [command options] || -p process.json <container-id>
|
||||
|
||||
Where "<container-id>" is the name for the instance of the container and
|
||||
"<command>" is the command to be executed in the container.
|
||||
"<command>" can't be empty unless a "-p" flag provided.
|
||||
|
||||
EXAMPLE:
|
||||
For example, if the container is configured to run the linux ps command the
|
||||
following will output a list of processes running in the container:
|
||||
|
||||
# runhcs exec <container-id> ps`,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "cwd",
|
||||
Usage: "current working directory in the container",
|
||||
},
|
||||
cli.StringSliceFlag{
|
||||
Name: "env, e",
|
||||
Usage: "set environment variables",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "tty, t",
|
||||
Usage: "allocate a pseudo-TTY",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "user, u",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "process, p",
|
||||
Usage: "path to the process.json",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "detach,d",
|
||||
Usage: "detach from the container's process",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "pid-file",
|
||||
Value: "",
|
||||
Usage: "specify the file to write the process id to",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "shim-log",
|
||||
Value: "",
|
||||
Usage: `path to the log file or named pipe (e.g. \\.\pipe\ProtectedPrefix\Administrators\runhcs-<container-id>-<exec-id>-log) for the launched shim process`,
|
||||
},
|
||||
},
|
||||
Before: appargs.Validate(argID, appargs.Rest(appargs.String)),
|
||||
Action: func(context *cli.Context) error {
|
||||
id := context.Args().First()
|
||||
pidFile, err := absPathOrEmpty(context.String("pid-file"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
shimLog, err := absPathOrEmpty(context.String("shim-log"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c, err := getContainer(id, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer c.Close()
|
||||
status, err := c.Status()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if status != containerRunning {
|
||||
return errContainerStopped
|
||||
}
|
||||
spec, err := getProcessSpec(context, c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p, err := startProcessShim(id, pidFile, shimLog, spec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !context.Bool("detach") {
|
||||
state, err := p.Wait()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
os.Exit(int(state.Sys().(syscall.WaitStatus).ExitCode))
|
||||
}
|
||||
return nil
|
||||
},
|
||||
SkipArgReorder: true,
|
||||
}
|
||||
|
||||
func getProcessSpec(context *cli.Context, c *container) (*specs.Process, error) {
|
||||
if path := context.String("process"); path != "" {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
var p specs.Process
|
||||
if err := json.NewDecoder(f).Decode(&p); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &p, validateProcessSpec(&p)
|
||||
}
|
||||
|
||||
// process via cli flags
|
||||
p := c.Spec.Process
|
||||
|
||||
if len(context.Args()) == 1 {
|
||||
return nil, fmt.Errorf("process args cannot be empty")
|
||||
}
|
||||
p.Args = context.Args()[1:]
|
||||
// override the cwd, if passed
|
||||
if context.String("cwd") != "" {
|
||||
p.Cwd = context.String("cwd")
|
||||
}
|
||||
// append the passed env variables
|
||||
p.Env = append(p.Env, context.StringSlice("env")...)
|
||||
|
||||
// set the tty
|
||||
if context.IsSet("tty") {
|
||||
p.Terminal = context.Bool("tty")
|
||||
}
|
||||
// override the user, if passed
|
||||
if context.String("user") != "" {
|
||||
p.User.Username = context.String("user")
|
||||
}
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func validateProcessSpec(spec *specs.Process) error {
|
||||
if spec.Cwd == "" {
|
||||
return fmt.Errorf("Cwd property must not be empty")
|
||||
}
|
||||
// IsAbs doesnt recognize Unix paths on Windows builds so handle that case
|
||||
// here.
|
||||
if !filepath.IsAbs(spec.Cwd) && !strings.HasPrefix(spec.Cwd, "/") {
|
||||
return fmt.Errorf("Cwd must be an absolute path")
|
||||
}
|
||||
if len(spec.Args) == 0 {
|
||||
return fmt.Errorf("args must not be empty")
|
||||
}
|
||||
return nil
|
||||
}
|
178
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/kill.go
generated
vendored
Normal file
178
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/kill.go
generated
vendored
Normal file
@ -0,0 +1,178 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/Microsoft/hcsshim/internal/appargs"
|
||||
"github.com/Microsoft/hcsshim/internal/guestrequest"
|
||||
"github.com/Microsoft/hcsshim/internal/hcs"
|
||||
"github.com/Microsoft/hcsshim/internal/schema1"
|
||||
"github.com/Microsoft/hcsshim/osversion"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var killCommand = cli.Command{
|
||||
Name: "kill",
|
||||
Usage: "kill sends the specified signal (default: SIGTERM) to the container's init process",
|
||||
ArgsUsage: `<container-id> [signal]
|
||||
|
||||
Where "<container-id>" is the name for the instance of the container and
|
||||
"[signal]" is the signal to be sent to the init process.
|
||||
|
||||
EXAMPLE:
|
||||
For example, if the container id is "ubuntu01" the following will send a "KILL"
|
||||
signal to the init process of the "ubuntu01" container:
|
||||
|
||||
# runhcs kill ubuntu01 KILL`,
|
||||
Flags: []cli.Flag{},
|
||||
Before: appargs.Validate(argID, appargs.Optional(appargs.String)),
|
||||
Action: func(context *cli.Context) error {
|
||||
id := context.Args().First()
|
||||
c, err := getContainer(id, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer c.Close()
|
||||
status, err := c.Status()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if status != containerRunning {
|
||||
return errContainerStopped
|
||||
}
|
||||
|
||||
signalsSupported := false
|
||||
|
||||
// The Signal feature was added in RS5
|
||||
if osversion.Get().Build >= osversion.RS5 {
|
||||
if c.IsHost || c.HostID != "" {
|
||||
var hostID string
|
||||
if c.IsHost {
|
||||
// This is the LCOW, Pod Sandbox, or Windows Xenon V2 for RS5+
|
||||
hostID = vmID(c.ID)
|
||||
} else {
|
||||
// This is the Nth container in a Pod
|
||||
hostID = c.HostID
|
||||
}
|
||||
uvm, err := hcs.OpenComputeSystem(hostID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer uvm.Close()
|
||||
if props, err := uvm.Properties(schema1.PropertyTypeGuestConnection); err == nil &&
|
||||
props.GuestConnectionInfo.GuestDefinedCapabilities.SignalProcessSupported {
|
||||
signalsSupported = true
|
||||
}
|
||||
} else if c.Spec.Linux == nil && c.Spec.Windows.HyperV == nil {
|
||||
// RS5+ Windows Argon
|
||||
signalsSupported = true
|
||||
}
|
||||
}
|
||||
|
||||
signal := 0
|
||||
if signalsSupported {
|
||||
signal, err = validateSigstr(context.Args().Get(1), signalsSupported, c.Spec.Linux != nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
var pid int
|
||||
if err := stateKey.Get(id, keyInitPid, &pid); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p, err := c.hc.OpenProcess(pid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer p.Close()
|
||||
|
||||
if signalsSupported && (c.Spec.Linux != nil || !c.Spec.Process.Terminal) {
|
||||
opts := guestrequest.SignalProcessOptions{
|
||||
Signal: signal,
|
||||
}
|
||||
return p.Signal(opts)
|
||||
}
|
||||
|
||||
// Legacy signal issue a kill
|
||||
return p.Kill()
|
||||
},
|
||||
}
|
||||
|
||||
func validateSigstr(sigstr string, signalsSupported bool, isLcow bool) (int, error) {
|
||||
errInvalidSignal := errors.Errorf("invalid signal '%s'", sigstr)
|
||||
|
||||
// All flavors including legacy default to SIGTERM on LCOW CtrlC on Windows
|
||||
if sigstr == "" {
|
||||
if isLcow {
|
||||
return 0xf, nil
|
||||
}
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
sigstr = strings.ToUpper(sigstr)
|
||||
|
||||
if !signalsSupported {
|
||||
// If signals arent supported we just validate that its a known signal.
|
||||
// We already return 0 since we only supported a platform Kill() at that
|
||||
// time.
|
||||
if isLcow {
|
||||
switch sigstr {
|
||||
case "15":
|
||||
fallthrough
|
||||
case "TERM":
|
||||
fallthrough
|
||||
case "SIGTERM":
|
||||
return 0, nil
|
||||
default:
|
||||
return 0, errInvalidSignal
|
||||
}
|
||||
}
|
||||
switch sigstr {
|
||||
// Docker sends a UNIX term in the supported Windows Signal map.
|
||||
case "15":
|
||||
fallthrough
|
||||
case "TERM":
|
||||
fallthrough
|
||||
case "0":
|
||||
fallthrough
|
||||
case "CTRLC":
|
||||
return 0, nil
|
||||
case "9":
|
||||
fallthrough
|
||||
case "KILL":
|
||||
return 0, nil
|
||||
default:
|
||||
return 0, errInvalidSignal
|
||||
}
|
||||
}
|
||||
|
||||
var sigmap map[string]int
|
||||
if isLcow {
|
||||
sigmap = signalMapLcow
|
||||
} else {
|
||||
sigmap = signalMapWindows
|
||||
}
|
||||
|
||||
signal, err := strconv.Atoi(sigstr)
|
||||
if err != nil {
|
||||
// Signal might still match the string value
|
||||
for k, v := range sigmap {
|
||||
if k == sigstr {
|
||||
return v, nil
|
||||
}
|
||||
}
|
||||
return 0, errInvalidSignal
|
||||
}
|
||||
|
||||
// Match signal by value
|
||||
for _, v := range sigmap {
|
||||
if signal == v {
|
||||
return signal, nil
|
||||
}
|
||||
}
|
||||
return 0, errInvalidSignal
|
||||
}
|
95
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/kill_test.go
generated
vendored
Normal file
95
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/kill_test.go
generated
vendored
Normal file
@ -0,0 +1,95 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func runValidateSigstrTest(sigstr string, signalsSupported, isLcow bool,
|
||||
expectedSignal int, expectedError bool, t *testing.T) {
|
||||
signal, err := validateSigstr(sigstr, signalsSupported, isLcow)
|
||||
if expectedError {
|
||||
if err == nil {
|
||||
t.Fatalf("Expected err: %v, got: nil", expectedError)
|
||||
} else if err.Error() != fmt.Sprintf("invalid signal '%s'", sigstr) {
|
||||
t.Fatalf("Expected err: %v, got: %v", expectedError, err)
|
||||
}
|
||||
}
|
||||
if signal != expectedSignal {
|
||||
t.Fatalf("Test - Signal: %s, Support: %v, LCOW: %v\nExpected signal: %v, got: %v",
|
||||
sigstr, signalsSupported, isLcow,
|
||||
expectedSignal, signal)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateSigstrEmpty(t *testing.T) {
|
||||
runValidateSigstrTest("", false, false, 0, false, t)
|
||||
runValidateSigstrTest("", false, true, 0xf, false, t)
|
||||
runValidateSigstrTest("", true, false, 0, false, t)
|
||||
runValidateSigstrTest("", true, true, 0xf, false, t)
|
||||
}
|
||||
|
||||
func TestValidateSigstrDefaultLCOW(t *testing.T) {
|
||||
runValidateSigstrTest("15", false, true, 0, false, t)
|
||||
runValidateSigstrTest("TERM", false, true, 0, false, t)
|
||||
runValidateSigstrTest("SIGTERM", false, true, 0, false, t)
|
||||
}
|
||||
|
||||
func TestValidateSigstrDefaultLCOWInvalid(t *testing.T) {
|
||||
runValidateSigstrTest("2", false, true, 0, true, t)
|
||||
runValidateSigstrTest("test", false, true, 0, true, t)
|
||||
}
|
||||
|
||||
func TestValidateSigstrDefaultWCOW(t *testing.T) {
|
||||
runValidateSigstrTest("15", false, false, 0, false, t)
|
||||
runValidateSigstrTest("TERM", false, false, 0, false, t)
|
||||
runValidateSigstrTest("0", false, false, 0, false, t)
|
||||
runValidateSigstrTest("CTRLC", false, false, 0, false, t)
|
||||
runValidateSigstrTest("9", false, false, 0, false, t)
|
||||
runValidateSigstrTest("KILL", false, false, 0, false, t)
|
||||
}
|
||||
|
||||
func TestValidateSigstrDefaultWCOWInvalid(t *testing.T) {
|
||||
runValidateSigstrTest("2", false, false, 0, true, t)
|
||||
runValidateSigstrTest("test", false, false, 0, true, t)
|
||||
}
|
||||
|
||||
func TestValidateSignalStringLCOW(t *testing.T) {
|
||||
for k, v := range signalMapLcow {
|
||||
runValidateSigstrTest(k, true, true, v, false, t)
|
||||
// run it again with a case not in the map
|
||||
lc := strings.ToLower(k)
|
||||
if k == lc {
|
||||
t.Fatalf("Expected lower casing - map: %v, got: %v", k, lc)
|
||||
}
|
||||
runValidateSigstrTest(lc, true, true, v, false, t)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateSignalStringWCOW(t *testing.T) {
|
||||
for k, v := range signalMapWindows {
|
||||
runValidateSigstrTest(k, true, false, v, false, t)
|
||||
// run it again with a case not in the map
|
||||
lc := strings.ToLower(k)
|
||||
if k == lc {
|
||||
t.Fatalf("Expected lower casing - map: %v, got: %v", k, lc)
|
||||
}
|
||||
runValidateSigstrTest(lc, true, false, v, false, t)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateSignalValueLCOW(t *testing.T) {
|
||||
for _, v := range signalMapLcow {
|
||||
str := strconv.Itoa(v)
|
||||
runValidateSigstrTest(str, true, true, v, false, t)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateSignalValueWCOW(t *testing.T) {
|
||||
for _, v := range signalMapWindows {
|
||||
str := strconv.Itoa(v)
|
||||
runValidateSigstrTest(str, true, false, v, false, t)
|
||||
}
|
||||
}
|
116
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/list.go
generated
vendored
Normal file
116
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/list.go
generated
vendored
Normal file
@ -0,0 +1,116 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
"time"
|
||||
|
||||
"encoding/json"
|
||||
|
||||
"github.com/Microsoft/hcsshim/internal/appargs"
|
||||
"github.com/Microsoft/hcsshim/internal/runhcs"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
const formatOptions = `table or json`
|
||||
|
||||
var listCommand = cli.Command{
|
||||
Name: "list",
|
||||
Usage: "lists containers started by runhcs with the given root",
|
||||
ArgsUsage: `
|
||||
|
||||
Where the given root is specified via the global option "--root"
|
||||
(default: "/run/runhcs").
|
||||
|
||||
EXAMPLE 1:
|
||||
To list containers created via the default "--root":
|
||||
# runhcs list
|
||||
|
||||
EXAMPLE 2:
|
||||
To list containers created using a non-default value for "--root":
|
||||
# runhcs --root value list`,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "format, f",
|
||||
Value: "table",
|
||||
Usage: `select one of: ` + formatOptions,
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "quiet, q",
|
||||
Usage: "display only container IDs",
|
||||
},
|
||||
},
|
||||
Before: appargs.Validate(),
|
||||
Action: func(context *cli.Context) error {
|
||||
s, err := getContainers(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if context.Bool("quiet") {
|
||||
for _, item := range s {
|
||||
fmt.Println(item.ID)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
switch context.String("format") {
|
||||
case "table":
|
||||
w := tabwriter.NewWriter(os.Stdout, 12, 1, 3, ' ', 0)
|
||||
fmt.Fprint(w, "ID\tPID\tSTATUS\tBUNDLE\tCREATED\tOWNER\n")
|
||||
for _, item := range s {
|
||||
fmt.Fprintf(w, "%s\t%d\t%s\t%s\t%s\t%s\n",
|
||||
item.ID,
|
||||
item.InitProcessPid,
|
||||
item.Status,
|
||||
item.Bundle,
|
||||
item.Created.Format(time.RFC3339Nano),
|
||||
item.Owner)
|
||||
}
|
||||
if err := w.Flush(); err != nil {
|
||||
return err
|
||||
}
|
||||
case "json":
|
||||
if err := json.NewEncoder(os.Stdout).Encode(s); err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("invalid format option")
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func getContainers(context *cli.Context) ([]runhcs.ContainerState, error) {
|
||||
ids, err := stateKey.Enumerate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var s []runhcs.ContainerState
|
||||
for _, id := range ids {
|
||||
c, err := getContainer(id, false)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "reading state for %s: %v\n", id, err)
|
||||
continue
|
||||
}
|
||||
status, err := c.Status()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "reading status for %s: %v\n", id, err)
|
||||
}
|
||||
|
||||
s = append(s, runhcs.ContainerState{
|
||||
ID: id,
|
||||
Version: c.Spec.Version,
|
||||
InitProcessPid: c.ShimPid,
|
||||
Status: string(status),
|
||||
Bundle: c.Bundle,
|
||||
Rootfs: c.Rootfs,
|
||||
Created: c.Created,
|
||||
Annotations: c.Spec.Annotations,
|
||||
})
|
||||
c.Close()
|
||||
}
|
||||
return s, nil
|
||||
}
|
174
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/main.go
generated
vendored
Normal file
174
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/main.go
generated
vendored
Normal file
@ -0,0 +1,174 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/Microsoft/go-winio"
|
||||
"github.com/Microsoft/go-winio/pkg/etwlogrus"
|
||||
"github.com/Microsoft/hcsshim/internal/regstate"
|
||||
"github.com/Microsoft/hcsshim/internal/runhcs"
|
||||
"github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
// Add a manifest to get proper Windows version detection.
|
||||
//
|
||||
// goversioninfo can be installed with "go get github.com/josephspurrier/goversioninfo/cmd/goversioninfo"
|
||||
|
||||
//go:generate goversioninfo -platform-specific
|
||||
|
||||
// version will be populated by the Makefile, read from
|
||||
// VERSION file of the source code.
|
||||
var version = ""
|
||||
|
||||
// gitCommit will be the hash that the binary was built from
|
||||
// and will be populated by the Makefile
|
||||
var gitCommit = ""
|
||||
|
||||
var stateKey *regstate.Key
|
||||
|
||||
var logFormat string
|
||||
|
||||
const (
|
||||
specConfig = "config.json"
|
||||
usage = `Open Container Initiative runtime for Windows
|
||||
|
||||
runhcs is a fork of runc, modified to run containers on Windows with or without Hyper-V isolation. Like runc, it is a command line client for running applications packaged according to the Open Container Initiative (OCI) format.
|
||||
|
||||
runhcs integrates with existing process supervisors to provide a production container runtime environment for applications. It can be used with your existing process monitoring tools and the container will be spawned as a direct child of the process supervisor.
|
||||
|
||||
Containers are configured using bundles. A bundle for a container is a directory that includes a specification file named "` + specConfig + `". Bundle contents will depend on the container type.
|
||||
|
||||
To start a new instance of a container:
|
||||
|
||||
# runhcs run [ -b bundle ] <container-id>
|
||||
|
||||
Where "<container-id>" is your name for the instance of the container that you are starting. The name you provide for the container instance must be unique on your host. Providing the bundle directory using "-b" is optional. The default value for "bundle" is the current directory.`
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Provider ID: 0b52781f-b24d-5685-ddf6-69830ed40ec3
|
||||
// Hook isn't closed explicitly, as it will exist until process exit.
|
||||
if hook, err := etwlogrus.NewHook("Microsoft.Virtualization.RunHCS"); err == nil {
|
||||
logrus.AddHook(hook)
|
||||
} else {
|
||||
logrus.Error(err)
|
||||
}
|
||||
|
||||
app := cli.NewApp()
|
||||
app.Name = "runhcs"
|
||||
app.Usage = usage
|
||||
|
||||
var v []string
|
||||
if version != "" {
|
||||
v = append(v, version)
|
||||
}
|
||||
if gitCommit != "" {
|
||||
v = append(v, fmt.Sprintf("commit: %s", gitCommit))
|
||||
}
|
||||
v = append(v, fmt.Sprintf("spec: %s", specs.Version))
|
||||
app.Version = strings.Join(v, "\n")
|
||||
|
||||
app.Flags = []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "debug",
|
||||
Usage: "enable debug output for logging",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "log",
|
||||
Value: "nul",
|
||||
Usage: `set the log file path or named pipe (e.g. \\.\pipe\ProtectedPrefix\Administrators\runhcs-log) where internal debug information is written`,
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "log-format",
|
||||
Value: "text",
|
||||
Usage: "set the format used by logs ('text' (default), or 'json')",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "owner",
|
||||
Value: "runhcs",
|
||||
Usage: "compute system owner",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "root",
|
||||
Value: "default",
|
||||
Usage: "registry key for storage of container state",
|
||||
},
|
||||
}
|
||||
app.Commands = []cli.Command{
|
||||
createCommand,
|
||||
createScratchCommand,
|
||||
deleteCommand,
|
||||
// eventsCommand,
|
||||
execCommand,
|
||||
killCommand,
|
||||
listCommand,
|
||||
pauseCommand,
|
||||
psCommand,
|
||||
resizeTtyCommand,
|
||||
resumeCommand,
|
||||
runCommand,
|
||||
shimCommand,
|
||||
startCommand,
|
||||
stateCommand,
|
||||
// updateCommand,
|
||||
vmshimCommand,
|
||||
}
|
||||
app.Before = func(context *cli.Context) error {
|
||||
if context.GlobalBool("debug") {
|
||||
logrus.SetLevel(logrus.DebugLevel)
|
||||
}
|
||||
if path := context.GlobalString("log"); path != "" {
|
||||
var f io.Writer
|
||||
var err error
|
||||
if strings.HasPrefix(path, runhcs.SafePipePrefix) {
|
||||
f, err = winio.DialPipe(path, nil)
|
||||
} else {
|
||||
f, err = os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_APPEND|os.O_SYNC, 0666)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logrus.SetOutput(f)
|
||||
}
|
||||
switch logFormat = context.GlobalString("log-format"); logFormat {
|
||||
case "text":
|
||||
// retain logrus's default.
|
||||
case "json":
|
||||
logrus.SetFormatter(new(logrus.JSONFormatter))
|
||||
default:
|
||||
return fmt.Errorf("unknown log-format %q", logFormat)
|
||||
}
|
||||
|
||||
var err error
|
||||
stateKey, err = regstate.Open(context.GlobalString("root"), false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
// If the command returns an error, cli takes upon itself to print
|
||||
// the error on cli.ErrWriter and exit.
|
||||
// Use our own writer here to ensure the log gets sent to the right location.
|
||||
fatalWriter.Writer = cli.ErrWriter
|
||||
cli.ErrWriter = &fatalWriter
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
fmt.Fprintln(cli.ErrWriter, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
type logErrorWriter struct {
|
||||
Writer io.Writer
|
||||
}
|
||||
|
||||
var fatalWriter logErrorWriter
|
||||
|
||||
func (f *logErrorWriter) Write(p []byte) (n int, err error) {
|
||||
logrus.Error(string(p))
|
||||
return f.Writer.Write(p)
|
||||
}
|
58
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/pause.go
generated
vendored
Normal file
58
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/pause.go
generated
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/Microsoft/hcsshim/internal/appargs"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var pauseCommand = cli.Command{
|
||||
Name: "pause",
|
||||
Usage: "pause suspends all processes inside the container",
|
||||
ArgsUsage: `<container-id>
|
||||
|
||||
Where "<container-id>" is the name for the instance of the container to be
|
||||
paused. `,
|
||||
Description: `The pause command suspends all processes in the instance of the container.
|
||||
|
||||
Use runhcs list to identify instances of containers and their current status.`,
|
||||
Before: appargs.Validate(argID),
|
||||
Action: func(context *cli.Context) error {
|
||||
id := context.Args().First()
|
||||
container, err := getContainer(id, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer container.Close()
|
||||
if err := container.hc.Pause(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var resumeCommand = cli.Command{
|
||||
Name: "resume",
|
||||
Usage: "resumes all processes that have been previously paused",
|
||||
ArgsUsage: `<container-id>
|
||||
|
||||
Where "<container-id>" is the name for the instance of the container to be
|
||||
resumed.`,
|
||||
Description: `The resume command resumes all processes in the instance of the container.
|
||||
|
||||
Use runhcs list to identify instances of containers and their current status.`,
|
||||
Before: appargs.Validate(argID),
|
||||
Action: func(context *cli.Context) error {
|
||||
id := context.Args().First()
|
||||
container, err := getContainer(id, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer container.Close()
|
||||
if err := container.hc.Resume(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
51
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/ps.go
generated
vendored
Normal file
51
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/ps.go
generated
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/Microsoft/hcsshim/internal/appargs"
|
||||
"github.com/Microsoft/hcsshim/internal/schema1"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var psCommand = cli.Command{
|
||||
Name: "ps",
|
||||
Usage: "ps displays the processes running inside a container",
|
||||
ArgsUsage: `<container-id> [ps options]`,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "format, f",
|
||||
Value: "json",
|
||||
Usage: `select one of: ` + formatOptions,
|
||||
},
|
||||
},
|
||||
Before: appargs.Validate(argID),
|
||||
Action: func(context *cli.Context) error {
|
||||
id := context.Args().First()
|
||||
container, err := getContainer(id, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer container.Close()
|
||||
|
||||
props, err := container.hc.Properties(schema1.PropertyTypeProcessList)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var pids []int
|
||||
for _, p := range props.ProcessList {
|
||||
pids = append(pids, int(p.ProcessId))
|
||||
}
|
||||
|
||||
switch context.String("format") {
|
||||
case "json":
|
||||
return json.NewEncoder(os.Stdout).Encode(pids)
|
||||
default:
|
||||
return fmt.Errorf("invalid format option")
|
||||
}
|
||||
},
|
||||
SkipArgReorder: true,
|
||||
}
|
BIN
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/resource_windows_386.syso
generated
vendored
Normal file
BIN
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/resource_windows_386.syso
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/resource_windows_amd64.syso
generated
vendored
Normal file
BIN
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/resource_windows_amd64.syso
generated
vendored
Normal file
Binary file not shown.
64
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/run.go
generated
vendored
Normal file
64
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/run.go
generated
vendored
Normal file
@ -0,0 +1,64 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
|
||||
"github.com/Microsoft/hcsshim/internal/appargs"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
// default action is to start a container
|
||||
var runCommand = cli.Command{
|
||||
Name: "run",
|
||||
Usage: "create and run a container",
|
||||
ArgsUsage: `<container-id>
|
||||
|
||||
Where "<container-id>" is your name for the instance of the container that you
|
||||
are starting. The name you provide for the container instance must be unique on
|
||||
your host.`,
|
||||
Description: `The run command creates an instance of a container for a bundle. The bundle
|
||||
is a directory with a specification file named "` + specConfig + `" and a root
|
||||
filesystem.
|
||||
|
||||
The specification file includes an args parameter. The args parameter is used
|
||||
to specify command(s) that get run when the container is started. To change the
|
||||
command(s) that get executed on start, edit the args parameter of the spec.`,
|
||||
Flags: append(createRunFlags,
|
||||
cli.BoolFlag{
|
||||
Name: "detach, d",
|
||||
Usage: "detach from the container's process",
|
||||
},
|
||||
),
|
||||
Before: appargs.Validate(argID),
|
||||
Action: func(context *cli.Context) error {
|
||||
cfg, err := containerConfigFromContext(context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c, err := createContainer(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p, err := os.FindProcess(c.ShimPid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = c.Exec()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !context.Bool("detach") {
|
||||
state, err := p.Wait()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.Remove()
|
||||
os.Exit(int(state.Sys().(syscall.WaitStatus).ExitCode))
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
10
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/runhcs.exe.manifest
generated
vendored
Normal file
10
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/runhcs.exe.manifest
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
||||
<description>runhcs</description>
|
||||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||
<application>
|
||||
<!-- Windows 10 -->
|
||||
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
|
||||
</application>
|
||||
</compatibility>
|
||||
</assembly>
|
323
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/shim.go
generated
vendored
Normal file
323
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/shim.go
generated
vendored
Normal file
@ -0,0 +1,323 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
winio "github.com/Microsoft/go-winio"
|
||||
"github.com/Microsoft/hcsshim/internal/appargs"
|
||||
"github.com/Microsoft/hcsshim/internal/hcs"
|
||||
"github.com/Microsoft/hcsshim/internal/lcow"
|
||||
"github.com/Microsoft/hcsshim/internal/runhcs"
|
||||
"github.com/Microsoft/hcsshim/internal/schema2"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
func containerPipePath(id string) string {
|
||||
return runhcs.SafePipePath("runhcs-shim-" + id)
|
||||
}
|
||||
|
||||
func newFile(context *cli.Context, param string) *os.File {
|
||||
fd := uintptr(context.Int(param))
|
||||
if fd == 0 {
|
||||
return nil
|
||||
}
|
||||
return os.NewFile(fd, "")
|
||||
}
|
||||
|
||||
var shimCommand = cli.Command{
|
||||
Name: "shim",
|
||||
Usage: `launch the process and proxy stdio (do not call it outside of runhcs)`,
|
||||
Hidden: true,
|
||||
Flags: []cli.Flag{
|
||||
&cli.IntFlag{Name: "stdin", Hidden: true},
|
||||
&cli.IntFlag{Name: "stdout", Hidden: true},
|
||||
&cli.IntFlag{Name: "stderr", Hidden: true},
|
||||
&cli.BoolFlag{Name: "exec", Hidden: true},
|
||||
cli.StringFlag{Name: "log-pipe", Hidden: true},
|
||||
},
|
||||
Before: appargs.Validate(argID),
|
||||
Action: func(context *cli.Context) error {
|
||||
logPipe := context.String("log-pipe")
|
||||
if logPipe != "" {
|
||||
lpc, err := winio.DialPipe(logPipe, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer lpc.Close()
|
||||
logrus.SetOutput(lpc)
|
||||
} else {
|
||||
logrus.SetOutput(os.Stderr)
|
||||
}
|
||||
fatalWriter.Writer = os.Stdout
|
||||
|
||||
id := context.Args().First()
|
||||
c, err := getContainer(id, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
// Asynchronously wait for the container to exit.
|
||||
containerExitCh := make(chan error)
|
||||
go func() {
|
||||
containerExitCh <- c.hc.Wait()
|
||||
}()
|
||||
|
||||
// Get File objects for the open stdio files passed in as arguments.
|
||||
stdin := newFile(context, "stdin")
|
||||
stdout := newFile(context, "stdout")
|
||||
stderr := newFile(context, "stderr")
|
||||
|
||||
exec := context.Bool("exec")
|
||||
terminateOnFailure := false
|
||||
|
||||
errorOut := io.WriteCloser(os.Stdout)
|
||||
|
||||
var spec *specs.Process
|
||||
|
||||
if exec {
|
||||
// Read the process spec from stdin.
|
||||
specj, err := ioutil.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
os.Stdin.Close()
|
||||
|
||||
spec = new(specs.Process)
|
||||
err = json.Unmarshal(specj, spec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
} else {
|
||||
// Stdin is not used.
|
||||
os.Stdin.Close()
|
||||
|
||||
// Listen on the named pipe associated with this container.
|
||||
l, err := winio.ListenPipe(c.ShimPipePath(), nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Alert the parent process that initialization has completed
|
||||
// successfully.
|
||||
errorOut.Write(runhcs.ShimSuccess)
|
||||
errorOut.Close()
|
||||
fatalWriter.Writer = ioutil.Discard
|
||||
|
||||
// When this process exits, clear this process's pid in the registry.
|
||||
defer func() {
|
||||
stateKey.Set(id, keyShimPid, 0)
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
if terminateOnFailure {
|
||||
if err = c.hc.Terminate(); hcs.IsPending(err) {
|
||||
<-containerExitCh
|
||||
}
|
||||
}
|
||||
}()
|
||||
terminateOnFailure = true
|
||||
|
||||
// Wait for a connection to the named pipe, exiting if the container
|
||||
// exits before this happens.
|
||||
var pipe net.Conn
|
||||
pipeCh := make(chan error)
|
||||
go func() {
|
||||
var err error
|
||||
pipe, err = l.Accept()
|
||||
pipeCh <- err
|
||||
}()
|
||||
|
||||
select {
|
||||
case err = <-pipeCh:
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case err = <-containerExitCh:
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return cli.NewExitError("", 1)
|
||||
}
|
||||
|
||||
// The next set of errors goes to the open pipe connection.
|
||||
errorOut = pipe
|
||||
fatalWriter.Writer = pipe
|
||||
|
||||
// The process spec comes from the original container spec.
|
||||
spec = c.Spec.Process
|
||||
}
|
||||
|
||||
// Create the process in the container.
|
||||
var wpp *hcsschema.ProcessParameters // Windows Process Parameters
|
||||
var lpp *lcow.ProcessParameters // Linux Process Parameters
|
||||
|
||||
var p *hcs.Process
|
||||
|
||||
if c.Spec.Linux == nil {
|
||||
environment := make(map[string]string)
|
||||
for _, v := range spec.Env {
|
||||
s := strings.SplitN(v, "=", 2)
|
||||
if len(s) == 2 && len(s[1]) > 0 {
|
||||
environment[s[0]] = s[1]
|
||||
}
|
||||
}
|
||||
wpp = &hcsschema.ProcessParameters{
|
||||
WorkingDirectory: spec.Cwd,
|
||||
EmulateConsole: spec.Terminal,
|
||||
Environment: environment,
|
||||
User: spec.User.Username,
|
||||
}
|
||||
for i, arg := range spec.Args {
|
||||
e := windows.EscapeArg(arg)
|
||||
if i == 0 {
|
||||
wpp.CommandLine = e
|
||||
} else {
|
||||
wpp.CommandLine += " " + e
|
||||
}
|
||||
}
|
||||
if spec.ConsoleSize != nil {
|
||||
wpp.ConsoleSize = []int32{
|
||||
int32(spec.ConsoleSize.Height),
|
||||
int32(spec.ConsoleSize.Width),
|
||||
}
|
||||
}
|
||||
|
||||
wpp.CreateStdInPipe = stdin != nil
|
||||
wpp.CreateStdOutPipe = stdout != nil
|
||||
wpp.CreateStdErrPipe = stderr != nil
|
||||
|
||||
p, err = c.hc.CreateProcess(wpp)
|
||||
|
||||
} else {
|
||||
lpp = &lcow.ProcessParameters{}
|
||||
if exec {
|
||||
lpp.OCIProcess = spec
|
||||
}
|
||||
|
||||
lpp.CreateStdInPipe = stdin != nil
|
||||
lpp.CreateStdOutPipe = stdout != nil
|
||||
lpp.CreateStdErrPipe = stderr != nil
|
||||
|
||||
p, err = c.hc.CreateProcess(lpp)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cstdin, cstdout, cstderr, err := p.Stdio()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !exec {
|
||||
err = stateKey.Set(c.ID, keyInitPid, p.Pid())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Store the Guest pid map
|
||||
err = stateKey.Set(c.ID, fmt.Sprintf(keyPidMapFmt, os.Getpid()), p.Pid())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
// Remove the Guest pid map when this process is cleaned up
|
||||
stateKey.Clear(c.ID, fmt.Sprintf(keyPidMapFmt, os.Getpid()))
|
||||
}()
|
||||
|
||||
terminateOnFailure = false
|
||||
|
||||
// Alert the connected process that the process was launched
|
||||
// successfully.
|
||||
errorOut.Write(runhcs.ShimSuccess)
|
||||
errorOut.Close()
|
||||
fatalWriter.Writer = ioutil.Discard
|
||||
|
||||
// Relay stdio.
|
||||
var wg sync.WaitGroup
|
||||
if cstdin != nil {
|
||||
go func() {
|
||||
io.Copy(cstdin, stdin)
|
||||
cstdin.Close()
|
||||
p.CloseStdin()
|
||||
}()
|
||||
}
|
||||
|
||||
if cstdout != nil {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
io.Copy(stdout, cstdout)
|
||||
stdout.Close()
|
||||
cstdout.Close()
|
||||
wg.Done()
|
||||
}()
|
||||
}
|
||||
|
||||
if cstderr != nil {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
io.Copy(stderr, cstderr)
|
||||
stderr.Close()
|
||||
cstderr.Close()
|
||||
wg.Done()
|
||||
}()
|
||||
}
|
||||
|
||||
err = p.Wait()
|
||||
wg.Wait()
|
||||
|
||||
// Attempt to get the exit code from the process.
|
||||
code := 1
|
||||
if err == nil {
|
||||
code, err = p.ExitCode()
|
||||
if err != nil {
|
||||
code = 1
|
||||
}
|
||||
}
|
||||
|
||||
if !exec {
|
||||
// Shutdown the container, waiting 5 minutes before terminating is
|
||||
// forcefully.
|
||||
const shutdownTimeout = time.Minute * 5
|
||||
waited := false
|
||||
err = c.hc.Shutdown()
|
||||
if hcs.IsPending(err) {
|
||||
select {
|
||||
case err = <-containerExitCh:
|
||||
waited = true
|
||||
case <-time.After(shutdownTimeout):
|
||||
err = hcs.ErrTimeout
|
||||
}
|
||||
}
|
||||
if hcs.IsAlreadyStopped(err) {
|
||||
err = nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
err = c.hc.Terminate()
|
||||
if waited {
|
||||
err = c.hc.Wait()
|
||||
} else {
|
||||
err = <-containerExitCh
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return cli.NewExitError("", code)
|
||||
},
|
||||
}
|
48
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/signalmap.go
generated
vendored
Normal file
48
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/signalmap.go
generated
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
package main
|
||||
|
||||
var signalMapLcow = map[string]int{
|
||||
"ABRT": 0x6,
|
||||
"ALRM": 0xe,
|
||||
"BUS": 0x7,
|
||||
"CHLD": 0x11,
|
||||
"CLD": 0x11,
|
||||
"CONT": 0x12,
|
||||
"FPE": 0x8,
|
||||
"HUP": 0x1,
|
||||
"ILL": 0x4,
|
||||
"INT": 0x2,
|
||||
"IO": 0x1d,
|
||||
"IOT": 0x6,
|
||||
"KILL": 0x9,
|
||||
"PIPE": 0xd,
|
||||
"POLL": 0x1d,
|
||||
"PROF": 0x1b,
|
||||
"PWR": 0x1e,
|
||||
"QUIT": 0x3,
|
||||
"SEGV": 0xb,
|
||||
"STKFLT": 0x10,
|
||||
"STOP": 0x13,
|
||||
"SYS": 0x1f,
|
||||
"TERM": 0xf,
|
||||
"TRAP": 0x5,
|
||||
"TSTP": 0x14,
|
||||
"TTIN": 0x15,
|
||||
"TTOU": 0x16,
|
||||
"URG": 0x17,
|
||||
"USR1": 0xa,
|
||||
"USR2": 0xc,
|
||||
"VTALRM": 0x1a,
|
||||
"WINCH": 0x1c,
|
||||
"XCPU": 0x18,
|
||||
"XFSZ": 0x19,
|
||||
}
|
||||
|
||||
var signalMapWindows = map[string]int{
|
||||
"CTRLC": 0x0,
|
||||
"CTRLBREAK": 0x1,
|
||||
"CTRLCLOSE": 0x2,
|
||||
"CTRLLOGOFF": 0x5,
|
||||
"CTRLSHUTDOWN": 0x6,
|
||||
"TERM": 0x0, // Docker sends the UNIX signal. Convert to CTRLC
|
||||
"KILL": 0x6, // Docker sends the UNIX signal. Convert to CTRLSHUTDOWN
|
||||
}
|
42
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/spec.go
generated
vendored
Normal file
42
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/spec.go
generated
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
// loadSpec loads the specification from the provided path.
|
||||
func loadSpec(cPath string) (spec *specs.Spec, err error) {
|
||||
cf, err := os.Open(cPath)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil, fmt.Errorf("JSON specification file %s not found", cPath)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
defer cf.Close()
|
||||
|
||||
if err = json.NewDecoder(cf).Decode(&spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return spec, nil
|
||||
}
|
||||
|
||||
// setupSpec performs initial setup based on the cli.Context for the container
|
||||
func setupSpec(context *cli.Context) (*specs.Spec, error) {
|
||||
bundle := context.String("bundle")
|
||||
if bundle != "" {
|
||||
if err := os.Chdir(bundle); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
spec, err := loadSpec(specConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return spec, nil
|
||||
}
|
43
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/start.go
generated
vendored
Normal file
43
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/start.go
generated
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/Microsoft/hcsshim/internal/appargs"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var startCommand = cli.Command{
|
||||
Name: "start",
|
||||
Usage: "executes the user defined process in a created container",
|
||||
ArgsUsage: `<container-id>
|
||||
|
||||
Where "<container-id>" is your name for the instance of the container that you
|
||||
are starting. The name you provide for the container instance must be unique on
|
||||
your host.`,
|
||||
Description: `The start command executes the user defined process in a created container.`,
|
||||
Before: appargs.Validate(argID),
|
||||
Action: func(context *cli.Context) error {
|
||||
id := context.Args().First()
|
||||
container, err := getContainer(id, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer container.Close()
|
||||
status, err := container.Status()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
switch status {
|
||||
case containerCreated:
|
||||
return container.Exec()
|
||||
case containerStopped:
|
||||
return errors.New("cannot start a container that has stopped")
|
||||
case containerRunning:
|
||||
return errors.New("cannot start an already running container")
|
||||
default:
|
||||
return fmt.Errorf("cannot start a container in the '%s' state", status)
|
||||
}
|
||||
},
|
||||
}
|
49
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/state.go
generated
vendored
Normal file
49
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/state.go
generated
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
|
||||
"github.com/Microsoft/hcsshim/internal/appargs"
|
||||
"github.com/Microsoft/hcsshim/internal/runhcs"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var stateCommand = cli.Command{
|
||||
Name: "state",
|
||||
Usage: "output the state of a container",
|
||||
ArgsUsage: `<container-id>
|
||||
|
||||
Where "<container-id>" is your name for the instance of the container.`,
|
||||
Description: `The state command outputs current state information for the
|
||||
instance of a container.`,
|
||||
Before: appargs.Validate(argID),
|
||||
Action: func(context *cli.Context) error {
|
||||
id := context.Args().First()
|
||||
c, err := getContainer(id, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer c.Close()
|
||||
status, err := c.Status()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cs := runhcs.ContainerState{
|
||||
Version: c.Spec.Version,
|
||||
ID: c.ID,
|
||||
InitProcessPid: c.ShimPid,
|
||||
Status: string(status),
|
||||
Bundle: c.Bundle,
|
||||
Rootfs: c.Rootfs,
|
||||
Created: c.Created,
|
||||
Annotations: c.Spec.Annotations,
|
||||
}
|
||||
data, err := json.MarshalIndent(cs, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
os.Stdout.Write(data)
|
||||
return nil
|
||||
},
|
||||
}
|
56
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/tty.go
generated
vendored
Normal file
56
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/tty.go
generated
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/Microsoft/hcsshim/internal/appargs"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var resizeTtyCommand = cli.Command{
|
||||
Name: "resize-tty",
|
||||
Usage: "resize-tty updates the terminal size for a container process",
|
||||
ArgsUsage: `<container-id> <width> <height>`,
|
||||
Flags: []cli.Flag{
|
||||
&cli.IntFlag{
|
||||
Name: "pid, p",
|
||||
Usage: "the process pid (defaults to init pid)",
|
||||
},
|
||||
},
|
||||
Before: appargs.Validate(
|
||||
argID,
|
||||
appargs.Int(10, 1, 65535),
|
||||
appargs.Int(10, 1, 65535),
|
||||
),
|
||||
Action: func(context *cli.Context) error {
|
||||
id := context.Args()[0]
|
||||
width, _ := strconv.ParseUint(context.Args()[1], 10, 16)
|
||||
height, _ := strconv.ParseUint(context.Args()[2], 10, 16)
|
||||
c, err := getContainer(id, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
pid := context.Int("pid")
|
||||
if pid == 0 {
|
||||
if err := stateKey.Get(id, keyInitPid, &pid); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
// If a pid was provided map it to its hcs pid.
|
||||
if err := stateKey.Get(id, fmt.Sprintf(keyPidMapFmt, pid), &pid); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
p, err := c.hc.OpenProcess(pid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer p.Close()
|
||||
|
||||
return p.ResizeConsole(uint16(width), uint16(height))
|
||||
},
|
||||
}
|
52
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/utils.go
generated
vendored
Normal file
52
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/utils.go
generated
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/Microsoft/hcsshim/internal/appargs"
|
||||
"github.com/Microsoft/hcsshim/internal/runhcs"
|
||||
)
|
||||
|
||||
var argID = appargs.NonEmptyString
|
||||
|
||||
func absPathOrEmpty(path string) (string, error) {
|
||||
if path == "" {
|
||||
return "", nil
|
||||
}
|
||||
if strings.HasPrefix(path, runhcs.SafePipePrefix) {
|
||||
if len(path) > len(runhcs.SafePipePrefix) {
|
||||
return runhcs.SafePipePath(path[len(runhcs.SafePipePrefix):]), nil
|
||||
}
|
||||
}
|
||||
return filepath.Abs(path)
|
||||
}
|
||||
|
||||
// createPidFile creates a file with the processes pid inside it atomically
|
||||
// it creates a temp file with the paths filename + '.' infront of it
|
||||
// then renames the file
|
||||
func createPidFile(path string, pid int) error {
|
||||
var (
|
||||
tmpDir = filepath.Dir(path)
|
||||
tmpName = filepath.Join(tmpDir, fmt.Sprintf(".%s", filepath.Base(path)))
|
||||
)
|
||||
f, err := os.OpenFile(tmpName, os.O_RDWR|os.O_CREATE|os.O_EXCL|os.O_SYNC, 0666)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = fmt.Fprintf(f, "%d", pid)
|
||||
f.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.Rename(tmpName, path)
|
||||
}
|
||||
|
||||
func closeWritePipe(pipe net.Conn) error {
|
||||
return pipe.(interface {
|
||||
CloseWrite() error
|
||||
}).CloseWrite()
|
||||
}
|
39
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/utils_test.go
generated
vendored
Normal file
39
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/utils_test.go
generated
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/Microsoft/hcsshim/internal/runhcs"
|
||||
)
|
||||
|
||||
func Test_AbsPathOrEmpty(t *testing.T) {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get test wd: %v", err)
|
||||
}
|
||||
|
||||
tests := []string{
|
||||
"",
|
||||
runhcs.SafePipePrefix + "test",
|
||||
runhcs.SafePipePrefix + "test with spaces",
|
||||
"test",
|
||||
"C:\\test..\\test",
|
||||
}
|
||||
expected := []string{
|
||||
"",
|
||||
runhcs.SafePipePrefix + "test",
|
||||
runhcs.SafePipePrefix + "test%20with%20spaces",
|
||||
wd + "\\test",
|
||||
"C:\\test..\\test",
|
||||
}
|
||||
for i, test := range tests {
|
||||
actual, err := absPathOrEmpty(test)
|
||||
if err != nil {
|
||||
t.Fatalf("absPathOrEmpty: error '%v'", err)
|
||||
}
|
||||
if actual != expected[i] {
|
||||
t.Fatalf("absPathOrEmpty: actual '%s' != '%s'", actual, expected[i])
|
||||
}
|
||||
}
|
||||
}
|
43
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/versioninfo.json
generated
vendored
Normal file
43
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/versioninfo.json
generated
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
{
|
||||
"FixedFileInfo": {
|
||||
"FileVersion": {
|
||||
"Major": 1,
|
||||
"Minor": 0,
|
||||
"Patch": 0,
|
||||
"Build": 0
|
||||
},
|
||||
"ProductVersion": {
|
||||
"Major": 1,
|
||||
"Minor": 0,
|
||||
"Patch": 0,
|
||||
"Build": 0
|
||||
},
|
||||
"FileFlagsMask": "3f",
|
||||
"FileFlags ": "00",
|
||||
"FileOS": "040004",
|
||||
"FileType": "01",
|
||||
"FileSubType": "00"
|
||||
},
|
||||
"StringFileInfo": {
|
||||
"Comments": "",
|
||||
"CompanyName": "",
|
||||
"FileDescription": "",
|
||||
"FileVersion": "",
|
||||
"InternalName": "",
|
||||
"LegalCopyright": "",
|
||||
"LegalTrademarks": "",
|
||||
"OriginalFilename": "",
|
||||
"PrivateBuild": "",
|
||||
"ProductName": "",
|
||||
"ProductVersion": "v1.0.0.0",
|
||||
"SpecialBuild": ""
|
||||
},
|
||||
"VarFileInfo": {
|
||||
"Translation": {
|
||||
"LangID": "0409",
|
||||
"CharsetID": "04B0"
|
||||
}
|
||||
},
|
||||
"IconPath": "",
|
||||
"ManifestPath": "runhcs.exe.manifest"
|
||||
}
|
209
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/vm.go
generated
vendored
Normal file
209
vendor/github.com/Microsoft/hcsshim/cmd/runhcs/vm.go
generated
vendored
Normal file
@ -0,0 +1,209 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"syscall"
|
||||
|
||||
winio "github.com/Microsoft/go-winio"
|
||||
"github.com/Microsoft/hcsshim/internal/appargs"
|
||||
"github.com/Microsoft/hcsshim/internal/logfields"
|
||||
"github.com/Microsoft/hcsshim/internal/runhcs"
|
||||
"github.com/Microsoft/hcsshim/internal/uvm"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
func vmID(id string) string {
|
||||
return id + "@vm"
|
||||
}
|
||||
|
||||
var vmshimCommand = cli.Command{
|
||||
Name: "vmshim",
|
||||
Usage: `launch a VM and containers inside it (do not call it outside of runhcs)`,
|
||||
Hidden: true,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{Name: "log-pipe", Hidden: true},
|
||||
cli.StringFlag{Name: "os", Hidden: true},
|
||||
},
|
||||
Before: appargs.Validate(argID),
|
||||
Action: func(context *cli.Context) error {
|
||||
logPipe := context.String("log-pipe")
|
||||
if logPipe != "" {
|
||||
lpc, err := winio.DialPipe(logPipe, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer lpc.Close()
|
||||
logrus.SetOutput(lpc)
|
||||
} else {
|
||||
logrus.SetOutput(os.Stderr)
|
||||
}
|
||||
fatalWriter.Writer = os.Stdout
|
||||
|
||||
pipePath := context.Args().First()
|
||||
|
||||
optsj, err := ioutil.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
os.Stdin.Close()
|
||||
|
||||
var opts interface{}
|
||||
isLCOW := context.String("os") == "linux"
|
||||
if isLCOW {
|
||||
opts = &uvm.OptionsLCOW{}
|
||||
} else {
|
||||
opts = &uvm.OptionsWCOW{}
|
||||
}
|
||||
|
||||
err = json.Unmarshal(optsj, opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Listen on the named pipe associated with this VM.
|
||||
l, err := winio.ListenPipe(pipePath, &winio.PipeConfig{MessageMode: true})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var vm *uvm.UtilityVM
|
||||
if isLCOW {
|
||||
vm, err = uvm.CreateLCOW(opts.(*uvm.OptionsLCOW))
|
||||
} else {
|
||||
vm, err = uvm.CreateWCOW(opts.(*uvm.OptionsWCOW))
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer vm.Close()
|
||||
if err = vm.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Asynchronously wait for the VM to exit.
|
||||
exitCh := make(chan error)
|
||||
go func() {
|
||||
exitCh <- vm.Wait()
|
||||
}()
|
||||
|
||||
defer vm.Terminate()
|
||||
|
||||
// Alert the parent process that initialization has completed
|
||||
// successfully.
|
||||
os.Stdout.Write(runhcs.ShimSuccess)
|
||||
os.Stdout.Close()
|
||||
fatalWriter.Writer = ioutil.Discard
|
||||
|
||||
pipeCh := make(chan net.Conn)
|
||||
go func() {
|
||||
for {
|
||||
conn, err := l.Accept()
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
continue
|
||||
}
|
||||
pipeCh <- conn
|
||||
}
|
||||
}()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-exitCh:
|
||||
return nil
|
||||
case pipe := <-pipeCh:
|
||||
err = processRequest(vm, pipe)
|
||||
if err == nil {
|
||||
_, err = pipe.Write(runhcs.ShimSuccess)
|
||||
// Wait until the pipe is closed before closing the
|
||||
// container so that it is properly handed off to the other
|
||||
// process.
|
||||
if err == nil {
|
||||
err = closeWritePipe(pipe)
|
||||
}
|
||||
if err == nil {
|
||||
ioutil.ReadAll(pipe)
|
||||
}
|
||||
} else {
|
||||
logrus.WithError(err).
|
||||
Error("failed creating container in VM")
|
||||
fmt.Fprintf(pipe, "%v", err)
|
||||
}
|
||||
pipe.Close()
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func processRequest(vm *uvm.UtilityVM, pipe net.Conn) error {
|
||||
var req runhcs.VMRequest
|
||||
err := json.NewDecoder(pipe).Decode(&req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logrus.WithFields(logrus.Fields{
|
||||
logfields.ContainerID: req.ID,
|
||||
logfields.VMShimOperation: req.Op,
|
||||
}).Debug("process request")
|
||||
c, err := getContainer(req.ID, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
if c != nil {
|
||||
c.Close()
|
||||
}
|
||||
}()
|
||||
switch req.Op {
|
||||
case runhcs.OpCreateContainer:
|
||||
err = createContainerInHost(c, vm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c2 := c
|
||||
c = nil
|
||||
go func() {
|
||||
c2.hc.Wait()
|
||||
c2.Close()
|
||||
}()
|
||||
|
||||
case runhcs.OpUnmountContainer, runhcs.OpUnmountContainerDiskOnly:
|
||||
err = c.unmountInHost(vm, req.Op == runhcs.OpUnmountContainer)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
case runhcs.OpSyncNamespace:
|
||||
return errors.New("Not implemented")
|
||||
default:
|
||||
panic("unknown operation")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type noVMError struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
func (err *noVMError) Error() string {
|
||||
return "VM " + err.ID + " cannot be contacted"
|
||||
}
|
||||
|
||||
func (c *container) issueVMRequest(op runhcs.VMRequestOp) error {
|
||||
req := runhcs.VMRequest{
|
||||
ID: c.ID,
|
||||
Op: op,
|
||||
}
|
||||
if err := runhcs.IssueVMRequest(c.VMPipePath(), &req); err != nil {
|
||||
if perr, ok := err.(*os.PathError); ok && perr.Err == syscall.ERROR_FILE_NOT_FOUND {
|
||||
return &noVMError{c.HostID}
|
||||
}
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
64
vendor/github.com/Microsoft/hcsshim/cmd/tar2ext4/tar2ext4.go
generated
vendored
Normal file
64
vendor/github.com/Microsoft/hcsshim/cmd/tar2ext4/tar2ext4.go
generated
vendored
Normal file
@ -0,0 +1,64 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/Microsoft/hcsshim/ext4/tar2ext4"
|
||||
)
|
||||
|
||||
var (
|
||||
input = flag.String("i", "", "input file")
|
||||
output = flag.String("o", "", "output file")
|
||||
overlay = flag.Bool("overlay", false, "produce overlayfs-compatible layer image")
|
||||
vhd = flag.Bool("vhd", false, "add a VHD footer to the end of the image")
|
||||
inlineData = flag.Bool("inline", false, "write small file data into the inode; not compatible with DAX")
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
if flag.NArg() != 0 || len(*output) == 0 {
|
||||
flag.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
err := func() (err error) {
|
||||
in := os.Stdin
|
||||
if *input != "" {
|
||||
in, err = os.Open(*input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
out, err := os.Create(*output)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var opts []tar2ext4.Option
|
||||
if *overlay {
|
||||
opts = append(opts, tar2ext4.ConvertWhiteout)
|
||||
}
|
||||
if *vhd {
|
||||
opts = append(opts, tar2ext4.AppendVhdFooter)
|
||||
}
|
||||
if *inlineData {
|
||||
opts = append(opts, tar2ext4.InlineData)
|
||||
}
|
||||
err = tar2ext4.Convert(in, out, opts...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Exhaust the tar stream.
|
||||
io.Copy(ioutil.Discard, in)
|
||||
return nil
|
||||
}()
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
36
vendor/github.com/Microsoft/hcsshim/cmd/wclayer/create.go
generated
vendored
Normal file
36
vendor/github.com/Microsoft/hcsshim/cmd/wclayer/create.go
generated
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/Microsoft/hcsshim"
|
||||
"github.com/Microsoft/hcsshim/internal/appargs"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var createCommand = cli.Command{
|
||||
Name: "create",
|
||||
Usage: "creates a new writable container layer",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringSliceFlag{
|
||||
Name: "layer, l",
|
||||
Usage: "paths to the read-only parent layers",
|
||||
},
|
||||
},
|
||||
ArgsUsage: "<layer path>",
|
||||
Before: appargs.Validate(appargs.NonEmptyString),
|
||||
Action: func(context *cli.Context) error {
|
||||
path, err := filepath.Abs(context.Args().First())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
layers, err := normalizeLayers(context.StringSlice("layer"), true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
di := driverInfo
|
||||
return hcsshim.CreateScratchLayer(di, path, layers[len(layers)-1], layers)
|
||||
},
|
||||
}
|
66
vendor/github.com/Microsoft/hcsshim/cmd/wclayer/export.go
generated
vendored
Normal file
66
vendor/github.com/Microsoft/hcsshim/cmd/wclayer/export.go
generated
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"compress/gzip"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
winio "github.com/Microsoft/go-winio"
|
||||
"github.com/Microsoft/hcsshim/internal/appargs"
|
||||
"github.com/Microsoft/hcsshim/internal/ociwclayer"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var exportCommand = cli.Command{
|
||||
Name: "export",
|
||||
Usage: "exports a layer to a tar file",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringSliceFlag{
|
||||
Name: "layer, l",
|
||||
Usage: "paths to the read-only parent layers",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "output, o",
|
||||
Usage: "output layer tar (defaults to stdout)",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "gzip, z",
|
||||
Usage: "compress output with gzip compression",
|
||||
},
|
||||
},
|
||||
ArgsUsage: "<layer path>",
|
||||
Before: appargs.Validate(appargs.NonEmptyString),
|
||||
Action: func(context *cli.Context) (err error) {
|
||||
path, err := filepath.Abs(context.Args().First())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
layers, err := normalizeLayers(context.StringSlice("layer"), true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = winio.EnableProcessPrivileges([]string{winio.SeBackupPrivilege})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fp := context.String("output")
|
||||
f := os.Stdout
|
||||
if fp != "" {
|
||||
f, err = os.Create(fp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
}
|
||||
w := io.Writer(f)
|
||||
if context.Bool("gzip") {
|
||||
w = gzip.NewWriter(w)
|
||||
}
|
||||
|
||||
return ociwclayer.ExportLayer(w, path, layers)
|
||||
},
|
||||
}
|
74
vendor/github.com/Microsoft/hcsshim/cmd/wclayer/import.go
generated
vendored
Normal file
74
vendor/github.com/Microsoft/hcsshim/cmd/wclayer/import.go
generated
vendored
Normal file
@ -0,0 +1,74 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"compress/gzip"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/Microsoft/go-winio"
|
||||
"github.com/Microsoft/hcsshim/internal/appargs"
|
||||
"github.com/Microsoft/hcsshim/internal/ociwclayer"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var importCommand = cli.Command{
|
||||
Name: "import",
|
||||
Usage: "imports a layer from a tar file",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringSliceFlag{
|
||||
Name: "layer, l",
|
||||
Usage: "paths to the read-only parent layers",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "input, i",
|
||||
Usage: "input layer tar (defaults to stdin)",
|
||||
},
|
||||
},
|
||||
ArgsUsage: "<layer path>",
|
||||
Before: appargs.Validate(appargs.NonEmptyString),
|
||||
Action: func(context *cli.Context) (err error) {
|
||||
path, err := filepath.Abs(context.Args().First())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
layers, err := normalizeLayers(context.StringSlice("layer"), false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fp := context.String("input")
|
||||
f := os.Stdin
|
||||
if fp != "" {
|
||||
f, err = os.Open(fp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
}
|
||||
r, err := addDecompressor(f)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = winio.EnableProcessPrivileges([]string{winio.SeBackupPrivilege, winio.SeRestorePrivilege})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = ociwclayer.ImportLayer(r, path, layers)
|
||||
return err
|
||||
},
|
||||
}
|
||||
|
||||
func addDecompressor(r io.Reader) (io.Reader, error) {
|
||||
b := bufio.NewReader(r)
|
||||
hdr, err := b.Peek(3)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if hdr[0] == 0x1f && hdr[1] == 0x8b && hdr[2] == 8 {
|
||||
return gzip.NewReader(b)
|
||||
}
|
||||
return b, nil
|
||||
}
|
88
vendor/github.com/Microsoft/hcsshim/cmd/wclayer/mount.go
generated
vendored
Normal file
88
vendor/github.com/Microsoft/hcsshim/cmd/wclayer/mount.go
generated
vendored
Normal file
@ -0,0 +1,88 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/Microsoft/hcsshim"
|
||||
"github.com/Microsoft/hcsshim/internal/appargs"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var mountCommand = cli.Command{
|
||||
Name: "mount",
|
||||
Usage: "mounts a scratch",
|
||||
ArgsUsage: "<scratch path>",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringSliceFlag{
|
||||
Name: "layer, l",
|
||||
Usage: "paths to the parent layers for this layer",
|
||||
},
|
||||
},
|
||||
Action: func(context *cli.Context) (err error) {
|
||||
if context.NArg() != 1 {
|
||||
return errors.New("invalid usage")
|
||||
}
|
||||
path, err := filepath.Abs(context.Args().First())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
layers, err := normalizeLayers(context.StringSlice("layer"), true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = hcsshim.ActivateLayer(driverInfo, path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
hcsshim.DeactivateLayer(driverInfo, path)
|
||||
}
|
||||
}()
|
||||
|
||||
err = hcsshim.PrepareLayer(driverInfo, path, layers)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
hcsshim.UnprepareLayer(driverInfo, path)
|
||||
}
|
||||
}()
|
||||
|
||||
mountPath, err := hcsshim.GetLayerMountPath(driverInfo, path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = fmt.Println(mountPath)
|
||||
return err
|
||||
},
|
||||
}
|
||||
|
||||
var unmountCommand = cli.Command{
|
||||
Name: "unmount",
|
||||
Usage: "unmounts a scratch",
|
||||
ArgsUsage: "<layer path>",
|
||||
Before: appargs.Validate(appargs.NonEmptyString),
|
||||
Action: func(context *cli.Context) (err error) {
|
||||
path, err := filepath.Abs(context.Args().First())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = hcsshim.UnprepareLayer(driverInfo, path)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
}
|
||||
err = hcsshim.DeactivateLayer(driverInfo, path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
31
vendor/github.com/Microsoft/hcsshim/cmd/wclayer/remove.go
generated
vendored
Normal file
31
vendor/github.com/Microsoft/hcsshim/cmd/wclayer/remove.go
generated
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
winio "github.com/Microsoft/go-winio"
|
||||
"github.com/Microsoft/hcsshim"
|
||||
"github.com/Microsoft/hcsshim/internal/appargs"
|
||||
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var removeCommand = cli.Command{
|
||||
Name: "remove",
|
||||
Usage: "permanently removes a layer directory in its entirety",
|
||||
ArgsUsage: "<layer path>",
|
||||
Before: appargs.Validate(appargs.NonEmptyString),
|
||||
Action: func(context *cli.Context) (err error) {
|
||||
path, err := filepath.Abs(context.Args().First())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = winio.EnableProcessPrivileges([]string{winio.SeBackupPrivilege, winio.SeRestorePrivilege})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return hcsshim.DestroyLayer(driverInfo, path)
|
||||
},
|
||||
}
|
BIN
vendor/github.com/Microsoft/hcsshim/cmd/wclayer/resource_windows_386.syso
generated
vendored
Normal file
BIN
vendor/github.com/Microsoft/hcsshim/cmd/wclayer/resource_windows_386.syso
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/github.com/Microsoft/hcsshim/cmd/wclayer/resource_windows_amd64.syso
generated
vendored
Normal file
BIN
vendor/github.com/Microsoft/hcsshim/cmd/wclayer/resource_windows_amd64.syso
generated
vendored
Normal file
Binary file not shown.
43
vendor/github.com/Microsoft/hcsshim/cmd/wclayer/versioninfo.json
generated
vendored
Normal file
43
vendor/github.com/Microsoft/hcsshim/cmd/wclayer/versioninfo.json
generated
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
{
|
||||
"FixedFileInfo": {
|
||||
"FileVersion": {
|
||||
"Major": 1,
|
||||
"Minor": 0,
|
||||
"Patch": 0,
|
||||
"Build": 0
|
||||
},
|
||||
"ProductVersion": {
|
||||
"Major": 1,
|
||||
"Minor": 0,
|
||||
"Patch": 0,
|
||||
"Build": 0
|
||||
},
|
||||
"FileFlagsMask": "3f",
|
||||
"FileFlags ": "00",
|
||||
"FileOS": "040004",
|
||||
"FileType": "01",
|
||||
"FileSubType": "00"
|
||||
},
|
||||
"StringFileInfo": {
|
||||
"Comments": "",
|
||||
"CompanyName": "",
|
||||
"FileDescription": "",
|
||||
"FileVersion": "",
|
||||
"InternalName": "",
|
||||
"LegalCopyright": "",
|
||||
"LegalTrademarks": "",
|
||||
"OriginalFilename": "",
|
||||
"PrivateBuild": "",
|
||||
"ProductName": "",
|
||||
"ProductVersion": "v1.0.0.0",
|
||||
"SpecialBuild": ""
|
||||
},
|
||||
"VarFileInfo": {
|
||||
"Translation": {
|
||||
"LangID": "0409",
|
||||
"CharsetID": "04B0"
|
||||
}
|
||||
},
|
||||
"IconPath": "",
|
||||
"ManifestPath": "wclayer.exe.manifest"
|
||||
}
|
10
vendor/github.com/Microsoft/hcsshim/cmd/wclayer/wclayer.exe.manifest
generated
vendored
Normal file
10
vendor/github.com/Microsoft/hcsshim/cmd/wclayer/wclayer.exe.manifest
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
||||
<description>wclayer</description>
|
||||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||
<application>
|
||||
<!-- Windows 10 -->
|
||||
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
|
||||
</application>
|
||||
</compatibility>
|
||||
</assembly>
|
60
vendor/github.com/Microsoft/hcsshim/cmd/wclayer/wclayer.go
generated
vendored
Normal file
60
vendor/github.com/Microsoft/hcsshim/cmd/wclayer/wclayer.go
generated
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/Microsoft/hcsshim"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
// Add a manifest to get proper Windows version detection.
|
||||
//
|
||||
// goversioninfo can be installed with "go get github.com/josephspurrier/goversioninfo/cmd/goversioninfo"
|
||||
|
||||
//go:generate goversioninfo -platform-specific
|
||||
|
||||
var usage = `Windows Container layer utility
|
||||
|
||||
wclayer is a command line tool for manipulating Windows Container
|
||||
storage layers. It can import and export layers from and to OCI format
|
||||
layer tar files, create new writable layers, and mount and unmount
|
||||
container images.`
|
||||
|
||||
var driverInfo = hcsshim.DriverInfo{}
|
||||
|
||||
func main() {
|
||||
app := cli.NewApp()
|
||||
app.Name = "wclayer"
|
||||
app.Commands = []cli.Command{
|
||||
createCommand,
|
||||
exportCommand,
|
||||
importCommand,
|
||||
mountCommand,
|
||||
removeCommand,
|
||||
unmountCommand,
|
||||
}
|
||||
app.Usage = usage
|
||||
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func normalizeLayers(il []string, needOne bool) ([]string, error) {
|
||||
if needOne && len(il) == 0 {
|
||||
return nil, errors.New("at least one read-only layer must be specified")
|
||||
}
|
||||
ol := make([]string, len(il))
|
||||
for i := range il {
|
||||
var err error
|
||||
ol[i], err = filepath.Abs(il[i])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return ol, nil
|
||||
}
|
Reference in New Issue
Block a user