Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate leo and tpi executables #662

Merged
merged 20 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
45 changes: 37 additions & 8 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
builds:
- env:
-
id: "tpi"
main: ./cmd/tpi
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:
# - freebsd
- windows
Expand All @@ -27,14 +27,43 @@ builds:
goarch: arm64
- goos: windows
goarch: arm
binary: '{{ .ProjectName }}_v{{ .Version }}'
binary: 'terraform-provider-iterative'
-
id: "leo"
main: ./cmd/leo
0x2b3bfa0 marked this conversation as resolved.
Show resolved Hide resolved
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 All @@ -43,7 +72,7 @@ checksum:
signs:
- artifacts: checksum
args:
# if you are using this is a GitHub action or some other automated pipeline, you
# if you are using this is a GitHub action or some other automated pipeline, you
# need to pass the batch flag to indicate its not interactive.
- "--batch"
- "--output"
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 ./cmd/tpi

test:
go test ./... ${TESTARGS} -timeout=30s -parallel=4
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions cmd/leo/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main

import (
"os"
"terraform-provider-iterative/iterative/utils"
)

func main() {
defer utils.WaitForAnalyticsAndHandlePanics()
tasdomas marked this conversation as resolved.
Show resolved Hide resolved
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 → cmd/tpi/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
10 changes: 5 additions & 5 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 @@ -61,10 +61,10 @@ sudo tee /etc/systemd/system/tpi-task.service > /dev/null <<END
WantedBy=default.target
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
curl --location --remote-name https://github.com/iterative/terraform-provider-iterative/releases/latest/download/leo_linux_amd64
sudo mv leo* /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
10 changes: 5 additions & 5 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 @@ -61,10 +61,10 @@ sudo tee /etc/systemd/system/tpi-task.service > /dev/null <<END
WantedBy=default.target
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
curl --location --remote-name https://github.com/iterative/terraform-provider-iterative/releases/latest/download/leo_linux_amd64
sudo mv leo* /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
10 changes: 5 additions & 5 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 @@ -61,10 +61,10 @@ sudo tee /etc/systemd/system/tpi-task.service > /dev/null <<END
WantedBy=default.target
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
curl --location --remote-name https://github.com/iterative/terraform-provider-iterative/releases/latest/download/leo_linux_amd64
sudo mv leo* /usr/bin/leo
tasdomas marked this conversation as resolved.
Show resolved Hide resolved
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