mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-19 09:16:29 +00:00
Merge pull request #1239 from justincormack/tool-add-files
Add some support to add files in Yaml config
This commit is contained in:
commit
355cbcab7c
@ -1,6 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"archive/tar"
|
||||
"bytes"
|
||||
"errors"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@ -8,12 +12,12 @@ import (
|
||||
)
|
||||
|
||||
type Moby struct {
|
||||
Kernel string
|
||||
Init string
|
||||
System []MobyImage
|
||||
Database []struct {
|
||||
File string
|
||||
Value string
|
||||
Kernel string
|
||||
Init string
|
||||
System []MobyImage
|
||||
Files []struct {
|
||||
Path string
|
||||
Contents string
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,3 +71,54 @@ func ConfigToRun(image *MobyImage) []string {
|
||||
|
||||
return args
|
||||
}
|
||||
|
||||
func Filesystem(m *Moby) (*bytes.Buffer, error) {
|
||||
buf := new(bytes.Buffer)
|
||||
tw := tar.NewWriter(buf)
|
||||
defer tw.Close()
|
||||
|
||||
for _, f := range m.Files {
|
||||
if f.Path == "" {
|
||||
return buf, errors.New("Did not specify path for file")
|
||||
}
|
||||
if f.Contents == "" {
|
||||
return buf, errors.New("Contents of file not specified")
|
||||
}
|
||||
// we need all the leading directories
|
||||
parts := strings.Split(path.Dir(f.Path), "/")
|
||||
root := ""
|
||||
for _, p := range parts {
|
||||
if p == "." || p == "/" {
|
||||
continue
|
||||
}
|
||||
if root == "" {
|
||||
root = p
|
||||
} else {
|
||||
root = root + "/" + p
|
||||
}
|
||||
hdr := &tar.Header{
|
||||
Name: root,
|
||||
Typeflag: tar.TypeDir,
|
||||
Mode: 0700,
|
||||
}
|
||||
err := tw.WriteHeader(hdr)
|
||||
if err != nil {
|
||||
return buf, err
|
||||
}
|
||||
}
|
||||
hdr := &tar.Header{
|
||||
Name: f.Path,
|
||||
Mode: 0600,
|
||||
Size: int64(len(f.Contents)),
|
||||
}
|
||||
err := tw.WriteHeader(hdr)
|
||||
if err != nil {
|
||||
return buf, err
|
||||
}
|
||||
_, err = tw.Write([]byte(f.Contents))
|
||||
if err != nil {
|
||||
return buf, err
|
||||
}
|
||||
}
|
||||
return buf, nil
|
||||
}
|
||||
|
@ -131,6 +131,13 @@ func build() {
|
||||
containers = append(containers, buffer)
|
||||
}
|
||||
|
||||
// add files
|
||||
buffer, err = Filesystem(m)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to add filesystem parts: %v", err)
|
||||
}
|
||||
containers = append(containers, buffer)
|
||||
|
||||
initrd, err := containersInitrd(containers)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to make initrd %v", err)
|
||||
|
@ -20,6 +20,6 @@ system:
|
||||
- CAP_SETUID
|
||||
- CAP_SETGID
|
||||
network_mode: host
|
||||
database:
|
||||
- file: etc/docker/daemon.json
|
||||
value: '{"debug": true}'
|
||||
files:
|
||||
- path: etc/docker/daemon.json
|
||||
contents: '{"debug": true}'
|
||||
|
Loading…
Reference in New Issue
Block a user