Skip to content

Commit

Permalink
chore(tiup-publisher): add logs (#177)
Browse files Browse the repository at this point in the history
Signed-off-by: wuhuizuo <wuhuizuo@126.com>

Signed-off-by: wuhuizuo <wuhuizuo@126.com>
  • Loading branch information
wuhuizuo authored Oct 9, 2024
1 parent f37a206 commit 0b8b9f9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 6 additions & 0 deletions tiup-publisher/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,26 @@ func (h *Handler) handleImpl(data *PublishRequestEvent) cloudevents.Result {
// 1. get the the tarball from data.From.
saveTo, err := downloadFile(data)
if err != nil {
log.Err(err).Msg("download file failed")
return cloudevents.NewReceipt(true, "download file failed: %v", err)
}
log.Info().Msg("download file success")

// 2. publish the tarball to the mirror.
if err := publish(saveTo, &data.Publish, h.mirrorsURL); err != nil {
log.Err(err).Msg("publish to mirror failed")
return cloudevents.NewReceipt(true, "publish to mirror failed: %v", err)
}
log.Info().Msg("publish to mirror success")

// 3. check the package is in the mirror.
// printf 'post_check "$(tiup mirror show)/%s-%s-%s-%s.tar.gz" "%s"\n' \
remoteURL := fmt.Sprintf("%s/%s-%s-%s-%s.tar.gz", h.mirrorsURL, data.Publish.Name, data.Publish.Version, data.Publish.OS, data.Publish.Arch)
if err := postCheck(saveTo, remoteURL); err != nil {
log.Err(err).Str("remote", remoteURL).Msg("post check failed")
return cloudevents.NewReceipt(true, "post check failed: %v", err)
}
log.Info().Str("remote", remoteURL).Msg("post check success")
return cloudevents.ResultACK
}

Expand Down
13 changes: 11 additions & 2 deletions tiup-publisher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"flag"
"os"
"strconv"

"github.com/cloudevents/sdk-go/v2/event"
"github.com/rs/zerolog"
Expand All @@ -14,8 +15,16 @@ import (
)

func main() {
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
logLevel, err := strconv.Atoi(os.Getenv("LOG_LEVEL"))
if err != nil {
logLevel = int(zerolog.InfoLevel) // default to INFO
}
log.Logger = log.Level(zerolog.Level(logLevel))

if os.Getenv("APP_ENV") == "development" {
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
}

configFile := flag.String("config", "./config.yaml", "Path to config file")
flag.Parse()
Expand Down

0 comments on commit 0b8b9f9

Please sign in to comment.