mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-05-08 08:13:25 +02:00
Aligns runner log output more closely with `actions/runner`: - Strip the whale, rocket, cloud, construction, chequered-flag, and exclamation-mark glyphs from log lines and drop the now-unused `logPrefix` constant. - Reword `no outputs used step '%s'` → `No outputs registered for step '%s'` (the original was ungrammatical and inaccurate — it fires when `set-output` references an unknown step ID). - Wrap the docker pull/network/create/start phase of job container startup in a `::group::Starting job container` / `::endgroup::` collapsible section, mirroring `actions/runner`. Since act drives Docker through the SDK rather than the CLI, we can't echo `##[command]/usr/bin/docker create ...` lines verbatim — instead the helper emits a summary inside the group: ``` ::group::Starting job container image: <image> name: <container-name> network: <network-name> ::endgroup:: ``` - Extracted the emit into a `printStartJobContainerGroup` helper (parallel to `printRunActionHeader` in `step_run.go`) and added a golden-style test `TestPrintStartJobContainerGroupGolden`. - Drive-by: replace two remaining literal `"raw_output"` strings in `run_context.go` with the existing `rawOutputField` constant. Closes #935 --- This PR was written with the help of Claude Opus 4.7 Reviewed-on: https://gitea.com/gitea/runner/pulls/940 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: silverwind <me@silverwind.io> Co-committed-by: silverwind <me@silverwind.io>
121 lines
3.6 KiB
Go
121 lines
3.6 KiB
Go
// Copyright 2023 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))
|
|
|
|
package container
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"gitea.com/gitea/runner/act/common"
|
|
|
|
"github.com/docker/docker/api/types"
|
|
"github.com/docker/docker/pkg/archive"
|
|
"github.com/moby/buildkit/frontend/dockerfile/dockerignore"
|
|
"github.com/moby/patternmatcher"
|
|
)
|
|
|
|
// NewDockerBuildExecutor function to create a run executor for the container
|
|
func NewDockerBuildExecutor(input NewDockerBuildExecutorInput) common.Executor {
|
|
return func(ctx context.Context) error {
|
|
logger := common.Logger(ctx)
|
|
if input.Platform != "" {
|
|
logger.Infof("docker build -t %s --platform %s %s", input.ImageTag, input.Platform, input.ContextDir)
|
|
} else {
|
|
logger.Infof("docker build -t %s %s", input.ImageTag, input.ContextDir)
|
|
}
|
|
if common.Dryrun(ctx) {
|
|
return nil
|
|
}
|
|
|
|
cli, err := GetDockerClient(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer cli.Close()
|
|
|
|
logger.Debugf("Building image from '%v'", input.ContextDir)
|
|
|
|
tags := []string{input.ImageTag}
|
|
options := types.ImageBuildOptions{
|
|
Tags: tags,
|
|
Remove: true,
|
|
Platform: input.Platform,
|
|
AuthConfigs: LoadDockerAuthConfigs(ctx),
|
|
Dockerfile: input.Dockerfile,
|
|
}
|
|
var buildContext io.ReadCloser
|
|
if input.BuildContext != nil {
|
|
buildContext = io.NopCloser(input.BuildContext)
|
|
} else {
|
|
buildContext, err = createBuildContext(ctx, input.ContextDir, input.Dockerfile)
|
|
}
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
defer buildContext.Close()
|
|
|
|
logger.Debugf("Creating image from context dir '%s' with tag '%s' and platform '%s'", input.ContextDir, input.ImageTag, input.Platform)
|
|
resp, err := cli.ImageBuild(ctx, buildContext, options)
|
|
|
|
err = logDockerResponse(logger, resp.Body, err != nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func createBuildContext(ctx context.Context, contextDir, relDockerfile string) (io.ReadCloser, error) {
|
|
common.Logger(ctx).Debugf("Creating archive for build context dir '%s' with relative dockerfile '%s'", contextDir, relDockerfile)
|
|
|
|
// And canonicalize dockerfile name to a platform-independent one
|
|
relDockerfile = archive.CanonicalTarNameForPath(relDockerfile)
|
|
|
|
f, err := os.Open(filepath.Join(contextDir, ".dockerignore"))
|
|
if err != nil && !os.IsNotExist(err) {
|
|
return nil, err
|
|
}
|
|
defer f.Close()
|
|
|
|
var excludes []string
|
|
if err == nil {
|
|
excludes, err = dockerignore.ReadAll(f) //nolint:staticcheck // pre-existing issue from nektos/act
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
// If .dockerignore mentions .dockerignore or the Dockerfile
|
|
// then make sure we send both files over to the daemon
|
|
// because Dockerfile is, obviously, needed no matter what, and
|
|
// .dockerignore is needed to know if either one needs to be
|
|
// removed. The daemon will remove them for us, if needed, after it
|
|
// parses the Dockerfile. Ignore errors here, as they will have been
|
|
// caught by validateContextDirectory above.
|
|
includes := []string{"."}
|
|
keepThem1, _ := patternmatcher.Matches(".dockerignore", excludes)
|
|
keepThem2, _ := patternmatcher.Matches(relDockerfile, excludes)
|
|
if keepThem1 || keepThem2 {
|
|
includes = append(includes, ".dockerignore", relDockerfile)
|
|
}
|
|
|
|
compression := archive.Uncompressed
|
|
buildCtx, err := archive.TarWithOptions(contextDir, &archive.TarOptions{
|
|
Compression: compression,
|
|
ExcludePatterns: excludes,
|
|
IncludeFiles: includes,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return buildCtx, nil
|
|
}
|