mirror of
https://gitea.com/gitea/runner.git
synced 2026-11-04 06:25:32 +00:00
1. Restructures the README into installation, quickstart, deployment, configuration, jobs and operation, and shortens it to user-facing prose. Option details are left to `config.example.yaml` and `docs/`, existing heading anchors are kept where possible. 2. FreeBSD builds used the Docker stub, so `docker://` labels, services and Docker actions failed there. The Docker code works on FreeBSD against a remote daemon, so it is enabled, and host jobs report `runner.os` as `FreeBSD`. 3. `make build` on Windows now writes `gitea-runner.exe`, taking the suffix from `go env GOEXE`. Reviewed-on: https://gitea.com/gitea/runner/pulls/1367 Reviewed-by: Lunny Xiao <[email protected]> Co-authored-by: silverwind <[email protected]>
79 lines
2.0 KiB
Go
79 lines
2.0 KiB
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// Copyright 2020 The nektos/act Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows || netbsd || freebsd))
|
|
|
|
package container
|
|
|
|
import (
|
|
"bufio"
|
|
"encoding/json/v2"
|
|
"errors"
|
|
"io"
|
|
|
|
"gitea.com/gitea/runner/act/common/logging"
|
|
)
|
|
|
|
type dockerMessage struct {
|
|
ID string `json:"id"`
|
|
Stream string `json:"stream"`
|
|
Error string `json:"error"`
|
|
ErrorDetail struct {
|
|
Message string `json:"message"`
|
|
} `json:"errorDetail"`
|
|
Status string `json:"status"`
|
|
Progress string `json:"progress"`
|
|
}
|
|
|
|
func logDockerResponse(logger *logging.Logger, dockerResponse io.ReadCloser, isError bool) error {
|
|
if dockerResponse == nil {
|
|
return nil
|
|
}
|
|
defer dockerResponse.Close()
|
|
|
|
scanner := bufio.NewScanner(dockerResponse)
|
|
scanner.Buffer(nil, 64*1024*1024) // a build echoes long instructions in one record
|
|
for scanner.Scan() {
|
|
line := scanner.Bytes()
|
|
var msg dockerMessage
|
|
if err := json.Unmarshal(line, &msg); err != nil {
|
|
writeLog(logger, false, "Unable to unmarshal line [%s] ==> %v", string(line), err)
|
|
continue
|
|
}
|
|
|
|
if msg.Error != "" {
|
|
writeLog(logger, isError, "%s", msg.Error)
|
|
return errors.New(msg.Error)
|
|
}
|
|
|
|
if msg.ErrorDetail.Message != "" {
|
|
writeLog(logger, isError, "%s", msg.ErrorDetail.Message)
|
|
return errors.New(msg.ErrorDetail.Message)
|
|
}
|
|
|
|
switch {
|
|
case msg.Status != "":
|
|
if msg.Progress != "" {
|
|
writeLog(logger, isError, "%s :: %s :: %s\n", msg.Status, msg.ID, msg.Progress)
|
|
} else {
|
|
writeLog(logger, isError, "%s :: %s\n", msg.Status, msg.ID)
|
|
}
|
|
case msg.Stream != "":
|
|
writeLog(logger, isError, "%s", msg.Stream)
|
|
default:
|
|
writeLog(logger, false, "Unable to handle line: %s", string(line))
|
|
}
|
|
}
|
|
|
|
return scanner.Err()
|
|
}
|
|
|
|
func writeLog(logger *logging.Logger, isError bool, format string, args ...any) {
|
|
if isError {
|
|
logger.Errorf(format, args...)
|
|
} else {
|
|
logger.Debugf(format, args...)
|
|
}
|
|
}
|