Skip to content

Commit a1a5092

Browse files
tasdomas0x2b3bfa0
andauthored
Separate leo and tpi executables (#662)
* 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 <0x2b3bfa0+git@googlemail.com>
1 parent 5f6b95d commit a1a5092

14 files changed

+82
-52
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ bin
77
/*.tfstate*
88
/crash.log
99

10+
# Build artefacts
11+
/dist
12+
1013
# Ignore any .tfvars files that are generated automatically for each Terraform run. Most
1114
# .tfvars files are managed as part of configuration and so should be included in
1215
# version control.

.goreleaser.yml

+36-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
builds:
2-
- env:
2+
-
3+
id: "tpi"
4+
main: ./main.go
5+
env:
36
- CGO_ENABLED=0
47
mod_timestamp: '{{ .CommitTimestamp }}'
58
flags:
69
- -trimpath
710
ldflags:
811
- -s -w
912
- -X terraform-provider-iterative/iterative/utils.Version={{.Version}}
10-
- -X main.version={{.Version}}
11-
- -X main.commit={{.Commit}}
12-
- -X main.date={{.Date}}
1313
goos:
1414
- windows
1515
- linux
@@ -26,14 +26,43 @@ builds:
2626
goarch: arm64
2727
- goos: windows
2828
goarch: arm
29-
binary: '{{ .ProjectName }}_v{{ .Version }}'
29+
binary: 'terraform-provider-iterative'
30+
-
31+
id: "leo"
32+
main: ./cmd/leo
33+
env:
34+
- CGO_ENABLED=0
35+
mod_timestamp: '{{ .CommitTimestamp }}'
36+
flags:
37+
- -trimpath
38+
ldflags:
39+
- -s -w
40+
- -X terraform-provider-iterative/iterative/utils.Version={{.Version}}
41+
goos:
42+
# - freebsd
43+
- windows
44+
- linux
45+
- darwin
46+
goarch:
47+
- amd64
48+
- '386'
49+
- arm
50+
- arm64
51+
ignore:
52+
- goos: darwin
53+
goarch: '386'
54+
- goos: windows
55+
goarch: arm64
56+
- goos: windows
57+
goarch: arm
58+
binary: 'leo'
3059
archives:
3160
- id: default
3261
format: zip
33-
name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}'
62+
name_template: '{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}'
3463
- id: agent
3564
format: binary
36-
name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}'
65+
name_template: '{{ .Binary }}_{{ .Os }}_{{ .Arch }}'
3766
checksum:
3867
name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS'
3968
algorithm: sha256

Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ INSTALL_PATH=~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/
99
default: build
1010

1111
build:
12-
go build
12+
go build ./...
1313

14-
install:
15-
GOBIN=${INSTALL_PATH} go install
14+
install_tpi:
15+
GOBIN=${INSTALL_PATH} go install ./...
1616

1717
test:
1818
go test ./... ${TESTARGS} -timeout=30s -parallel=4
File renamed without changes.
File renamed without changes.
File renamed without changes.

cmd/leo/main.go

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package main
2+
3+
import (
4+
"os"
5+
)
6+
7+
func main() {
8+
cmd := NewCmd()
9+
err := cmd.Execute()
10+
if err != nil {
11+
os.Exit(1)
12+
}
13+
}
File renamed without changes.

cmd/root.go cmd/leo/root.go

+10-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package cmd
1+
package main
22

33
import (
44
"fmt"
@@ -11,13 +11,12 @@ import (
1111
"github.com/spf13/pflag"
1212
"github.com/spf13/viper"
1313

14+
"terraform-provider-iterative/cmd/leo/create"
15+
"terraform-provider-iterative/cmd/leo/delete"
16+
"terraform-provider-iterative/cmd/leo/list"
17+
"terraform-provider-iterative/cmd/leo/read"
18+
"terraform-provider-iterative/cmd/leo/stop"
1419
"terraform-provider-iterative/task/common"
15-
16-
"terraform-provider-iterative/cmd/create"
17-
"terraform-provider-iterative/cmd/delete"
18-
"terraform-provider-iterative/cmd/list"
19-
"terraform-provider-iterative/cmd/read"
20-
"terraform-provider-iterative/cmd/stop"
2120
)
2221

2322
type Options struct {
@@ -27,15 +26,8 @@ type Options struct {
2726
common.Cloud
2827
}
2928

30-
func Execute() {
31-
cmd := New()
32-
err := cmd.Execute()
33-
if err != nil {
34-
os.Exit(1)
35-
}
36-
}
37-
38-
func New() *cobra.Command {
29+
// NewCmd initializes the subcommand structure.
30+
func NewCmd() *cobra.Command {
3931
o := Options{
4032
Cloud: common.Cloud{
4133
Timeouts: common.Timeouts{
@@ -48,10 +40,9 @@ func New() *cobra.Command {
4840
}
4941

5042
cmd := &cobra.Command{
51-
Use: "task",
43+
Use: "leo",
5244
Short: "Run code in the cloud",
53-
Long: `Task is a command-line tool that allows
54-
data scientists to run code in the cloud.`,
45+
Long: `leo is a command-line tool that allows data scientists to run code in the cloud.`,
5546
}
5647

5748
cmd.AddCommand(create.New(&o.Cloud))
File renamed without changes.

main.go

+2-11
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
11
package main
22

33
import (
4-
"os"
5-
64
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
75
"github.com/hashicorp/terraform-plugin-sdk/v2/plugin"
86

9-
"terraform-provider-iterative/iterative/utils"
107
"terraform-provider-iterative/iterative"
11-
"terraform-provider-iterative/cmd"
8+
"terraform-provider-iterative/iterative/utils"
129
)
1310

1411
func main() {
15-
defer utils.WaitForAnalyticsAndHandlePanics()
16-
17-
if os.Getenv(plugin.Handshake.MagicCookieKey) != plugin.Handshake.MagicCookieValue {
18-
cmd.Execute()
19-
return
20-
}
21-
12+
defer utils.WaitForAnalyticsAndHandlePanics()
2213
plugin.Serve(&plugin.ServeOpts{
2314
ProviderFunc: func() *schema.Provider {
2415
return iterative.Provider()

task/common/machine/machine-script.sh.tpl

+5-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ source /opt/task/credentials
1414
if ! test -z "$CI"; then
1515
cml rerun-workflow
1616
fi
17-
(systemctl is-system-running | grep stopping) || tpi stop --cloud="$TPI_TASK_CLOUD_PROVIDER" --region="$TPI_TASK_CLOUD_REGION" "$TPI_TASK_IDENTIFIER";
17+
(systemctl is-system-running | grep stopping) || leo stop --cloud="$TPI_TASK_CLOUD_PROVIDER" --region="$TPI_TASK_CLOUD_REGION" "$TPI_TASK_IDENTIFIER";
1818
END
1919

2020
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 <<END
6262
END
6363

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

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

task/common/machine/testdata/machine_script_full.golden

+5-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ source /opt/task/credentials
1414
if ! test -z "$CI"; then
1515
cml rerun-workflow
1616
fi
17-
(systemctl is-system-running | grep stopping) || tpi stop --cloud="$TPI_TASK_CLOUD_PROVIDER" --region="$TPI_TASK_CLOUD_REGION" "$TPI_TASK_IDENTIFIER";
17+
(systemctl is-system-running | grep stopping) || leo stop --cloud="$TPI_TASK_CLOUD_PROVIDER" --region="$TPI_TASK_CLOUD_REGION" "$TPI_TASK_IDENTIFIER";
1818
END
1919

2020
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 <<END
6262
END
6363

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

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

task/common/machine/testdata/machine_script_minimal.golden

+5-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ source /opt/task/credentials
1414
if ! test -z "$CI"; then
1515
cml rerun-workflow
1616
fi
17-
(systemctl is-system-running | grep stopping) || tpi stop --cloud="$TPI_TASK_CLOUD_PROVIDER" --region="$TPI_TASK_CLOUD_REGION" "$TPI_TASK_IDENTIFIER";
17+
(systemctl is-system-running | grep stopping) || leo stop --cloud="$TPI_TASK_CLOUD_PROVIDER" --region="$TPI_TASK_CLOUD_REGION" "$TPI_TASK_IDENTIFIER";
1818
END
1919

2020
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 <<END
6262
END
6363

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

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

0 commit comments

Comments
 (0)