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

Reflect OS exit code and Add logs command #41

Merged
merged 7 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 25 additions & 0 deletions cmd/docker/log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package docker

import (
"fmt"

"github.com/cm-mayfly/cm-mayfly/common"
"github.com/spf13/cobra"
)

// pullCmd represents the pull command
var logCmd = &cobra.Command{
Use: "logs",
Short: "View output from Cloud-Migrator system containers",
Long: `View output from Cloud-Migrator system containers`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("\n[View output from Cloud-Migrator system containers.]")
cmdStr := fmt.Sprintf("COMPOSE_PROJECT_NAME=%s docker compose -f %s logs --follow %s", ProjectName, DockerFilePath, ServiceName)
//fmt.Println(cmdStr)
common.SysCall(cmdStr)
},
}

func init() {
dockerCmd.AddCommand(logCmd)
}
5 changes: 4 additions & 1 deletion cmd/rest/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rest

import (
"fmt"
"os"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -35,11 +36,13 @@ var restGetCmd = &cobra.Command{
resp, err := req.Get(url)
if err != nil {
fmt.Println("Error:", err)
return
os.Exit(1)
//return
}

// 응답 출력
ProcessResultInfo(resp)
ProcessOsExitcode(resp) // for docker compose healthy check
},
}

Expand Down
16 changes: 16 additions & 0 deletions cmd/rest/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package rest
import (
"fmt"
"io/ioutil"
"os"

"strings"

Expand Down Expand Up @@ -71,6 +72,9 @@ var restCmd = &cobra.Command{
//fmt.Println("============ REST 메인 호출됨!!!! ")
fmt.Println(cmd.Help()) // root.go에서는 도움말만 출력 함.
},

// PersistentPostRun: func(cmd *cobra.Command, args []string) {
// },
}

func SetBasicAuth() {
Expand Down Expand Up @@ -164,6 +168,18 @@ func ProcessResultInfo(resp *resty.Response) {
}
}

// Handles OS exit code for docker-compose's healthy checks.
func ProcessOsExitcode(resp *resty.Response) {
// Checking response status codes
if resp.StatusCode() != 200 {
if isVerbose {
fmt.Fprintf(os.Stderr, "Received non-200 response: %d\n", resp.StatusCode())
}
exitCode := resp.StatusCode() / 100 // First digit (2xx, 3xx, 4xx, 5xx)
os.Exit(exitCode) // One of 0, 3, 4, or 5
}
}

func ShowTraceInfo(resp *resty.Response) {
// Explore trace info
fmt.Println("Request Trace Info:")
Expand Down
Loading