React to change in logs directory for each app

This commit is contained in:
Radu Matei 2018-04-12 16:34:18 +03:00
Родитель f0ca0b3ac3
Коммит ce57a270ee
2 изменённых файлов: 17 добавлений и 5 удалений

Просмотреть файл

@ -7,6 +7,7 @@ import (
"io/ioutil"
"os"
"os/signal"
"path/filepath"
"syscall"
"time"
@ -79,7 +80,7 @@ func (cn *connectCmd) run(runningEnvironment string) (err error) {
ports = overridePorts
}
buildID, err := getLatestBuildID()
buildID, err := getLatestBuildID(deployedApp.Name)
if err != nil {
return err
}
@ -143,9 +144,9 @@ func writeContainerLogs(out io.Writer, in io.ReadCloser, containerName string) e
}
}
func getLatestBuildID() (string, error) {
func getLatestBuildID(appName string) (string, error) {
h := draftpath.Home(homePath())
files, err := ioutil.ReadDir(h.Logs())
files, err := ioutil.ReadDir(filepath.Join(h.Logs(), appName))
if err != nil {
return "", err
}

Просмотреть файл

@ -7,12 +7,17 @@ import (
"path/filepath"
"github.com/Azure/draft/pkg/draft/draftpath"
"github.com/Azure/draft/pkg/draft/local"
"github.com/hpcloud/tail"
"github.com/spf13/cobra"
)
const logsDesc = `This command outputs logs from the draft server to help debug builds.`
var (
runningEnvironment string
)
type logsCmd struct {
out io.Writer
appName string
@ -35,7 +40,12 @@ func newLogsCmd(out io.Writer) *cobra.Command {
Long: logsDesc,
PreRunE: lc.complete,
RunE: func(cmd *cobra.Command, args []string) error {
b, err := getLatestBuildID()
deployedApp, err := local.DeployedApplication(draftToml, runningEnvironment)
if err != nil {
return err
}
lc.appName = deployedApp.Name
b, err := getLatestBuildID(lc.appName)
if err != nil {
return fmt.Errorf("cannot get latest build: %v", err)
}
@ -51,6 +61,7 @@ func newLogsCmd(out io.Writer) *cobra.Command {
f := cmd.Flags()
f.BoolVar(&lc.tail, "tail", false, "tail the logs file as it's being written")
f.UintVar(&lc.line, "line", 20, "line location to tail from (offset from end of file)")
f.StringVarP(&runningEnvironment, environmentFlagName, environmentFlagShorthand, defaultDraftEnvironment(), environmentFlagUsage)
return cmd
}
@ -67,7 +78,7 @@ func (l *logsCmd) run(_ *cobra.Command, _ []string) error {
}
func (l *logsCmd) dumpLogs() error {
f, err := os.Open(filepath.Join(l.home.Logs(), l.buildID))
f, err := os.Open(filepath.Join(l.home.Logs(), l.appName, l.buildID))
if err != nil {
return fmt.Errorf("could not read logs for %s: %v", l.buildID, err)
}