Skip to content

Commit

Permalink
feat(pkg): add the create command
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsimonemms committed Jun 16, 2023
1 parent ae961d6 commit 7b02643
Show file tree
Hide file tree
Showing 7 changed files with 305 additions and 31 deletions.
9 changes: 9 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,14 @@
"staticcheck": "go install honnef.co/go/tools/cmd/staticcheck@latest",
"goimports": "go install golang.org/x/tools/cmd/goimports@latest",
"pre-commit": "pre-commit install --install-hooks -t pre-commit -t commit-msg"
},
"containerEnv": {
"DISK_IMAGE": "ubuntu-22.04",
"DISK_SIZE": "30",
"MACHINE_ID": "some-machine-id",
"MACHINE_FOLDER": "/home/vscode/.ssh",
"MACHINE_TYPE": "cx11",
"REGION": "nbg1",
"TOKEN": ""
}
}
30 changes: 30 additions & 0 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,43 @@ limitations under the License.
package cmd

import (
"context"
"strconv"

"github.com/mrsimonemms/devpod-provider-hetzner/pkg/hetzner"
"github.com/mrsimonemms/devpod-provider-hetzner/pkg/options"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

// createCmd represents the create command
var createCmd = &cobra.Command{
Use: "create",
Short: "Create an instance",
RunE: func(cmd *cobra.Command, args []string) error {
options, err := options.FromEnv(false)
if err != nil {
return err
}

ctx := context.Background()
h := hetzner.NewHetzner(options.Token)

req, publicKey, err := h.BuildServerOptions(ctx, options)
if err != nil {
return err
}
if publicKey == nil {
return errors.New("no public key generated")
}

diskSize, err := strconv.Atoi(options.DiskSize)
if err != nil {
return errors.Wrap(err, "parse disk size")
}

return h.Create(ctx, req, diskSize, *publicKey)
},
}

func init() {
Expand Down
19 changes: 11 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.19
require (
github.com/hetznercloud/hcloud-go v1.45.1
github.com/loft-sh/devpod v0.1.9
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.7.0
)

Expand All @@ -28,22 +29,22 @@ require (
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/loft-sh/utils v0.0.15 // indirect
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/mattn/go-isatty v0.0.8 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/moby/term v0.0.0-20221205130635-1aeaba878587 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.15.1 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/crypto v0.6.0 // indirect
golang.org/x/crypto v0.7.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/term v0.7.0 // indirect
Expand All @@ -53,8 +54,10 @@ require (
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/square/go-jose.v2 v2.5.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/api v0.22.5 // indirect
k8s.io/apimachinery v0.22.5 // indirect
k8s.io/klog/v2 v2.30.0 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.1.2 // indirect
k8s.io/api v0.23.4 // indirect
k8s.io/apimachinery v0.23.4 // indirect
k8s.io/klog/v2 v2.80.1 // indirect
k8s.io/utils v0.0.0-20230505201702-9f6742963106 // indirect
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
)
Loading

0 comments on commit 7b02643

Please sign in to comment.