Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to add extra file. Allows using a registry mirror with dind. #79

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Here are all currently driver parameters listed that you can use.
| **--kvm-boot2docker-url** | Sets the url from which host the image is loaded. By default it's not set. |
| **--kvm-cache-mode** | Sets the caching mode of the kvm machine. Defaults to `default`. |
| **--kvm-io-mode-url** | Sets the disk io mode of the kvm machine. Defaults to `threads`. |
| **--kvm-extra-file** | Adds the specified file to /home/docker (optional). |



28 changes: 28 additions & 0 deletions kvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type Driver struct {
DiskPath string
CacheMode string
IOMode string
ExtraFile string
connectionString string
conn *libvirt.Connect
VM *libvirt.Domain
Expand Down Expand Up @@ -136,6 +137,11 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
Usage: "Disk IO mode: threads, native",
Value: "threads",
},
mcnflag.StringFlag{
Name: "kvm-extra-file",
Usage: "adds the specified file to /home/docker",
Value: "",
},
mcnflag.StringFlag{
EnvVar: "KVM_SSH_USER",
Name: "kvm-ssh-user",
Expand Down Expand Up @@ -200,6 +206,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.SSHUser = flags.String("kvm-ssh-user")
d.SSHPort = 22
d.DiskPath = d.ResolveStorePath(fmt.Sprintf("%s.img", d.MachineName))
d.ExtraFile = flags.String("kvm-extra-file")
return nil
}

Expand Down Expand Up @@ -714,13 +721,34 @@ func (d *Driver) generateDiskImage(size int) error {
if _, err := tw.Write([]byte(pubKey)); err != nil {
return err
}
if d.ExtraFile != "" {
log.Debugf("Reading extra file from: %s", d.ExtraFile)
fi, err := os.Stat(d.ExtraFile)
if err != nil {
return err
}
file = &tar.Header{Name: fi.Name(), Size: fi.Size(), Mode: 0644}
if err := tw.WriteHeader(file); err != nil {
return err
}
srcFile, err := os.Open(d.ExtraFile)
if err != nil {
return err
}
defer srcFile.Close()
_, err = io.Copy(tw, srcFile)
if err != nil {
return err
}
}
file = &tar.Header{Name: ".ssh/authorized_keys2", Size: int64(len(pubKey)), Mode: 0644}
if err := tw.WriteHeader(file); err != nil {
return err
}
if _, err := tw.Write([]byte(pubKey)); err != nil {
return err
}

if err := tw.Close(); err != nil {
return err
}
Expand Down