diff --git a/.gitignore b/.gitignore index 928af133..ff0f28bf 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,9 @@ bin /*.tfstate* /crash.log +# Build artefacts +/dist + # Ignore any .tfvars files that are generated automatically for each Terraform run. Most # .tfvars files are managed as part of configuration and so should be included in # version control. diff --git a/.goreleaser.yml b/.goreleaser.yml index 7c469855..f14c7fba 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,5 +1,8 @@ builds: -- env: +- + id: "tpi" + main: ./main.go + env: - CGO_ENABLED=0 mod_timestamp: '{{ .CommitTimestamp }}' flags: @@ -7,9 +10,6 @@ builds: ldflags: - -s -w - -X terraform-provider-iterative/iterative/utils.Version={{.Version}} - - -X main.version={{.Version}} - - -X main.commit={{.Commit}} - - -X main.date={{.Date}} goos: - windows - linux @@ -26,14 +26,43 @@ builds: goarch: arm64 - goos: windows goarch: arm - binary: '{{ .ProjectName }}_v{{ .Version }}' + binary: 'terraform-provider-iterative' +- + id: "leo" + main: ./cmd/leo + env: + - CGO_ENABLED=0 + mod_timestamp: '{{ .CommitTimestamp }}' + flags: + - -trimpath + ldflags: + - -s -w + - -X terraform-provider-iterative/iterative/utils.Version={{.Version}} + goos: + # - freebsd + - windows + - linux + - darwin + goarch: + - amd64 + - '386' + - arm + - arm64 + ignore: + - goos: darwin + goarch: '386' + - goos: windows + goarch: arm64 + - goos: windows + goarch: arm + binary: 'leo' archives: - id: default format: zip - name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}' + name_template: '{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}' - id: agent format: binary - name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}' + name_template: '{{ .Binary }}_{{ .Os }}_{{ .Arch }}' checksum: name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS' algorithm: sha256 diff --git a/Makefile b/Makefile index c1cf0489..c9549dee 100644 --- a/Makefile +++ b/Makefile @@ -9,10 +9,10 @@ INSTALL_PATH=~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/ default: build build: - go build + go build ./... -install: - GOBIN=${INSTALL_PATH} go install +install_tpi: + GOBIN=${INSTALL_PATH} go install ./... test: go test ./... ${TESTARGS} -timeout=30s -parallel=4 diff --git a/cmd/create/create.go b/cmd/leo/create/create.go similarity index 100% rename from cmd/create/create.go rename to cmd/leo/create/create.go diff --git a/cmd/delete/delete.go b/cmd/leo/delete/delete.go similarity index 100% rename from cmd/delete/delete.go rename to cmd/leo/delete/delete.go diff --git a/cmd/list/list.go b/cmd/leo/list/list.go similarity index 100% rename from cmd/list/list.go rename to cmd/leo/list/list.go diff --git a/cmd/leo/main.go b/cmd/leo/main.go new file mode 100644 index 00000000..52c5ed26 --- /dev/null +++ b/cmd/leo/main.go @@ -0,0 +1,13 @@ +package main + +import ( + "os" +) + +func main() { + cmd := NewCmd() + err := cmd.Execute() + if err != nil { + os.Exit(1) + } +} diff --git a/cmd/read/read.go b/cmd/leo/read/read.go similarity index 100% rename from cmd/read/read.go rename to cmd/leo/read/read.go diff --git a/cmd/root.go b/cmd/leo/root.go similarity index 89% rename from cmd/root.go rename to cmd/leo/root.go index 4c4c4cf2..4d6a8b82 100644 --- a/cmd/root.go +++ b/cmd/leo/root.go @@ -1,4 +1,4 @@ -package cmd +package main import ( "fmt" @@ -11,13 +11,12 @@ import ( "github.com/spf13/pflag" "github.com/spf13/viper" + "terraform-provider-iterative/cmd/leo/create" + "terraform-provider-iterative/cmd/leo/delete" + "terraform-provider-iterative/cmd/leo/list" + "terraform-provider-iterative/cmd/leo/read" + "terraform-provider-iterative/cmd/leo/stop" "terraform-provider-iterative/task/common" - - "terraform-provider-iterative/cmd/create" - "terraform-provider-iterative/cmd/delete" - "terraform-provider-iterative/cmd/list" - "terraform-provider-iterative/cmd/read" - "terraform-provider-iterative/cmd/stop" ) type Options struct { @@ -27,15 +26,8 @@ type Options struct { common.Cloud } -func Execute() { - cmd := New() - err := cmd.Execute() - if err != nil { - os.Exit(1) - } -} - -func New() *cobra.Command { +// NewCmd initializes the subcommand structure. +func NewCmd() *cobra.Command { o := Options{ Cloud: common.Cloud{ Timeouts: common.Timeouts{ @@ -48,10 +40,9 @@ func New() *cobra.Command { } cmd := &cobra.Command{ - Use: "task", + Use: "leo", Short: "Run code in the cloud", - Long: `Task is a command-line tool that allows - data scientists to run code in the cloud.`, + Long: `leo is a command-line tool that allows data scientists to run code in the cloud.`, } cmd.AddCommand(create.New(&o.Cloud)) diff --git a/cmd/stop/stop.go b/cmd/leo/stop/stop.go similarity index 100% rename from cmd/stop/stop.go rename to cmd/leo/stop/stop.go diff --git a/main.go b/main.go index b1867aac..52ea8965 100644 --- a/main.go +++ b/main.go @@ -1,24 +1,15 @@ package main import ( - "os" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/plugin" - "terraform-provider-iterative/iterative/utils" "terraform-provider-iterative/iterative" - "terraform-provider-iterative/cmd" + "terraform-provider-iterative/iterative/utils" ) func main() { - defer utils.WaitForAnalyticsAndHandlePanics() - - if os.Getenv(plugin.Handshake.MagicCookieKey) != plugin.Handshake.MagicCookieValue { - cmd.Execute() - return - } - + defer utils.WaitForAnalyticsAndHandlePanics() plugin.Serve(&plugin.ServeOpts{ ProviderFunc: func() *schema.Provider { return iterative.Provider() diff --git a/task/common/machine/machine-script.sh.tpl b/task/common/machine/machine-script.sh.tpl index c757597a..7f7cc5e6 100755 --- a/task/common/machine/machine-script.sh.tpl +++ b/task/common/machine/machine-script.sh.tpl @@ -14,7 +14,7 @@ source /opt/task/credentials if ! test -z "$CI"; then cml rerun-workflow fi -(systemctl is-system-running | grep stopping) || tpi stop --cloud="$TPI_TASK_CLOUD_PROVIDER" --region="$TPI_TASK_CLOUD_REGION" "$TPI_TASK_IDENTIFIER"; +(systemctl is-system-running | grep stopping) || leo stop --cloud="$TPI_TASK_CLOUD_PROVIDER" --region="$TPI_TASK_CLOUD_REGION" "$TPI_TASK_IDENTIFIER"; END chmod u=rwx,g=rx,o=rx /usr/bin/tpi-task-shutdown @@ -62,9 +62,10 @@ sudo tee /etc/systemd/system/tpi-task.service > /dev/null < /dev/null < /dev/null <