Skip to content
Commits on Source (6)
......@@ -3,13 +3,13 @@ on:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16
go-version: 1.18
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
......
......@@ -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.8.0/docker-machine-driver-hetzner_3.8.0_linux_amd64.tar.gz
$ tar -xvf docker-machine-driver-hetzner_3.8.0_linux_amd64.tar.gz
$ wget https://github.com/JonasProgrammer/docker-machine-driver-hetzner/releases/download/3.8.1/docker-machine-driver-hetzner_3.8.1_linux_amd64.tar.gz
$ tar -xvf docker-machine-driver-hetzner_3.8.1_linux_amd64.tar.gz
# Make it executable and copy the binary in a directory accessible with your $PATH
$ chmod +x docker-machine-driver-hetzner
......
......@@ -3,7 +3,6 @@ package main
import (
"context"
"fmt"
"io/ioutil"
"net"
"os"
"strings"
......@@ -97,7 +96,6 @@ const (
// NewDriver initializes a new driver instance; see [drivers.Driver.NewDriver]
func NewDriver() *Driver {
return &Driver{
Image: defaultImage,
Type: defaultType,
IsExistingKey: false,
BaseDriver: &drivers.BaseDriver{},
......@@ -122,7 +120,7 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
EnvVar: "HETZNER_IMAGE",
Name: flagImage,
Usage: "Image to use for server creation",
Value: defaultImage,
Value: "",
},
mcnflag.IntFlag{
EnvVar: "HETZNER_IMAGE_ID",
......@@ -244,6 +242,10 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
// SetConfigFromFlags handles additional driver arguments as retrieved by [Driver.GetCreateFlags];
// see [drivers.Driver.SetConfigFromFlags]
func (d *Driver) SetConfigFromFlags(opts drivers.DriverOptions) error {
return d.setConfigFromFlags(opts)
}
func (d *Driver) setConfigFromFlagsImpl(opts drivers.DriverOptions) error {
d.AccessToken = opts.String(flagAPIToken)
d.Image = opts.String(flagImage)
d.ImageID = opts.Int(flagImageID)
......@@ -268,7 +270,7 @@ func (d *Driver) SetConfigFromFlags(opts drivers.DriverOptions) error {
d.placementGroup = opts.String(flagPlacementGroup)
if opts.Bool(flagAutoSpread) {
if d.placementGroup != "" {
return errors.Errorf(flagAutoSpread + " and " + flagPlacementGroup + " are mutually exclusive")
return d.flagFailure("%v and %v are mutually exclusive", flagAutoSpread, flagPlacementGroup)
}
d.placementGroup = autoSpreadPgName
}
......@@ -281,15 +283,17 @@ func (d *Driver) SetConfigFromFlags(opts drivers.DriverOptions) error {
d.SetSwarmConfigFromFlags(opts)
if d.AccessToken == "" {
return errors.Errorf("hetzner requires --%v to be set", flagAPIToken)
return d.flagFailure("hetzner requires --%v to be set", flagAPIToken)
}
if d.ImageID != 0 && d.Image != defaultImage {
return errors.Errorf("--%v and --%v are mutually exclusive", flagImage, flagImageID)
if d.ImageID != 0 && d.Image != "" && d.Image != defaultImage /* support legacy behaviour */ {
return d.flagFailure("--%v and --%v are mutually exclusive", flagImage, flagImageID)
} else if d.ImageID == 0 && d.Image == "" {
d.Image = defaultImage
}
if d.DisablePublic4 && d.DisablePublic6 && !d.UsePrivateNetwork {
return errors.Errorf("--%v must be used if public networking is disabled (hint: implicitly set by --%v)",
return d.flagFailure("--%v must be used if public networking is disabled (hint: implicitly set by --%v)",
flagUsePrivateNetwork, flagDisablePublic)
}
......@@ -311,7 +315,7 @@ func (d *Driver) setLabelsFromFlags(opts drivers.DriverOptions) error {
for _, label := range opts.StringSlice(flagServerLabel) {
split := strings.SplitN(label, "=", 2)
if len(split) != 2 {
return errors.Errorf("server label %v is not in key=value format", label)
return d.flagFailure("server label %v is not in key=value format", label)
}
d.ServerLabels[split[0]] = split[1]
}
......@@ -330,7 +334,7 @@ func (d *Driver) setLabelsFromFlags(opts drivers.DriverOptions) error {
func (d *Driver) PreCreateCheck() error {
if d.IsExistingKey {
if d.originalKey == "" {
return errors.New("specifying an existing key ID requires the existing key path to be set as well")
return d.flagFailure("specifying an existing key ID requires the existing key path to be set as well")
}
key, err := d.getKey()
......@@ -338,7 +342,7 @@ func (d *Driver) PreCreateCheck() error {
return errors.Wrap(err, "could not get key")
}
buf, err := ioutil.ReadFile(d.originalKey + ".pub")
buf, err := os.ReadFile(d.originalKey + ".pub")
if err != nil {
return errors.Wrap(err, "could not read public key")
}
......@@ -582,7 +586,7 @@ func (d *Driver) createRemoteKeys() error {
if d.KeyID == 0 {
log.Infof("Creating SSH key...")
buf, err := ioutil.ReadFile(d.GetSSHKeyPath() + ".pub")
buf, err := os.ReadFile(d.GetSSHKeyPath() + ".pub")
if err != nil {
return errors.Wrap(err, "could not read ssh public key")
}
......
//go:build !flag_debug
package main
import (
"github.com/docker/machine/libmachine/drivers"
"github.com/pkg/errors"
)
func (d *Driver) flagFailure(format string, args ...interface{}) error {
return errors.Errorf(format, args...)
}
func (d *Driver) setConfigFromFlags(opts drivers.DriverOptions) error {
return d.setConfigFromFlagsImpl(opts)
}
//go:build flag_debug
package main
import (
"encoding/json"
"fmt"
"github.com/docker/machine/libmachine/drivers"
"github.com/pkg/errors"
)
var lastOpts drivers.DriverOptions
func (d *Driver) flagFailure(format string, args ...interface{}) error {
// machine driver may not flush logs received when getting an RPC error, so we have to resort to this terribleness
line1 := fmt.Sprintf("Flag failure detected:\n -> last opts: %v\n -> driver state %v", lastOpts, d)
var line2 string
if out, err := json.MarshalIndent(d, "", " "); err == nil {
line2 = fmt.Sprintf(" -> driver json:\n%s", out)
} else {
line2 = fmt.Sprintf("could not encode driver json: %v", err)
}
combined := append([]interface{}{line1, line2}, args...)
return errors.Errorf("%s\n%s\n"+format, combined...)
}
func (d *Driver) setConfigFromFlags(opts drivers.DriverOptions) error {
lastOpts = opts
return d.setConfigFromFlagsImpl(opts)
}