Switch runc and containerd startup to be entirely Go

At present they use a small shared function called "prepare"
that does the read-write remounts, that I will switch to doing overlay
mounts soon.

Signed-off-by: Justin Cormack <justin.cormack@docker.com>
This commit is contained in:
Justin Cormack
2017-07-26 16:16:25 +01:00
parent 5194bf13d1
commit cb2ca4ef66
14 changed files with 128 additions and 56 deletions

View File

@@ -23,6 +23,7 @@ RUN cp bin/containerd bin/ctr bin/containerd-shim /usr/bin/
ADD cmd /go/src/cmd
RUN cd /go/src/cmd/service && ./skanky-vendor.sh $GOPATH/src/github.com/containerd/containerd
RUN go-compile.sh /go/src/cmd/service
RUN mkdir -p /etc/init.d && ln -s /usr/bin/service /etc/init.d/020-containerd
WORKDIR /
COPY . .
@@ -33,4 +34,5 @@ WORKDIR /
COPY --from=alpine /usr/bin/containerd /usr/bin/ctr /usr/bin/containerd-shim /go/bin/service /usr/bin/
COPY --from=alpine /etc/containerd/config.toml /etc/containerd/
COPY --from=alpine /usr/share/zoneinfo/UTC /etc/localtime
COPY --from=alpine /etc/init.d/ /etc/init.d/
COPY etc etc/

View File

@@ -1,5 +1,5 @@
IMAGE=containerd
NETWORK=1
DEPS=$(wildcard etc/init.d/*) $(wildcard cmd/service/*.go) etc/containerd/config.toml
DEPS=$(wildcard cmd/service/*.go) etc/containerd/config.toml
include ../package.mk

View File

@@ -66,9 +66,8 @@ func main() {
args := flag.Args()
if len(args) < 1 {
fmt.Printf("Please specify a command.\n\n")
flag.Usage()
os.Exit(1)
systemInitCmd(args)
os.Exit(0)
}
switch args[0] {

View File

@@ -0,0 +1,21 @@
package main
// Please note this file is shared between pkg/runc and pkg/containerd
// Update it in both places if you make changes
import (
"path/filepath"
"syscall"
)
func prepare(path string) error {
rootfs := filepath.Join(path, "rootfs")
if err := syscall.Mount(rootfs, rootfs, "", syscall.MS_BIND, ""); err != nil {
return err
}
// remount rw
if err := syscall.Mount("", rootfs, "", syscall.MS_REMOUNT, ""); err != nil {
return err
}
return nil
}

View File

@@ -58,6 +58,10 @@ func startCmd(args []string) {
func start(service, sock, path, dumpSpec string) (string, uint32, string, error) {
rootfs := filepath.Join(path, service, "rootfs")
if err := prepare(filepath.Join(path, service)); err != nil {
return "", 0, "preparing rootfs", err
}
client, err := containerd.New(sock)
if err != nil {
return "", 0, "creating containerd client", err

View File

@@ -1,14 +0,0 @@
#!/bin/sh
# start service containers
if [ -d /containers/services ]
then
for f in $(find /containers/services -mindepth 1 -maxdepth 1 | sort)
do
/bin/mount --bind "$f/rootfs" "$f/rootfs"
mount -o remount,rw "$f/rootfs"
done
fi
service system-init