Skip to content

Commit

Permalink
Merge pull request #41 from MZC-CSC/develop
Browse files Browse the repository at this point in the history
Reflect OS exit code and Add logs command
  • Loading branch information
MZC-CSC authored Nov 4, 2024
2 parents 32ed414 + fc9d0eb commit 84752b7
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 4,315 deletions.
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

0 comments on commit 84752b7

Please sign in to comment.