Skip to content
Commits on Source (4)
......@@ -15,8 +15,8 @@ You can find sources and pre-compiled binaries [here](https://github.com/JonasPr
```bash
# Download the binary (this example downloads the binary for linux amd64)
$ wget https://github.com/JonasProgrammer/docker-machine-driver-hetzner/releases/download/3.9.2/docker-machine-driver-hetzner_3.9.2_linux_amd64.tar.gz
$ tar -xvf docker-machine-driver-hetzner_3.9.2_linux_amd64.tar.gz
$ wget https://github.com/JonasProgrammer/docker-machine-driver-hetzner/releases/download/3.10.0/docker-machine-driver-hetzner_3.10.0_linux_amd64.tar.gz
$ tar -xvf docker-machine-driver-hetzner_3.10.0_linux_amd64.tar.gz
# Make it executable and copy the binary in a directory accessible with your $PATH
$ chmod +x docker-machine-driver-hetzner
......@@ -100,6 +100,7 @@ $ docker-machine create \
see [SSH Keys API](https://docs.hetzner.cloud/#resources-ssh-keys-get) for how to get a list
- `--hetzner-additional-key`: Upload an additional public key associated with the server, or associate an existing one with the same fingerprint. Can be specified multiple times.
- `--hetzner-user-data`: Cloud-init based User data
- `--hetzner-user-data-from-file`: Use Cloud-init based User data as file, `--hetzner-user-data` as file name
- `--hetzner-volumes`: Volume IDs or names which should be attached to the server
- `--hetzner-networks`: Network IDs or names which should be attached to the server private network interface
- `--hetzner-use-private-network`: Use private network
......
......@@ -39,6 +39,7 @@ type Driver struct {
ServerID int
cachedServer *hcloud.Server
userData string
userDataFromFile bool
Volumes []string
Networks []string
UsePrivateNetwork bool
......@@ -71,6 +72,7 @@ const (
flagExKeyID = "hetzner-existing-key-id"
flagExKeyPath = "hetzner-existing-key-path"
flagUserData = "hetzner-user-data"
flagUserDataFromFile = "hetzner-user-data-from-file"
flagVolumes = "hetzner-volumes"
flagNetworks = "hetzner-networks"
flagUsePrivateNetwork = "hetzner-use-private-network"
......@@ -163,6 +165,11 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
Usage: "Cloud-init based User data",
Value: "",
},
mcnflag.BoolFlag{
EnvVar: "HETZNER_USER_DATA_FROM_FILE",
Name: flagUserDataFromFile,
Usage: "Cloud-init based User data is file",
},
mcnflag.StringSliceFlag{
EnvVar: "HETZNER_VOLUMES",
Name: flagVolumes,
......@@ -273,6 +280,7 @@ func (d *Driver) setConfigFromFlagsImpl(opts drivers.DriverOptions) error {
d.IsExistingKey = d.KeyID != 0
d.originalKey = opts.String(flagExKeyPath)
d.userData = opts.String(flagUserData)
d.userDataFromFile = opts.Bool(flagUserDataFromFile)
d.Volumes = opts.StringSlice(flagVolumes)
d.Networks = opts.StringSlice(flagNetworks)
disablePublic := opts.Bool(flagDisablePublic)
......@@ -526,9 +534,14 @@ func (d *Driver) makeCreateServerOptions() (*hcloud.ServerCreateOpts, error) {
return nil, err
}
userData, err := d.getUserData()
if err != nil {
return nil, err
}
srvopts := hcloud.ServerCreateOpts{
Name: d.GetMachineName(),
UserData: d.userData,
UserData: userData,
Labels: d.ServerLabels,
PlacementGroup: pgrp,
}
......@@ -573,6 +586,20 @@ func (d *Driver) makeCreateServerOptions() (*hcloud.ServerCreateOpts, error) {
return &srvopts, nil
}
func (d *Driver) getUserData() (string, error) {
userData := d.userData
if !d.userDataFromFile {
return userData, nil
}
readUserData, err := os.ReadFile(d.userData)
if err != nil {
return "", err
}
return string(readUserData), nil
}
func (d *Driver) setPublicNetIfRequired(srvopts *hcloud.ServerCreateOpts) error {
pip4, err := d.getPrimaryIPv4()
if err != nil {
......