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

chore(tiup-publisher): add logs #177

Merged
merged 1 commit into from
Oct 9, 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
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