mirror of
https://github.com/linuxkit/linuxkit.git
synced 2026-01-06 05:04:01 +00:00
Move base images directory to top level
These are standalone, better to have them at the top. Signed-off-by: Justin Cormack <justin.cormack@docker.com>
This commit is contained in:
4
base/binfmt/.gitignore
vendored
Normal file
4
base/binfmt/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
dev
|
||||
proc
|
||||
sys
|
||||
usr
|
||||
3
base/binfmt/Dockerfile
Normal file
3
base/binfmt/Dockerfile
Normal file
@@ -0,0 +1,3 @@
|
||||
FROM scratch
|
||||
COPY . ./
|
||||
CMD ["/usr/bin/binfmt", "-dir", "/etc/binfmt.d/", "-mount", "/binfmt_misc"]
|
||||
54
base/binfmt/Makefile
Normal file
54
base/binfmt/Makefile
Normal file
@@ -0,0 +1,54 @@
|
||||
# Tag da39a3ee5e6b4b0d3255bfef95601890afd80709
|
||||
QEMU_IMAGE=mobylinux/qemu-user-static@sha256:6c022f700dc6c263c9107c08aa29b4eae3b43b7b7594b7be3e421f69b51f53e5
|
||||
QEMU_FILES=qemu-arm qemu-aarch64 qemu-ppc64le
|
||||
QEMU_BINARIES=$(addprefix usr/bin/,$(QEMU_FILES))
|
||||
|
||||
# Tag: 56f72369b2100961d418cd8a614a6019bb53dc9c
|
||||
GO_COMPILE=mobylinux/go-compile@sha256:98eb2ded03c6bb717b5b19c5723f221b00e85c18352c042d0c8470a4fb32ea24
|
||||
BINFMT_BINARY=usr/bin/binfmt
|
||||
|
||||
# Tag: alpine:3.5
|
||||
SHA_IMAGE=alpine@sha256:dfbd4a3a8ebca874ebd2474f044a0b33600d4523d03b0df76e5c5986cb02d7e8
|
||||
|
||||
IMAGE=binfmt
|
||||
|
||||
.PHONY: tag push clean container
|
||||
default: push
|
||||
|
||||
$(QEMU_BINARIES):
|
||||
mkdir -p $(dir $@)
|
||||
docker run --rm --net=none $(QEMU_IMAGE) tar cf - $@ | tar xf -
|
||||
|
||||
$(BINFMT_BINARY): main.go
|
||||
mkdir -p $(dir $@)
|
||||
tar cf - $^ | docker run --rm --net=none --log-driver=none -i $(GO_COMPILE) -o $@ | tar xf -
|
||||
|
||||
DIRS=dev proc sys
|
||||
$(DIRS):
|
||||
mkdir -p $@
|
||||
|
||||
DEPS=$(DIRS) $(QEMU_BINARIES) $(BINFMT_BINARY) etc/binfmt.d/00_moby.conf
|
||||
|
||||
container: Dockerfile $(DEPS)
|
||||
tar cf - $^ | docker build --no-cache -t $(IMAGE):build -
|
||||
|
||||
hash: Dockerfile $(DEPS)
|
||||
find $^ -type f | xargs cat | docker run --rm -i $(SHA_IMAGE) sha1sum - | sed 's/ .*//' > hash
|
||||
|
||||
push: hash container
|
||||
docker pull mobylinux/$(IMAGE):$(shell cat hash) || \
|
||||
(docker tag $(IMAGE):build mobylinux/$(IMAGE):$(shell cat hash) && \
|
||||
docker push mobylinux/$(IMAGE):$(shell cat hash))
|
||||
docker rmi $(IMAGE):build
|
||||
rm -f hash
|
||||
|
||||
tag: hash container
|
||||
docker pull mobylinux/$(IMAGE):$(shell cat hash) || \
|
||||
docker tag $(IMAGE):build mobylinux/$(IMAGE):$(shell cat hash)
|
||||
docker rmi $(IMAGE):build
|
||||
rm -f hash
|
||||
|
||||
clean:
|
||||
rm -rf hash $(DIRS) usr
|
||||
|
||||
.DELETE_ON_ERROR:
|
||||
3
base/binfmt/etc/binfmt.d/00_moby.conf
Normal file
3
base/binfmt/etc/binfmt.d/00_moby.conf
Normal file
@@ -0,0 +1,3 @@
|
||||
:qemu-aarch64:M:0:\x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-aarch64:CF
|
||||
:qemu-arm:M:0:\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-arm:CF
|
||||
:qemu-ppc64le:M:0:\x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x15\x00:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\x00:/usr/bin/qemu-ppc64le:CF
|
||||
93
base/binfmt/main.go
Normal file
93
base/binfmt/main.go
Normal file
@@ -0,0 +1,93 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
var (
|
||||
dir string
|
||||
mount string
|
||||
)
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&dir, "dir", "/etc/binfmt.d", "directory with config files")
|
||||
flag.StringVar(&mount, "mount", "/proc/sys/fs/binfmt_misc", "binfmt_misc mount point")
|
||||
}
|
||||
|
||||
func binfmt(line []byte) error {
|
||||
register := filepath.Join(mount, "register")
|
||||
file, err := os.OpenFile(register, os.O_WRONLY, 0)
|
||||
if err != nil {
|
||||
e, ok := err.(*os.PathError)
|
||||
if ok && e.Err == syscall.ENOENT {
|
||||
return fmt.Errorf("ENOENT opening %s is it mounted?", register)
|
||||
}
|
||||
if ok && e.Err == syscall.EPERM {
|
||||
return fmt.Errorf("EPERM opening %s check permissions?", register)
|
||||
}
|
||||
return fmt.Errorf("Cannot open %s: %s", register, err)
|
||||
}
|
||||
defer file.Close()
|
||||
// short writes should not occur on sysfs, cannot usefully recover
|
||||
_, err = file.Write(line)
|
||||
if err != nil {
|
||||
e, ok := err.(*os.PathError)
|
||||
if ok && e.Err == syscall.EEXIST {
|
||||
// clear existing entry
|
||||
split := bytes.SplitN(line[1:], []byte(":"), 2)
|
||||
if len(split) == 0 {
|
||||
return fmt.Errorf("Cannot determine arch from: %s", line)
|
||||
}
|
||||
arch := filepath.Join(mount, string(split[0]))
|
||||
clear, err := os.OpenFile(arch, os.O_WRONLY, 0)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Cannot open %s: %s", arch, err)
|
||||
}
|
||||
defer clear.Close()
|
||||
_, err = clear.Write([]byte("-1"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("Cannot write to %s: %s", arch, err)
|
||||
}
|
||||
_, err = file.Write(line)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Cannot write to %s: %s", register, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Cannot write to %s: %s", register, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
files, err := ioutil.ReadDir(dir)
|
||||
if err != nil {
|
||||
log.Fatalf("Cannot read directory %s: %s", dir, err)
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
contents, err := ioutil.ReadFile(filepath.Join(dir, file.Name()))
|
||||
if err != nil {
|
||||
log.Fatalf("Cannot read file %s: %s", file.Name(), err)
|
||||
}
|
||||
lines := bytes.Split(contents, []byte("\n"))
|
||||
for _, line := range lines {
|
||||
if len(line) == 0 {
|
||||
continue
|
||||
}
|
||||
err = binfmt(line)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user