本文整理汇总了Golang中github.com/deis/pkg/log.Debug函数的典型用法代码示例。如果您正苦于以下问题:Golang Debug函数的具体用法?Golang Debug怎么用?Golang Debug使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Debug函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Run
// Run runs the git-receive hook. This func is effectively the main for the git-receive hook,
// although it is called from the main in boot.go.
func Run(conf *Config, fs sys.FS, env sys.Env, storageDriver storagedriver.StorageDriver) error {
log.Debug("Running git hook")
builderKey, err := builderconf.GetBuilderKey()
if err != nil {
return err
}
kubeClient, err := client.NewInCluster()
if err != nil {
return fmt.Errorf("couldn't reach the api server (%s)", err)
}
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
line := scanner.Text()
oldRev, newRev, refName, err := readLine(line)
if err != nil {
return fmt.Errorf("reading STDIN (%s)", err)
}
log.Debug("read [%s,%s,%s]", oldRev, newRev, refName)
// if we're processing a receive-pack on an existing repo, run a build
if strings.HasPrefix(conf.SSHOriginalCommand, "git-receive-pack") {
if err := build(conf, storageDriver, kubeClient, fs, env, builderKey, newRev); err != nil {
return err
}
}
}
return scanner.Err()
}
示例2: Configure
// Configure creates a new SSH configuration object.
//
// Config sets a PublicKeyCallback handler that forwards public key auth
// requests to the route named "pubkeyAuth".
//
// This assumes certain details about our environment, like the location of the
// host keys. It also provides only key-based authentication.
// ConfigureServerSshConfig
//
// Returns:
// An *ssh.ServerConfig
func Configure() (*ssh.ServerConfig, error) {
cfg := &ssh.ServerConfig{
PublicKeyCallback: func(m ssh.ConnMetadata, k ssh.PublicKey) (*ssh.Permissions, error) {
return AuthKey(k)
},
}
hostKeyTypes := []string{"rsa", "dsa", "ecdsa"}
pathTpl := "/var/run/secrets/deis/builder/ssh/ssh-host-%s-key"
for _, t := range hostKeyTypes {
path := fmt.Sprintf(pathTpl, t)
key, err := ioutil.ReadFile(path)
if err != nil {
log.Debug("Failed to read key %s (skipping): %s", path, err)
return nil, err
}
hk, err := ssh.ParsePrivateKey(key)
if err != nil {
log.Debug("Failed to parse host key %s (skipping): %s", path, err)
return nil, err
}
log.Debug("Parsed host key %s.", path)
cfg.AddHostKey(hk)
}
return cfg, nil
}
示例3: createRepo
// createRepo creates a new Git repo if it is not present already.
//
// Largely inspired by gitreceived from Flynn.
//
// Returns a bool indicating whether a project was created (true) or already
// existed (false).
func createRepo(repoPath string) (bool, error) {
createLock.Lock()
defer createLock.Unlock()
fi, err := os.Stat(repoPath)
if err == nil && fi.IsDir() {
// Nothing to do.
log.Debug("Directory %s already exists.", repoPath)
return false, nil
} else if os.IsNotExist(err) {
log.Debug("Creating new directory at %s", repoPath)
// Create directory
if err := os.MkdirAll(repoPath, 0755); err != nil {
log.Err("Failed to create repository: %s", err)
return false, err
}
cmd := exec.Command("git", "init", "--bare")
cmd.Dir = repoPath
if out, err := cmd.CombinedOutput(); err != nil {
log.Info("git init output: %s", out)
return false, err
}
return true, nil
} else if err == nil {
return false, errors.New("Expected directory, found file.")
}
return false, err
}
示例4: run
// run prints the command it will execute to the debug log, then runs it and returns the result of run
func run(cmd *exec.Cmd) error {
cmdStr := strings.Join(cmd.Args, " ")
if cmd.Dir != "" {
log.Debug("running [%s] in directory %s", cmdStr, cmd.Dir)
} else {
log.Debug("running [%s]", cmdStr)
}
return cmd.Run()
}
示例5: getProcFile
func getProcFile(getter storage.ObjectGetter, dirName, procfileKey string, bType buildType) (deisAPI.ProcessType, error) {
procType := deisAPI.ProcessType{}
if _, err := os.Stat(fmt.Sprintf("%s/Procfile", dirName)); err == nil {
rawProcFile, err := ioutil.ReadFile(fmt.Sprintf("%s/Procfile", dirName))
if err != nil {
return nil, fmt.Errorf("error in reading %s/Procfile (%s)", dirName, err)
}
if err := yaml.Unmarshal(rawProcFile, &procType); err != nil {
return nil, fmt.Errorf("procfile %s/ProcFile is malformed (%s)", dirName, err)
}
return procType, nil
}
if bType != buildTypeProcfile {
return procType, nil
}
log.Debug("Procfile not present. Getting it from the buildpack")
rawProcFile, err := getter.GetContent(context.Background(), procfileKey)
if err != nil {
return nil, fmt.Errorf("error in reading %s (%s)", procfileKey, err)
}
if err := yaml.Unmarshal(rawProcFile, &procType); err != nil {
return nil, fmt.Errorf("procfile %s is malformed (%s)", procfileKey, err)
}
return procType, nil
}
示例6: getAppConfig
func getAppConfig(conf *Config, builderKey, userName, appName string) (*pkg.Config, error) {
url := controllerURLStr(conf, "v2", "hooks", "config")
data, err := json.Marshal(&pkg.ConfigHook{
ReceiveUser: userName,
ReceiveRepo: appName,
})
if err != nil {
return nil, err
}
b := bytes.NewReader(data)
req, err := http.NewRequest("POST", url, b)
if err != nil {
return nil, err
}
setReqHeaders(builderKey, req)
log.Debug("Workflow request POST /v2/hooks/config\n%s", string(data))
res, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
if res.StatusCode != 200 {
return nil, newUnexpectedControllerStatusCode(url, 200, res.StatusCode)
}
ret := &pkg.Config{}
if err := json.NewDecoder(res.Body).Decode(ret); err != nil {
return nil, err
}
return ret, nil
}
示例7: AuthKey
// AuthKey authenticates based on a public key.
func AuthKey(key ssh.PublicKey, cnf *Config) (*ssh.Permissions, error) {
log.Info("Starting ssh authentication")
client, err := controller.New(cnf.ControllerHost, cnf.ControllerPort)
if err != nil {
return nil, err
}
fp := fingerprint(key)
userInfo, err := hooks.UserFromKey(client, fp)
if controller.CheckAPICompat(client, err) != nil {
log.Info("Failed to authenticate user ssh key %s with the controller: %s", fp, err)
return nil, err
}
apps := strings.Join(userInfo.Apps, ", ")
log.Debug("Key accepted for user %s.", userInfo.Username)
perm := &ssh.Permissions{
Extensions: map[string]string{
"user": userInfo.Username,
"fingerprint": fp,
"apps": apps,
},
}
return perm, nil
}
示例8: receive
func receive(conf *Config, builderKey, gitSha string) error {
urlStr := controllerURLStr(conf, "v2", "hooks", "push")
bodyMap := map[string]string{
"receive_user": conf.Username,
"receive_repo": conf.App(),
"sha": gitSha,
"fingerprint": conf.Fingerprint,
"ssh_connection": conf.SSHConnection,
"ssh_original_command": conf.SSHOriginalCommand,
}
var body bytes.Buffer
if err := json.NewEncoder(&body).Encode(bodyMap); err != nil {
return err
}
log.Debug("Workflow request /v2/hooks/push (body elided)")
req, err := http.NewRequest("POST", urlStr, &body)
if err != nil {
return err
}
setReqHeaders(builderKey, req)
// TODO: use ctxhttp here (https://godoc.org/golang.org/x/net/context/ctxhttp)
resp, err := http.DefaultClient.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != 201 {
return newUnexpectedControllerStatusCode(urlStr, 201, resp.StatusCode)
}
return nil
}
示例9: publishRelease
func publishRelease(conf *Config, builderKey string, buildHook *pkg.BuildHook) (*pkg.BuildHookResponse, error) {
var b bytes.Buffer
if err := json.NewEncoder(&b).Encode(buildHook); err != nil {
return nil, err
}
postBody := strings.Replace(string(b.Bytes()), "'", "", -1)
if potentialExploit.MatchString(postBody) {
return nil, fmt.Errorf("an environment variable in the app is trying to exploit Shellshock")
}
url := controllerURLStr(conf, "v2", "hooks", "build")
log.Debug("Controller request POST /v2/hooks/build\n%s", postBody)
req, err := http.NewRequest("POST", url, strings.NewReader(postBody))
if err != nil {
return nil, err
}
setReqHeaders(builderKey, req)
res, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
if res.StatusCode < 200 || res.StatusCode > 299 {
errMsg := new(pkg.ControllerErrorResponse)
if err := json.NewDecoder(res.Body).Decode(errMsg); err != nil {
//If an error occurs decoding the json print the whole response body
respBody, err := ioutil.ReadAll(res.Body)
if err != nil {
return nil, err
}
return nil, newUnexpectedControllerError(string(respBody))
}
return nil, newUnexpectedControllerError(errMsg.ErrorMsg)
}
ret := new(pkg.BuildHookResponse)
if err := json.NewDecoder(res.Body).Decode(ret); err != nil {
return nil, err
}
return ret, nil
}
示例10: main
func main() {
if os.Getenv("DEBUG") == "true" {
pkglog.DefaultLogger.SetDebug(true)
cookoolog.Level = cookoolog.LogDebug
}
pkglog.Debug("Running in debug mode")
app := cli.NewApp()
app.Commands = []cli.Command{
{
Name: "server",
Aliases: []string{"srv"},
Usage: "Run the git server",
Action: func(c *cli.Context) {
cnf := new(sshd.Config)
if err := conf.EnvConfig(serverConfAppName, cnf); err != nil {
pkglog.Err("getting config for %s [%s]", serverConfAppName, err)
os.Exit(1)
}
pkglog.Info("starting fetcher on port %d", cnf.FetcherPort)
go fetcher.Serve(cnf.FetcherPort)
pkglog.Info("starting SSH server on %s:%d", cnf.SSHHostIP, cnf.SSHHostPort)
os.Exit(pkg.Run(cnf.SSHHostIP, cnf.SSHHostPort, "boot"))
},
},
{
Name: "git-receive",
Aliases: []string{"gr"},
Usage: "Run the git-receive hook",
Action: func(c *cli.Context) {
cnf := new(gitreceive.Config)
if err := conf.EnvConfig(gitReceiveConfAppName, cnf); err != nil {
pkglog.Err("Error getting config for %s [%s]", gitReceiveConfAppName, err)
os.Exit(1)
}
cnf.CheckDurations()
if err := gitreceive.Run(cnf); err != nil {
pkglog.Err("running git receive hook [%s]", err)
os.Exit(1)
}
},
},
}
app.Run(os.Args)
}
示例11: getAppConfig
func getAppConfig(conf *Config, builderKey, userName, appName string) (*pkg.Config, error) {
url := controllerURLStr(conf, "v2", "hooks", "config")
data, err := json.Marshal(&pkg.ConfigHook{
ReceiveUser: userName,
ReceiveRepo: appName,
})
if err != nil {
return nil, err
}
b := bytes.NewReader(data)
req, err := http.NewRequest("POST", url, b)
if err != nil {
return nil, err
}
setReqHeaders(builderKey, req)
log.Debug("Controller request POST /v2/hooks/config\n%s", string(data))
res, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
if res.StatusCode < 200 || res.StatusCode > 299 {
errMsg := new(pkg.ControllerErrorResponse)
if err := json.NewDecoder(res.Body).Decode(errMsg); err != nil {
//If an error occurs decoding the json print the whole response body
respBody, err := ioutil.ReadAll(res.Body)
if err != nil {
return nil, err
}
return nil, newUnexpectedControllerError(string(respBody))
}
return nil, newUnexpectedControllerError(errMsg.ErrorMsg)
}
ret := &pkg.Config{}
if err := json.NewDecoder(res.Body).Decode(ret); err != nil {
return nil, err
}
return ret, nil
}
示例12: receive
func receive(conf *Config, builderKey, gitSha string) error {
urlStr := controllerURLStr(conf, "v2", "hooks", "push")
bodyMap := map[string]string{
"receive_user": conf.Username,
"receive_repo": conf.App(),
"sha": gitSha,
"fingerprint": conf.Fingerprint,
"ssh_connection": conf.SSHConnection,
"ssh_original_command": conf.SSHOriginalCommand,
}
var body bytes.Buffer
if err := json.NewEncoder(&body).Encode(bodyMap); err != nil {
return err
}
log.Debug("Controller request /v2/hooks/push (body elided)")
req, err := http.NewRequest("POST", urlStr, &body)
if err != nil {
return err
}
setReqHeaders(builderKey, req)
// TODO: use ctxhttp here (https://godoc.org/golang.org/x/net/context/ctxhttp)
resp, err := http.DefaultClient.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode < 200 || resp.StatusCode > 299 {
errMsg := new(pkg.ControllerErrorResponse)
if err := json.NewDecoder(resp.Body).Decode(errMsg); err != nil {
//If an error occurs decoding the json print the whole response body
respBody, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
return newUnexpectedControllerError(string(respBody))
}
return newUnexpectedControllerError(errMsg.ErrorMsg)
}
return nil
}
示例13: AuthKey
// AuthKey authenticates based on a public key.
func AuthKey(key ssh.PublicKey) (*ssh.Permissions, error) {
log.Info("Starting ssh authentication")
userInfo, err := controller.UserInfoFromKey(key)
if err != nil {
return nil, err
}
userInfo.Key = string(ssh.MarshalAuthorizedKey(key))
apps := strings.Join(userInfo.Apps, ", ")
log.Debug("Key accepted for user %s.", userInfo.Username)
perm := &ssh.Permissions{
Extensions: map[string]string{
"user": userInfo.Username,
"fingerprint": userInfo.Fingerprint,
"apps": apps,
},
}
return perm, nil
}
示例14: build
func build(conf *Config, kubeClient *client.Client, rawGitSha string) error {
repo := conf.Repository
gitSha, err := git.NewSha(rawGitSha)
if err != nil {
return err
}
appName := conf.App()
repoDir := filepath.Join(conf.GitHome, repo)
buildDir := filepath.Join(repoDir, "build")
slugName := fmt.Sprintf("%s:git-%s", appName, gitSha.Short())
if err := os.MkdirAll(buildDir, os.ModeDir); err != nil {
return fmt.Errorf("making the build directory %s (%s)", buildDir, err)
}
tmpDir := buildDir + gitSha.Short()
err = os.MkdirAll(tmpDir, 0777)
if err != nil {
return fmt.Errorf("unable to create tmpdir %s (%s)", buildDir, err)
}
slugBuilderInfo := storage.NewSlugBuilderInfo(appName, slugName, gitSha)
// build a tarball from the new objects
appTgz := fmt.Sprintf("%s.tar.gz", appName)
gitArchiveCmd := repoCmd(repoDir, "git", "archive", "--format=tar.gz", fmt.Sprintf("--output=%s", appTgz), gitSha.Short())
gitArchiveCmd.Stdout = os.Stdout
gitArchiveCmd.Stderr = os.Stderr
if err := run(gitArchiveCmd); err != nil {
return fmt.Errorf("running %s (%s)", strings.Join(gitArchiveCmd.Args, " "), err)
}
// untar the archive into the temp dir
tarCmd := repoCmd(repoDir, "tar", "-xzf", appTgz, "-C", fmt.Sprintf("%s/", tmpDir))
tarCmd.Stdout = os.Stdout
tarCmd.Stderr = os.Stderr
if err := run(tarCmd); err != nil {
return fmt.Errorf("running %s (%s)", strings.Join(tarCmd.Args, " "), err)
}
bType := getBuildTypeForDir(tmpDir)
usingDockerfile := bType == buildTypeDockerfile
procType := pkg.ProcessType{}
if bType == buildTypeProcfile {
rawProcFile, err := ioutil.ReadFile(fmt.Sprintf("%s/Procfile", tmpDir))
if err != nil {
return fmt.Errorf("reading %s/Procfile", tmpDir)
}
if err := yaml.Unmarshal(rawProcFile, &procType); err != nil {
return fmt.Errorf("procfile %s/ProcFile is malformed (%s)", tmpDir, err)
}
}
var pod *api.Pod
var buildPodName string
if usingDockerfile {
buildPodName = dockerBuilderPodName(appName, gitSha.Short())
pod = dockerBuilderPod(
conf.Debug,
false,
buildPodName,
conf.PodNamespace,
slugBuilderInfo.TarURL(),
slugName,
)
} else {
buildPodName = slugBuilderPodName(appName, gitSha.Short())
pod = slugbuilderPod(
conf.Debug,
false,
buildPodName,
conf.PodNamespace,
slugBuilderInfo.TarURL(),
slugBuilderInfo.PushURL(),
)
}
log.Info("Starting build... but first, coffee!")
log.Debug("Starting pod %s", buildPodName)
json, err := prettyPrintJSON(pod)
if err == nil {
log.Debug("Pod spec: %v", json)
} else {
log.Debug("Error creating json representaion of pod spec: %v", err)
}
podsInterface := kubeClient.Pods(conf.PodNamespace)
newPod, err := podsInterface.Create(pod)
if err != nil {
return fmt.Errorf("creating builder pod (%s)", err)
}
if err := waitForPod(kubeClient, newPod.Namespace, newPod.Name, conf.BuilderPodTickDuration(), conf.BuilderPodWaitDuration()); err != nil {
return fmt.Errorf("watching events for builder pod startup (%s)", err)
}
req := kubeClient.Get().Namespace(newPod.Namespace).Name(newPod.Name).Resource("pods").SubResource("log").VersionedParams(
//.........这里部分代码省略.........
示例15: build
func build(conf *Config, s3Client *s3.S3, kubeClient *client.Client, builderKey, rawGitSha string) error {
repo := conf.Repository
gitSha, err := git.NewSha(rawGitSha)
if err != nil {
return err
}
appName := conf.App()
repoDir := filepath.Join(conf.GitHome, repo)
buildDir := filepath.Join(repoDir, "build")
slugName := fmt.Sprintf("%s:git-%s", appName, gitSha.Short())
if err := os.MkdirAll(buildDir, os.ModeDir); err != nil {
return fmt.Errorf("making the build directory %s (%s)", buildDir, err)
}
tmpDir, err := ioutil.TempDir(buildDir, "tmp")
if err != nil {
return fmt.Errorf("unable to create tmpdir %s (%s)", buildDir, err)
}
slugBuilderInfo := storage.NewSlugBuilderInfo(s3Client.Endpoint, appName, slugName, gitSha)
// Get the application config from the controller, so we can check for a custom buildpack URL
appConf, err := getAppConfig(conf, builderKey, conf.Username, appName)
if err != nil {
return fmt.Errorf("getting app config for %s (%s)", appName, err)
}
log.Debug("got the following config back for app %s: %+v", appName, *appConf)
var buildPackURL string
if buildPackURLInterface, ok := appConf.Values["BUILDPACK_URL"]; ok {
if bpStr, ok := buildPackURLInterface.(string); ok {
log.Debug("found custom buildpack URL %s", bpStr)
buildPackURL = bpStr
}
}
// build a tarball from the new objects
appTgz := fmt.Sprintf("%s.tar.gz", appName)
gitArchiveCmd := repoCmd(repoDir, "git", "archive", "--format=tar.gz", fmt.Sprintf("--output=%s", appTgz), gitSha.Short())
gitArchiveCmd.Stdout = os.Stdout
gitArchiveCmd.Stderr = os.Stderr
if err := run(gitArchiveCmd); err != nil {
return fmt.Errorf("running %s (%s)", strings.Join(gitArchiveCmd.Args, " "), err)
}
absAppTgz := fmt.Sprintf("%s/%s", repoDir, appTgz)
// untar the archive into the temp dir
tarCmd := repoCmd(repoDir, "tar", "-xzf", appTgz, "-C", fmt.Sprintf("%s/", tmpDir))
tarCmd.Stdout = os.Stdout
tarCmd.Stderr = os.Stderr
if err := run(tarCmd); err != nil {
return fmt.Errorf("running %s (%s)", strings.Join(tarCmd.Args, " "), err)
}
bType := getBuildTypeForDir(tmpDir)
usingDockerfile := bType == buildTypeDockerfile
procType := pkg.ProcessType{}
if bType == buildTypeProcfile {
rawProcFile, err := ioutil.ReadFile(fmt.Sprintf("%s/Procfile", tmpDir))
if err != nil {
return fmt.Errorf("reading %s/Procfile", tmpDir)
}
if err := yaml.Unmarshal(rawProcFile, &procType); err != nil {
return fmt.Errorf("procfile %s/ProcFile is malformed (%s)", tmpDir, err)
}
}
bucketName := "git"
if err := storage.CreateBucket(s3Client, bucketName); err != nil {
log.Warn("create bucket error: %+v", err)
}
appTgzReader, err := os.Open(absAppTgz)
if err != nil {
return fmt.Errorf("opening %s for read (%s)", appTgz, err)
}
log.Debug("Uploading tar to %s/%s/%s", s3Client.Endpoint, bucketName, slugBuilderInfo.TarKey())
if err := storage.UploadObject(s3Client, bucketName, slugBuilderInfo.TarKey(), appTgzReader); err != nil {
return fmt.Errorf("uploading %s to %s/%s (%v)", absAppTgz, bucketName, slugBuilderInfo.TarKey(), err)
}
creds := storage.CredsOK()
var pod *api.Pod
var buildPodName string
if usingDockerfile {
buildPodName = dockerBuilderPodName(appName, gitSha.Short())
pod = dockerBuilderPod(
conf.Debug,
creds,
buildPodName,
conf.PodNamespace,
appConf.Values,
slugBuilderInfo.TarURL(),
slugName,
)
//.........这里部分代码省略.........