X Tutup
Skip to content

Commit 2b8f022

Browse files
author
John Howard
committed
runtime compiles on Windows
Signed-off-by: John Howard <jhoward@microsoft.com>
1 parent ab74e7b commit 2b8f022

File tree

16 files changed

+390
-281
lines changed

16 files changed

+390
-281
lines changed

api/grpc/server/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (s *apiServer) Signal(ctx context.Context, r *types.SignalRequest) (*types.
7878
}
7979

8080
func (s *apiServer) AddProcess(ctx context.Context, r *types.AddProcessRequest) (*types.AddProcessResponse, error) {
81-
process := &specs.Process{
81+
process := &runtime.ProcessSpec{
8282
Terminal: r.Terminal,
8383
Args: r.Args,
8484
Env: r.Env,

runtime/container.go

Lines changed: 3 additions & 199 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,9 @@ import (
44
"encoding/json"
55
"io/ioutil"
66
"os"
7-
"os/exec"
87
"path/filepath"
9-
"syscall"
10-
"time"
118

129
"github.com/Sirupsen/logrus"
13-
"github.com/opencontainers/runc/libcontainer"
14-
"github.com/opencontainers/specs"
1510
)
1611

1712
type Container interface {
@@ -22,7 +17,7 @@ type Container interface {
2217
// Start starts the init process of the container
2318
Start(checkpoint string, s Stdio) (Process, error)
2419
// Exec starts another process in an existing container
25-
Exec(string, specs.Process, Stdio) (Process, error)
20+
Exec(string, ProcessSpec, Stdio) (Process, error)
2621
// Delete removes the container's state and any resources
2722
Delete() error
2823
// Processes returns all the containers processes that have been added
@@ -173,81 +168,8 @@ func (c *container) Labels() []string {
173168
return c.labels
174169
}
175170

176-
func (c *container) Start(checkpoint string, s Stdio) (Process, error) {
177-
processRoot := filepath.Join(c.root, c.id, InitProcessID)
178-
if err := os.Mkdir(processRoot, 0755); err != nil {
179-
return nil, err
180-
}
181-
cmd := exec.Command("containerd-shim",
182-
c.id, c.bundle,
183-
)
184-
cmd.Dir = processRoot
185-
cmd.SysProcAttr = &syscall.SysProcAttr{
186-
Setpgid: true,
187-
}
188-
spec, err := c.readSpec()
189-
if err != nil {
190-
return nil, err
191-
}
192-
config := &processConfig{
193-
checkpoint: checkpoint,
194-
root: processRoot,
195-
id: InitProcessID,
196-
c: c,
197-
stdio: s,
198-
spec: spec,
199-
processSpec: spec.Process,
200-
}
201-
p, err := newProcess(config)
202-
if err != nil {
203-
return nil, err
204-
}
205-
if err := cmd.Start(); err != nil {
206-
return nil, err
207-
}
208-
if _, err := p.getPid(); err != nil {
209-
return p, nil
210-
}
211-
c.processes[InitProcessID] = p
212-
return p, nil
213-
}
214-
215-
func (c *container) Exec(pid string, spec specs.Process, s Stdio) (Process, error) {
216-
processRoot := filepath.Join(c.root, c.id, pid)
217-
if err := os.Mkdir(processRoot, 0755); err != nil {
218-
return nil, err
219-
}
220-
cmd := exec.Command("containerd-shim",
221-
c.id, c.bundle,
222-
)
223-
cmd.Dir = processRoot
224-
cmd.SysProcAttr = &syscall.SysProcAttr{
225-
Setpgid: true,
226-
}
227-
config := &processConfig{
228-
exec: true,
229-
id: pid,
230-
root: processRoot,
231-
c: c,
232-
processSpec: spec,
233-
stdio: s,
234-
}
235-
p, err := newProcess(config)
236-
if err != nil {
237-
return nil, err
238-
}
239-
if err := cmd.Start(); err != nil {
240-
return nil, err
241-
}
242-
if _, err := p.getPid(); err != nil {
243-
return p, nil
244-
}
245-
c.processes[pid] = p
246-
return p, nil
247-
}
248-
249-
func (c *container) readSpec() (*platformSpec, error) {
250-
var spec platformSpec
171+
func (c *container) readSpec() (*PlatformSpec, error) {
172+
var spec PlatformSpec
251173
f, err := os.Open(filepath.Join(c.bundle, "config.json"))
252174
if err != nil {
253175
return nil, err
@@ -259,14 +181,6 @@ func (c *container) readSpec() (*platformSpec, error) {
259181
return &spec, nil
260182
}
261183

262-
func (c *container) Pause() error {
263-
return exec.Command("runc", "pause", c.id).Run()
264-
}
265-
266-
func (c *container) Resume() error {
267-
return exec.Command("runc", "resume", c.id).Run()
268-
}
269-
270184
func (c *container) State() State {
271185
return Running
272186
}
@@ -287,113 +201,3 @@ func (c *container) RemoveProcess(pid string) error {
287201
delete(c.processes, pid)
288202
return os.RemoveAll(filepath.Join(c.root, c.id, pid))
289203
}
290-
291-
func (c *container) Checkpoints() ([]Checkpoint, error) {
292-
dirs, err := ioutil.ReadDir(filepath.Join(c.bundle, "checkpoints"))
293-
if err != nil {
294-
return nil, err
295-
}
296-
var out []Checkpoint
297-
for _, d := range dirs {
298-
if !d.IsDir() {
299-
continue
300-
}
301-
path := filepath.Join(c.bundle, "checkpoints", d.Name(), "config.json")
302-
data, err := ioutil.ReadFile(path)
303-
if err != nil {
304-
return nil, err
305-
}
306-
var cpt Checkpoint
307-
if err := json.Unmarshal(data, &cpt); err != nil {
308-
return nil, err
309-
}
310-
out = append(out, cpt)
311-
}
312-
return out, nil
313-
}
314-
315-
func (c *container) Checkpoint(cpt Checkpoint) error {
316-
if err := os.MkdirAll(filepath.Join(c.bundle, "checkpoints"), 0755); err != nil {
317-
return err
318-
}
319-
path := filepath.Join(c.bundle, "checkpoints", cpt.Name)
320-
if err := os.Mkdir(path, 0755); err != nil {
321-
return err
322-
}
323-
f, err := os.Create(filepath.Join(path, "config.json"))
324-
if err != nil {
325-
return err
326-
}
327-
cpt.Created = time.Now()
328-
err = json.NewEncoder(f).Encode(cpt)
329-
f.Close()
330-
if err != nil {
331-
return err
332-
}
333-
args := []string{
334-
"checkpoint",
335-
"--image-path", path,
336-
}
337-
add := func(flags ...string) {
338-
args = append(args, flags...)
339-
}
340-
if !cpt.Exit {
341-
add("--leave-running")
342-
}
343-
if cpt.Shell {
344-
add("--shell-job")
345-
}
346-
if cpt.Tcp {
347-
add("--tcp-established")
348-
}
349-
if cpt.UnixSockets {
350-
add("--ext-unix-sk")
351-
}
352-
add(c.id)
353-
return exec.Command("runc", args...).Run()
354-
}
355-
356-
func (c *container) DeleteCheckpoint(name string) error {
357-
return os.RemoveAll(filepath.Join(c.bundle, "checkpoints", name))
358-
}
359-
360-
func (c *container) Pids() ([]int, error) {
361-
container, err := c.getLibctContainer()
362-
if err != nil {
363-
return nil, err
364-
}
365-
return container.Processes()
366-
}
367-
368-
func (c *container) Stats() (*Stat, error) {
369-
container, err := c.getLibctContainer()
370-
if err != nil {
371-
return nil, err
372-
}
373-
now := time.Now()
374-
stats, err := container.Stats()
375-
if err != nil {
376-
return nil, err
377-
}
378-
return &Stat{
379-
Timestamp: now,
380-
Data: stats,
381-
}, nil
382-
}
383-
384-
func (c *container) getLibctContainer() (libcontainer.Container, error) {
385-
f, err := libcontainer.New(specs.LinuxStateDirectory, libcontainer.Cgroupfs)
386-
if err != nil {
387-
return nil, err
388-
}
389-
return f.Load(c.id)
390-
}
391-
392-
func hostIDFromMap(id uint32, mp []specs.IDMapping) int {
393-
for _, m := range mp {
394-
if (id >= m.ContainerID) && (id <= (m.ContainerID + m.Size - 1)) {
395-
return int(m.HostID + (id - m.ContainerID))
396-
}
397-
}
398-
return 0
399-
}

0 commit comments

Comments
 (0)
X Tutup