Skip to content

Commit

Permalink
After commands moved after supervisord configuration
Browse files Browse the repository at this point in the history
* New vscode debug profile
* Fixed error color output of after commands
  • Loading branch information
by-cx committed Jan 13, 2023
1 parent be6d014 commit 762a5b9
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 17 deletions.
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "up test_projects/hellopython2",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceRoot}",
"cwd": "${workspaceRoot}/test_projects/hellopython2",
"args": [
"up"
]
}

]
}
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
VERSION=0.7
VERSION=0.8
TESTIMAGE_VERSION=v1

.PHONY: all
all: release

.PHONY: preparation
preparation:
preparation: clean
sed -i "s/const version = \"[0-9\.]*\"/const version = \"${VERSION}\"/" main.go
mkdir -p bin
go mod tidy
Expand Down Expand Up @@ -38,7 +38,7 @@ release: bin/rostictl-${VERSION}.linux.arm bin/rostictl-${VERSION}.linux.arm64 b

.PHONY: clean
clean: preparation
rm bin/*
rm -f bin/*

.PHONY: build-test-image
build-test-image:
Expand Down
43 changes: 31 additions & 12 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/rosti-cz/cli/src/state"
"github.com/urfave/cli/v2"
"golang.org/x/crypto/ssh/terminal"
"gopkg.in/yaml.v2"
)

// Import existing application
Expand Down Expand Up @@ -365,18 +366,6 @@ func commandUp(c *cli.Context) error {
return err
}

for _, cmd := range rostifile.AfterCommands {
fmt.Printf(".. running command: %s\n", cmd)
buf, err = sshClient.Run("/bin/sh -c '" + cmd + "'")
if err != nil {
fmt.Print("Command '")
cWhite.Print(cmd)
cYellow.Println("' error:")
cRed.Println(buf.String())
return err
}
}

// Setup crontab
if len(rostifile.Crontabs) > 0 {
cYellow.Println(".. setting up crontabs")
Expand Down Expand Up @@ -432,6 +421,18 @@ redirect_stderr=true
}
}

// Setup after commands
for _, cmd := range rostifile.AfterCommands {
cYellow.Print(".. running command:")
fmt.Printf(" %s\n", cmd)
buf, err = sshClient.Run("/bin/sh -c '" + cmd + "'")
if err != nil {
cRed.Println("error: ", err)
cRed.Println(buf.String())
return err
}
}

// Done
cYellow.Println(".. all done, let's check status of the application")

Expand Down Expand Up @@ -719,3 +720,21 @@ func commandVersion(c *cli.Context) error {
fmt.Println("Version:", version)
return nil
}

func commandRostifile(c *cli.Context) error {
rostifile, err := parser.Parse()
if err != nil {
return err
}

fmt.Println("Rostifile:")
fmt.Println("----------")
body, err := yaml.Marshal(rostifile)
if err != nil {
return err
}

fmt.Println(string(body))

return nil
}
8 changes: 7 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/urfave/cli/v2"
)

const version = "0.6"
const version = "0.8"

func handleError(err error) {
log.Fatalln(err)
Expand Down Expand Up @@ -102,6 +102,12 @@ func main() {
Usage: "Creates a new Rostifile in the current working directory",
Action: commandInit,
},
{
Name: "rostifile",
Aliases: []string{},
Usage: "Read Rostifile into internal structure and encodes it again (for debugging)",
Action: commandRostifile,
},
{

Name: "import",
Expand Down
1 change: 0 additions & 1 deletion src/rostiapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ func (c *Client) DoApp(id uint, action string) error {
func (c *Client) GetPlans() ([]Plan, error) {
plans := []Plan{}

fmt.Printf("Company ID: %d\n", c.CompanyID)
body, statusCode, err := c.call("GET", strconv.Itoa(int(c.CompanyID))+"/"+"plans/", []byte(""))
if err != nil {
return plans, err
Expand Down

0 comments on commit 762a5b9

Please sign in to comment.