Skip to content

Commit

Permalink
Separate leo and tpi executables (#662)
Browse files Browse the repository at this point in the history
* Separate leo and tpi.

* Update goreleaser config to build leo and tpi separately.

* Add dist to .gitignore.

* Use leo name.

* Minor Makefile update.

* Update machine script.

* Update golden files.

* Keep terraform-provider-iterative in package root.

* Keep using existing tpi release in machine script.

* Update golden files.

* Address review comments.

Co-authored-by: Helio Machado <[email protected]>
  • Loading branch information
tasdomas and 0x2b3bfa0 authored Oct 10, 2022
1 parent 5f6b95d commit a1a5092
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 52 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
43 changes: 36 additions & 7 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
builds:
- env:
-
id: "tpi"
main: ./main.go
env:
- CGO_ENABLED=0
mod_timestamp: '{{ .CommitTimestamp }}'
flags:
- -trimpath
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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions cmd/leo/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import (
"os"
)

func main() {
cmd := NewCmd()
err := cmd.Execute()
if err != nil {
os.Exit(1)
}
}
File renamed without changes.
29 changes: 10 additions & 19 deletions cmd/root.go → cmd/leo/root.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package main

import (
"fmt"
Expand All @@ -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 {
Expand All @@ -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{
Expand All @@ -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))
Expand Down
File renamed without changes.
13 changes: 2 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
9 changes: 5 additions & 4 deletions task/common/machine/machine-script.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -62,9 +62,10 @@ sudo tee /etc/systemd/system/tpi-task.service > /dev/null <<END
END

curl --location --remote-name https://github.com/iterative/terraform-provider-iterative/releases/latest/download/terraform-provider-iterative_linux_amd64
sudo mv terraform-provider-iterative* /usr/bin/tpi
sudo chmod u=rwx,g=rx,o=rx /usr/bin/tpi
sudo chown root:root /usr/bin/tpi
# TODO: replace download location with https://github.com/iterative/terraform-provider-iterative/releases/latest/download/leo_linux_amd64
sudo mv terraform-provider-iterative* /usr/bin/leo
sudo chmod u=rwx,g=rx,o=rx /usr/bin/leo
sudo chown root:root /usr/bin/leo

curl --location --remote-name https://github.com/iterative/cml/releases/latest/download/cml-linux
chmod u=rwx,g=rx,o=rx cml-linux
Expand Down
9 changes: 5 additions & 4 deletions task/common/machine/testdata/machine_script_full.golden
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -62,9 +62,10 @@ sudo tee /etc/systemd/system/tpi-task.service > /dev/null <<END
END

curl --location --remote-name https://github.com/iterative/terraform-provider-iterative/releases/latest/download/terraform-provider-iterative_linux_amd64
sudo mv terraform-provider-iterative* /usr/bin/tpi
sudo chmod u=rwx,g=rx,o=rx /usr/bin/tpi
sudo chown root:root /usr/bin/tpi
# TODO: replace download location with https://github.com/iterative/terraform-provider-iterative/releases/latest/download/leo_linux_amd64
sudo mv terraform-provider-iterative* /usr/bin/leo
sudo chmod u=rwx,g=rx,o=rx /usr/bin/leo
sudo chown root:root /usr/bin/leo

curl --location --remote-name https://github.com/iterative/cml/releases/latest/download/cml-linux
chmod u=rwx,g=rx,o=rx cml-linux
Expand Down
9 changes: 5 additions & 4 deletions task/common/machine/testdata/machine_script_minimal.golden
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -62,9 +62,10 @@ sudo tee /etc/systemd/system/tpi-task.service > /dev/null <<END
END

curl --location --remote-name https://github.com/iterative/terraform-provider-iterative/releases/latest/download/terraform-provider-iterative_linux_amd64
sudo mv terraform-provider-iterative* /usr/bin/tpi
sudo chmod u=rwx,g=rx,o=rx /usr/bin/tpi
sudo chown root:root /usr/bin/tpi
# TODO: replace download location with https://github.com/iterative/terraform-provider-iterative/releases/latest/download/leo_linux_amd64
sudo mv terraform-provider-iterative* /usr/bin/leo
sudo chmod u=rwx,g=rx,o=rx /usr/bin/leo
sudo chown root:root /usr/bin/leo

curl --location --remote-name https://github.com/iterative/cml/releases/latest/download/cml-linux
chmod u=rwx,g=rx,o=rx cml-linux
Expand Down

0 comments on commit a1a5092

Please sign in to comment.