mirror of
https://gitea.com/gitea/runner.git
synced 2026-11-18 05:43:42 +00:00
fix: repair free-disk-space build on illumos, Solaris, NetBSD and OpenBSD (#1416)
The runner did not build on illumos, Solaris, NetBSD and OpenBSD: `internal/pkg/disk` called `unix.Statfs`, which `golang.org/x/sys/unix` lacks on illumos, Solaris and NetBSD (they have `statvfs(2)`) and exposes with `F_`-prefixed fields on OpenBSD. Each now has an implementation matching its syscall. FreeBSD and DragonFly report a negative available-block count once root writes into the reserved blocks. It wrapped to ~16 EiB free, so the disk health check and cache eviction saw plenty of space exactly when the disk was full. A shared helper clamps it to zero and absorbs the per-platform integer types. CI only built for the host, which let this and https://gitea.com/gitea/runner/pulls/1098 through. `make cross-check` vets code and tests on one target per distinct set of platform files, plus linux/arm for its 32-bit syscall fields, and runs as its own job in parallel to the others. It also surfaced docker-only tests lacking the docker build tag, which are fixed too. Assisted-by: Claude Code:claude-opus-5-5 Co-authored-by: rosekanari <[email protected]>
This commit is contained in:
1 parent
0e4c8b6b78
commit
bcc0b715cd
18 files changed
+122
-17
No files matched your search
@@ -57,6 +57,15 @@ jobs:
|
|||||||
make coverage-report
|
make coverage-report
|
||||||
cat .tmp/coverage.md >> "$GITHUB_STEP_SUMMARY"
|
cat .tmp/coverage.md >> "$GITHUB_STEP_SUMMARY"
|
||||||
|
|
||||||
|
cross:
|
||||||
|
name: cross-compile
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
|
||||||
|
- uses: ./.gitea/actions/go-setup
|
||||||
|
- name: cross-compile
|
||||||
|
run: make cross-check
|
||||||
|
|
||||||
windows:
|
windows:
|
||||||
name: test on windows
|
name: test on windows
|
||||||
runs-on: ubuntu-latest-kvm
|
runs-on: ubuntu-latest-kvm
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
- Read `DEVELOPMENT.md` for internals and conventions
|
- Read `DEVELOPMENT.md` for internals and conventions
|
||||||
- Ensure no trailing whitespace in edited files
|
- Ensure no trailing whitespace in edited files
|
||||||
- Run `make fmt` after `.go` edits, `make tidy` after `go.mod` edits, and `make checks` for the non-lint source checks
|
- Run `make fmt` after `.go` edits, `make tidy` after `go.mod` edits, and `make checks` for the non-lint source checks
|
||||||
- Lint what changed with `make lint-go`, and `make lint-go-windows` for Windows and platform-split files
|
- Lint what changed with `make lint-go`, and `make lint-go-windows` for Windows and platform-split files. Run `make cross-check` after platform-split edits
|
||||||
- Fix the cause rather than disabling a linter or weakening a test. Where unavoidable, use the narrowest scope with a trailing comment giving the reason
|
- Fix the cause rather than disabling a linter or weakening a test. Where unavoidable, use the narrowest scope with a trailing comment giving the reason
|
||||||
- Run single go tests with `go test -run '^TestName$' ./modulepath/`. `make test` self-skips the integration tests without docker or network, `make test-dind` runs the daemon-facing tests against the built dind image
|
- Run single go tests with `go test -run '^TestName$' ./modulepath/`. `make test` self-skips the integration tests without docker or network, `make test-dind` runs the daemon-facing tests against the built dind image
|
||||||
- Write the fewest, fastest tests covering the behavior, extending an existing one where possible. Prefer unit tests where logic is testable in isolation
|
- Write the fewest, fastest tests covering the behavior, extending an existing one where possible. Prefer unit tests where logic is testable in isolation
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ GOVULNCHECK_PACKAGE ?= golang.org/x/vuln/cmd/[email protected] # renovate: data
|
|||||||
|
|
||||||
GOTEST_FLAGS ?= -race -timeout 20m -parallel 8
|
GOTEST_FLAGS ?= -race -timeout 20m -parallel 8
|
||||||
|
|
||||||
|
CROSS_TARGETS ?= darwin/arm64 freebsd/amd64 linux/arm netbsd/amd64 openbsd/amd64 solaris/amd64 # one per platform file set, linux/arm for 32-bit syscall fields
|
||||||
|
|
||||||
STATIC ?=
|
STATIC ?=
|
||||||
EXTLDFLAGS ?=
|
EXTLDFLAGS ?=
|
||||||
ifneq ($(STATIC),)
|
ifneq ($(STATIC),)
|
||||||
@@ -100,6 +102,12 @@ deps-tools: ## install tool dependencies
|
|||||||
.PHONY: checks
|
.PHONY: checks
|
||||||
checks: tidy-check fmt-check security-check ## run the non-lint source checks
|
checks: tidy-check fmt-check security-check ## run the non-lint source checks
|
||||||
|
|
||||||
|
.PHONY: cross-check
|
||||||
|
cross-check: $(addprefix cross-check/,$(CROSS_TARGETS)) ## check that code and tests compile on every supported platform
|
||||||
|
|
||||||
|
cross-check/%:
|
||||||
|
GOOS=$(word 1,$(subst /, ,$*)) GOARCH=$(word 2,$(subst /, ,$*)) CGO_ENABLED=0 $(GO) vet -gcflags='all=-N -l' ./...
|
||||||
|
|
||||||
.PHONY: lint
|
.PHONY: lint
|
||||||
lint: lint-go lint-go-windows ## lint everything
|
lint: lint-go lint-go-windows ## lint everything
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
// Copyright 2022 The nektos/act Authors. All rights reserved.
|
// Copyright 2022 The nektos/act Authors. All rights reserved.
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows || netbsd || freebsd))
|
||||||
|
|
||||||
// This file is based on https://github.com/docker/cli/blob/4a63305d74332de5ceba7fcbccbc3cbb7412f5ba/cli/command/container/opts_test.go with:
|
// This file is based on https://github.com/docker/cli/blob/4a63305d74332de5ceba7fcbccbc3cbb7412f5ba/cli/command/container/opts_test.go with:
|
||||||
// * appended with license information
|
// * appended with license information
|
||||||
// * added tests for the locally changed parseDevice, validateDevice and invalidParameter
|
// * added tests for the locally changed parseDevice, validateDevice and invalidParameter
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows || netbsd || freebsd))
|
||||||
|
|
||||||
package container
|
package container
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
// Copyright 2020 The nektos/act Authors. All rights reserved.
|
// Copyright 2020 The nektos/act Authors. All rights reserved.
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows || netbsd || freebsd))
|
||||||
|
|
||||||
package container
|
package container
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows || netbsd || freebsd))
|
||||||
|
|
||||||
package container
|
package container
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows || netbsd || freebsd))
|
||||||
|
|
||||||
package container
|
package container
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
// Copyright 2020 The nektos/act Authors. All rights reserved.
|
// Copyright 2020 The nektos/act Authors. All rights reserved.
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows || netbsd || freebsd))
|
||||||
|
|
||||||
package container
|
package container
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
// Copyright 2020 The nektos/act Authors. All rights reserved.
|
// Copyright 2020 The nektos/act Authors. All rights reserved.
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows || netbsd || freebsd))
|
||||||
|
|
||||||
package container
|
package container
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -16,8 +16,13 @@ import (
|
|||||||
"gitea.com/gitea/runner/act/common"
|
"gitea.com/gitea/runner/act/common"
|
||||||
|
|
||||||
"github.com/moby/moby/api/types/system"
|
"github.com/moby/moby/api/types/system"
|
||||||
|
"github.com/moby/moby/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func GetDockerClient(context.Context) (client.APIClient, error) {
|
||||||
|
return nil, errors.ErrUnsupported
|
||||||
|
}
|
||||||
|
|
||||||
func IsolatedCacheContainer(context.Context, netip.Addr, string) (string, error) {
|
func IsolatedCacheContainer(context.Context, netip.Addr, string) (string, error) {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
@@ -25,13 +30,13 @@ func IsolatedCacheContainer(context.Context, netip.Addr, string) (string, error)
|
|||||||
// ImageExistsLocally returns a boolean indicating if an image with the
|
// ImageExistsLocally returns a boolean indicating if an image with the
|
||||||
// requested name, tag and architecture exists in the local docker image store
|
// requested name, tag and architecture exists in the local docker image store
|
||||||
func ImageExistsLocally(ctx context.Context, imageName, platform string) (bool, error) {
|
func ImageExistsLocally(ctx context.Context, imageName, platform string) (bool, error) {
|
||||||
return false, errors.New("Unsupported Operation")
|
return false, errors.ErrUnsupported
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveImage removes image from local store, the function is used to run different
|
// RemoveImage removes image from local store, the function is used to run different
|
||||||
// container image architectures
|
// container image architectures
|
||||||
func RemoveImage(ctx context.Context, imageName string, force, pruneChildren bool) (bool, error) {
|
func RemoveImage(ctx context.Context, imageName string, force, pruneChildren bool) (bool, error) {
|
||||||
return false, errors.New("Unsupported Operation")
|
return false, errors.ErrUnsupported
|
||||||
}
|
}
|
||||||
|
|
||||||
func RemoveDockerJobResources(_ context.Context, _ string) error {
|
func RemoveDockerJobResources(_ context.Context, _ string) error {
|
||||||
@@ -43,20 +48,20 @@ func NewDockerProxy(_ context.Context, _ string) *DockerProxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func StartDockerProxy(daemonSocket, dir, job string) (*DockerProxy, error) {
|
func StartDockerProxy(daemonSocket, dir, job string) (*DockerProxy, error) {
|
||||||
return nil, errors.New("Unsupported Operation")
|
return nil, errors.ErrUnsupported
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDockerBuildExecutor function to create a run executor for the container
|
// NewDockerBuildExecutor function to create a run executor for the container
|
||||||
func NewDockerBuildExecutor(input NewDockerBuildExecutorInput) common.Executor {
|
func NewDockerBuildExecutor(input NewDockerBuildExecutorInput) common.Executor {
|
||||||
return func(ctx context.Context) error {
|
return func(ctx context.Context) error {
|
||||||
return errors.New("Unsupported Operation")
|
return errors.ErrUnsupported
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDockerPullExecutor function to create a run executor for the container
|
// NewDockerPullExecutor function to create a run executor for the container
|
||||||
func NewDockerPullExecutor(input NewDockerPullExecutorInput) common.Executor {
|
func NewDockerPullExecutor(input NewDockerPullExecutorInput) common.Executor {
|
||||||
return func(ctx context.Context) error {
|
return func(ctx context.Context) error {
|
||||||
return errors.New("Unsupported Operation")
|
return errors.ErrUnsupported
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows || netbsd || freebsd))
|
||||||
|
|
||||||
package container
|
package container
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
//go:build openbsd
|
||||||
|
|
||||||
|
package disk
|
||||||
|
|
||||||
|
import "golang.org/x/sys/unix"
|
||||||
|
|
||||||
|
// FreeBytes reports the space available to an unprivileged user on the volume holding path.
|
||||||
|
func FreeBytes(path string) (uint64, error) {
|
||||||
|
var stat unix.Statfs_t
|
||||||
|
if err := unix.Statfs(path, &stat); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return availableBytes(stat.F_bavail, stat.F_bsize), nil
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
//go:build !aix && !darwin && !dragonfly && !freebsd && !linux && !netbsd && !openbsd && !solaris && !windows
|
//go:build !unix && !windows
|
||||||
|
|
||||||
package disk
|
package disk
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
//go:build aix || darwin || dragonfly || freebsd || linux
|
||||||
|
|
||||||
|
package disk
|
||||||
|
|
||||||
|
import "golang.org/x/sys/unix"
|
||||||
|
|
||||||
|
// FreeBytes reports the space available to an unprivileged user on the volume holding path.
|
||||||
|
func FreeBytes(path string) (uint64, error) {
|
||||||
|
var stat unix.Statfs_t
|
||||||
|
if err := unix.Statfs(path, &stat); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return availableBytes(stat.Bavail, stat.Bsize), nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
//go:build netbsd || solaris
|
||||||
|
|
||||||
|
package disk
|
||||||
|
|
||||||
|
import "golang.org/x/sys/unix"
|
||||||
|
|
||||||
|
// FreeBytes reports the space available to an unprivileged user on the volume holding path.
|
||||||
|
func FreeBytes(path string) (uint64, error) {
|
||||||
|
var stat unix.Statvfs_t
|
||||||
|
if err := unix.Statvfs(path, &stat); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
// statvfs(2) counts blocks in f_frsize units, f_bsize is the preferred I/O size and differs on ZFS
|
||||||
|
return availableBytes(stat.Bavail, stat.Frsize), nil
|
||||||
|
}
|
||||||
@@ -1,17 +1,10 @@
|
|||||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
|
//go:build unix
|
||||||
|
|
||||||
package disk
|
package disk
|
||||||
|
|
||||||
import "golang.org/x/sys/unix"
|
func availableBytes[Count, Size ~int32 | ~int64 | ~uint32 | ~uint64](count Count, size Size) uint64 {
|
||||||
|
return uint64(max(count, 0)) * uint64(size) // signed BSD counts go negative once root fills the reserved blocks
|
||||||
// FreeBytes reports the space available to an unprivileged user on the volume holding path.
|
|
||||||
func FreeBytes(path string) (uint64, error) {
|
|
||||||
var stat unix.Statfs_t
|
|
||||||
if err := unix.Statfs(path, &stat); err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return uint64(stat.Bavail) * uint64(stat.Bsize), nil //nolint:unconvert // Bavail/Bsize signedness differs by platform
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
//go:build unix
|
||||||
|
|
||||||
|
package disk
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestFreeBytes(t *testing.T) {
|
||||||
|
free, err := FreeBytes(t.TempDir())
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Positive(t, free)
|
||||||
|
|
||||||
|
assert.Equal(t, uint64(1536), availableBytes(int64(3), uint32(512)))
|
||||||
|
assert.Zero(t, availableBytes(int64(-3), uint32(512)))
|
||||||
|
}
|
||||||
Reference in new issue
Block a user