mirror of
https://gitea.com/gitea/runner.git
synced 2026-11-05 14:55:44 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af2b3f6df5 | ||
|
|
785313cc21 | ||
|
|
41f1e08bec | ||
|
|
4158e05dae | ||
|
|
e356c2ed85 | ||
|
|
ed940db4f0 | ||
|
|
755af87095 | ||
|
|
b9aa47d1a5 | ||
|
|
0d84ec6dab | ||
|
|
b769a9765f | ||
|
|
9c4c66e70f | ||
|
|
42858c61df |
No files matched your search
@@ -44,8 +44,6 @@ linters:
|
|||||||
- $all
|
- $all
|
||||||
- "!**/act/common/logging/**"
|
- "!**/act/common/logging/**"
|
||||||
deny:
|
deny:
|
||||||
- pkg: github.com/sirupsen/logrus
|
|
||||||
desc: log through gitea.com/gitea/runner/act/common/logging
|
|
||||||
- pkg: log/slog
|
- pkg: log/slog
|
||||||
desc: log through gitea.com/gitea/runner/act/common/logging
|
desc: log through gitea.com/gitea/runner/act/common/logging
|
||||||
nolintlint:
|
nolintlint:
|
||||||
|
|||||||
+6
-6
@@ -33,18 +33,18 @@ depending on the prefix:
|
|||||||
|
|
||||||
## Logging
|
## Logging
|
||||||
|
|
||||||
Log through `act/common/logging`; the linter rejects importing `log/slog` or logrus elsewhere.
|
Log through `act/common/logging`; the linter rejects importing `log/slog` elsewhere.
|
||||||
A job's logger comes from `common.Logger(ctx)`; code with no job uses the package functions
|
A job's logger comes from `common.Logger(ctx)`; code with no job uses the package functions
|
||||||
(`logging.Infof`, `logging.With`). Both take printf-style messages, and `With("key", value)` adds
|
(`logging.Infof`, `logging.With`). Both take printf-style messages, and `With("key", value)` adds
|
||||||
fields.
|
fields.
|
||||||
|
|
||||||
- The process-wide logger masks the secrets of every live task, the job logger masks its own.
|
- The process-wide logger masks the secrets of every live task, the job logger masks its own.
|
||||||
Going around either leaks them.
|
Going around either leaks them.
|
||||||
- Libraries that log through logrus's or slog's global logger are forwarded to the process-wide
|
- The job logger's output can reach the job log workflow authors see, the process-wide logger's
|
||||||
one, so they follow its level and masking too.
|
stays on the runner host, so keep operator-only detail (host paths, internal addresses) off the
|
||||||
- That forwarding only works while logrus's global logger is left as `logging` configures it. A
|
job logger.
|
||||||
dependency that calls `logrus.SetOutput` or `SetLevel` breaks it, so check
|
- Libraries that log through slog's global logger are forwarded to the process-wide one, so they
|
||||||
`logging.LogrusBridgeIntact()` when adding or upgrading one.
|
follow its level and masking too. Avoid dependencies that log through logrus, nothing forwards it.
|
||||||
- Tests read what was logged with `logtest.NewLogger()`, or `logtest.SetDefault(t)` for the
|
- Tests read what was logged with `logtest.NewLogger()`, or `logtest.SetDefault(t)` for the
|
||||||
package functions.
|
package functions.
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -1,7 +1,7 @@
|
|||||||
### BUILDER STAGE
|
### BUILDER STAGE
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
FROM golang:1.27-alpine3.23 AS builder
|
FROM golang:1.27-alpine AS builder
|
||||||
|
|
||||||
# Do not remove `git` here, it is required for getting runner version when executing `make build`
|
# Do not remove `git` here, it is required for getting runner version when executing `make build`
|
||||||
RUN apk add --no-cache make git
|
RUN apk add --no-cache make git
|
||||||
@@ -17,7 +17,7 @@ RUN make clean && make build
|
|||||||
### DIND VARIANT
|
### DIND VARIANT
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
FROM docker:29.7.2-dind AS dind
|
FROM docker:29.9.1-dind AS dind
|
||||||
|
|
||||||
ARG VERSION=dev
|
ARG VERSION=dev
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ ENTRYPOINT ["s6-svscan","/etc/s6"]
|
|||||||
### DIND-ROOTLESS VARIANT
|
### DIND-ROOTLESS VARIANT
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
FROM docker:29.7.2-dind-rootless AS dind-rootless
|
FROM docker:29.9.1-dind-rootless AS dind-rootless
|
||||||
|
|
||||||
ARG VERSION=dev
|
ARG VERSION=dev
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +1,14 @@
|
|||||||
DIST := dist
|
DIST := dist
|
||||||
EXECUTABLE := gitea-runner
|
EXECUTABLE := gitea-runner
|
||||||
DIST_DIRS := $(DIST)/binaries $(DIST)/release
|
|
||||||
GO ?= go
|
GO ?= go
|
||||||
SHASUM ?= shasum -a 256
|
|
||||||
HAS_GO = $(shell hash $(GO) > /dev/null 2>&1 && echo "GO" || echo "NOGO" )
|
HAS_GO = $(shell hash $(GO) > /dev/null 2>&1 && echo "GO" || echo "NOGO" )
|
||||||
XGO_PACKAGE ?= src.techknowlogick.com/[email protected] # renovate: datasource=go
|
|
||||||
XGO_VERSION := go-1.27.x
|
|
||||||
GXZ_PACKAGE ?= github.com/ulikunitz/xz/cmd/[email protected] # renovate: datasource=go
|
|
||||||
|
|
||||||
PODMAN_TEST_IMAGE ?= quay.io/containers/podman:v5.8.4-immutable@sha256:90405e3c6a86f33c5a6f8dbdfa8e02a98143a8ba4337b84bdaec5336d2ef008a # renovate: datasource=docker
|
PODMAN_TEST_IMAGE ?= quay.io/containers/podman:v5.8.9-immutable@sha256:87f42f37fa85b421664c30b8f5f9cfc23920057f5e5fcadf0b6f68d9edc6d415 # renovate: datasource=docker
|
||||||
E2E_JOB_IMAGE ?= docker.gitea.com/runner-images:ubuntu-latest@sha256:0e62e56b382ebf485bff1e51a05cbe27c708545a2e91425467fd31eb3e249521 # renovate: datasource=docker
|
E2E_JOB_IMAGE ?= docker.gitea.com/runner-images:ubuntu-latest@sha256:0e62e56b382ebf485bff1e51a05cbe27c708545a2e91425467fd31eb3e249521 # renovate: datasource=docker
|
||||||
SERVICE_IMAGE ?= nginx:1.31.4-alpine@sha256:db35bfc6b2951e7f8a72db5db120288c127ffaeeb4a6d4b95a26fead017d5913 # renovate: datasource=docker
|
SERVICE_IMAGE ?= nginx:1.31.7-alpine@sha256:892bb2152464f0c5d8972593a5f5afaf8054552580b699d95f8ff4af08c2d33d # renovate: datasource=docker
|
||||||
E2E_GITEA_IMAGE ?= gitea/gitea:main-nightly
|
E2E_GITEA_IMAGE ?= gitea/gitea:main-nightly
|
||||||
E2E_K3S_IMAGE ?= rancher/k3s:v1.36.4-k3s1@sha256:edad48e12bf81c3a09ac1c05c0c0ffaaa22145980b989d6fae84543a76b83657 # renovate: datasource=docker
|
E2E_K3S_IMAGE ?= rancher/k3s:v1.37.1-k3s1@sha256:ca7f37d993d82ef0dcdcfecb2e0e2618ea541dbaffc620c8cedebe01a82acd0d # renovate: datasource=docker
|
||||||
|
|
||||||
LINUX_ARCHS ?= linux/amd64,linux/arm64
|
|
||||||
DARWIN_ARCHS ?= darwin-12/amd64,darwin-12/arm64
|
|
||||||
WINDOWS_ARCHS ?= windows/amd64
|
|
||||||
GOFILES := $(shell find . -type f -name "*.go" -o -name "go.mod" ! -name "generated.*")
|
GOFILES := $(shell find . -type f -name "*.go" -o -name "go.mod" ! -name "generated.*")
|
||||||
|
|
||||||
DOCKER_IMAGE ?= gitea/runner
|
DOCKER_IMAGE ?= gitea/runner
|
||||||
@@ -38,9 +30,6 @@ endif
|
|||||||
ifeq ($(HAS_GO), GO)
|
ifeq ($(HAS_GO), GO)
|
||||||
GOPATH ?= $(shell $(GO) env GOPATH)
|
GOPATH ?= $(shell $(GO) env GOPATH)
|
||||||
export PATH := $(GOPATH)/bin:$(PATH)
|
export PATH := $(GOPATH)/bin:$(PATH)
|
||||||
|
|
||||||
CGO_EXTRA_CFLAGS := -DSQLITE_MAX_VARIABLE_NUMBER=32766
|
|
||||||
CGO_CFLAGS ?= $(shell $(GO) env CGO_CFLAGS) $(CGO_EXTRA_CFLAGS)
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(OS), Windows_NT)
|
ifeq ($(OS), Windows_NT)
|
||||||
@@ -108,8 +97,6 @@ fmt-check: ## check the Go code formatting
|
|||||||
.PHONY: deps-tools
|
.PHONY: deps-tools
|
||||||
deps-tools: ## install tool dependencies
|
deps-tools: ## install tool dependencies
|
||||||
$(GO) install $(GOLANGCI_LINT_PACKAGE) & \
|
$(GO) install $(GOLANGCI_LINT_PACKAGE) & \
|
||||||
$(GO) install $(GXZ_PACKAGE) & \
|
|
||||||
$(GO) install $(XGO_PACKAGE) & \
|
|
||||||
$(GO) install $(GOVULNCHECK_PACKAGE) & \
|
$(GO) install $(GOVULNCHECK_PACKAGE) & \
|
||||||
wait
|
wait
|
||||||
|
|
||||||
@@ -187,45 +174,6 @@ $(EXECUTABLE): $(GOFILES)
|
|||||||
deps-backend: ## install backend dependencies
|
deps-backend: ## install backend dependencies
|
||||||
$(GO) mod download
|
$(GO) mod download
|
||||||
|
|
||||||
.PHONY: release
|
|
||||||
release: release-windows release-linux release-darwin release-copy release-compress release-check ## build release artifacts
|
|
||||||
|
|
||||||
$(DIST_DIRS):
|
|
||||||
mkdir -p $(DIST_DIRS)
|
|
||||||
|
|
||||||
.PHONY: release-windows
|
|
||||||
release-windows: | $(DIST_DIRS)
|
|
||||||
CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) run $(XGO_PACKAGE) -go $(XGO_VERSION) -buildmode exe -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '-s -w -linkmode external -extldflags "-static" $(LDFLAGS)' -targets '$(WINDOWS_ARCHS)' -out $(EXECUTABLE)-$(VERSION) .
|
|
||||||
ifeq ($(CI),true)
|
|
||||||
cp -r /build/* $(DIST)/binaries/
|
|
||||||
endif
|
|
||||||
|
|
||||||
.PHONY: release-linux
|
|
||||||
release-linux: | $(DIST_DIRS)
|
|
||||||
CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) run $(XGO_PACKAGE) -go $(XGO_VERSION) -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '-s -w -linkmode external -extldflags "-static" $(LDFLAGS)' -targets '$(LINUX_ARCHS)' -out $(EXECUTABLE)-$(VERSION) .
|
|
||||||
ifeq ($(CI),true)
|
|
||||||
cp -r /build/* $(DIST)/binaries/
|
|
||||||
endif
|
|
||||||
|
|
||||||
.PHONY: release-darwin
|
|
||||||
release-darwin: | $(DIST_DIRS)
|
|
||||||
CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) run $(XGO_PACKAGE) -go $(XGO_VERSION) -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '-s -w $(LDFLAGS)' -targets '$(DARWIN_ARCHS)' -out $(EXECUTABLE)-$(VERSION) .
|
|
||||||
ifeq ($(CI),true)
|
|
||||||
cp -r /build/* $(DIST)/binaries/
|
|
||||||
endif
|
|
||||||
|
|
||||||
.PHONY: release-copy
|
|
||||||
release-copy: | $(DIST_DIRS)
|
|
||||||
cd $(DIST); for file in `find . -type f -name "*"`; do cp $${file} ./release/; done;
|
|
||||||
|
|
||||||
.PHONY: release-check
|
|
||||||
release-check: | $(DIST_DIRS)
|
|
||||||
cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "checksumming $${file}" && $(SHASUM) `echo $${file} | sed 's/^..//'` > $${file}.sha256; done;
|
|
||||||
|
|
||||||
.PHONY: release-compress
|
|
||||||
release-compress: | $(DIST_DIRS)
|
|
||||||
cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "compressing $${file}" && $(GO) run $(GXZ_PACKAGE) -k -9 $${file}; done;
|
|
||||||
|
|
||||||
.PHONY: docker
|
.PHONY: docker
|
||||||
docker: ## build the docker image
|
docker: ## build the docker image
|
||||||
if ! docker buildx version >/dev/null 2>&1; then \
|
if ! docker buildx version >/dev/null 2>&1; then \
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
On the runner:
|
On the runner:
|
||||||
|
|
||||||
- `git` 2.34.1 or newer on `PATH`, to download actions and reusable workflows.
|
- `git` 2.34.1 or newer on `PATH`, to clone reusable workflows, and actions whose host serves no archive of them.
|
||||||
- `docker` or `podman` with `podman.socket` enabled, for docker mode, Docker actions and `docker://` steps. To install Docker CE, follow the official [install instructions](https://docs.docker.com/engine/install/).
|
- `docker` or `podman` with `podman.socket` enabled, for docker mode, Docker actions and `docker://` steps. To install Docker CE, follow the official [install instructions](https://docs.docker.com/engine/install/).
|
||||||
|
|
||||||
Where steps run, in the job image or on the runner in host mode:
|
Where steps run, in the job image or on the runner in host mode:
|
||||||
@@ -242,7 +242,7 @@ A job's `services` are started before its steps run. When a service's image or i
|
|||||||
```yaml
|
```yaml
|
||||||
services:
|
services:
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:17
|
image: postgres:18
|
||||||
options: >-
|
options: >-
|
||||||
--health-cmd pg_isready
|
--health-cmd pg_isready
|
||||||
--health-interval 5s
|
--health-interval 5s
|
||||||
@@ -368,7 +368,7 @@ While the runner is idle it cleans up after earlier jobs:
|
|||||||
- when `container.bind_workdir` is enabled, stale task workspace directories older than `runner.workdir_cleanup_age` are removed (default: `24h`; set `0` to disable)
|
- when `container.bind_workdir` is enabled, stale task workspace directories older than `runner.workdir_cleanup_age` are removed (default: `24h`; set `0` to disable)
|
||||||
- only purely numeric subdirectories under `container.workdir_parent` are treated as task workspaces and may be removed
|
- only purely numeric subdirectories under `container.workdir_parent` are treated as task workspaces and may be removed
|
||||||
- cleanup assumes `container.workdir_parent` is not shared across multiple runners
|
- cleanup assumes `container.workdir_parent` is not shared across multiple runners
|
||||||
- on runners that use docker, per-job networks left behind by jobs the runner did not live to tear down are removed, identified by the `com.gitea.runner.uuid` label carrying this runner's uuid
|
- on runners that use docker, per-job networks and volumes left behind by jobs the runner did not live to tear down are removed once unused and 10 minutes old, identified by the `com.gitea.runner.uuid` label carrying this runner's uuid
|
||||||
- on runners with `kubernetes` labels, job pods with that label older than `runner.workdir_cleanup_age` are removed the same way, together with their Secrets
|
- on runners with `kubernetes` labels, job pods with that label older than `runner.workdir_cleanup_age` are removed the same way, together with their Secrets
|
||||||
- cleanup runs every `runner.idle_cleanup_interval` (default: `10m`; set `0` to disable), and setting either knob to `0` disables all of the above
|
- cleanup runs every `runner.idle_cleanup_interval` (default: `10m`; set `0` to disable), and setting either knob to `0` disables all of the above
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ import (
|
|||||||
"gitea.com/gitea/runner/act/common/logging"
|
"gitea.com/gitea/runner/act/common/logging"
|
||||||
"gitea.com/gitea/runner/internal/pkg/disk"
|
"gitea.com/gitea/runner/internal/pkg/disk"
|
||||||
|
|
||||||
"github.com/julienschmidt/httprouter"
|
|
||||||
"github.com/timshannon/bolthold"
|
"github.com/timshannon/bolthold"
|
||||||
"go.etcd.io/bbolt"
|
"go.etcd.io/bbolt"
|
||||||
)
|
)
|
||||||
@@ -80,7 +79,7 @@ type Handler struct {
|
|||||||
dir string
|
dir string
|
||||||
storage cacheStorage
|
storage cacheStorage
|
||||||
s3 *s3Storage
|
s3 *s3Storage
|
||||||
router *httprouter.Router
|
router *http.ServeMux
|
||||||
listener net.Listener
|
listener net.Listener
|
||||||
port int
|
port int
|
||||||
server *http.Server
|
server *http.Server
|
||||||
@@ -201,22 +200,22 @@ func StartHandler(opts Options) (*Handler, error) {
|
|||||||
}
|
}
|
||||||
h.secret = secret
|
h.secret = secret
|
||||||
|
|
||||||
router := httprouter.New()
|
router := http.NewServeMux()
|
||||||
router.GET(apiPath+"/cache", h.bearerAuth(h.find))
|
router.HandleFunc("GET "+apiPath+"/cache", h.bearerAuth(h.find))
|
||||||
router.POST(apiPath+"/caches", h.bearerAuth(h.reserve))
|
router.HandleFunc("POST "+apiPath+"/caches", h.bearerAuth(h.reserve))
|
||||||
router.PATCH(apiPath+"/caches/:id", h.bearerAuth(h.upload))
|
router.HandleFunc("PATCH "+apiPath+"/caches/{id}", h.bearerAuth(h.upload))
|
||||||
router.POST(apiPath+"/caches/:id", h.bearerAuth(h.commit))
|
router.HandleFunc("POST "+apiPath+"/caches/{id}", h.bearerAuth(h.commit))
|
||||||
router.POST(apiPath+"/clean", h.bearerAuth(h.clean))
|
router.HandleFunc("POST "+apiPath+"/clean", h.bearerAuth(h.clean))
|
||||||
// Artifact GET is signed via query-string HMAC because @actions/cache
|
// Artifact GET is signed via query-string HMAC because @actions/cache
|
||||||
// does not attach Authorization when downloading archiveLocation.
|
// does not attach Authorization when downloading archiveLocation.
|
||||||
router.GET(apiPath+"/artifacts/:id", h.signedAuth("", h.get))
|
router.HandleFunc("GET "+apiPath+"/artifacts/{id}", h.signedAuth("", h.get))
|
||||||
// Control-plane: a remote runner registers/revokes per-job tokens so the
|
// Control-plane: a remote runner registers/revokes per-job tokens so the
|
||||||
// cache API can authenticate them. Always wired so the routes exist; the
|
// cache API can authenticate them. Always wired so the routes exist; the
|
||||||
// handlers themselves 401 when internalSecret is unset.
|
// handlers themselves 401 when internalSecret is unset.
|
||||||
router.POST(internalPath+"/register", h.internalAuth(h.internalRegister))
|
router.HandleFunc("POST "+internalPath+"/register", h.internalAuth(h.internalRegister))
|
||||||
router.POST(internalPath+"/revoke", h.internalAuth(h.internalRevoke))
|
router.HandleFunc("POST "+internalPath+"/revoke", h.internalAuth(h.internalRevoke))
|
||||||
h.registerV2Routes(router)
|
h.registerV2Routes(router)
|
||||||
router.NotFound = http.HandlerFunc(h.forwardOrNotFound)
|
router.HandleFunc(artifactServicePath, h.forwardOrNotFound)
|
||||||
|
|
||||||
h.router = router
|
h.router = router
|
||||||
|
|
||||||
@@ -498,7 +497,7 @@ func (h *Handler) importMetadata(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GET /_apis/artifactcache/cache
|
// GET /_apis/artifactcache/cache
|
||||||
func (h *Handler) find(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
func (h *Handler) find(w http.ResponseWriter, r *http.Request) {
|
||||||
cred := credFromContext(r.Context())
|
cred := credFromContext(r.Context())
|
||||||
keys := strings.Split(r.URL.Query().Get("keys"), ",")
|
keys := strings.Split(r.URL.Query().Get("keys"), ",")
|
||||||
version := r.URL.Query().Get("version")
|
version := r.URL.Query().Get("version")
|
||||||
@@ -549,7 +548,7 @@ func (h *Handler) lookupCache(db *bolthold.Store, repo string, keys []string, ve
|
|||||||
}
|
}
|
||||||
|
|
||||||
// POST /_apis/artifactcache/caches
|
// POST /_apis/artifactcache/caches
|
||||||
func (h *Handler) reserve(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
func (h *Handler) reserve(w http.ResponseWriter, r *http.Request) {
|
||||||
cred := credFromContext(r.Context())
|
cred := credFromContext(r.Context())
|
||||||
api := &Request{}
|
api := &Request{}
|
||||||
if err := json.UnmarshalRead(r.Body, api); err != nil {
|
if err := json.UnmarshalRead(r.Body, api); err != nil {
|
||||||
@@ -581,9 +580,9 @@ func (h *Handler) reserve(w http.ResponseWriter, r *http.Request, _ httprouter.P
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PATCH /_apis/artifactcache/caches/:id
|
// PATCH /_apis/artifactcache/caches/:id
|
||||||
func (h *Handler) upload(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
|
func (h *Handler) upload(w http.ResponseWriter, r *http.Request) {
|
||||||
cred := credFromContext(r.Context())
|
cred := credFromContext(r.Context())
|
||||||
id, err := strconv.ParseInt(params.ByName("id"), 10, 64)
|
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.responseJSON(w, r, 400, err)
|
h.responseJSON(w, r, 400, err)
|
||||||
return
|
return
|
||||||
@@ -629,9 +628,9 @@ func (h *Handler) upload(w http.ResponseWriter, r *http.Request, params httprout
|
|||||||
}
|
}
|
||||||
|
|
||||||
// POST /_apis/artifactcache/caches/:id
|
// POST /_apis/artifactcache/caches/:id
|
||||||
func (h *Handler) commit(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
|
func (h *Handler) commit(w http.ResponseWriter, r *http.Request) {
|
||||||
cred := credFromContext(r.Context())
|
cred := credFromContext(r.Context())
|
||||||
id, err := strconv.ParseInt(params.ByName("id"), 10, 64)
|
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.responseJSON(w, r, 400, err)
|
h.responseJSON(w, r, 400, err)
|
||||||
return
|
return
|
||||||
@@ -716,8 +715,8 @@ func (h *Handler) commitCache(cache *Cache) error {
|
|||||||
// @actions/cache toolkit downloads archiveLocation without Authorization.
|
// @actions/cache toolkit downloads archiveLocation without Authorization.
|
||||||
// Repository scoping is already enforced at find() time; the signature binds
|
// Repository scoping is already enforced at find() time; the signature binds
|
||||||
// the URL to the specific cache ID and an expiry.
|
// the URL to the specific cache ID and an expiry.
|
||||||
func (h *Handler) get(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
|
func (h *Handler) get(w http.ResponseWriter, r *http.Request) {
|
||||||
id, err := strconv.ParseInt(params.ByName("id"), 10, 64)
|
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.responseJSON(w, r, 400, err)
|
h.responseJSON(w, r, 400, err)
|
||||||
return
|
return
|
||||||
@@ -727,7 +726,7 @@ func (h *Handler) get(w http.ResponseWriter, r *http.Request, params httprouter.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// POST /_apis/artifactcache/clean
|
// POST /_apis/artifactcache/clean
|
||||||
func (h *Handler) clean(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
func (h *Handler) clean(w http.ResponseWriter, r *http.Request) {
|
||||||
// TODO: don't support force deleting cache entries
|
// TODO: don't support force deleting cache entries
|
||||||
// see: https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries
|
// see: https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries
|
||||||
|
|
||||||
@@ -737,8 +736,8 @@ func (h *Handler) clean(w http.ResponseWriter, r *http.Request, _ httprouter.Par
|
|||||||
// bearerAuth resolves ACTIONS_RUNTIME_TOKEN against the set of currently
|
// bearerAuth resolves ACTIONS_RUNTIME_TOKEN against the set of currently
|
||||||
// registered jobs. A match attaches the job's JobCredential to the request
|
// registered jobs. A match attaches the job's JobCredential to the request
|
||||||
// context; a miss returns 401 before the handler body runs.
|
// context; a miss returns 401 before the handler body runs.
|
||||||
func (h *Handler) bearerAuth(handler httprouter.Handle) httprouter.Handle {
|
func (h *Handler) bearerAuth(handler http.HandlerFunc) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
h.logger.Debugf("%s %s", r.Method, r.URL.Path)
|
h.logger.Debugf("%s %s", r.Method, r.URL.Path)
|
||||||
token := bearerToken(r)
|
token := bearerToken(r)
|
||||||
if token == "" {
|
if token == "" {
|
||||||
@@ -751,7 +750,7 @@ func (h *Handler) bearerAuth(handler httprouter.Handle) httprouter.Handle {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx := context.WithValue(r.Context(), credKey{}, cred)
|
ctx := context.WithValue(r.Context(), credKey{}, cred)
|
||||||
handler(w, r.WithContext(ctx), params)
|
handler(w, r.WithContext(ctx))
|
||||||
go h.gcCache()
|
go h.gcCache()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -766,10 +765,10 @@ func (h *Handler) unauthorized(w http.ResponseWriter, r *http.Request, err error
|
|||||||
|
|
||||||
// signedAuth authenticates a signed URL. purpose separates the flavours of URL the
|
// signedAuth authenticates a signed URL. purpose separates the flavours of URL the
|
||||||
// handler hands out, so one cannot be replayed as another; see computeSignature.
|
// handler hands out, so one cannot be replayed as another; see computeSignature.
|
||||||
func (h *Handler) signedAuth(purpose string, handler httprouter.Handle) httprouter.Handle {
|
func (h *Handler) signedAuth(purpose string, handler http.HandlerFunc) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
h.logger.Debugf("%s %s", r.Method, r.URL.Path)
|
h.logger.Debugf("%s %s", r.Method, r.URL.Path)
|
||||||
id, err := strconv.ParseInt(params.ByName("id"), 10, 64)
|
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.responseJSON(w, r, 400, err)
|
h.responseJSON(w, r, 400, err)
|
||||||
return
|
return
|
||||||
@@ -794,7 +793,7 @@ func (h *Handler) signedAuth(purpose string, handler httprouter.Handle) httprout
|
|||||||
h.responseJSON(w, r, http.StatusUnauthorized, errors.New("bad signature"))
|
h.responseJSON(w, r, http.StatusUnauthorized, errors.New("bad signature"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
handler(w, r, params)
|
handler(w, r)
|
||||||
go h.gcCache()
|
go h.gcCache()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -803,8 +802,8 @@ func (h *Handler) signedAuth(purpose string, handler httprouter.Handle) httprout
|
|||||||
// constant-time-equal the configured internalSecret. If the secret is empty,
|
// constant-time-equal the configured internalSecret. If the secret is empty,
|
||||||
// the control-plane is disabled and every request gets 404 — which matches
|
// the control-plane is disabled and every request gets 404 — which matches
|
||||||
// the upstream nektos/act behavior of "the route does not exist".
|
// the upstream nektos/act behavior of "the route does not exist".
|
||||||
func (h *Handler) internalAuth(handler httprouter.Handle) httprouter.Handle {
|
func (h *Handler) internalAuth(handler http.HandlerFunc) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
if h.internalSecret == "" {
|
if h.internalSecret == "" {
|
||||||
http.NotFound(w, r)
|
http.NotFound(w, r)
|
||||||
return
|
return
|
||||||
@@ -814,7 +813,7 @@ func (h *Handler) internalAuth(handler httprouter.Handle) httprouter.Handle {
|
|||||||
h.responseJSON(w, r, http.StatusUnauthorized, errors.New("internal: bad secret"))
|
h.responseJSON(w, r, http.StatusUnauthorized, errors.New("internal: bad secret"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
handler(w, r, params)
|
handler(w, r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -837,7 +836,7 @@ func (h *Handler) ResultsURL(cred JobCredential) string {
|
|||||||
return h.baseURL(cred)
|
return h.baseURL(cred)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) internalRegister(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
func (h *Handler) internalRegister(w http.ResponseWriter, r *http.Request) {
|
||||||
var body internalRegisterBody
|
var body internalRegisterBody
|
||||||
if err := json.UnmarshalRead(r.Body, &body); err != nil {
|
if err := json.UnmarshalRead(r.Body, &body); err != nil {
|
||||||
h.responseJSON(w, r, http.StatusBadRequest, err)
|
h.responseJSON(w, r, http.StatusBadRequest, err)
|
||||||
@@ -852,7 +851,7 @@ func (h *Handler) internalRegister(w http.ResponseWriter, r *http.Request, _ htt
|
|||||||
}
|
}
|
||||||
|
|
||||||
// POST /_internal/revoke
|
// POST /_internal/revoke
|
||||||
func (h *Handler) internalRevoke(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
func (h *Handler) internalRevoke(w http.ResponseWriter, r *http.Request) {
|
||||||
var body internalRevokeBody
|
var body internalRevokeBody
|
||||||
if err := json.UnmarshalRead(r.Body, &body); err != nil {
|
if err := json.UnmarshalRead(r.Body, &body); err != nil {
|
||||||
h.responseJSON(w, r, http.StatusBadRequest, err)
|
h.responseJSON(w, r, http.StatusBadRequest, err)
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/julienschmidt/httprouter"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// The cache service v2 API. A client on this version talks twirp to
|
// The cache service v2 API. A client on this version talks twirp to
|
||||||
@@ -44,16 +42,16 @@ const (
|
|||||||
twirpUnauthenticated = "unauthenticated"
|
twirpUnauthenticated = "unauthenticated"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *Handler) registerV2Routes(router *httprouter.Router) {
|
func (h *Handler) registerV2Routes(router *http.ServeMux) {
|
||||||
router.POST(cacheServiceV2Path+"/CreateCacheEntry", h.bearerAuth(h.v2CreateCacheEntry))
|
router.HandleFunc("POST "+cacheServiceV2Path+"/CreateCacheEntry", h.bearerAuth(h.v2CreateCacheEntry))
|
||||||
router.POST(cacheServiceV2Path+"/FinalizeCacheEntryUpload", h.bearerAuth(h.v2FinalizeCacheEntryUpload))
|
router.HandleFunc("POST "+cacheServiceV2Path+"/FinalizeCacheEntryUpload", h.bearerAuth(h.v2FinalizeCacheEntryUpload))
|
||||||
router.POST(cacheServiceV2Path+"/GetCacheEntryDownloadURL", h.bearerAuth(h.v2GetCacheEntryDownloadURL))
|
router.HandleFunc("POST "+cacheServiceV2Path+"/GetCacheEntryDownloadURL", h.bearerAuth(h.v2GetCacheEntryDownloadURL))
|
||||||
router.PUT(blobPath+"/:id", h.signedAuth(blobUploadPurpose, h.v2UploadBlob))
|
router.HandleFunc("PUT "+blobPath+"/{id}", h.signedAuth(blobUploadPurpose, h.v2UploadBlob))
|
||||||
}
|
}
|
||||||
|
|
||||||
// An entry that already exists is reported as not ok, which is how the client learns to skip
|
// An entry that already exists is reported as not ok, which is how the client learns to skip
|
||||||
// the upload.
|
// the upload.
|
||||||
func (h *Handler) v2CreateCacheEntry(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
func (h *Handler) v2CreateCacheEntry(w http.ResponseWriter, r *http.Request) {
|
||||||
cred := credFromContext(r.Context())
|
cred := credFromContext(r.Context())
|
||||||
req, err := decodeTwirpRequest[v2CreateRequest](r)
|
req, err := decodeTwirpRequest[v2CreateRequest](r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -123,7 +121,7 @@ func (h *Handler) v2CreateCacheEntry(w http.ResponseWriter, r *http.Request, _ h
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) v2FinalizeCacheEntryUpload(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
func (h *Handler) v2FinalizeCacheEntryUpload(w http.ResponseWriter, r *http.Request) {
|
||||||
cred := credFromContext(r.Context())
|
cred := credFromContext(r.Context())
|
||||||
req, err := decodeTwirpRequest[v2FinalizeRequest](r)
|
req, err := decodeTwirpRequest[v2FinalizeRequest](r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -172,7 +170,7 @@ func (h *Handler) v2FinalizeCacheEntryUpload(w http.ResponseWriter, r *http.Requ
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) v2GetCacheEntryDownloadURL(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
func (h *Handler) v2GetCacheEntryDownloadURL(w http.ResponseWriter, r *http.Request) {
|
||||||
cred := credFromContext(r.Context())
|
cred := credFromContext(r.Context())
|
||||||
req, err := decodeTwirpRequest[v2DownloadRequest](r)
|
req, err := decodeTwirpRequest[v2DownloadRequest](r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -207,8 +205,8 @@ func (h *Handler) v2GetCacheEntryDownloadURL(w http.ResponseWriter, r *http.Requ
|
|||||||
// The archive arrives over the subset of the Azure blob API the toolkit uses: a small
|
// The archive arrives over the subset of the Azure blob API the toolkit uses: a small
|
||||||
// cache is a single PUT, a large one is staged as blocks that a final block list puts
|
// cache is a single PUT, a large one is staged as blocks that a final block list puts
|
||||||
// in order.
|
// in order.
|
||||||
func (h *Handler) v2UploadBlob(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
|
func (h *Handler) v2UploadBlob(w http.ResponseWriter, r *http.Request) {
|
||||||
id, err := strconv.ParseUint(params.ByName("id"), 10, 64)
|
id, err := strconv.ParseUint(r.PathValue("id"), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.responseJSON(w, r, http.StatusBadRequest, err)
|
h.responseJSON(w, r, http.StatusBadRequest, err)
|
||||||
return
|
return
|
||||||
|
|||||||
+14
-21
@@ -19,8 +19,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitea.com/gitea/runner/act/common"
|
"gitea.com/gitea/runner/act/common"
|
||||||
|
|
||||||
"github.com/julienschmidt/httprouter"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type FileContainerResourceURL struct {
|
type FileContainerResourceURL struct {
|
||||||
@@ -67,24 +65,21 @@ func writeJSON(w http.ResponseWriter, value any) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func uploads(router *httprouter.Router, baseDir string) {
|
func uploads(router *http.ServeMux, baseDir string) {
|
||||||
router.POST("/_apis/pipelines/workflows/:runId/artifacts", func(w http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
router.HandleFunc("POST /_apis/pipelines/workflows/{runId}/artifacts", func(w http.ResponseWriter, req *http.Request) {
|
||||||
runID := params.ByName("runId")
|
|
||||||
|
|
||||||
writeJSON(w, FileContainerResourceURL{
|
writeJSON(w, FileContainerResourceURL{
|
||||||
FileContainerResourceURL: fmt.Sprintf("http://%s/upload/%s", req.Host, runID),
|
FileContainerResourceURL: fmt.Sprintf("http://%s/upload/%s", req.Host, req.PathValue("runId")),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
router.PUT("/upload/:runId", func(w http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
router.HandleFunc("PUT /upload/{runId}", func(w http.ResponseWriter, req *http.Request) {
|
||||||
itemPath := req.URL.Query().Get("itemPath")
|
itemPath := req.URL.Query().Get("itemPath")
|
||||||
runID := params.ByName("runId")
|
|
||||||
|
|
||||||
if req.Header.Get("Content-Encoding") == "gzip" {
|
if req.Header.Get("Content-Encoding") == "gzip" {
|
||||||
itemPath += gzipExtension
|
itemPath += gzipExtension
|
||||||
}
|
}
|
||||||
|
|
||||||
safeRunPath := safeResolve(baseDir, runID)
|
safeRunPath := safeResolve(baseDir, req.PathValue("runId"))
|
||||||
safePath := safeResolve(safeRunPath, itemPath)
|
safePath := safeResolve(safeRunPath, itemPath)
|
||||||
|
|
||||||
if err := os.MkdirAll(filepath.Dir(safePath), os.ModePerm); err != nil {
|
if err := os.MkdirAll(filepath.Dir(safePath), os.ModePerm); err != nil {
|
||||||
@@ -114,16 +109,16 @@ func uploads(router *httprouter.Router, baseDir string) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
router.PATCH("/_apis/pipelines/workflows/:runId/artifacts", func(w http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
router.HandleFunc("PATCH /_apis/pipelines/workflows/{runId}/artifacts", func(w http.ResponseWriter, _req *http.Request) {
|
||||||
writeJSON(w, ResponseMessage{
|
writeJSON(w, ResponseMessage{
|
||||||
Message: "success",
|
Message: "success",
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func downloads(router *httprouter.Router, baseDir string) {
|
func downloads(router *http.ServeMux, baseDir string) {
|
||||||
router.GET("/_apis/pipelines/workflows/:runId/artifacts", func(w http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
router.HandleFunc("GET /_apis/pipelines/workflows/{runId}/artifacts", func(w http.ResponseWriter, req *http.Request) {
|
||||||
runID := params.ByName("runId")
|
runID := req.PathValue("runId")
|
||||||
|
|
||||||
safePath := safeResolve(baseDir, runID)
|
safePath := safeResolve(baseDir, runID)
|
||||||
|
|
||||||
@@ -146,8 +141,8 @@ func downloads(router *httprouter.Router, baseDir string) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
router.GET("/download/:container", func(w http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
router.HandleFunc("GET /download/{container}", func(w http.ResponseWriter, req *http.Request) {
|
||||||
container := params.ByName("container")
|
container := req.PathValue("container")
|
||||||
itemPath := req.URL.Query().Get("itemPath")
|
itemPath := req.URL.Query().Get("itemPath")
|
||||||
safePath := safeResolve(baseDir, filepath.Join(container, itemPath))
|
safePath := safeResolve(baseDir, filepath.Join(container, itemPath))
|
||||||
|
|
||||||
@@ -183,10 +178,8 @@ func downloads(router *httprouter.Router, baseDir string) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
router.GET("/artifact/*path", func(w http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
router.HandleFunc("GET /artifact/{path...}", func(w http.ResponseWriter, req *http.Request) {
|
||||||
path := params.ByName("path")[1:]
|
safePath := safeResolve(baseDir, req.PathValue("path"))
|
||||||
|
|
||||||
safePath := safeResolve(baseDir, path)
|
|
||||||
|
|
||||||
file, err := os.Open(safePath)
|
file, err := os.Open(safePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -214,7 +207,7 @@ func Serve(ctx context.Context, artifactPath, addr, port string) context.CancelF
|
|||||||
return cancel
|
return cancel
|
||||||
}
|
}
|
||||||
|
|
||||||
router := httprouter.New()
|
router := http.NewServeMux()
|
||||||
|
|
||||||
logger.Debugf("Artifacts base path '%s'", artifactPath)
|
logger.Debugf("Artifacts base path '%s'", artifactPath)
|
||||||
uploads(router, artifactPath)
|
uploads(router, artifactPath)
|
||||||
|
|||||||
@@ -19,14 +19,13 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/julienschmidt/httprouter"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestArtifactFlow(t *testing.T) {
|
func TestArtifactFlow(t *testing.T) {
|
||||||
artifactPath := t.TempDir()
|
artifactPath := t.TempDir()
|
||||||
|
|
||||||
router := httprouter.New()
|
router := http.NewServeMux()
|
||||||
uploads(router, artifactPath)
|
uploads(router, artifactPath)
|
||||||
downloads(router, artifactPath)
|
downloads(router, artifactPath)
|
||||||
server := httptest.NewServer(router)
|
server := httptest.NewServer(router)
|
||||||
|
|||||||
@@ -0,0 +1,238 @@
|
|||||||
|
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
package git
|
||||||
|
|
||||||
|
import (
|
||||||
|
"archive/tar"
|
||||||
|
"bytes"
|
||||||
|
"compress/gzip"
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"io"
|
||||||
|
"math/rand/v2"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"gitea.com/gitea/runner/act/common"
|
||||||
|
)
|
||||||
|
|
||||||
|
var archiveRetryDelay = func(retryAfter string) time.Duration { // as actions/runner backs off
|
||||||
|
if seconds, err := strconv.Atoi(retryAfter); err == nil {
|
||||||
|
return min(max(time.Duration(seconds)*time.Second, 10*time.Second), 10*time.Minute)
|
||||||
|
}
|
||||||
|
return time.Duration(10+rand.IntN(21)) * time.Second
|
||||||
|
}
|
||||||
|
|
||||||
|
func FetchAction(ctx context.Context, input NewGitCloneExecutorInput) (string, string, error) { // input.Dir is one clone URL and ref's, holding a directory per commit
|
||||||
|
unlock, err := AcquireCloneLock(ctx, input.Dir)
|
||||||
|
if err != nil {
|
||||||
|
return "", "", err
|
||||||
|
}
|
||||||
|
defer unlock()
|
||||||
|
if err := os.MkdirAll(input.Dir, 0o755); err != nil {
|
||||||
|
return "", "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
tree := func(sha string) string { return filepath.Join(input.Dir, sha) }
|
||||||
|
record := filepath.Join(input.Dir, "ref")
|
||||||
|
data, _ := os.ReadFile(record)
|
||||||
|
sha, etag, _ := strings.Cut(string(data), "\n")
|
||||||
|
if !isFullObjectID(sha) || !exists(tree(sha)) {
|
||||||
|
sha, etag = "", ""
|
||||||
|
} else if input.OfflineMode || isFullObjectID(input.Ref) {
|
||||||
|
return tree(sha), sha, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
newSha, newEtag, err := downloadArchive(ctx, input, sha, etag)
|
||||||
|
if err != nil && ctx.Err() == nil {
|
||||||
|
common.Logger(ctx).Debugf("Cloning %s@%s: %v", input.URL, input.Ref, err)
|
||||||
|
newEtag = ""
|
||||||
|
newSha, err = exportClone(ctx, input)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return "", "", err
|
||||||
|
}
|
||||||
|
if newSha != sha || newEtag != etag {
|
||||||
|
if err := os.WriteFile(record, []byte(newSha+"\n"+newEtag), 0o600); err != nil {
|
||||||
|
return "", "", err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tree(newSha), newSha, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func downloadArchive(ctx context.Context, input NewGitCloneExecutorInput, sha, etag string) (string, string, error) {
|
||||||
|
rewritten, err := gitOutput(ctx, "", "ls-remote", "--get-url", input.URL)
|
||||||
|
if err != nil {
|
||||||
|
return "", "", err
|
||||||
|
}
|
||||||
|
source, err := url.Parse(rewritten)
|
||||||
|
if err != nil || source.Scheme != "http" && source.Scheme != "https" || hexRefRegex.MatchString(input.Ref) && !isFullObjectID(input.Ref) { // only git tells a short commit from a branch
|
||||||
|
return "", "", errors.New("no archive")
|
||||||
|
}
|
||||||
|
archive := source.JoinPath("archive", input.Ref+".tar.gz")
|
||||||
|
if source.Host == "github.com" {
|
||||||
|
source.Host = "codeload.github.com"
|
||||||
|
archive = source.JoinPath("tar.gz", input.Ref)
|
||||||
|
}
|
||||||
|
client := &http.Client{Transport: input.Transport, Timeout: 5 * time.Minute, CheckRedirect: func(request *http.Request, via []*http.Request) error {
|
||||||
|
if len(via) >= 10 {
|
||||||
|
return errors.New("stopped after 10 redirects")
|
||||||
|
}
|
||||||
|
if request.URL.Host != via[0].URL.Host || request.URL.Scheme != via[0].URL.Scheme { // the token stays on its origin
|
||||||
|
request.Header.Del("Authorization")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}}
|
||||||
|
for attempt := 1; ; attempt++ {
|
||||||
|
newSha, newEtag, retryAfter, err := downloadArchiveOnce(ctx, client, archive.String(), input.Token, sha, etag, input.Dir)
|
||||||
|
if retryAfter == 0 || attempt == 3 || ctx.Err() != nil {
|
||||||
|
return newSha, newEtag, err
|
||||||
|
}
|
||||||
|
common.Logger(ctx).Warnf("Failed to download action '%s'. Error: %v. Back off %s before retry.", archive.Redacted(), err, retryAfter)
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return "", "", ctx.Err()
|
||||||
|
case <-time.After(retryAfter):
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func downloadArchiveOnce(ctx context.Context, client *http.Client, archive, token, sha, etag, dir string) (string, string, time.Duration, error) {
|
||||||
|
request, err := http.NewRequestWithContext(ctx, http.MethodGet, archive, nil)
|
||||||
|
if err != nil {
|
||||||
|
return "", "", 0, err
|
||||||
|
}
|
||||||
|
if etag != "" {
|
||||||
|
request.Header.Set("If-None-Match", etag)
|
||||||
|
}
|
||||||
|
if token != "" {
|
||||||
|
request.SetBasicAuth("token", token)
|
||||||
|
}
|
||||||
|
response, err := client.Do(request)
|
||||||
|
if err != nil {
|
||||||
|
var opErr *net.OpError
|
||||||
|
if errors.As(err, &opErr) && opErr.Op == "dial" {
|
||||||
|
return "", "", 0, err
|
||||||
|
}
|
||||||
|
return "", "", archiveRetryDelay(""), err
|
||||||
|
}
|
||||||
|
defer response.Body.Close()
|
||||||
|
switch status := response.StatusCode; {
|
||||||
|
case status == http.StatusNotModified && sha != "":
|
||||||
|
return sha, etag, 0, nil
|
||||||
|
case status == http.StatusOK:
|
||||||
|
newEtag := response.Header.Get("ETag")
|
||||||
|
gz, err := gzip.NewReader(response.Body)
|
||||||
|
if err == nil {
|
||||||
|
sha, err = extractTree(gz, dir, !strings.HasSuffix(newEtag, `-false"`)) // Gitea's mark of an unprefixed archive
|
||||||
|
}
|
||||||
|
var netErr net.Error
|
||||||
|
if errors.Is(err, io.ErrUnexpectedEOF) || errors.As(err, &netErr) {
|
||||||
|
return "", "", archiveRetryDelay(""), err
|
||||||
|
}
|
||||||
|
return sha, newEtag, 0, err
|
||||||
|
case status == http.StatusRequestTimeout || status == http.StatusTooManyRequests || status >= http.StatusInternalServerError:
|
||||||
|
return "", "", archiveRetryDelay(response.Header.Get("Retry-After")), errors.New(response.Status)
|
||||||
|
default:
|
||||||
|
return "", "", 0, errors.New(response.Status)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func exportClone(ctx context.Context, input NewGitCloneExecutorInput) (string, error) {
|
||||||
|
clone := input
|
||||||
|
clone.Dir = filepath.Join(input.Dir, "git")
|
||||||
|
sha, _, err := resolveClone(ctx, clone)
|
||||||
|
if err != nil || exists(filepath.Join(input.Dir, sha)) {
|
||||||
|
return sha, err
|
||||||
|
}
|
||||||
|
archive, err := runGit(ctx, clone.Dir, nil, "archive", "--format=tar", sha)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
_, err = extractTree(bytes.NewReader(archive), input.Dir, false)
|
||||||
|
return sha, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func extractTree(archive io.Reader, dir string, strip bool) (string, error) { // into dir/<commit of the pax header>, strip dropping the directory wrapping the files
|
||||||
|
temp, err := os.MkdirTemp(dir, "tmp-")
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(temp)
|
||||||
|
root, err := os.OpenRoot(temp)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
defer root.Close()
|
||||||
|
|
||||||
|
sha := ""
|
||||||
|
reader := tar.NewReader(archive)
|
||||||
|
for {
|
||||||
|
header, err := reader.Next()
|
||||||
|
if errors.Is(err, io.EOF) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if header.Typeflag == tar.TypeXGlobalHeader {
|
||||||
|
if sha = header.PAXRecords["comment"]; isFullObjectID(sha) && exists(filepath.Join(dir, sha)) {
|
||||||
|
return sha, nil
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
name := header.Name
|
||||||
|
if strip {
|
||||||
|
_, name, _ = strings.Cut(name, "/")
|
||||||
|
}
|
||||||
|
if name = strings.TrimSuffix(name, "/"); name == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
switch header.Typeflag {
|
||||||
|
case tar.TypeDir:
|
||||||
|
err = root.MkdirAll(name, 0o755)
|
||||||
|
case tar.TypeReg:
|
||||||
|
err = writeTreeFile(root, name, header.Mode, reader)
|
||||||
|
case tar.TypeSymlink:
|
||||||
|
if err = root.Symlink(header.Linkname, name); err != nil && runtime.GOOS == "windows" {
|
||||||
|
err = writeTreeFile(root, name, 0, strings.NewReader(header.Linkname))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !isFullObjectID(sha) {
|
||||||
|
return "", errors.New("the archive names no commit")
|
||||||
|
}
|
||||||
|
if err := root.Close(); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return sha, os.Rename(temp, filepath.Join(dir, sha))
|
||||||
|
}
|
||||||
|
|
||||||
|
func writeTreeFile(root *os.Root, name string, mode int64, content io.Reader) error {
|
||||||
|
perm := os.FileMode(0o644)
|
||||||
|
if mode&0o111 != 0 {
|
||||||
|
perm = 0o755
|
||||||
|
}
|
||||||
|
file, err := root.OpenFile(name, os.O_CREATE|os.O_EXCL|os.O_WRONLY, perm)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = io.Copy(file, content)
|
||||||
|
return errors.Join(err, file.Close())
|
||||||
|
}
|
||||||
|
|
||||||
|
func exists(name string) bool {
|
||||||
|
_, err := os.Stat(name)
|
||||||
|
return err == nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,225 @@
|
|||||||
|
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
package git
|
||||||
|
|
||||||
|
import (
|
||||||
|
"archive/tar"
|
||||||
|
"bytes"
|
||||||
|
"encoding/base64"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"net/http/cgi"
|
||||||
|
"net/http/httptest"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestFetchAction(t *testing.T) {
|
||||||
|
original := archiveRetryDelay
|
||||||
|
archiveRetryDelay = func(_retryAfter string) time.Duration { return time.Nanosecond }
|
||||||
|
t.Cleanup(func() { archiveRetryDelay = original })
|
||||||
|
|
||||||
|
root := t.TempDir()
|
||||||
|
remote := filepath.Join(root, "org", "action")
|
||||||
|
require.NoError(t, gitCmd("init", "--initial-branch=main", remote))
|
||||||
|
require.NoError(t, os.WriteFile(filepath.Join(remote, "action.yml"), []byte("name: action\n"), 0o644))
|
||||||
|
require.NoError(t, os.WriteFile(filepath.Join(remote, "run.sh"), []byte("#!/bin/sh\n"), 0o755))
|
||||||
|
require.NoError(t, os.Symlink("action.yml", filepath.Join(remote, "link")))
|
||||||
|
require.NoError(t, gitCmd("-C", remote, "add", "."))
|
||||||
|
require.NoError(t, gitCmd("-C", remote, "commit", "-m", "initial"))
|
||||||
|
require.NoError(t, gitCmd("-C", remote, "tag", "v1"))
|
||||||
|
|
||||||
|
gitPath, err := exec.LookPath("git")
|
||||||
|
require.NoError(t, err)
|
||||||
|
backend := &cgi.Handler{Path: gitPath, Args: []string{"http-backend"}, Env: []string{"GIT_PROJECT_ROOT=" + root, "GIT_HTTP_EXPORT_ALL=1"}}
|
||||||
|
var mu sync.Mutex
|
||||||
|
var archiveRequests []http.Header
|
||||||
|
var mirror *httptest.Server
|
||||||
|
requests, archives, failures := 0, "", 0
|
||||||
|
handler := http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
|
||||||
|
mu.Lock()
|
||||||
|
defer mu.Unlock()
|
||||||
|
requests++
|
||||||
|
ref, ok := strings.CutPrefix(request.URL.Path, "/org/action/archive/")
|
||||||
|
if !ok {
|
||||||
|
backend.ServeHTTP(writer, request)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
archiveRequests = append(archiveRequests, request.Header.Clone())
|
||||||
|
switch {
|
||||||
|
case failures > 0:
|
||||||
|
failures--
|
||||||
|
writer.WriteHeader(http.StatusServiceUnavailable)
|
||||||
|
return
|
||||||
|
case archives == "none":
|
||||||
|
http.NotFound(writer, request)
|
||||||
|
return
|
||||||
|
case archives == "unreachable":
|
||||||
|
http.Redirect(writer, request, "http://127.0.0.1:1"+request.URL.Path, http.StatusFound)
|
||||||
|
return
|
||||||
|
case archives == "redirect" && request.Host != mirror.Listener.Addr().String():
|
||||||
|
http.Redirect(writer, request, mirror.URL+request.URL.Path, http.StatusFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
sha, _ := gitOutput(request.Context(), remote, "rev-parse", strings.TrimSuffix(ref, ".tar.gz"))
|
||||||
|
etag := fmt.Sprintf(`W/"%s-tar.gz-%t"`, sha, archives != "unprefixed")
|
||||||
|
if request.Header.Get("If-None-Match") == etag {
|
||||||
|
writer.WriteHeader(http.StatusNotModified)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
args := []string{"archive", "--format=tar.gz", sha}
|
||||||
|
if archives != "unprefixed" {
|
||||||
|
args = append(args, "--prefix=action/")
|
||||||
|
}
|
||||||
|
archive, _ := runGit(request.Context(), remote, nil, args...)
|
||||||
|
writer.Header().Set("ETag", etag)
|
||||||
|
_, _ = writer.Write(archive)
|
||||||
|
})
|
||||||
|
server := httptest.NewServer(handler)
|
||||||
|
mirror = httptest.NewServer(handler)
|
||||||
|
t.Cleanup(server.Close)
|
||||||
|
t.Cleanup(mirror.Close)
|
||||||
|
serve := func(mode string, failing int) {
|
||||||
|
mu.Lock()
|
||||||
|
defer mu.Unlock()
|
||||||
|
requests, archives, failures, archiveRequests = 0, mode, failing, nil
|
||||||
|
}
|
||||||
|
served := func() (int, []http.Header) {
|
||||||
|
mu.Lock()
|
||||||
|
defer mu.Unlock()
|
||||||
|
return requests, append([]http.Header(nil), archiveRequests...)
|
||||||
|
}
|
||||||
|
newInput := func(ref string) NewGitCloneExecutorInput {
|
||||||
|
return NewGitCloneExecutorInput{URL: server.URL + "/org/action", Ref: ref, Dir: t.TempDir(), Token: "secret"}
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Run("downloads, revalidates and follows a moved tag", func(t *testing.T) {
|
||||||
|
serve("prefixed", 0)
|
||||||
|
input := newInput("v1")
|
||||||
|
tree, sha, err := FetchAction(t.Context(), input)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, gitRevParse(t, remote, "v1"), sha)
|
||||||
|
assert.Equal(t, filepath.Join(input.Dir, sha), tree)
|
||||||
|
assert.NoDirExists(t, filepath.Join(tree, ".git"))
|
||||||
|
info, err := os.Stat(filepath.Join(tree, "run.sh"))
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, os.FileMode(0o755), info.Mode().Perm())
|
||||||
|
link, err := os.Readlink(filepath.Join(tree, "link"))
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, "action.yml", link)
|
||||||
|
|
||||||
|
again, _, err := FetchAction(t.Context(), input)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, tree, again)
|
||||||
|
|
||||||
|
require.NoError(t, gitCmd("-C", remote, "commit", "--allow-empty", "-m", "moved"))
|
||||||
|
require.NoError(t, gitCmd("-C", remote, "tag", "--force", "v1"))
|
||||||
|
moved, movedSha, err := FetchAction(t.Context(), input)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, gitRevParse(t, remote, "v1"), movedSha)
|
||||||
|
assert.NotEqual(t, tree, moved)
|
||||||
|
assert.FileExists(t, filepath.Join(tree, "action.yml"))
|
||||||
|
|
||||||
|
input.OfflineMode = true
|
||||||
|
_, offlineSha, err := FetchAction(t.Context(), input)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, movedSha, offlineSha)
|
||||||
|
|
||||||
|
requests, headers := served()
|
||||||
|
assert.Equal(t, 3, requests)
|
||||||
|
require.Len(t, headers, 3)
|
||||||
|
assert.Equal(t, "Basic "+base64.StdEncoding.EncodeToString([]byte("token:secret")), headers[0].Get("Authorization"))
|
||||||
|
assert.Empty(t, headers[0].Get("If-None-Match"))
|
||||||
|
assert.Equal(t, fmt.Sprintf(`W/"%s-tar.gz-true"`, sha), headers[1].Get("If-None-Match"))
|
||||||
|
assert.Equal(t, headers[1].Get("If-None-Match"), headers[2].Get("If-None-Match"))
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("downloads a pinned commit once and rejects a short one", func(t *testing.T) {
|
||||||
|
serve("prefixed", 0)
|
||||||
|
sha := gitRevParse(t, remote, "main")
|
||||||
|
input := newInput(sha)
|
||||||
|
for range 2 {
|
||||||
|
tree, got, err := FetchAction(t.Context(), input)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, sha, got)
|
||||||
|
assert.FileExists(t, filepath.Join(tree, "action.yml"))
|
||||||
|
}
|
||||||
|
_, _, err := FetchAction(t.Context(), newInput(sha[:7]))
|
||||||
|
require.ErrorIs(t, err, ErrShortRef)
|
||||||
|
_, headers := served()
|
||||||
|
assert.Len(t, headers, 1)
|
||||||
|
assert.NoDirExists(t, filepath.Join(input.Dir, "git"))
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("retries a failing download and drops the token on a redirect to another origin", func(t *testing.T) {
|
||||||
|
serve("redirect", 2)
|
||||||
|
input := newInput("main")
|
||||||
|
_, sha, err := FetchAction(t.Context(), input)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, gitRevParse(t, remote, "main"), sha)
|
||||||
|
assert.NoDirExists(t, filepath.Join(input.Dir, "git"))
|
||||||
|
_, headers := served()
|
||||||
|
require.Len(t, headers, 4)
|
||||||
|
assert.NotEmpty(t, headers[2].Get("Authorization"))
|
||||||
|
assert.Empty(t, headers[3].Get("Authorization"))
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("keeps an unprefixed archive whole, downloads where insteadOf points and exports a clone without an archive or from an unreachable host", func(t *testing.T) {
|
||||||
|
for _, mode := range []string{"unprefixed", "none", "unreachable"} {
|
||||||
|
serve(mode, 0)
|
||||||
|
tree, sha, err := FetchAction(t.Context(), newInput("main"))
|
||||||
|
require.NoError(t, err, mode)
|
||||||
|
assert.Equal(t, gitRevParse(t, remote, "main"), sha, mode)
|
||||||
|
assert.FileExists(t, filepath.Join(tree, "action.yml"), mode)
|
||||||
|
assert.NoDirExists(t, filepath.Join(tree, ".git"), mode)
|
||||||
|
_, headers := served()
|
||||||
|
assert.Len(t, headers, 1, mode)
|
||||||
|
}
|
||||||
|
|
||||||
|
serve("prefixed", 0)
|
||||||
|
config := filepath.Join(t.TempDir(), "gitconfig")
|
||||||
|
require.NoError(t, os.WriteFile(config, []byte("[url \""+server.URL+"/org/\"]\n\tinsteadOf = https://example.invalid/org/\n"), 0o644))
|
||||||
|
t.Setenv("GIT_CONFIG_GLOBAL", config)
|
||||||
|
input := newInput("main")
|
||||||
|
input.URL = "https://example.invalid/org/action"
|
||||||
|
_, sha, err := FetchAction(t.Context(), input)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, gitRevParse(t, remote, "main"), sha)
|
||||||
|
_, headers := served()
|
||||||
|
assert.Len(t, headers, 1)
|
||||||
|
assert.NoDirExists(t, filepath.Join(input.Dir, "git"))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestExtractTreeConfinesEntries(t *testing.T) {
|
||||||
|
outside := t.TempDir()
|
||||||
|
for name, entries := range map[string][]*tar.Header{
|
||||||
|
"parent path": {{Name: "../escape", Typeflag: tar.TypeReg}},
|
||||||
|
"through a symlink": {{Name: "out", Typeflag: tar.TypeSymlink, Linkname: outside}, {Name: "out/escape", Typeflag: tar.TypeReg}},
|
||||||
|
} {
|
||||||
|
t.Run(name, func(t *testing.T) {
|
||||||
|
var archive bytes.Buffer
|
||||||
|
writer := tar.NewWriter(&archive)
|
||||||
|
require.NoError(t, writer.WriteHeader(&tar.Header{Typeflag: tar.TypeXGlobalHeader, PAXRecords: map[string]string{"comment": strings.Repeat("a", 40)}}))
|
||||||
|
for _, entry := range entries {
|
||||||
|
require.NoError(t, writer.WriteHeader(entry))
|
||||||
|
}
|
||||||
|
require.NoError(t, writer.Close())
|
||||||
|
|
||||||
|
dir := t.TempDir()
|
||||||
|
_, err := extractTree(&archive, dir, false)
|
||||||
|
require.Error(t, err)
|
||||||
|
assert.NoFileExists(t, filepath.Join(dir, "escape"))
|
||||||
|
assert.NoFileExists(t, filepath.Join(outside, "escape"))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
+28
-26
@@ -10,6 +10,7 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@@ -178,13 +179,10 @@ type NewGitCloneExecutorInput struct {
|
|||||||
// 0 for full clone.
|
// 0 for full clone.
|
||||||
Depth int
|
Depth int
|
||||||
|
|
||||||
// Quiet drops the informational clone line to debug level, for callers that log their own
|
|
||||||
// download summary (the setup section's action report).
|
|
||||||
Quiet bool
|
|
||||||
|
|
||||||
// For Gitea
|
// For Gitea
|
||||||
InsecureSkipTLS bool
|
InsecureSkipTLS bool
|
||||||
ClientCertFile, ClientKeyFile string // PEM, absolute as git runs in other directories
|
ClientCertFile, ClientKeyFile string // PEM, absolute as git runs in other directories
|
||||||
|
Transport http.RoundTripper // for FetchAction's archive downloads, nil for http.DefaultTransport
|
||||||
}
|
}
|
||||||
|
|
||||||
// CloneIfRequired reports whether an existing local clone was reused.
|
// CloneIfRequired reports whether an existing local clone was reused.
|
||||||
@@ -221,11 +219,7 @@ func CloneIfRequired(ctx context.Context, input NewGitCloneExecutorInput, logger
|
|||||||
func NewGitCloneExecutor(input NewGitCloneExecutorInput) common.Executor {
|
func NewGitCloneExecutor(input NewGitCloneExecutorInput) common.Executor {
|
||||||
return func(ctx context.Context) error {
|
return func(ctx context.Context) error {
|
||||||
logger := common.Logger(ctx)
|
logger := common.Logger(ctx)
|
||||||
if input.Quiet {
|
logger.Infof("git clone '%s' # ref=%s", input.URL, input.Ref)
|
||||||
logger.Debugf("git clone '%s' # ref=%s", input.URL, input.Ref)
|
|
||||||
} else {
|
|
||||||
logger.Infof("git clone '%s' # ref=%s", input.URL, input.Ref)
|
|
||||||
}
|
|
||||||
logger.Debugf(" cloning %s to %s", input.URL, input.Dir)
|
logger.Debugf(" cloning %s to %s", input.URL, input.Dir)
|
||||||
unlock, err := AcquireCloneLock(ctx, input.Dir)
|
unlock, err := AcquireCloneLock(ctx, input.Dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -233,24 +227,10 @@ func NewGitCloneExecutor(input NewGitCloneExecutorInput) common.Executor {
|
|||||||
}
|
}
|
||||||
defer unlock()
|
defer unlock()
|
||||||
|
|
||||||
reused, err := CloneIfRequired(ctx, input, logger)
|
resolved, reused, err := resolveClone(ctx, input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
resolved, err := resolveRef(ctx, input.Dir, input.Ref)
|
|
||||||
if errors.Is(err, ErrShortRef) || (err != nil && input.OfflineMode) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if !input.OfflineMode && (err != nil || (reused && !isFullHash(input.Ref, resolved))) {
|
|
||||||
if err := fetch(ctx, input); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
resolved, err = resolveRef(ctx, input.Dir, input.Ref)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
logger.Errorf("Unable to resolve %s: %v", input.Ref, err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if _, err := runGit(ctx, input.Dir, nil, "checkout", "--force", "--detach", resolved); err != nil {
|
if _, err := runGit(ctx, input.Dir, nil, "checkout", "--force", "--detach", resolved); err != nil {
|
||||||
return fmt.Errorf("checkout %s: %w", resolved, err)
|
return fmt.Errorf("checkout %s: %w", resolved, err)
|
||||||
}
|
}
|
||||||
@@ -264,6 +244,28 @@ func NewGitCloneExecutor(input NewGitCloneExecutorInput) common.Executor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func resolveClone(ctx context.Context, input NewGitCloneExecutorInput) (string, bool, error) { // the caller holds input.Dir's lock
|
||||||
|
logger := common.Logger(ctx)
|
||||||
|
reused, err := CloneIfRequired(ctx, input, logger)
|
||||||
|
if err != nil {
|
||||||
|
return "", false, err
|
||||||
|
}
|
||||||
|
resolved, err := resolveRef(ctx, input.Dir, input.Ref)
|
||||||
|
if errors.Is(err, ErrShortRef) || (err != nil && input.OfflineMode) {
|
||||||
|
return "", false, err
|
||||||
|
}
|
||||||
|
if !input.OfflineMode && (err != nil || (reused && !isFullHash(input.Ref, resolved))) {
|
||||||
|
if err := fetch(ctx, input); err != nil {
|
||||||
|
return "", false, err
|
||||||
|
}
|
||||||
|
resolved, err = resolveRef(ctx, input.Dir, input.Ref)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
logger.Errorf("Unable to resolve %s: %v", input.Ref, err)
|
||||||
|
}
|
||||||
|
return resolved, reused, err
|
||||||
|
}
|
||||||
|
|
||||||
func clone(ctx context.Context, input NewGitCloneExecutorInput) error {
|
func clone(ctx context.Context, input NewGitCloneExecutorInput) error {
|
||||||
if input.Depth > 0 && isFullObjectID(input.Ref) {
|
if input.Depth > 0 && isFullObjectID(input.Ref) {
|
||||||
if err := shallowPinnedClone(ctx, input); err == nil {
|
if err := shallowPinnedClone(ctx, input); err == nil {
|
||||||
@@ -304,7 +306,7 @@ func shallowPinnedClone(ctx context.Context, input NewGitCloneExecutorInput) err
|
|||||||
}
|
}
|
||||||
|
|
||||||
func fetch(ctx context.Context, input NewGitCloneExecutorInput) error {
|
func fetch(ctx context.Context, input NewGitCloneExecutorInput) error {
|
||||||
args := []string{"fetch", "--force", "--prune"}
|
args := []string{"fetch", "--force", "--no-prune"}
|
||||||
if _, err := os.Stat(filepath.Join(input.Dir, ".git", "shallow")); err == nil {
|
if _, err := os.Stat(filepath.Join(input.Dir, ".git", "shallow")); err == nil {
|
||||||
args = append(args, "--depth", "1", "--no-tags")
|
args = append(args, "--depth", "1", "--no-tags")
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-41
@@ -21,7 +21,6 @@ import (
|
|||||||
"testing/synctest"
|
"testing/synctest"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitea.com/gitea/runner/act/common"
|
|
||||||
"gitea.com/gitea/runner/act/common/logging"
|
"gitea.com/gitea/runner/act/common/logging"
|
||||||
"gitea.com/gitea/runner/act/common/logging/logtest"
|
"gitea.com/gitea/runner/act/common/logging/logtest"
|
||||||
"gitea.com/gitea/runner/internal/pkg/lock"
|
"gitea.com/gitea/runner/internal/pkg/lock"
|
||||||
@@ -354,6 +353,8 @@ func TestGitCloneExecutorFollowsRemoteRefChanges(t *testing.T) {
|
|||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
clone := NewGitCloneExecutor(NewGitCloneExecutorInput{URL: remoteDir, Ref: "main", Dir: dir})
|
clone := NewGitCloneExecutor(NewGitCloneExecutorInput{URL: remoteDir, Ref: "main", Dir: dir})
|
||||||
require.NoError(t, clone(t.Context()))
|
require.NoError(t, clone(t.Context()))
|
||||||
|
require.NoError(t, gitCmd("-C", dir, "config", "fetch.prune", "true"))
|
||||||
|
require.NoError(t, clone(t.Context()))
|
||||||
|
|
||||||
require.NoError(t, gitCmd("-C", workDir, "reset", "--hard", "HEAD~1"))
|
require.NoError(t, gitCmd("-C", workDir, "reset", "--hard", "HEAD~1"))
|
||||||
require.NoError(t, gitCmd("-C", workDir, "commit", "--allow-empty", "-m", "feature-rewritten"))
|
require.NoError(t, gitCmd("-C", workDir, "commit", "--allow-empty", "-m", "feature-rewritten"))
|
||||||
@@ -361,11 +362,20 @@ func TestGitCloneExecutorFollowsRemoteRefChanges(t *testing.T) {
|
|||||||
require.NoError(t, clone(t.Context()), "a non-fast-forward ref must update")
|
require.NoError(t, clone(t.Context()), "a non-fast-forward ref must update")
|
||||||
assert.Equal(t, "feature-rewritten", gitHeadSubject(t, dir))
|
assert.Equal(t, "feature-rewritten", gitHeadSubject(t, dir))
|
||||||
|
|
||||||
tagClone := NewGitCloneExecutor(NewGitCloneExecutorInput{URL: remoteDir, Ref: "v9", Dir: t.TempDir()})
|
tagDir := t.TempDir()
|
||||||
|
tagClone := NewGitCloneExecutor(NewGitCloneExecutorInput{URL: remoteDir, Ref: "v9", Dir: tagDir})
|
||||||
require.Error(t, tagClone(t.Context()))
|
require.Error(t, tagClone(t.Context()))
|
||||||
require.NoError(t, gitCmd("-C", workDir, "tag", "v9"))
|
require.NoError(t, gitCmd("-C", workDir, "tag", "v9"))
|
||||||
require.NoError(t, gitCmd("-C", workDir, "push", "origin", "v9"))
|
require.NoError(t, gitCmd("-C", workDir, "push", "origin", "v9"))
|
||||||
require.NoError(t, tagClone(t.Context()), "a tag published after a failed lookup must be fetched")
|
require.NoError(t, tagClone(t.Context()), "a tag published after a failed lookup must be fetched")
|
||||||
|
|
||||||
|
require.NoError(t, gitCmd("-C", workDir, "commit", "--allow-empty", "-m", "tag-moved"))
|
||||||
|
require.NoError(t, gitCmd("-C", workDir, "tag", "--force", "v9"))
|
||||||
|
require.NoError(t, gitCmd("-C", workDir, "push", "--force", "origin", "v9"))
|
||||||
|
for range 2 {
|
||||||
|
require.NoError(t, tagClone(t.Context()), "a moved tag must update and stay current")
|
||||||
|
assert.Equal(t, "tag-moved", gitHeadSubject(t, tagDir))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGitCloneExecutorOfflineMode(t *testing.T) {
|
func TestGitCloneExecutorOfflineMode(t *testing.T) {
|
||||||
@@ -415,45 +425,6 @@ func TestGitCloneExecutorOfflineMode(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGitCloneExecutorQuietDemotesCloneLine(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
remoteDir := t.TempDir()
|
|
||||||
require.NoError(t, gitCmd("init", "--bare", "--initial-branch=main", remoteDir))
|
|
||||||
workDir := t.TempDir()
|
|
||||||
require.NoError(t, gitCmd("clone", remoteDir, workDir))
|
|
||||||
require.NoError(t, gitCmd("-C", workDir, "checkout", "-b", "main"))
|
|
||||||
require.NoError(t, gitCmd("-C", workDir, "commit", "--allow-empty", "-m", "initial"))
|
|
||||||
require.NoError(t, gitCmd("-C", workDir, "push", "-u", "origin", "main"))
|
|
||||||
|
|
||||||
// Quiet callers report the download themselves, so the clone line must not reach the job log.
|
|
||||||
for name, quiet := range map[string]bool{"quiet": true, "not quiet": false} {
|
|
||||||
t.Run(name, func(t *testing.T) {
|
|
||||||
hook := logtest.New()
|
|
||||||
logger := logging.New(logging.NewLevelHandler(hook, logging.LevelInfo))
|
|
||||||
ctx := common.WithLogger(t.Context(), logger.With("job", "j1"))
|
|
||||||
|
|
||||||
require.NoError(t, NewGitCloneExecutor(NewGitCloneExecutorInput{
|
|
||||||
URL: remoteDir,
|
|
||||||
Ref: "main",
|
|
||||||
Dir: t.TempDir(),
|
|
||||||
Quiet: quiet,
|
|
||||||
})(ctx))
|
|
||||||
|
|
||||||
var cloneLines int
|
|
||||||
for _, entry := range hook.AllRecords() {
|
|
||||||
if strings.HasPrefix(entry.Message, "git clone ") {
|
|
||||||
cloneLines++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if quiet {
|
|
||||||
assert.Zero(t, cloneLines)
|
|
||||||
} else {
|
|
||||||
assert.Equal(t, 1, cloneLines)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGitCloneExecutorShallow(t *testing.T) {
|
func TestGitCloneExecutorShallow(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
// Build a local "remote" with several commits on main plus a tag, so a full clone would pull noticeably more history than a shallow one.
|
// Build a local "remote" with several commits on main plus a tag, so a full clone would pull noticeably more history than a shallow one.
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// TextOptions describes how the process-wide Logger writes a record as text.
|
// TextOptions describes how the process-wide Logger writes a record as text.
|
||||||
@@ -41,11 +39,8 @@ func Default() *Logger { return std.Load() }
|
|||||||
// initial console Logger.
|
// initial console Logger.
|
||||||
func SetDefault(l *Logger) { std.Store(l) }
|
func SetDefault(l *Logger) { std.Store(l) }
|
||||||
|
|
||||||
// SetLevel sets the minimum level of the initial process-wide Logger and of what libraries log through logrus.
|
// SetLevel sets the minimum level of the initial process-wide Logger.
|
||||||
func SetLevel(level Level) {
|
func SetLevel(level Level) { stdState.level.Set(slog.Level(level)) }
|
||||||
stdState.level.Set(slog.Level(level))
|
|
||||||
logrus.SetLevel(toLogrusLevel(level))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetLevel returns the minimum level of the initial process-wide Logger.
|
// GetLevel returns the minimum level of the initial process-wide Logger.
|
||||||
func GetLevel() Level { return Level(stdState.level.Level()) }
|
func GetLevel() Level { return Level(stdState.level.Level()) }
|
||||||
@@ -72,7 +67,6 @@ func SetReportCaller(on bool) {
|
|||||||
stdState.mu.Lock()
|
stdState.mu.Lock()
|
||||||
defer stdState.mu.Unlock()
|
defer stdState.mu.Unlock()
|
||||||
stdState.reportCaller = on
|
stdState.reportCaller = on
|
||||||
logrus.SetReportCaller(on)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Enabled(level Level) bool { return Default().Enabled(level) }
|
func Enabled(level Level) bool { return Default().Enabled(level) }
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import (
|
|||||||
"gitea.com/gitea/runner/act/common/logging"
|
"gitea.com/gitea/runner/act/common/logging"
|
||||||
"gitea.com/gitea/runner/act/common/logging/logtest"
|
"gitea.com/gitea/runner/act/common/logging/logtest"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
@@ -132,43 +131,6 @@ func TestSlogHandler(t *testing.T) {
|
|||||||
assert.Contains(t, out, "error=boom")
|
assert.Contains(t, out, "error=boom")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLogrusBridge(t *testing.T) {
|
|
||||||
prevLevel, prevDefault := logging.GetLevel(), logging.Default()
|
|
||||||
t.Cleanup(func() {
|
|
||||||
logging.SetLevel(prevLevel)
|
|
||||||
logging.SetReportCaller(false)
|
|
||||||
logging.SetDefault(prevDefault)
|
|
||||||
})
|
|
||||||
logging.SetLevel(logging.LevelInfo)
|
|
||||||
assert.False(t, logrus.IsLevelEnabled(logrus.DebugLevel))
|
|
||||||
logging.SetLevel(logging.LevelTrace)
|
|
||||||
logging.SetReportCaller(true)
|
|
||||||
h := logtest.NewWithLevel(logging.LevelTrace)
|
|
||||||
logging.SetDefault(logging.New(h))
|
|
||||||
|
|
||||||
logrus.WithField("lib", "docker").Warnf("from a library %d", 1)
|
|
||||||
_, _, line, _ := runtime.Caller(0)
|
|
||||||
logrus.Debug("below")
|
|
||||||
logrus.Trace("lowest")
|
|
||||||
|
|
||||||
recs := h.AllRecords()
|
|
||||||
require.Len(t, recs, 3)
|
|
||||||
assert.Equal(t, "from a library 1", recs[0].Message)
|
|
||||||
assert.Equal(t, logging.LevelWarn, recs[0].Level)
|
|
||||||
v, _ := recs[0].Attr("lib")
|
|
||||||
assert.Equal(t, "docker", v)
|
|
||||||
assert.Equal(t, logging.LevelDebug, recs[1].Level)
|
|
||||||
f := frameOf(t, recs[1].PC)
|
|
||||||
assert.True(t, strings.HasSuffix(f.Function, "TestLogrusBridge"), f.Function)
|
|
||||||
assert.Equal(t, line+1, f.Line)
|
|
||||||
assert.Equal(t, logging.LevelTrace, recs[2].Level)
|
|
||||||
|
|
||||||
h = logtest.New() // logrus passes Debug, the Logger does not
|
|
||||||
logging.SetDefault(logging.New(h))
|
|
||||||
logrus.Debug("dropped")
|
|
||||||
assert.Empty(t, h.AllRecords())
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSlogBridge(t *testing.T) {
|
func TestSlogBridge(t *testing.T) {
|
||||||
h := logtest.SetDefault(t)
|
h := logtest.SetDefault(t)
|
||||||
slog.With("lib", "actionslib").Warn("from a library", "n", 1)
|
slog.With("lib", "actionslib").Warn("from a library", "n", 1)
|
||||||
@@ -185,19 +147,3 @@ func TestSlogBridge(t *testing.T) {
|
|||||||
assert.EqualValues(t, 1, n)
|
assert.EqualValues(t, 1, n)
|
||||||
assert.Equal(t, line-1, frameOf(t, recs[0].PC).Line)
|
assert.Equal(t, line-1, frameOf(t, recs[0].PC).Line)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLogrusBridgeIntact(t *testing.T) {
|
|
||||||
assert.True(t, logging.LogrusBridgeIntact())
|
|
||||||
|
|
||||||
prev := logrus.StandardLogger().Out
|
|
||||||
t.Cleanup(func() { logrus.SetOutput(prev) })
|
|
||||||
logrus.SetOutput(&strings.Builder{}) // what a dependency doing this would do
|
|
||||||
assert.False(t, logging.LogrusBridgeIntact())
|
|
||||||
logrus.SetOutput(prev)
|
|
||||||
assert.True(t, logging.LogrusBridgeIntact())
|
|
||||||
|
|
||||||
prevLevel := logrus.GetLevel()
|
|
||||||
t.Cleanup(func() { logrus.SetLevel(prevLevel) })
|
|
||||||
logrus.SetLevel(logrus.PanicLevel)
|
|
||||||
assert.False(t, logging.LogrusBridgeIntact())
|
|
||||||
}
|
|
||||||
@@ -1,102 +0,0 @@
|
|||||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
package logging
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"io"
|
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Libraries the runner depends on, such as docker/cli and moby/go-archive, log through
|
|
||||||
// logrus's global logger. Hand what they log to the process-wide Logger, so it follows the same
|
|
||||||
// level, format and secret masking as the rest of the output.
|
|
||||||
func init() {
|
|
||||||
logrus.SetOutput(io.Discard)
|
|
||||||
logrus.SetFormatter(discardFormatter{})
|
|
||||||
logrus.SetLevel(toLogrusLevel(GetLevel()))
|
|
||||||
logrus.AddHook(bridgeHook{})
|
|
||||||
}
|
|
||||||
|
|
||||||
type discardFormatter struct{}
|
|
||||||
|
|
||||||
func (discardFormatter) Format(*logrus.Entry) ([]byte, error) { return nil, nil }
|
|
||||||
|
|
||||||
type bridgeHook struct{}
|
|
||||||
|
|
||||||
func (bridgeHook) Levels() []logrus.Level { return logrus.AllLevels }
|
|
||||||
|
|
||||||
func (bridgeHook) Fire(e *logrus.Entry) error {
|
|
||||||
l := Default()
|
|
||||||
level := fromLogrusLevel(e.Level)
|
|
||||||
ctx := e.Context
|
|
||||||
if ctx == nil {
|
|
||||||
ctx = context.Background()
|
|
||||||
}
|
|
||||||
if !l.h.Enabled(ctx, level) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
attrs := make([]Attr, 0, len(e.Data))
|
|
||||||
for k, v := range e.Data {
|
|
||||||
attrs = append(attrs, Attr{Key: k, Value: v})
|
|
||||||
}
|
|
||||||
r := Record{Time: e.Time, Level: level, Message: e.Message, Attrs: attrs}
|
|
||||||
if e.Caller != nil {
|
|
||||||
r.PC = e.Caller.PC + 1 // Frame.PC is one below the return address Record.PC holds
|
|
||||||
}
|
|
||||||
return l.h.Handle(ctx, r)
|
|
||||||
}
|
|
||||||
|
|
||||||
func toLogrusLevel(l Level) logrus.Level {
|
|
||||||
switch {
|
|
||||||
case l <= LevelTrace:
|
|
||||||
return logrus.TraceLevel
|
|
||||||
case l <= LevelDebug:
|
|
||||||
return logrus.DebugLevel
|
|
||||||
case l <= LevelInfo:
|
|
||||||
return logrus.InfoLevel
|
|
||||||
case l <= LevelWarn:
|
|
||||||
return logrus.WarnLevel
|
|
||||||
default:
|
|
||||||
return logrus.ErrorLevel
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func fromLogrusLevel(l logrus.Level) Level {
|
|
||||||
switch l {
|
|
||||||
case logrus.TraceLevel:
|
|
||||||
return LevelTrace
|
|
||||||
case logrus.DebugLevel:
|
|
||||||
return LevelDebug
|
|
||||||
case logrus.InfoLevel:
|
|
||||||
return LevelInfo
|
|
||||||
case logrus.WarnLevel:
|
|
||||||
return LevelWarn
|
|
||||||
default:
|
|
||||||
return LevelError
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// LogrusBridgeIntact reports whether logrus's global logger is still set up as the bridge needs,
|
|
||||||
// discarding its own output and following the process-wide level. A dependency that calls
|
|
||||||
// logrus.SetOutput or SetLevel breaks that, and its lines then show up twice, or at the wrong level.
|
|
||||||
func LogrusBridgeIntact() bool {
|
|
||||||
std := logrus.StandardLogger()
|
|
||||||
if std.Out != io.Discard || std.GetLevel() != toLogrusLevel(GetLevel()) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
for _, level := range logrus.AllLevels {
|
|
||||||
found := false
|
|
||||||
for _, h := range std.Hooks[level] {
|
|
||||||
if _, ok := h.(bridgeHook); ok {
|
|
||||||
found = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !found {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
+244
-13
@@ -7,20 +7,33 @@
|
|||||||
package container
|
package container
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/base64"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/fs"
|
||||||
|
"maps"
|
||||||
|
"net"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"os/user"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"gitea.com/gitea/runner/act/common"
|
"gitea.com/gitea/runner/act/common"
|
||||||
|
|
||||||
"github.com/distribution/reference"
|
"github.com/distribution/reference"
|
||||||
"github.com/docker/cli/cli/config"
|
|
||||||
"github.com/moby/moby/api/types/registry"
|
"github.com/moby/moby/api/types/registry"
|
||||||
)
|
)
|
||||||
|
|
||||||
func LoadDockerAuthConfig(ctx context.Context, image string) (registry.AuthConfig, error) {
|
func LoadDockerAuthConfig(ctx context.Context, image string) (registry.AuthConfig, error) {
|
||||||
logger := common.Logger(ctx)
|
logger := common.Logger(ctx)
|
||||||
// config.LoadDefaultConfigFile panics on nil io.Writer when the config
|
cfg, err := loadDockerConfig(ctx)
|
||||||
// file is malformed; use config.Load to route errors through the logger.
|
|
||||||
cfg, err := config.Load(config.Dir())
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warnf("Could not load docker config: %v", err)
|
logger.Warnf("Could not load docker config: %v", err)
|
||||||
return registry.AuthConfig{}, err
|
return registry.AuthConfig{}, err
|
||||||
@@ -34,32 +47,27 @@ func LoadDockerAuthConfig(ctx context.Context, image string) (registry.AuthConfi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
authConfig, err := cfg.GetAuthConfig(registryKey)
|
authConfig, err := cfg.authConfig(ctx, registryKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warnf("Could not get auth config from docker config: %v", err)
|
logger.Warnf("Could not get auth config from docker config: %v", err)
|
||||||
return registry.AuthConfig{}, err
|
return registry.AuthConfig{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return registry.AuthConfig(authConfig), nil
|
return authConfig, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadDockerAuthConfigs(ctx context.Context) map[string]registry.AuthConfig {
|
func LoadDockerAuthConfigs(ctx context.Context) map[string]registry.AuthConfig {
|
||||||
logger := common.Logger(ctx)
|
logger := common.Logger(ctx)
|
||||||
cfg, err := config.Load(config.Dir())
|
cfg, err := loadDockerConfig(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warnf("Could not load docker config: %v", err)
|
logger.Warnf("Could not load docker config: %v", err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
creds, err := cfg.GetAllCredentials()
|
authConfigs, err := cfg.allAuthConfigs(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warnf("Could not get docker auth configs: %v", err)
|
logger.Warnf("Could not get docker auth configs: %v", err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
authConfigs := make(map[string]registry.AuthConfig, len(creds))
|
|
||||||
for k, v := range creds {
|
|
||||||
authConfigs[k] = registry.AuthConfig(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
return authConfigs
|
return authConfigs
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,3 +77,226 @@ func registryAuthConfigKey(domainName string) string {
|
|||||||
}
|
}
|
||||||
return domainName
|
return domainName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type dockerConfig struct {
|
||||||
|
Auths map[string]registry.AuthConfig `json:"auths"`
|
||||||
|
CredsStore string `json:"credsStore"`
|
||||||
|
CredHelpers map[string]string `json:"credHelpers"`
|
||||||
|
env map[string]registry.AuthConfig // from DOCKER_AUTH_CONFIG, nil when unset or unusable
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadDockerConfig(ctx context.Context) (*dockerConfig, error) {
|
||||||
|
dir := os.Getenv("DOCKER_CONFIG")
|
||||||
|
if dir == "" {
|
||||||
|
home, _ := os.UserHomeDir()
|
||||||
|
if home == "" && runtime.GOOS != "windows" {
|
||||||
|
if current, err := user.Current(); err == nil {
|
||||||
|
home = current.HomeDir
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dir = filepath.Join(home, ".docker")
|
||||||
|
}
|
||||||
|
cfg := &dockerConfig{}
|
||||||
|
filename := filepath.Join(dir, "config.json")
|
||||||
|
file, err := os.Open(filename)
|
||||||
|
if err != nil && !errors.Is(err, fs.ErrNotExist) {
|
||||||
|
return nil, fmt.Errorf("loading config file: %w", err)
|
||||||
|
}
|
||||||
|
if err == nil {
|
||||||
|
defer file.Close()
|
||||||
|
if err := json.NewDecoder(file).Decode(cfg); err != nil && !errors.Is(err, io.EOF) {
|
||||||
|
return nil, fmt.Errorf("parsing config file (%s): %w", filename, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for address, auth := range cfg.Auths {
|
||||||
|
if auth.Auth != "" {
|
||||||
|
if auth.Username, auth.Password, err = decodeAuth(auth.Auth); err != nil {
|
||||||
|
return nil, fmt.Errorf("parsing config file (%s): %w", filename, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
auth.Auth, auth.ServerAddress = "", address
|
||||||
|
cfg.Auths[address] = auth
|
||||||
|
}
|
||||||
|
if value := os.Getenv("DOCKER_AUTH_CONFIG"); value != "" {
|
||||||
|
if cfg.env, err = parseDockerAuthConfigEnv(value); err != nil {
|
||||||
|
common.Logger(ctx).Warnf("Failed to create credential store from DOCKER_AUTH_CONFIG: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cfg, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodeAuth(auth string) (string, string, error) {
|
||||||
|
decoded, err := base64.StdEncoding.DecodeString(auth)
|
||||||
|
if err != nil {
|
||||||
|
return "", "", err
|
||||||
|
}
|
||||||
|
username, password, ok := strings.Cut(string(decoded), ":")
|
||||||
|
if !ok || username == "" {
|
||||||
|
return "", "", errors.New("invalid auth configuration file")
|
||||||
|
}
|
||||||
|
return username, strings.Trim(password, "\x00"), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseDockerAuthConfigEnv(value string) (map[string]registry.AuthConfig, error) {
|
||||||
|
var env struct {
|
||||||
|
Auths map[string]struct {
|
||||||
|
Auth string `json:"auth"`
|
||||||
|
} `json:"auths"`
|
||||||
|
}
|
||||||
|
decoder := json.NewDecoder(strings.NewReader(value))
|
||||||
|
decoder.DisallowUnknownFields()
|
||||||
|
if err := decoder.Decode(&env); err != nil && !errors.Is(err, io.EOF) {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if decoder.More() {
|
||||||
|
return nil, errors.New("DOCKER_AUTH_CONFIG does not support more than one JSON object")
|
||||||
|
}
|
||||||
|
auths := make(map[string]registry.AuthConfig, len(env.Auths))
|
||||||
|
for address, entry := range env.Auths {
|
||||||
|
if entry.Auth == "" {
|
||||||
|
return nil, fmt.Errorf("DOCKER_AUTH_CONFIG environment variable is missing key `auth` for %s", address)
|
||||||
|
}
|
||||||
|
username, password, err := decodeAuth(entry.Auth)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
auths[address] = registry.AuthConfig{Username: username, Password: password, ServerAddress: address}
|
||||||
|
}
|
||||||
|
return auths, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *dockerConfig) authConfig(ctx context.Context, key string) (registry.AuthConfig, error) {
|
||||||
|
if auth, ok := c.env[key]; ok {
|
||||||
|
return auth, nil
|
||||||
|
}
|
||||||
|
helper := c.CredsStore
|
||||||
|
if named, ok := c.CredHelpers[key]; ok {
|
||||||
|
helper = named
|
||||||
|
}
|
||||||
|
if helper == "" {
|
||||||
|
return c.fileAuth(key), nil
|
||||||
|
}
|
||||||
|
auth := c.fileAuth(key)
|
||||||
|
stored, err := helperCredentials(ctx, helper, key)
|
||||||
|
if err != nil {
|
||||||
|
return auth, err
|
||||||
|
}
|
||||||
|
auth.Username, auth.Password, auth.IdentityToken, auth.ServerAddress = stored.Username, stored.Password, stored.IdentityToken, stored.ServerAddress
|
||||||
|
return auth, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *dockerConfig) fileAuth(key string) registry.AuthConfig {
|
||||||
|
if auth, ok := c.Auths[key]; ok {
|
||||||
|
return auth
|
||||||
|
}
|
||||||
|
for address, auth := range c.Auths {
|
||||||
|
if registryHostname(address) == key {
|
||||||
|
return auth
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return registry.AuthConfig{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *dockerConfig) allAuthConfigs(ctx context.Context) (map[string]registry.AuthConfig, error) {
|
||||||
|
var auths map[string]registry.AuthConfig
|
||||||
|
if c.CredsStore == "" {
|
||||||
|
auths = maps.Clone(c.Auths)
|
||||||
|
} else {
|
||||||
|
var err error
|
||||||
|
if auths, err = c.helperAuthConfigs(ctx); err != nil {
|
||||||
|
if c.env == nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
common.Logger(ctx).Warnf("Could not list the credentials of docker-credential-%s: %v", c.CredsStore, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if auths == nil {
|
||||||
|
auths = map[string]registry.AuthConfig{}
|
||||||
|
}
|
||||||
|
maps.Copy(auths, c.env)
|
||||||
|
if c.CredsStore == "" {
|
||||||
|
c.Auths = maps.Clone(auths) // docker's file store holds the DOCKER_AUTH_CONFIG entries after listing, and credHelpers set to "" read it
|
||||||
|
}
|
||||||
|
for address := range c.CredHelpers {
|
||||||
|
auth, err := c.authConfig(ctx, registryAuthConfigKey(address))
|
||||||
|
if err != nil {
|
||||||
|
common.Logger(ctx).Warnf("Failed to get credentials for registry: %s: %v", address, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
auths[address] = auth
|
||||||
|
}
|
||||||
|
return auths, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *dockerConfig) helperAuthConfigs(ctx context.Context) (map[string]registry.AuthConfig, error) {
|
||||||
|
out, err := runCredentialHelper(ctx, c.CredsStore, "list", "unused")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error listing credentials - err: %w, out: `%s`", err, strings.TrimSpace(string(out)))
|
||||||
|
}
|
||||||
|
var addresses map[string]string
|
||||||
|
if err := json.NewDecoder(bytes.NewReader(out)).Decode(&addresses); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
auths := make(map[string]registry.AuthConfig, len(addresses))
|
||||||
|
for address := range addresses {
|
||||||
|
stored, err := helperCredentials(ctx, c.CredsStore, address)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
auth := c.Auths[address]
|
||||||
|
auth.Username, auth.Password, auth.IdentityToken = stored.Username, stored.Password, stored.IdentityToken
|
||||||
|
if auth.ServerAddress == "" {
|
||||||
|
auth.ServerAddress = stored.ServerAddress
|
||||||
|
}
|
||||||
|
auths[address] = auth
|
||||||
|
}
|
||||||
|
return auths, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func helperCredentials(ctx context.Context, helper, address string) (registry.AuthConfig, error) {
|
||||||
|
out, err := runCredentialHelper(ctx, helper, "get", address)
|
||||||
|
if err != nil {
|
||||||
|
if strings.TrimSpace(string(out)) == "credentials not found in native keychain" {
|
||||||
|
return registry.AuthConfig{}, nil
|
||||||
|
}
|
||||||
|
return registry.AuthConfig{}, fmt.Errorf("error getting credentials - err: %w, out: `%s`", err, strings.TrimSpace(string(out)))
|
||||||
|
}
|
||||||
|
var stored struct{ Username, Secret string }
|
||||||
|
if err := json.NewDecoder(bytes.NewReader(out)).Decode(&stored); err != nil {
|
||||||
|
return registry.AuthConfig{}, err
|
||||||
|
}
|
||||||
|
if stored.Username == "<token>" {
|
||||||
|
return registry.AuthConfig{IdentityToken: stored.Secret, ServerAddress: address}, nil
|
||||||
|
}
|
||||||
|
return registry.AuthConfig{Username: stored.Username, Password: stored.Secret, ServerAddress: address}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func runCredentialHelper(ctx context.Context, helper, action, input string) ([]byte, error) {
|
||||||
|
cmd := exec.CommandContext(ctx, "docker-credential-"+helper, action)
|
||||||
|
cmd.Stdin = strings.NewReader(input)
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
return cmd.Output()
|
||||||
|
}
|
||||||
|
|
||||||
|
func registryHostname(address string) string {
|
||||||
|
if _, rest, ok := strings.Cut(address, "://"); ok {
|
||||||
|
if u, err := url.Parse(address); err == nil && u.Hostname() != "" {
|
||||||
|
if u.Port() == "" {
|
||||||
|
return u.Hostname()
|
||||||
|
}
|
||||||
|
return net.JoinHostPort(u.Hostname(), u.Port())
|
||||||
|
}
|
||||||
|
if host, _, _ := strings.Cut(rest, "/"); host != "" {
|
||||||
|
if colon := strings.LastIndex(host, ":"); strings.Count(host, ":") > 1 && !strings.HasPrefix(host, "[") && isDigits(host[colon+1:]) {
|
||||||
|
return net.JoinHostPort(host[:colon], host[colon+1:])
|
||||||
|
}
|
||||||
|
return host
|
||||||
|
}
|
||||||
|
}
|
||||||
|
host, _, _ := strings.Cut(address, "/")
|
||||||
|
return host
|
||||||
|
}
|
||||||
|
|
||||||
|
func isDigits(s string) bool {
|
||||||
|
return s != "" && strings.Trim(s, "0123456789") == ""
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
//go:build !windows && !(WITHOUT_DOCKER || !(linux || darwin || netbsd))
|
||||||
|
|
||||||
|
package container
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/base64"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/moby/moby/api/types/registry"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestLoadDockerAuthConfigFromFileHelpersAndEnv(t *testing.T) {
|
||||||
|
dir := t.TempDir()
|
||||||
|
require.NoError(t, os.WriteFile(filepath.Join(dir, "docker-credential-fake"), []byte("#!/bin/sh\nread -r server\n[ \"$1\" = get ] && [ \"$server\" = helper.example.com ] && exec echo '{\"Username\":\"helped\",\"Secret\":\"pw\"}'\necho 'credentials not found in native keychain'\nexit 1\n"), 0o755))
|
||||||
|
t.Setenv("PATH", dir+string(os.PathListSeparator)+os.Getenv("PATH"))
|
||||||
|
auth := func(credentials string) string { return base64.StdEncoding.EncodeToString([]byte(credentials)) }
|
||||||
|
require.NoError(t, os.WriteFile(filepath.Join(dir, "config.json"), []byte(`{"auths": {"https://legacy.example.com/v1/": {"auth": "`+auth("legacy:pw")+`"}}, "credHelpers": {"helper.example.com": "fake", "gone.example.com": "fake", "env-legacy.example.com": ""}}`), 0o600))
|
||||||
|
t.Setenv("DOCKER_CONFIG", dir)
|
||||||
|
t.Setenv("DOCKER_AUTH_CONFIG", `{"auths": {"env.example.com": {"auth": "`+auth("env:pw")+`"}, "https://env-legacy.example.com/v1/": {"auth": "`+auth("env:pw")+`"}}}`)
|
||||||
|
|
||||||
|
for image, want := range map[string]registry.AuthConfig{
|
||||||
|
"legacy.example.com/app": {Username: "legacy", Password: "pw", ServerAddress: "https://legacy.example.com/v1/"},
|
||||||
|
"helper.example.com/app": {Username: "helped", Password: "pw", ServerAddress: "helper.example.com"},
|
||||||
|
"env.example.com/app": {Username: "env", Password: "pw", ServerAddress: "env.example.com"},
|
||||||
|
"gone.example.com/app": {},
|
||||||
|
} {
|
||||||
|
got, err := LoadDockerAuthConfig(t.Context(), image)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, want, got, image)
|
||||||
|
}
|
||||||
|
assert.Equal(t, map[string]registry.AuthConfig{
|
||||||
|
"https://legacy.example.com/v1/": {Username: "legacy", Password: "pw", ServerAddress: "https://legacy.example.com/v1/"},
|
||||||
|
"helper.example.com": {Username: "helped", Password: "pw", ServerAddress: "helper.example.com"},
|
||||||
|
"gone.example.com": {},
|
||||||
|
"env.example.com": {Username: "env", Password: "pw", ServerAddress: "env.example.com"},
|
||||||
|
"https://env-legacy.example.com/v1/": {Username: "env", Password: "pw", ServerAddress: "https://env-legacy.example.com/v1/"},
|
||||||
|
"env-legacy.example.com": {Username: "env", Password: "pw", ServerAddress: "https://env-legacy.example.com/v1/"},
|
||||||
|
}, LoadDockerAuthConfigs(t.Context()))
|
||||||
|
}
|
||||||
@@ -7,15 +7,18 @@
|
|||||||
package container
|
package container
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"archive/tar"
|
||||||
"context"
|
"context"
|
||||||
"io"
|
"io"
|
||||||
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"gitea.com/gitea/runner/act/common"
|
"gitea.com/gitea/runner/act/common"
|
||||||
|
|
||||||
"github.com/moby/go-archive"
|
|
||||||
"github.com/moby/go-archive/compression"
|
|
||||||
"github.com/moby/moby/client"
|
"github.com/moby/moby/client"
|
||||||
"github.com/moby/patternmatcher"
|
"github.com/moby/patternmatcher"
|
||||||
"github.com/moby/patternmatcher/ignorefile"
|
"github.com/moby/patternmatcher/ignorefile"
|
||||||
@@ -115,14 +118,140 @@ func createBuildContext(ctx context.Context, contextDir, relDockerfile string) (
|
|||||||
includes = append(includes, ".dockerignore", relDockerfile)
|
includes = append(includes, ".dockerignore", relDockerfile)
|
||||||
}
|
}
|
||||||
|
|
||||||
buildCtx, err := archive.TarWithOptions(contextDir, &archive.TarOptions{
|
pm, err := patternmatcher.New(excludes)
|
||||||
Compression: compression.None,
|
|
||||||
ExcludePatterns: excludes,
|
|
||||||
IncludeFiles: includes,
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
reader, writer := io.Pipe()
|
||||||
return buildCtx, nil
|
go func() { writer.CloseWithError(writeBuildContext(ctx, writer, contextDir, includes, pm)) }()
|
||||||
|
return reader, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func writeBuildContext(ctx context.Context, w io.Writer, contextDir string, includes []string, pm *patternmatcher.PatternMatcher) error {
|
||||||
|
tw := tar.NewWriter(w)
|
||||||
|
seen := map[string]bool{}
|
||||||
|
hardlinks := map[uint64]string{}
|
||||||
|
buffer := make([]byte, 32*1024)
|
||||||
|
for _, include := range includes {
|
||||||
|
include = filepath.FromSlash(include)
|
||||||
|
var parents []parentMatch
|
||||||
|
root := strings.TrimSuffix(contextDir, string(filepath.Separator)) + string(filepath.Separator) + include // unlike filepath.Join, follows a symlinked context dir as docker build does
|
||||||
|
err := filepath.WalkDir(root, func(file string, entry fs.DirEntry, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return leaveOut(ctx, file, err)
|
||||||
|
}
|
||||||
|
rel, err := filepath.Rel(contextDir, file)
|
||||||
|
if err != nil || rel == "." {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if rel != include {
|
||||||
|
for len(parents) > 0 && !strings.HasPrefix(rel, parents[len(parents)-1].dir+string(filepath.Separator)) {
|
||||||
|
parents = parents[:len(parents)-1]
|
||||||
|
}
|
||||||
|
var parentInfo patternmatcher.MatchInfo
|
||||||
|
if len(parents) > 0 {
|
||||||
|
parentInfo = parents[len(parents)-1].info
|
||||||
|
}
|
||||||
|
skip, info, err := pm.MatchesUsingParentResults(rel, parentInfo)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if entry.IsDir() {
|
||||||
|
parents = append(parents, parentMatch{rel, info})
|
||||||
|
}
|
||||||
|
if skip {
|
||||||
|
if entry.IsDir() && !hasExceptionWithin(pm, rel) {
|
||||||
|
return filepath.SkipDir
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if seen[rel] {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
seen[rel] = true
|
||||||
|
return addBuildContextEntry(ctx, tw, file, rel, entry, hardlinks, buffer)
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tw.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
type parentMatch struct {
|
||||||
|
dir string
|
||||||
|
info patternmatcher.MatchInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
func hasExceptionWithin(pm *patternmatcher.PatternMatcher, dir string) bool {
|
||||||
|
dirPrefix := dir + string(filepath.Separator)
|
||||||
|
for _, pattern := range pm.Patterns() {
|
||||||
|
if pattern.Exclusion() && strings.HasPrefix(pattern.String()+string(filepath.Separator), dirPrefix) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func leaveOut(ctx context.Context, file string, err error) error {
|
||||||
|
common.Logger(ctx).Warnf("Leaving %s out of the build context: %v", file, err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func addBuildContextEntry(ctx context.Context, tw *tar.Writer, file, rel string, entry fs.DirEntry, hardlinks map[uint64]string, buffer []byte) error {
|
||||||
|
info, err := entry.Info()
|
||||||
|
if err != nil {
|
||||||
|
return leaveOut(ctx, file, err)
|
||||||
|
}
|
||||||
|
if info.Mode()&fs.ModeSocket != 0 {
|
||||||
|
return nil // tar has no socket type
|
||||||
|
}
|
||||||
|
var link string
|
||||||
|
if info.Mode()&fs.ModeSymlink != 0 {
|
||||||
|
if link, err = os.Readlink(file); err != nil {
|
||||||
|
return leaveOut(ctx, file, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
header, err := tar.FileInfoHeader(noNameLookups{info}, link)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
header.Name = filepath.ToSlash(rel)
|
||||||
|
inode, linked := hardlinkInode(info)
|
||||||
|
if target, ok := hardlinks[inode]; linked && ok {
|
||||||
|
header.Typeflag, header.Linkname, header.Size = tar.TypeLink, target, 0
|
||||||
|
}
|
||||||
|
var content *os.File
|
||||||
|
if header.Typeflag == tar.TypeReg && header.Size > 0 {
|
||||||
|
if content, err = os.Open(file); err != nil {
|
||||||
|
return leaveOut(ctx, file, err)
|
||||||
|
}
|
||||||
|
defer content.Close()
|
||||||
|
}
|
||||||
|
if linked && header.Typeflag != tar.TypeLink {
|
||||||
|
hardlinks[inode] = header.Name
|
||||||
|
}
|
||||||
|
if info.IsDir() {
|
||||||
|
header.Name += "/"
|
||||||
|
}
|
||||||
|
header.Format = tar.FormatPAX
|
||||||
|
header.ModTime = header.ModTime.Truncate(time.Second)
|
||||||
|
header.AccessTime, header.ChangeTime = time.Time{}, time.Time{}
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
header.Mode = header.Mode&0o755 | 0o111 // Windows has no exec bit, so mark everything executable like docker build
|
||||||
|
}
|
||||||
|
if err := tw.WriteHeader(header); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if content != nil {
|
||||||
|
_, err = io.CopyBuffer(tw, struct{ io.Reader }{content}, buffer) // hides os.File's WriteTo, which would allocate a buffer per file
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
type noNameLookups struct{ fs.FileInfo } // leaves Uname and Gname empty like docker build, so packing never waits on NSS
|
||||||
|
|
||||||
|
func (noNameLookups) Uname() (string, error) { return "", nil }
|
||||||
|
|
||||||
|
func (noNameLookups) Gname() (string, error) { return "", nil }
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows || netbsd))
|
||||||
|
|
||||||
|
package container
|
||||||
|
|
||||||
|
import (
|
||||||
|
"archive/tar"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCreateBuildContextFollowsDockerignoreAndSymlinkedRootButKeepsDockerfile(t *testing.T) {
|
||||||
|
dir := t.TempDir()
|
||||||
|
for name, content := range map[string]string{
|
||||||
|
".dockerignore": "*.log\nbuild\n!build/keep.txt\nDockerfile", "Dockerfile": "FROM scratch", "a.txt": "a",
|
||||||
|
"a.log": "log", "build/drop.txt": "drop", "build/keep.txt": "keep",
|
||||||
|
} {
|
||||||
|
require.NoError(t, os.MkdirAll(filepath.Join(dir, filepath.Dir(name)), 0o755))
|
||||||
|
require.NoError(t, os.WriteFile(filepath.Join(dir, name), []byte(content), 0o644))
|
||||||
|
}
|
||||||
|
require.NoError(t, os.Mkdir(filepath.Join(dir, "empty"), 0o755))
|
||||||
|
|
||||||
|
contexts := []string{dir}
|
||||||
|
if link := filepath.Join(t.TempDir(), "link"); os.Symlink(dir, link) == nil {
|
||||||
|
contexts = append(contexts, link+string(filepath.Separator))
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, contextDir := range contexts {
|
||||||
|
buildContext, err := createBuildContext(t.Context(), contextDir, "Dockerfile")
|
||||||
|
require.NoError(t, err)
|
||||||
|
var names []string
|
||||||
|
for reader := tar.NewReader(buildContext); ; {
|
||||||
|
header, err := reader.Next()
|
||||||
|
if err == io.EOF {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
require.NoError(t, err)
|
||||||
|
names = append(names, header.Name)
|
||||||
|
}
|
||||||
|
require.NoError(t, buildContext.Close())
|
||||||
|
require.Equal(t, []string{".dockerignore", "a.txt", "build/keep.txt", "empty/", "Dockerfile"}, names, contextDir)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
//go:build !WITHOUT_DOCKER && (linux || darwin || netbsd)
|
||||||
|
|
||||||
|
package container
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/fs"
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
func hardlinkInode(info fs.FileInfo) (uint64, bool) {
|
||||||
|
if stat, ok := info.Sys().(*syscall.Stat_t); ok && !info.IsDir() && stat.Nlink > 1 {
|
||||||
|
return stat.Ino, true
|
||||||
|
}
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
//go:build !WITHOUT_DOCKER && (linux || darwin || netbsd)
|
||||||
|
|
||||||
|
package container
|
||||||
|
|
||||||
|
import (
|
||||||
|
"archive/tar"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"syscall"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCreateBuildContextKeepsHardlinkedSpecialFilesLinked(t *testing.T) {
|
||||||
|
dir := t.TempDir()
|
||||||
|
require.NoError(t, syscall.Mkfifo(filepath.Join(dir, "first"), 0o644))
|
||||||
|
require.NoError(t, os.Link(filepath.Join(dir, "first"), filepath.Join(dir, "second")))
|
||||||
|
|
||||||
|
buildContext, err := createBuildContext(t.Context(), dir, "Dockerfile")
|
||||||
|
require.NoError(t, err)
|
||||||
|
defer buildContext.Close()
|
||||||
|
reader := tar.NewReader(buildContext)
|
||||||
|
first, err := reader.Next()
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, byte(tar.TypeFifo), first.Typeflag)
|
||||||
|
second, err := reader.Next()
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, byte(tar.TypeLink), second.Typeflag)
|
||||||
|
assert.Equal(t, first.Name, second.Linkname)
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
//go:build !WITHOUT_DOCKER
|
||||||
|
|
||||||
|
package container
|
||||||
|
|
||||||
|
import "io/fs"
|
||||||
|
|
||||||
|
func hardlinkInode(_info fs.FileInfo) (uint64, bool) { return 0, false }
|
||||||
@@ -6,7 +6,8 @@
|
|||||||
|
|
||||||
// This file is exact copy of https://github.com/docker/cli/blob/4a63305d74332de5ceba7fcbccbc3cbb7412f5ba/cli/command/container/opts.go with:
|
// This file is exact copy of https://github.com/docker/cli/blob/4a63305d74332de5ceba7fcbccbc3cbb7412f5ba/cli/command/container/opts.go with:
|
||||||
// * appended with license information
|
// * appended with license information
|
||||||
// * regexp and loader.ParseVolume in place of the import-restricted internal/lazyregexp and internal/volumespec
|
// * regexp and ParseVolume in place of the import-restricted internal/lazyregexp and internal/volumespec
|
||||||
|
// * cdiDeviceName in place of the container-device-interface parser's IsQualifiedName
|
||||||
// * jsontext in place of json.Compact for the seccomp profile
|
// * jsontext in place of json.Compact for the seccomp profile
|
||||||
// * invalidParameter from the package's errors.go, and convertPortSet/convertPortMap for the callers in docker_run.go
|
// * invalidParameter from the package's errors.go, and convertPortSet/convertPortMap for the callers in docker_run.go
|
||||||
//
|
//
|
||||||
@@ -33,14 +34,12 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
cerrdefs "github.com/containerd/errdefs"
|
cerrdefs "github.com/containerd/errdefs"
|
||||||
"github.com/docker/cli/cli/compose/loader"
|
|
||||||
"github.com/docker/cli/opts"
|
"github.com/docker/cli/opts"
|
||||||
"github.com/docker/go-connections/nat"
|
"github.com/docker/go-connections/nat"
|
||||||
"github.com/moby/moby/api/types/container"
|
"github.com/moby/moby/api/types/container"
|
||||||
"github.com/moby/moby/api/types/mount"
|
"github.com/moby/moby/api/types/mount"
|
||||||
"github.com/moby/moby/api/types/network"
|
"github.com/moby/moby/api/types/network"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
cdi "tags.cncf.io/container-device-interface/pkg/parser"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -388,7 +387,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
|
|||||||
volumes := copts.volumes.GetMap()
|
volumes := copts.volumes.GetMap()
|
||||||
// add any bind targets to the list of container volumes
|
// add any bind targets to the list of container volumes
|
||||||
for bind := range volumes {
|
for bind := range volumes {
|
||||||
parsed, err := loader.ParseVolume(bind)
|
parsed, err := ParseVolume(bind)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -396,7 +395,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
|
|||||||
if parsed.Source != "" {
|
if parsed.Source != "" {
|
||||||
toBind := bind
|
toBind := bind
|
||||||
|
|
||||||
if parsed.Type == string(mount.TypeBind) {
|
if parsed.Type == mount.TypeBind {
|
||||||
if hostPart, targetPath, ok := strings.Cut(bind, ":"); ok {
|
if hostPart, targetPath, ok := strings.Cut(bind, ":"); ok {
|
||||||
if !filepath.IsAbs(hostPart) && strings.HasPrefix(hostPart, ".") {
|
if !filepath.IsAbs(hostPart) && strings.HasPrefix(hostPart, ".") {
|
||||||
if absHostPart, err := filepath.Abs(hostPart); err == nil {
|
if absHostPart, err := filepath.Abs(hostPart); err == nil {
|
||||||
@@ -504,7 +503,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
|
|||||||
deviceMappings := make([]container.DeviceMapping, 0, len(devices))
|
deviceMappings := make([]container.DeviceMapping, 0, len(devices))
|
||||||
cdiDeviceNames := make([]string, 0, len(devices))
|
cdiDeviceNames := make([]string, 0, len(devices))
|
||||||
for _, device := range devices {
|
for _, device := range devices {
|
||||||
if cdi.IsQualifiedName(device) {
|
if cdiDeviceName.MatchString(device) {
|
||||||
cdiDeviceNames = append(cdiDeviceNames, device)
|
cdiDeviceNames = append(cdiDeviceNames, device)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -1197,6 +1196,8 @@ func convertPortSet(ports nat.PortSet) (network.PortSet, error) {
|
|||||||
return converted, nil
|
return converted, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var cdiDeviceName = regexp.MustCompile(`^[a-zA-Z]([a-zA-Z0-9_.-]*[a-zA-Z0-9])?/[a-zA-Z]([a-zA-Z0-9_.-]*[a-zA-Z0-9])?=[a-zA-Z0-9]([a-zA-Z0-9_.:-]*[a-zA-Z0-9])?$`)
|
||||||
|
|
||||||
func convertPortMap(bindings nat.PortMap) (network.PortMap, error) {
|
func convertPortMap(bindings nat.PortMap) (network.PortMap, error) {
|
||||||
converted := make(network.PortMap, len(bindings))
|
converted := make(network.PortMap, len(bindings))
|
||||||
for port, portBindings := range bindings {
|
for port, portBindings := range bindings {
|
||||||
|
|||||||
@@ -25,13 +25,11 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/google/go-cmp/cmp/cmpopts"
|
|
||||||
"github.com/moby/moby/api/types/container"
|
"github.com/moby/moby/api/types/container"
|
||||||
networktypes "github.com/moby/moby/api/types/network"
|
networktypes "github.com/moby/moby/api/types/network"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
"gotest.tools/v3/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
is "gotest.tools/v3/assert/cmp"
|
"github.com/stretchr/testify/require"
|
||||||
"gotest.tools/v3/skip"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func mustParseMAC(s string) networktypes.HardwareAddr {
|
func mustParseMAC(s string) networktypes.HardwareAddr {
|
||||||
@@ -90,7 +88,7 @@ func setupRunFlags() (*pflag.FlagSet, *containerOptions) {
|
|||||||
func mustParse(t *testing.T, args string) (*container.Config, *container.HostConfig, *networktypes.NetworkingConfig) {
|
func mustParse(t *testing.T, args string) (*container.Config, *container.HostConfig, *networktypes.NetworkingConfig) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
config, hostConfig, nwConfig, err := parseRun(append(strings.Split(args, " "), "ubuntu", "bash"))
|
config, hostConfig, nwConfig, err := parseRun(append(strings.Split(args, " "), "ubuntu", "bash"))
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
return config, hostConfig, nwConfig
|
return config, hostConfig, nwConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,12 +154,12 @@ func TestParseRunLinks(t *testing.T) {
|
|||||||
for _, tc := range tests {
|
for _, tc := range tests {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
_, hostConfig, netConfig := mustParse(t, tc.input)
|
_, hostConfig, netConfig := mustParse(t, tc.input)
|
||||||
assert.Check(t, is.DeepEqual(hostConfig.Links, tc.expHostConfigLinks))
|
assert.Equal(t, tc.expHostConfigLinks, hostConfig.Links)
|
||||||
assert.Check(t, is.Len(netConfig.EndpointsConfig, len(tc.expNetConfigLinks)))
|
assert.Len(t, netConfig.EndpointsConfig, len(tc.expNetConfigLinks))
|
||||||
for netName, expLinks := range tc.expNetConfigLinks {
|
for netName, expLinks := range tc.expNetConfigLinks {
|
||||||
nc, ok := netConfig.EndpointsConfig[netName]
|
nc, ok := netConfig.EndpointsConfig[netName]
|
||||||
assert.Assert(t, ok)
|
require.True(t, ok)
|
||||||
assert.Check(t, is.DeepEqual(nc.Links, expLinks))
|
assert.Equal(t, expLinks, nc.Links)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -169,15 +167,15 @@ func TestParseRunLinks(t *testing.T) {
|
|||||||
|
|
||||||
func TestParseRunWithoutUmask(t *testing.T) {
|
func TestParseRunWithoutUmask(t *testing.T) {
|
||||||
_, hostConfig, _, err := parseRun([]string{"ubuntu", "bash"})
|
_, hostConfig, _, err := parseRun([]string{"ubuntu", "bash"})
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Assert(t, hostConfig.Umask == nil)
|
require.Nil(t, hostConfig.Umask)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseRunUmask(t *testing.T) {
|
func TestParseRunUmask(t *testing.T) {
|
||||||
_, hostConfig, _, err := parseRun([]string{"--umask", "0022", "ubuntu", "bash"})
|
_, hostConfig, _, err := parseRun([]string{"--umask", "0022", "ubuntu", "bash"})
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Assert(t, hostConfig.Umask != nil)
|
require.NotNil(t, hostConfig.Umask)
|
||||||
assert.Equal(t, uint32(0o22), *hostConfig.Umask)
|
require.Equal(t, uint32(0o22), *hostConfig.Umask)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseRunAttach(t *testing.T) {
|
func TestParseRunAttach(t *testing.T) {
|
||||||
@@ -225,9 +223,9 @@ func TestParseRunAttach(t *testing.T) {
|
|||||||
for _, tc := range tests {
|
for _, tc := range tests {
|
||||||
t.Run(tc.input, func(t *testing.T) {
|
t.Run(tc.input, func(t *testing.T) {
|
||||||
config, _, _ := mustParse(t, tc.input)
|
config, _, _ := mustParse(t, tc.input)
|
||||||
assert.Equal(t, config.AttachStdin, tc.expected.AttachStdin)
|
require.Equal(t, tc.expected.AttachStdin, config.AttachStdin)
|
||||||
assert.Equal(t, config.AttachStdout, tc.expected.AttachStdout)
|
require.Equal(t, tc.expected.AttachStdout, config.AttachStdout)
|
||||||
assert.Equal(t, config.AttachStderr, tc.expected.AttachStderr)
|
require.Equal(t, tc.expected.AttachStderr, config.AttachStderr)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -273,7 +271,7 @@ func TestParseRunWithInvalidArgs(t *testing.T) {
|
|||||||
flags, _ := setupRunFlags()
|
flags, _ := setupRunFlags()
|
||||||
for _, tc := range tests {
|
for _, tc := range tests {
|
||||||
t.Run(strings.Join(tc.args, " "), func(t *testing.T) {
|
t.Run(strings.Join(tc.args, " "), func(t *testing.T) {
|
||||||
assert.Error(t, flags.Parse(tc.args), tc.error)
|
require.EqualError(t, flags.Parse(tc.args), tc.error)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -396,23 +394,23 @@ func TestRunFlagsParseWithMemory(t *testing.T) {
|
|||||||
flags, _ := setupRunFlags()
|
flags, _ := setupRunFlags()
|
||||||
args := []string{"--memory=invalid", "img", "cmd"}
|
args := []string{"--memory=invalid", "img", "cmd"}
|
||||||
err := flags.Parse(args)
|
err := flags.Parse(args)
|
||||||
assert.ErrorContains(t, err, `invalid argument "invalid" for "-m, --memory" flag`)
|
require.ErrorContains(t, err, `invalid argument "invalid" for "-m, --memory" flag`)
|
||||||
|
|
||||||
_, hostconfig, _ := mustParse(t, "--memory=1G")
|
_, hostconfig, _ := mustParse(t, "--memory=1G")
|
||||||
assert.Check(t, is.Equal(int64(1073741824), hostconfig.Memory))
|
assert.Equal(t, int64(1073741824), hostconfig.Memory)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseWithMemorySwap(t *testing.T) {
|
func TestParseWithMemorySwap(t *testing.T) {
|
||||||
flags, _ := setupRunFlags()
|
flags, _ := setupRunFlags()
|
||||||
args := []string{"--memory-swap=invalid", "img", "cmd"}
|
args := []string{"--memory-swap=invalid", "img", "cmd"}
|
||||||
err := flags.Parse(args)
|
err := flags.Parse(args)
|
||||||
assert.ErrorContains(t, err, `invalid argument "invalid" for "--memory-swap" flag`)
|
require.ErrorContains(t, err, `invalid argument "invalid" for "--memory-swap" flag`)
|
||||||
|
|
||||||
_, hostconfig, _ := mustParse(t, "--memory-swap=1G")
|
_, hostconfig, _ := mustParse(t, "--memory-swap=1G")
|
||||||
assert.Check(t, is.Equal(int64(1073741824), hostconfig.MemorySwap))
|
assert.Equal(t, int64(1073741824), hostconfig.MemorySwap)
|
||||||
|
|
||||||
_, hostconfig, _ = mustParse(t, "--memory-swap=-1")
|
_, hostconfig, _ = mustParse(t, "--memory-swap=-1")
|
||||||
assert.Check(t, is.Equal(int64(-1), hostconfig.MemorySwap))
|
assert.Equal(t, int64(-1), hostconfig.MemorySwap)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseHostname(t *testing.T) {
|
func TestParseHostname(t *testing.T) {
|
||||||
@@ -474,7 +472,7 @@ func TestParseWithExpose(t *testing.T) {
|
|||||||
for expose, expectedError := range tests {
|
for expose, expectedError := range tests {
|
||||||
t.Run(expose, func(t *testing.T) {
|
t.Run(expose, func(t *testing.T) {
|
||||||
_, _, _, err := parseRun([]string{fmt.Sprintf("--expose=%v", expose), "img", "cmd"})
|
_, _, _, err := parseRun([]string{fmt.Sprintf("--expose=%v", expose), "img", "cmd"})
|
||||||
assert.Error(t, err, expectedError)
|
require.EqualError(t, err, expectedError)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -489,10 +487,10 @@ func TestParseWithExpose(t *testing.T) {
|
|||||||
for expose, exposedPorts := range tests {
|
for expose, exposedPorts := range tests {
|
||||||
t.Run(expose, func(t *testing.T) {
|
t.Run(expose, func(t *testing.T) {
|
||||||
config, _, _, err := parseRun([]string{fmt.Sprintf("--expose=%v", expose), "img", "cmd"})
|
config, _, _, err := parseRun([]string{fmt.Sprintf("--expose=%v", expose), "img", "cmd"})
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
for _, port := range exposedPorts {
|
for _, port := range exposedPorts {
|
||||||
_, ok := config.ExposedPorts[port]
|
_, ok := config.ExposedPorts[port]
|
||||||
assert.Check(t, ok, "missing port %q in exposed ports: %#+v", port, config.ExposedPorts[port])
|
assert.True(t, ok, "missing port %q in exposed ports: %#+v", port, config.ExposedPorts[port])
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -501,18 +499,20 @@ func TestParseWithExpose(t *testing.T) {
|
|||||||
t.Run("merge with published", func(t *testing.T) {
|
t.Run("merge with published", func(t *testing.T) {
|
||||||
// Merge with actual published port
|
// Merge with actual published port
|
||||||
config, _, _, err := parseRun([]string{"--publish=80", "--expose=80-81/tcp", "img", "cmd"})
|
config, _, _, err := parseRun([]string{"--publish=80", "--expose=80-81/tcp", "img", "cmd"})
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Check(t, is.Len(config.ExposedPorts, 2))
|
assert.Len(t, config.ExposedPorts, 2)
|
||||||
ports := []networktypes.Port{networktypes.MustParsePort("80/tcp"), networktypes.MustParsePort("81/tcp")}
|
ports := []networktypes.Port{networktypes.MustParsePort("80/tcp"), networktypes.MustParsePort("81/tcp")}
|
||||||
for _, port := range ports {
|
for _, port := range ports {
|
||||||
_, ok := config.ExposedPorts[port]
|
_, ok := config.ExposedPorts[port]
|
||||||
assert.Check(t, ok, "missing port %q in exposed ports: %#+v", port, config.ExposedPorts[port])
|
assert.True(t, ok, "missing port %q in exposed ports: %#+v", port, config.ExposedPorts[port])
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseDevice(t *testing.T) {
|
func TestParseDevice(t *testing.T) {
|
||||||
skip.If(t, runtime.GOOS != "linux") // Windows and macOS validate server-side
|
if runtime.GOOS != "linux" {
|
||||||
|
t.Skip("Windows and macOS validate server-side")
|
||||||
|
}
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
devices []string
|
devices []string
|
||||||
deviceMapping *container.DeviceMapping
|
deviceMapping *container.DeviceMapping
|
||||||
@@ -586,17 +586,17 @@ func TestParseDevice(t *testing.T) {
|
|||||||
|
|
||||||
_, hostconfig, _, err := parseRun(args)
|
_, hostconfig, _, err := parseRun(args)
|
||||||
|
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
if tc.deviceMapping != nil {
|
if tc.deviceMapping != nil {
|
||||||
if assert.Check(t, is.Len(hostconfig.Devices, 1)) {
|
if assert.Len(t, hostconfig.Devices, 1) {
|
||||||
assert.Check(t, is.DeepEqual(*tc.deviceMapping, hostconfig.Devices[0]))
|
assert.Equal(t, *tc.deviceMapping, hostconfig.Devices[0])
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
assert.Check(t, is.Len(hostconfig.Devices, 0))
|
assert.Empty(t, hostconfig.Devices)
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Check(t, is.DeepEqual(tc.deviceRequests, hostconfig.DeviceRequests))
|
assert.Equal(t, tc.deviceRequests, hostconfig.DeviceRequests)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -665,11 +665,11 @@ func TestParseDeviceByServerOS(t *testing.T) {
|
|||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
got, err := parseDevice(tc.device, tc.serverOS)
|
got, err := parseDevice(tc.device, tc.serverOS)
|
||||||
if tc.wantErr != "" {
|
if tc.wantErr != "" {
|
||||||
assert.Error(t, err, tc.wantErr)
|
require.EqualError(t, err, tc.wantErr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, got, tc.want)
|
require.Equal(t, tc.want, got)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -848,13 +848,13 @@ func TestParseNetworkConfig(t *testing.T) {
|
|||||||
_, hConfig, nwConfig, err := parseRun(tc.flags)
|
_, hConfig, nwConfig, err := parseRun(tc.flags)
|
||||||
|
|
||||||
if tc.expectedErr != "" {
|
if tc.expectedErr != "" {
|
||||||
assert.Error(t, err, tc.expectedErr)
|
require.EqualError(t, err, tc.expectedErr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
assert.DeepEqual(t, hConfig.NetworkMode, tc.expectedHostCfg.NetworkMode)
|
require.Equal(t, tc.expectedHostCfg.NetworkMode, hConfig.NetworkMode)
|
||||||
assert.DeepEqual(t, nwConfig.EndpointsConfig, tc.expected, cmpopts.EquateComparable(netip.Addr{}))
|
require.Equal(t, tc.expected, nwConfig.EndpointsConfig)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -863,24 +863,24 @@ func TestParseModes(t *testing.T) {
|
|||||||
// pid ko
|
// pid ko
|
||||||
flags, copts := setupRunFlags()
|
flags, copts := setupRunFlags()
|
||||||
args := []string{"--pid=container:", "img", "cmd"}
|
args := []string{"--pid=container:", "img", "cmd"}
|
||||||
assert.NilError(t, flags.Parse(args))
|
require.NoError(t, flags.Parse(args))
|
||||||
_, err := parse(flags, copts, runtime.GOOS)
|
_, err := parse(flags, copts, runtime.GOOS)
|
||||||
assert.ErrorContains(t, err, "--pid: invalid PID mode")
|
require.ErrorContains(t, err, "--pid: invalid PID mode")
|
||||||
|
|
||||||
// pid ok
|
// pid ok
|
||||||
_, hostconfig, _, err := parseRun([]string{"--pid=host", "img", "cmd"})
|
_, hostconfig, _, err := parseRun([]string{"--pid=host", "img", "cmd"})
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
if !hostconfig.PidMode.Valid() {
|
if !hostconfig.PidMode.Valid() {
|
||||||
t.Fatalf("Expected a valid PidMode, got %v", hostconfig.PidMode)
|
t.Fatalf("Expected a valid PidMode, got %v", hostconfig.PidMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
// uts ko
|
// uts ko
|
||||||
_, _, _, err = parseRun([]string{"--uts=container:", "img", "cmd"}) //nolint:dogsled // verbatim copy from docker/cli tests
|
_, _, _, err = parseRun([]string{"--uts=container:", "img", "cmd"}) //nolint:dogsled // verbatim copy from docker/cli tests
|
||||||
assert.ErrorContains(t, err, "--uts: invalid UTS mode")
|
require.ErrorContains(t, err, "--uts: invalid UTS mode")
|
||||||
|
|
||||||
// uts ok
|
// uts ok
|
||||||
_, hostconfig, _, err = parseRun([]string{"--uts=host", "img", "cmd"})
|
_, hostconfig, _, err = parseRun([]string{"--uts=host", "img", "cmd"})
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
if !hostconfig.UTSMode.Valid() {
|
if !hostconfig.UTSMode.Valid() {
|
||||||
t.Fatalf("Expected a valid UTSMode, got %v", hostconfig.UTSMode)
|
t.Fatalf("Expected a valid UTSMode, got %v", hostconfig.UTSMode)
|
||||||
}
|
}
|
||||||
@@ -892,11 +892,11 @@ func TestRunFlagsParseShmSize(t *testing.T) {
|
|||||||
args := []string{"--shm-size=a128m", "img", "cmd"}
|
args := []string{"--shm-size=a128m", "img", "cmd"}
|
||||||
expectedErr := `invalid argument "a128m" for "--shm-size" flag:`
|
expectedErr := `invalid argument "a128m" for "--shm-size" flag:`
|
||||||
err := flags.Parse(args)
|
err := flags.Parse(args)
|
||||||
assert.ErrorContains(t, err, expectedErr)
|
require.ErrorContains(t, err, expectedErr)
|
||||||
|
|
||||||
// shm-size ok
|
// shm-size ok
|
||||||
_, hostconfig, _, err := parseRun([]string{"--shm-size=128m", "img", "cmd"})
|
_, hostconfig, _, err := parseRun([]string{"--shm-size=128m", "img", "cmd"})
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
if hostconfig.ShmSize != 134217728 {
|
if hostconfig.ShmSize != 134217728 {
|
||||||
t.Fatalf("Expected a valid ShmSize, got %d", hostconfig.ShmSize)
|
t.Fatalf("Expected a valid ShmSize, got %d", hostconfig.ShmSize)
|
||||||
}
|
}
|
||||||
@@ -967,11 +967,11 @@ func TestParseRestartPolicy(t *testing.T) {
|
|||||||
t.Run(tc.input, func(t *testing.T) {
|
t.Run(tc.input, func(t *testing.T) {
|
||||||
_, hostConfig, _, err := parseRun([]string{"--restart=" + tc.input, "img", "cmd"})
|
_, hostConfig, _, err := parseRun([]string{"--restart=" + tc.input, "img", "cmd"})
|
||||||
if tc.expectedErr != "" {
|
if tc.expectedErr != "" {
|
||||||
assert.Check(t, is.Error(err, tc.expectedErr))
|
assert.Nil(t, hostConfig)
|
||||||
assert.Check(t, is.Nil(hostConfig))
|
assert.EqualError(t, err, tc.expectedErr)
|
||||||
} else {
|
} else {
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Check(t, is.DeepEqual(hostConfig.RestartPolicy, tc.expected))
|
assert.Equal(t, tc.expected, hostConfig.RestartPolicy)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -980,7 +980,7 @@ func TestParseRestartPolicy(t *testing.T) {
|
|||||||
func TestParseRestartPolicyAutoRemove(t *testing.T) {
|
func TestParseRestartPolicyAutoRemove(t *testing.T) {
|
||||||
_, _, _, err := parseRun([]string{"--rm", "--restart=always", "img", "cmd"}) //nolint:dogsled // verbatim copy from docker/cli tests
|
_, _, _, err := parseRun([]string{"--rm", "--restart=always", "img", "cmd"}) //nolint:dogsled // verbatim copy from docker/cli tests
|
||||||
const expected = "conflicting options: cannot specify both --restart and --rm"
|
const expected = "conflicting options: cannot specify both --restart and --rm"
|
||||||
assert.Check(t, is.Error(err, expected))
|
assert.EqualError(t, err, expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseHealth(t *testing.T) {
|
func TestParseHealth(t *testing.T) {
|
||||||
@@ -1118,12 +1118,14 @@ func TestParseLabelfileVariables(t *testing.T) { //nolint:dupl // verbatim copy
|
|||||||
|
|
||||||
func TestParseEntryPoint(t *testing.T) {
|
func TestParseEntryPoint(t *testing.T) {
|
||||||
config, _, _, err := parseRun([]string{"--entrypoint=anything", "cmd", "img"})
|
config, _, _, err := parseRun([]string{"--entrypoint=anything", "cmd", "img"})
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Check(t, is.DeepEqual(config.Entrypoint, []string{"anything"}))
|
assert.Equal(t, []string{"anything"}, config.Entrypoint)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValidateDevice(t *testing.T) {
|
func TestValidateDevice(t *testing.T) {
|
||||||
skip.If(t, runtime.GOOS != "linux") // Windows and macOS validate server-side
|
if runtime.GOOS != "linux" {
|
||||||
|
t.Skip("Windows and macOS validate server-side")
|
||||||
|
}
|
||||||
valid := []string{
|
valid := []string{
|
||||||
"/home",
|
"/home",
|
||||||
"/home:/home",
|
"/home:/home",
|
||||||
@@ -1222,22 +1224,22 @@ func TestValidateDeviceByServerOS(t *testing.T) {
|
|||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
got, err := validateDevice(tc.value, tc.serverOS)
|
got, err := validateDevice(tc.value, tc.serverOS)
|
||||||
if tc.wantError != "" {
|
if tc.wantError != "" {
|
||||||
assert.Error(t, err, tc.wantError)
|
require.EqualError(t, err, tc.wantError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, got, tc.want)
|
require.Equal(t, tc.want, got)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDeviceCgroupRulesAndInvalidParameter(t *testing.T) {
|
func TestDeviceCgroupRulesAndInvalidParameter(t *testing.T) {
|
||||||
got, err := validateDeviceCgroupRule("c 1:3 rwm")
|
got, err := validateDeviceCgroupRule("c 1:3 rwm")
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, got, "c 1:3 rwm")
|
require.Equal(t, "c 1:3 rwm", got)
|
||||||
|
|
||||||
_, err = validateDeviceCgroupRule("invalid")
|
_, err = validateDeviceCgroupRule("invalid")
|
||||||
assert.Error(t, err, "invalid device cgroup format 'invalid'")
|
require.EqualError(t, err, "invalid device cgroup format 'invalid'")
|
||||||
|
|
||||||
if invalidParameter(nil) != nil {
|
if invalidParameter(nil) != nil {
|
||||||
t.Fatal("invalidParameter(nil) should be nil")
|
t.Fatal("invalidParameter(nil) should be nil")
|
||||||
@@ -1245,9 +1247,9 @@ func TestDeviceCgroupRulesAndInvalidParameter(t *testing.T) {
|
|||||||
cause := errors.New("bad input")
|
cause := errors.New("bad input")
|
||||||
err = invalidParameter(cause)
|
err = invalidParameter(cause)
|
||||||
var invalid interface{ InvalidParameter() }
|
var invalid interface{ InvalidParameter() }
|
||||||
assert.Assert(t, errors.As(err, &invalid))
|
require.ErrorAs(t, err, &invalid)
|
||||||
assert.Assert(t, errors.Is(err, cause))
|
require.ErrorIs(t, err, cause)
|
||||||
assert.Equal(t, invalidParameter(err), err) // already invalid, so not wrapped twice
|
require.Condition(t, func() bool { return invalidParameter(err) == err })
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseSystemPaths(t *testing.T) {
|
func TestParseSystemPaths(t *testing.T) {
|
||||||
@@ -1298,9 +1300,9 @@ func TestParseSystemPaths(t *testing.T) {
|
|||||||
|
|
||||||
for _, tc := range tests {
|
for _, tc := range tests {
|
||||||
securityOpts, maskedPaths, readonlyPaths := parseSystemPaths(tc.in)
|
securityOpts, maskedPaths, readonlyPaths := parseSystemPaths(tc.in)
|
||||||
assert.DeepEqual(t, securityOpts, tc.out)
|
require.Equal(t, tc.out, securityOpts)
|
||||||
assert.DeepEqual(t, maskedPaths, tc.masked)
|
require.Equal(t, tc.masked, maskedPaths)
|
||||||
assert.DeepEqual(t, readonlyPaths, tc.readonly)
|
require.Equal(t, tc.readonly, readonlyPaths)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1322,9 +1324,9 @@ func TestConvertToStandardNotation(t *testing.T) {
|
|||||||
for key, ports := range valid {
|
for key, ports := range valid {
|
||||||
convertedPorts, err := convertToStandardNotation(ports)
|
convertedPorts, err := convertToStandardNotation(ports)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
assert.DeepEqual(t, strings.Split(key, " "), convertedPorts)
|
require.Equal(t, strings.Split(key, " "), convertedPorts)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, ports := range invalid {
|
for _, ports := range invalid {
|
||||||
|
|||||||
@@ -53,7 +53,9 @@ func removeOrphanNetworks(ctx context.Context, cli client.APIClient, runnerUUID,
|
|||||||
networks:
|
networks:
|
||||||
for _, n := range networks.Items {
|
for _, n := range networks.Items {
|
||||||
result, err := cli.NetworkInspect(ctx, n.ID, client.NetworkInspectOptions{})
|
result, err := cli.NetworkInspect(ctx, n.ID, client.NetworkInspectOptions{})
|
||||||
if err != nil {
|
if cerrdefs.IsNotFound(err) {
|
||||||
|
continue
|
||||||
|
} else if err != nil {
|
||||||
errs = append(errs, fmt.Errorf("failed to inspect network %s: %w", n.Name, err))
|
errs = append(errs, fmt.Errorf("failed to inspect network %s: %w", n.Name, err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -71,7 +73,9 @@ networks:
|
|||||||
continue networks
|
continue networks
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if _, err := cli.NetworkRemove(ctx, n.ID, client.NetworkRemoveOptions{}); err != nil {
|
if _, err := cli.NetworkRemove(ctx, n.ID, client.NetworkRemoveOptions{}); cerrdefs.IsNotFound(err) {
|
||||||
|
continue
|
||||||
|
} else if err != nil {
|
||||||
errs = append(errs, fmt.Errorf("failed to remove network %s: %w", n.Name, err))
|
errs = append(errs, fmt.Errorf("failed to remove network %s: %w", n.Name, err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -203,36 +207,35 @@ func NewDockerNetworkRemoveExecutor(name string) common.Executor {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cli.Close()
|
defer cli.Close()
|
||||||
|
return removeNetwork(ctx, cli, name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Make sure that all network of the specified name are removed
|
func removeNetwork(ctx context.Context, cli client.APIClient, name string) error {
|
||||||
// cli.NetworkRemove refuses to remove a network if there are duplicates
|
networks, err := cli.NetworkList(ctx, client.NetworkListOptions{}) // NetworkRemove by name refuses duplicates, so remove each by ID
|
||||||
networks, err := cli.NetworkList(ctx, client.NetworkListOptions{})
|
if err != nil {
|
||||||
if err != nil {
|
return err
|
||||||
|
}
|
||||||
|
var errs []error
|
||||||
|
for _, n := range networks.Items {
|
||||||
|
if n.Name != name {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
result, err := cli.NetworkInspect(ctx, n.ID, client.NetworkInspectOptions{})
|
||||||
|
if cerrdefs.IsNotFound(err) {
|
||||||
|
continue
|
||||||
|
} else if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// For Gitea, reduce log noise
|
if len(result.Network.Containers) != 0 {
|
||||||
// common.Logger(ctx).Debugf("%v", networks)
|
common.Logger(ctx).Warnf("Refusing to remove network %s because it still has active endpoints, the orphan cleanup reclaims it once they are gone", name)
|
||||||
var errs []error
|
continue
|
||||||
for _, n := range networks.Items {
|
}
|
||||||
if n.Name == name {
|
if _, err = cli.NetworkRemove(ctx, n.ID, client.NetworkRemoveOptions{}); err != nil && !cerrdefs.IsNotFound(err) {
|
||||||
result, err := cli.NetworkInspect(ctx, n.ID, client.NetworkInspectOptions{})
|
errs = append(errs, fmt.Errorf("failed to remove network %s: %w", name, err))
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// it holds a subnet out of the daemon's pool until something reclaims it
|
|
||||||
if len(result.Network.Containers) != 0 {
|
|
||||||
common.Logger(ctx).Warnf("Refusing to remove network %s because it still has active endpoints, the idle cleanup reclaims it once they are gone", name)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if _, err = cli.NetworkRemove(ctx, n.ID, client.NetworkRemoveOptions{}); err != nil {
|
|
||||||
errs = append(errs, fmt.Errorf("failed to remove network %s: %w", name, err))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return errors.Join(errs...)
|
|
||||||
}
|
}
|
||||||
|
return errors.Join(errs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsolatedCacheContainer returns the container holding addr, when jobs on jobNetwork cannot reach it there.
|
// IsolatedCacheContainer returns the container holding addr, when jobs on jobNetwork cannot reach it there.
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ func TestConnectAndDisconnectNetwork(t *testing.T) {
|
|||||||
// Of this runner's networks, only the ones nothing but its own cache container is attached to
|
// Of this runner's networks, only the ones nothing but its own cache container is attached to
|
||||||
// and old enough to predate any job now starting are the runner's to reclaim. An unexpected
|
// and old enough to predate any job now starting are the runner's to reclaim. An unexpected
|
||||||
// NetworkRemove fails the test on its own, since testify has no expectation to match it against.
|
// NetworkRemove fails the test on its own, since testify has no expectation to match it against.
|
||||||
func TestRemoveOrphanNetworks(t *testing.T) {
|
func TestRemoveNetworks(t *testing.T) {
|
||||||
ctx := t.Context()
|
ctx := t.Context()
|
||||||
cutoff := time.Date(2026, time.April, 29, 20, 0, 0, 0, time.UTC)
|
cutoff := time.Date(2026, time.April, 29, 20, 0, 0, 0, time.UTC)
|
||||||
client := &mockDockerClient{}
|
client := &mockDockerClient{}
|
||||||
@@ -128,11 +128,13 @@ func TestRemoveOrphanNetworks(t *testing.T) {
|
|||||||
{ID: "starting"},
|
{ID: "starting"},
|
||||||
{ID: "cached"},
|
{ID: "cached"},
|
||||||
{ID: "shared"},
|
{ID: "shared"},
|
||||||
|
{ID: "gone"},
|
||||||
|
{ID: "raced"},
|
||||||
}}, nil)
|
}}, nil)
|
||||||
client.On("NetworkInspect", ctx, "orphan", mobyclient.NetworkInspectOptions{}).
|
client.On("NetworkInspect", ctx, "orphan", mobyclient.NetworkInspectOptions{}).
|
||||||
Return(mobyclient.NetworkInspectResult{}, nil)
|
Return(mobyclient.NetworkInspectResult{}, nil).Twice()
|
||||||
client.On("NetworkInspect", ctx, "busy", mobyclient.NetworkInspectOptions{}).
|
client.On("NetworkInspect", ctx, "busy", mobyclient.NetworkInspectOptions{}).
|
||||||
Return(mobyclient.NetworkInspectResult{Network: network.Inspect{Containers: map[string]network.EndpointResource{"c": {}}}}, nil)
|
Return(mobyclient.NetworkInspectResult{Network: network.Inspect{Containers: map[string]network.EndpointResource{"c": {}}}}, nil).Twice()
|
||||||
client.On("NetworkInspect", ctx, "starting", mobyclient.NetworkInspectOptions{}).
|
client.On("NetworkInspect", ctx, "starting", mobyclient.NetworkInspectOptions{}).
|
||||||
Return(mobyclient.NetworkInspectResult{Network: network.Inspect{
|
Return(mobyclient.NetworkInspectResult{Network: network.Inspect{
|
||||||
Network: network.Network{Created: cutoff.Add(time.Second)},
|
Network: network.Network{Created: cutoff.Add(time.Second)},
|
||||||
@@ -142,13 +144,28 @@ func TestRemoveOrphanNetworks(t *testing.T) {
|
|||||||
Return(mobyclient.NetworkInspectResult{Network: network.Inspect{Containers: map[string]network.EndpointResource{"0123456789abcdef": {}}}}, nil)
|
Return(mobyclient.NetworkInspectResult{Network: network.Inspect{Containers: map[string]network.EndpointResource{"0123456789abcdef": {}}}}, nil)
|
||||||
client.On("NetworkInspect", ctx, "shared", mobyclient.NetworkInspectOptions{}).
|
client.On("NetworkInspect", ctx, "shared", mobyclient.NetworkInspectOptions{}).
|
||||||
Return(mobyclient.NetworkInspectResult{Network: network.Inspect{Containers: map[string]network.EndpointResource{"0123456789abcdef": {}, "job": {}}}}, nil)
|
Return(mobyclient.NetworkInspectResult{Network: network.Inspect{Containers: map[string]network.EndpointResource{"0123456789abcdef": {}, "job": {}}}}, nil)
|
||||||
|
client.On("NetworkInspect", ctx, "gone", mobyclient.NetworkInspectOptions{}).
|
||||||
|
Return(mobyclient.NetworkInspectResult{}, cerrdefs.ErrNotFound).Twice()
|
||||||
|
client.On("NetworkInspect", ctx, "raced", mobyclient.NetworkInspectOptions{}).
|
||||||
|
Return(mobyclient.NetworkInspectResult{}, nil).Twice()
|
||||||
|
client.On("NetworkRemove", ctx, "raced", mobyclient.NetworkRemoveOptions{}).
|
||||||
|
Return(mobyclient.NetworkRemoveResult{}, cerrdefs.ErrNotFound).Twice()
|
||||||
client.On("NetworkRemove", ctx, "orphan", mobyclient.NetworkRemoveOptions{}).
|
client.On("NetworkRemove", ctx, "orphan", mobyclient.NetworkRemoveOptions{}).
|
||||||
Return(mobyclient.NetworkRemoveResult{}, nil)
|
Return(mobyclient.NetworkRemoveResult{}, nil).Twice()
|
||||||
client.On("NetworkDisconnect", ctx, "cached", mobyclient.NetworkDisconnectOptions{Container: "0123456789abcdef", Force: true}).
|
client.On("NetworkDisconnect", ctx, "cached", mobyclient.NetworkDisconnectOptions{Container: "0123456789abcdef", Force: true}).
|
||||||
Return(nil).Once()
|
Return(nil).Once()
|
||||||
client.On("NetworkRemove", ctx, "cached", mobyclient.NetworkRemoveOptions{}).
|
client.On("NetworkRemove", ctx, "cached", mobyclient.NetworkRemoveOptions{}).
|
||||||
Return(mobyclient.NetworkRemoveResult{}, nil).Once()
|
Return(mobyclient.NetworkRemoveResult{}, nil).Once()
|
||||||
|
|
||||||
require.NoError(t, removeOrphanNetworks(ctx, client, "runner-1", "0123456789ab", cutoff))
|
require.NoError(t, removeOrphanNetworks(ctx, client, "runner-1", "0123456789ab", cutoff))
|
||||||
|
|
||||||
|
client.On("NetworkList", ctx, mobyclient.NetworkListOptions{}).Return(mobyclient.NetworkListResult{Items: []network.Summary{
|
||||||
|
{ID: "orphan", Name: "job"},
|
||||||
|
{ID: "busy", Name: "job"},
|
||||||
|
{ID: "gone", Name: "job"},
|
||||||
|
{ID: "raced", Name: "job"},
|
||||||
|
{ID: "shared", Name: "other"},
|
||||||
|
}}, nil)
|
||||||
|
require.NoError(t, removeNetwork(ctx, client, "job"))
|
||||||
client.AssertExpectations(t)
|
client.AssertExpectations(t)
|
||||||
}
|
}
|
||||||
@@ -12,7 +12,6 @@ import (
|
|||||||
"gitea.com/gitea/runner/act/common/logging"
|
"gitea.com/gitea/runner/act/common/logging"
|
||||||
"gitea.com/gitea/runner/act/common/logging/logtest"
|
"gitea.com/gitea/runner/act/common/logging/logtest"
|
||||||
|
|
||||||
"github.com/docker/cli/cli/config"
|
|
||||||
assert "github.com/stretchr/testify/assert"
|
assert "github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
@@ -44,10 +43,7 @@ func TestCleanImage(t *testing.T) {
|
|||||||
func TestGetImagePullOptions(t *testing.T) {
|
func TestGetImagePullOptions(t *testing.T) {
|
||||||
ctx := t.Context()
|
ctx := t.Context()
|
||||||
|
|
||||||
orig := config.Dir()
|
t.Setenv("DOCKER_CONFIG", "/non-existent/docker")
|
||||||
t.Cleanup(func() { config.SetDir(orig) })
|
|
||||||
|
|
||||||
config.SetDir("/non-existent/docker")
|
|
||||||
|
|
||||||
options, err := getImagePullOptions(ctx, NewDockerPullExecutorInput{})
|
options, err := getImagePullOptions(ctx, NewDockerPullExecutorInput{})
|
||||||
assert.NoError(t, err, "Failed to create ImagePullOptions") //nolint:testifylint // pre-existing issue from nektos/act
|
assert.NoError(t, err, "Failed to create ImagePullOptions") //nolint:testifylint // pre-existing issue from nektos/act
|
||||||
@@ -61,7 +57,7 @@ func TestGetImagePullOptions(t *testing.T) {
|
|||||||
assert.NoError(t, err, "Failed to create ImagePullOptions") //nolint:testifylint // pre-existing issue from nektos/act
|
assert.NoError(t, err, "Failed to create ImagePullOptions") //nolint:testifylint // pre-existing issue from nektos/act
|
||||||
assert.Equal(t, "eyJ1c2VybmFtZSI6InVzZXJuYW1lIiwicGFzc3dvcmQiOiJwYXNzd29yZCJ9", options.RegistryAuth, "Username and Password should be provided")
|
assert.Equal(t, "eyJ1c2VybmFtZSI6InVzZXJuYW1lIiwicGFzc3dvcmQiOiJwYXNzd29yZCJ9", options.RegistryAuth, "Username and Password should be provided")
|
||||||
|
|
||||||
config.SetDir("testdata/docker-pull-options")
|
t.Setenv("DOCKER_CONFIG", "testdata/docker-pull-options")
|
||||||
|
|
||||||
options, err = getImagePullOptions(ctx, NewDockerPullExecutorInput{
|
options, err = getImagePullOptions(ctx, NewDockerPullExecutorInput{
|
||||||
Image: "nektos/act",
|
Image: "nektos/act",
|
||||||
|
|||||||
+58
-21
@@ -13,6 +13,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -27,11 +28,8 @@ import (
|
|||||||
"gitea.com/gitea/runner/act/common"
|
"gitea.com/gitea/runner/act/common"
|
||||||
"gitea.com/gitea/runner/act/common/logging"
|
"gitea.com/gitea/runner/act/common/logging"
|
||||||
|
|
||||||
"dario.cat/mergo"
|
|
||||||
"github.com/bmatcuk/doublestar/v4"
|
"github.com/bmatcuk/doublestar/v4"
|
||||||
cerrdefs "github.com/containerd/errdefs"
|
cerrdefs "github.com/containerd/errdefs"
|
||||||
"github.com/docker/cli/cli/compose/loader"
|
|
||||||
"github.com/docker/cli/cli/connhelper"
|
|
||||||
"github.com/docker/cli/opts"
|
"github.com/docker/cli/opts"
|
||||||
"github.com/moby/moby/api/pkg/stdcopy"
|
"github.com/moby/moby/api/pkg/stdcopy"
|
||||||
"github.com/moby/moby/api/types/container"
|
"github.com/moby/moby/api/types/container"
|
||||||
@@ -372,15 +370,13 @@ func GetDockerClient(ctx context.Context) (cli client.APIClient, err error) {
|
|||||||
dockerHost := os.Getenv("DOCKER_HOST")
|
dockerHost := os.Getenv("DOCKER_HOST")
|
||||||
|
|
||||||
if strings.HasPrefix(dockerHost, "ssh://") {
|
if strings.HasPrefix(dockerHost, "ssh://") {
|
||||||
var helper *connhelper.ConnectionHelper
|
var args []string
|
||||||
|
if args, err = sshArgs(dockerHost); err != nil {
|
||||||
helper, err = connhelper.GetConnectionHelper(dockerHost)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
cli, err = client.New(
|
cli, err = client.New(
|
||||||
client.WithHost(helper.Host),
|
client.WithHost("http://docker.example.com"), // the dialer below ignores the address
|
||||||
client.WithDialContext(helper.Dialer),
|
client.WithDialContext(func(context.Context, string, string) (net.Conn, error) { return dialCommand("ssh", args...) }),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
cli, err = client.New(client.FromEnv)
|
cli, err = client.New(client.FromEnv)
|
||||||
@@ -622,10 +618,7 @@ func (cr *containerReference) mergeContainerConfigs(ctx context.Context, config
|
|||||||
|
|
||||||
logger.Debugf("Custom container.Config from options ==> %+v", containerConfig.Config)
|
logger.Debugf("Custom container.Config from options ==> %+v", containerConfig.Config)
|
||||||
|
|
||||||
err = mergo.Merge(config, containerConfig.Config, mergo.WithOverride, mergo.WithAppendSlice)
|
overlay(reflect.ValueOf(config).Elem(), reflect.ValueOf(containerConfig.Config).Elem(), true)
|
||||||
if err != nil {
|
|
||||||
return nil, nil, fmt.Errorf("cannot merge container.Config options: '%s': '%w'", options, err)
|
|
||||||
}
|
|
||||||
logger.Debugf("Merged container.Config ==> %+v", config)
|
logger.Debugf("Merged container.Config ==> %+v", config)
|
||||||
|
|
||||||
logger.Debugf("Custom container.HostConfig from options ==> %+v", containerConfig.HostConfig)
|
logger.Debugf("Custom container.HostConfig from options ==> %+v", containerConfig.HostConfig)
|
||||||
@@ -635,10 +628,7 @@ func (cr *containerReference) mergeContainerConfigs(ctx context.Context, config
|
|||||||
binds := hostConfig.Binds
|
binds := hostConfig.Binds
|
||||||
mounts := hostConfig.Mounts
|
mounts := hostConfig.Mounts
|
||||||
networkMode := hostConfig.NetworkMode
|
networkMode := hostConfig.NetworkMode
|
||||||
err = mergo.Merge(hostConfig, containerConfig.HostConfig, mergo.WithOverride)
|
overlay(reflect.ValueOf(hostConfig).Elem(), reflect.ValueOf(containerConfig.HostConfig).Elem(), false)
|
||||||
if err != nil {
|
|
||||||
return nil, nil, fmt.Errorf("cannot merge container.HostConfig options: '%s': '%w'", options, err)
|
|
||||||
}
|
|
||||||
hostConfig.Binds = binds
|
hostConfig.Binds = binds
|
||||||
hostConfig.Mounts = mounts
|
hostConfig.Mounts = mounts
|
||||||
if cf.name != "" {
|
if cf.name != "" {
|
||||||
@@ -1117,7 +1107,7 @@ func (cr *containerReference) sanitizeConfig(ctx context.Context, config *contai
|
|||||||
// sanitize binds
|
// sanitize binds
|
||||||
sanitizedBinds := make([]string, 0, len(hostConfig.Binds))
|
sanitizedBinds := make([]string, 0, len(hostConfig.Binds))
|
||||||
for _, bind := range hostConfig.Binds {
|
for _, bind := range hostConfig.Binds {
|
||||||
parsed, err := loader.ParseVolume(bind)
|
parsed, err := ParseVolume(bind)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warnf("parse volume [%s] error: %v", bind, err)
|
logger.Warnf("parse volume [%s] error: %v", bind, err)
|
||||||
continue
|
continue
|
||||||
@@ -1127,8 +1117,8 @@ func (cr *containerReference) sanitizeConfig(ctx context.Context, config *contai
|
|||||||
sanitizedBinds = append(sanitizedBinds, bind)
|
sanitizedBinds = append(sanitizedBinds, bind)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if matcher.isValid(parsed.Source, mount.Type(parsed.Type), parsed.ReadOnly) {
|
if matcher.isValid(parsed.Source, parsed.Type, parsed.ReadOnly) {
|
||||||
if matcher.needsNoCopy(parsed.Source, mount.Type(parsed.Type)) && (parsed.Volume == nil || !parsed.Volume.NoCopy) {
|
if matcher.needsNoCopy(parsed.Source, parsed.Type) && !parsed.NoCopy {
|
||||||
bind += ",nocopy"
|
bind += ",nocopy"
|
||||||
}
|
}
|
||||||
sanitizedBinds = append(sanitizedBinds, bind)
|
sanitizedBinds = append(sanitizedBinds, bind)
|
||||||
@@ -1168,9 +1158,56 @@ func SanitizeBinds(ctx context.Context, validVolumes, binds []string) []string {
|
|||||||
return hostConfig.Binds
|
return hostConfig.Binds
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func overlay(dst, src reflect.Value, appendSlices bool) {
|
||||||
|
switch dst.Kind() {
|
||||||
|
case reflect.Struct:
|
||||||
|
opaque := true
|
||||||
|
for i := range dst.NumField() {
|
||||||
|
if dst.Type().Field(i).IsExported() {
|
||||||
|
opaque = false
|
||||||
|
overlay(dst.Field(i), src.Field(i), appendSlices)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if opaque {
|
||||||
|
dst.Set(src)
|
||||||
|
}
|
||||||
|
case reflect.Map:
|
||||||
|
if src.IsNil() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if dst.IsNil() {
|
||||||
|
dst.Set(reflect.MakeMap(dst.Type()))
|
||||||
|
}
|
||||||
|
for key, value := range src.Seq2() {
|
||||||
|
dst.SetMapIndex(key, value)
|
||||||
|
}
|
||||||
|
case reflect.Slice:
|
||||||
|
if appendSlices {
|
||||||
|
dst.Set(reflect.AppendSlice(dst, src))
|
||||||
|
} else if src.Len() > 0 {
|
||||||
|
dst.Set(src)
|
||||||
|
}
|
||||||
|
case reflect.Pointer:
|
||||||
|
if src.IsNil() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if dst.IsNil() {
|
||||||
|
dst.Set(src)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
overlay(dst.Elem(), src.Elem(), appendSlices)
|
||||||
|
case reflect.Array:
|
||||||
|
dst.Set(src)
|
||||||
|
default:
|
||||||
|
if !src.IsZero() {
|
||||||
|
dst.Set(src)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// bindTarget returns the container path a bind mounts onto, empty if it cannot be parsed.
|
// bindTarget returns the container path a bind mounts onto, empty if it cannot be parsed.
|
||||||
func bindTarget(bind string) string {
|
func bindTarget(bind string) string {
|
||||||
parsed, err := loader.ParseVolume(bind)
|
parsed, err := ParseVolume(bind)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,111 @@
|
|||||||
|
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows || netbsd))
|
||||||
|
|
||||||
|
package container
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/docker/cli/cli/connhelper/ssh"
|
||||||
|
)
|
||||||
|
|
||||||
|
func sshArgs(daemonURL string) ([]string, error) {
|
||||||
|
spec, err := ssh.ParseURL(daemonURL)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
remote := []string{"docker", "system", "dial-stdio"}
|
||||||
|
if strings.Trim(spec.Path, "/") != "" {
|
||||||
|
remote = []string{"docker", "--host=unix://" + spec.Path, "system", "dial-stdio"}
|
||||||
|
}
|
||||||
|
return spec.Command([]string{"-o", "ConnectTimeout=30", "-T"}, remote...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func dialCommand(name string, args ...string) (net.Conn, error) {
|
||||||
|
conn := &commandConn{cmd: exec.Command(name, args...)}
|
||||||
|
conn.cmd.SysProcAttr = sshSysProcAttr() // a session of its own like docker's, so a ProxyCommand never reads the runner's terminal: https://github.com/docker/cli/issues/1707
|
||||||
|
conn.cmd.Stderr = &conn.stderr
|
||||||
|
conn.cmd.WaitDelay = time.Second // a ProxyCommand child keeping stderr open would otherwise block Wait after ssh exits
|
||||||
|
conn.wait = sync.OnceValue(func() error {
|
||||||
|
if err := conn.cmd.Wait(); err != nil && !errors.Is(err, exec.ErrWaitDelay) {
|
||||||
|
return fmt.Errorf("%s: %w: %s", strings.Join(conn.cmd.Args, " "), err, strings.TrimSpace(conn.stderr.String()))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
var err error
|
||||||
|
if conn.stdin, err = conn.cmd.StdinPipe(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if conn.stdout, err = conn.cmd.StdoutPipe(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return conn, conn.cmd.Start()
|
||||||
|
}
|
||||||
|
|
||||||
|
type commandConn struct {
|
||||||
|
cmd *exec.Cmd
|
||||||
|
stdin io.WriteCloser
|
||||||
|
stdout io.ReadCloser
|
||||||
|
stderr cappedBuffer
|
||||||
|
wait func() error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *commandConn) waitWithin(timeout time.Duration) error {
|
||||||
|
timer := time.AfterFunc(timeout, func() { _ = c.cmd.Process.Kill() })
|
||||||
|
defer timer.Stop()
|
||||||
|
return c.wait()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *commandConn) Read(p []byte) (int, error) {
|
||||||
|
n, err := c.stdout.Read(p)
|
||||||
|
if errors.Is(err, io.EOF) {
|
||||||
|
if waitErr := c.waitWithin(10 * time.Second); waitErr != nil {
|
||||||
|
return n, waitErr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return n, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *commandConn) Write(p []byte) (int, error) { return c.stdin.Write(p) }
|
||||||
|
|
||||||
|
// CloseWrite lets the daemon see the end of a hijacked stream, like a TCP half-close.
|
||||||
|
func (c *commandConn) CloseWrite() error { return c.stdin.Close() }
|
||||||
|
|
||||||
|
func (c *commandConn) Close() error {
|
||||||
|
_ = c.stdin.Close()
|
||||||
|
if c.cmd.Process.Signal(syscall.SIGTERM) != nil { // SIGTERM lets ssh take its ProxyCommand down, Windows only kills
|
||||||
|
_ = c.cmd.Process.Kill()
|
||||||
|
}
|
||||||
|
_ = c.waitWithin(3 * time.Second)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *commandConn) LocalAddr() net.Addr { return &net.UnixAddr{Name: "stdio", Net: "unix"} }
|
||||||
|
|
||||||
|
func (c *commandConn) RemoteAddr() net.Addr { return &net.UnixAddr{Name: "stdio", Net: "unix"} }
|
||||||
|
|
||||||
|
func (c *commandConn) SetDeadline(_deadline time.Time) error { return nil }
|
||||||
|
|
||||||
|
func (c *commandConn) SetReadDeadline(_deadline time.Time) error { return nil }
|
||||||
|
|
||||||
|
func (c *commandConn) SetWriteDeadline(_deadline time.Time) error { return nil }
|
||||||
|
|
||||||
|
type cappedBuffer struct{ bytes.Buffer }
|
||||||
|
|
||||||
|
func (b *cappedBuffer) Write(p []byte) (int, error) {
|
||||||
|
if b.Len() > 4096 {
|
||||||
|
b.Reset()
|
||||||
|
}
|
||||||
|
return b.Buffer.Write(p)
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
//go:build !WITHOUT_DOCKER
|
||||||
|
|
||||||
|
package container
|
||||||
|
|
||||||
|
import "syscall"
|
||||||
|
|
||||||
|
func sshSysProcAttr() *syscall.SysProcAttr {
|
||||||
|
return &syscall.SysProcAttr{Setsid: true, Pdeathsig: syscall.SIGKILL}
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
//go:build !(WITHOUT_DOCKER || !(linux || darwin || windows || netbsd))
|
||||||
|
|
||||||
|
package container
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"os/exec"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSSHArgs(t *testing.T) {
|
||||||
|
args, err := sshArgs("ssh://me@host:2222/run/user/1000/my docker.sock")
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, []string{"-l", "me", "-p", "2222", "-o", "ConnectTimeout=30", "-T", "--", "host", "docker '--host=unix:///run/user/1000/my docker.sock' system dial-stdio"}, args)
|
||||||
|
|
||||||
|
args, err = sshArgs("ssh://[::1]")
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, []string{"-o", "ConnectTimeout=30", "-T", "--", "::1", "docker system dial-stdio"}, args)
|
||||||
|
|
||||||
|
for _, invalid := range []string{"ssh://me:secret@host", "ssh://host?x=1", "ssh://host#x", "ssh://"} {
|
||||||
|
_, err := sshArgs(invalid)
|
||||||
|
assert.Error(t, err, invalid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDialCommandStreamsStdioAndReportsExit(t *testing.T) {
|
||||||
|
if _, err := exec.LookPath("sh"); err != nil {
|
||||||
|
t.Skip("needs a POSIX shell")
|
||||||
|
}
|
||||||
|
conn, err := dialCommand("sh", "-c", "cat")
|
||||||
|
require.NoError(t, err)
|
||||||
|
_, err = conn.Write([]byte("ping"))
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NoError(t, conn.(interface{ CloseWrite() error }).CloseWrite())
|
||||||
|
echoed, err := io.ReadAll(conn)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, "ping", string(echoed))
|
||||||
|
require.NoError(t, conn.Close())
|
||||||
|
|
||||||
|
conn, err = dialCommand("sh", "-c", "exec 3<&0; cat <&3 >/dev/null & echo 'no route to host' >&2; exit 255")
|
||||||
|
require.NoError(t, err)
|
||||||
|
_, err = io.ReadAll(conn)
|
||||||
|
require.ErrorContains(t, err, "no route to host")
|
||||||
|
require.NoError(t, conn.Close())
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
//go:build !WITHOUT_DOCKER && (darwin || netbsd)
|
||||||
|
|
||||||
|
package container
|
||||||
|
|
||||||
|
import "syscall"
|
||||||
|
|
||||||
|
func sshSysProcAttr() *syscall.SysProcAttr {
|
||||||
|
return &syscall.SysProcAttr{Setsid: true}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
//go:build !WITHOUT_DOCKER
|
||||||
|
|
||||||
|
package container
|
||||||
|
|
||||||
|
import "syscall"
|
||||||
|
|
||||||
|
func sshSysProcAttr() *syscall.SysProcAttr { return nil }
|
||||||
@@ -338,7 +338,7 @@ func (e *HostEnvironment) exec(ctx context.Context, command []string, cmdline st
|
|||||||
} else {
|
} else {
|
||||||
defer k.Close()
|
defer k.Close()
|
||||||
}
|
}
|
||||||
err = cmd.Wait()
|
err = treeKill.Wait(ctx, cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if exitErr, ok := errors.AsType[*exec.ExitError](err); ok {
|
if exitErr, ok := errors.AsType[*exec.ExitError](err); ok {
|
||||||
return ExitCodeError(exitErr.ExitCode())
|
return ExitCodeError(exitErr.ExitCode())
|
||||||
|
|||||||
@@ -93,17 +93,29 @@ func (p *KubernetesPod) JobContainer(input *NewContainerInput) ExecutionsEnviron
|
|||||||
return p.job
|
return p.job
|
||||||
}
|
}
|
||||||
|
|
||||||
var invalidLabelChars = regexp.MustCompile(`[^a-z0-9-]+`)
|
var (
|
||||||
|
invalidLabelChars = regexp.MustCompile(`[^a-z0-9-]+`)
|
||||||
|
dnsSubdomain = regexp.MustCompile(`^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$`)
|
||||||
|
)
|
||||||
|
|
||||||
// KubernetesServiceName returns the container name and hostname of service id, made a DNS label as both must be.
|
// kubernetesServiceName returns the container name of service id, made a DNS label as it must be.
|
||||||
func KubernetesServiceName(id string) string {
|
func kubernetesServiceName(id string) string {
|
||||||
name := strings.Trim(invalidLabelChars.ReplaceAllString(strings.ToLower(id), "-"), "-")
|
name := strings.Trim(invalidLabelChars.ReplaceAllString(strings.ToLower(id), "-"), "-")
|
||||||
return strings.TrimRight(name[:min(63, len(name))], "-")
|
return strings.TrimRight(name[:min(63, len(name))], "-")
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServiceContainer returns a container of the pod the job reaches at hostname KubernetesServiceName(id).
|
// KubernetesServiceHostnames returns the hostnames of service id, its container name and, where hostAliases accept it as a DNS subdomain, id lowercased.
|
||||||
|
func KubernetesServiceHostnames(id string) []string {
|
||||||
|
name, host := kubernetesServiceName(id), strings.ToLower(id)
|
||||||
|
if host != name && len(host) <= 253 && dnsSubdomain.MatchString(host) { // https://github.com/kubernetes/apimachinery/blob/v0.35.1/pkg/util/validation/validation.go#L198-L207
|
||||||
|
return []string{name, host}
|
||||||
|
}
|
||||||
|
return []string{name}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ServiceContainer returns a container of the pod the job reaches at KubernetesServiceHostnames(id).
|
||||||
func (p *KubernetesPod) ServiceContainer(id string, input *NewContainerInput) ExecutionsEnvironment {
|
func (p *KubernetesPod) ServiceContainer(id string, input *NewContainerInput) ExecutionsEnvironment {
|
||||||
service := &kubernetesContainer{pod: p, id: id, name: KubernetesServiceName(id), input: input}
|
service := &kubernetesContainer{pod: p, id: id, name: kubernetesServiceName(id), input: input}
|
||||||
p.services = append(p.services, service)
|
p.services = append(p.services, service)
|
||||||
return service
|
return service
|
||||||
}
|
}
|
||||||
@@ -131,7 +143,7 @@ func (p *KubernetesPod) create(ctx context.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, service := range p.services {
|
for _, service := range p.services {
|
||||||
if !strings.EqualFold(service.id, service.name) {
|
if !slices.ContainsFunc(KubernetesServiceHostnames(service.id), func(hostname string) bool { return strings.EqualFold(hostname, service.id) }) { // glibc and Go match /etc/hosts case-insensitively
|
||||||
common.Logger(ctx).Warnf("Service %s is reachable as %s or localhost, as a Kubernetes hostname cannot be %q", service.id, service.name, service.id)
|
common.Logger(ctx).Warnf("Service %s is reachable as %s or localhost, as a Kubernetes hostname cannot be %q", service.id, service.name, service.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -165,7 +177,8 @@ func (p *KubernetesPod) manifest(secret string, secretData map[string]string, me
|
|||||||
serviceTemplate = templateContainers[index]
|
serviceTemplate = templateContainers[index]
|
||||||
templateSpec["containers"] = slices.Delete(slices.Clone(templateContainers), index, index+1)
|
templateSpec["containers"] = slices.Delete(slices.Clone(templateContainers), index, index+1)
|
||||||
}
|
}
|
||||||
var containers, hostnames, volumes []any
|
var containers, volumes []any
|
||||||
|
var hostnames []string
|
||||||
names := map[string]bool{}
|
names := map[string]bool{}
|
||||||
for _, container := range templateContainers {
|
for _, container := range templateContainers {
|
||||||
names[manifestField(container, "name")] = true
|
names[manifestField(container, "name")] = true
|
||||||
@@ -184,7 +197,7 @@ func (p *KubernetesPod) manifest(secret string, secretData map[string]string, me
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
containers = append(containers, mergeManifest(serviceTemplate, spec, ""))
|
containers = append(containers, mergeManifest(serviceTemplate, spec, ""))
|
||||||
hostnames = append(hostnames, c.name)
|
hostnames = append(hostnames, KubernetesServiceHostnames(c.id)...)
|
||||||
}
|
}
|
||||||
for _, name := range []string{"workspace", "act"} {
|
for _, name := range []string{"workspace", "act"} {
|
||||||
if !slices.ContainsFunc(templateVolumes, func(volume any) bool { return manifestField(volume, "name") == name }) {
|
if !slices.ContainsFunc(templateVolumes, func(volume any) bool { return manifestField(volume, "name") == name }) {
|
||||||
|
|||||||
@@ -129,6 +129,19 @@ func serveLocalExec(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestKubernetesServiceHostnames(t *testing.T) {
|
||||||
|
for id, hostnames := range map[string][]string{
|
||||||
|
"db": {"db"},
|
||||||
|
"My_DB": {"my-db"},
|
||||||
|
"devstoreaccount1.azurite.local": {"devstoreaccount1-azurite-local", "devstoreaccount1.azurite.local"},
|
||||||
|
"DB.Local": {"db-local", "db.local"},
|
||||||
|
strings.Repeat("a", 64): {strings.Repeat("a", 63), strings.Repeat("a", 64)},
|
||||||
|
strings.Repeat("a", 254): {strings.Repeat("a", 63)},
|
||||||
|
} {
|
||||||
|
assert.Equal(t, hostnames, KubernetesServiceHostnames(id), id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestKubernetesPodRunsJobThroughAPI(t *testing.T) {
|
func TestKubernetesPodRunsJobThroughAPI(t *testing.T) {
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
t.Skip("uses POSIX shell")
|
t.Skip("uses POSIX shell")
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
package container
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"slices"
|
||||||
|
"strings"
|
||||||
|
"unicode"
|
||||||
|
"unicode/utf8"
|
||||||
|
|
||||||
|
"github.com/moby/moby/api/types/mount"
|
||||||
|
)
|
||||||
|
|
||||||
|
type VolumeSpec struct {
|
||||||
|
Type mount.Type
|
||||||
|
Source string
|
||||||
|
Target string
|
||||||
|
ReadOnly bool
|
||||||
|
NoCopy bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// ParseVolume parses spec like `docker run -v` does, without knowing the target platform.
|
||||||
|
func ParseVolume(spec string) (VolumeSpec, error) {
|
||||||
|
switch len(spec) {
|
||||||
|
case 0:
|
||||||
|
return VolumeSpec{}, errors.New("invalid empty volume spec")
|
||||||
|
case 1, 2:
|
||||||
|
return VolumeSpec{Type: mount.TypeVolume, Target: spec}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
spec = string([]rune(spec)) // each invalid UTF-8 byte becomes U+FFFD, as in the JSON the daemon receives
|
||||||
|
var parts []string
|
||||||
|
for rest := spec; ; {
|
||||||
|
start := 0
|
||||||
|
if hasDriveLetter(rest) {
|
||||||
|
start = strings.IndexByte(rest, ':') + 1
|
||||||
|
}
|
||||||
|
end := strings.IndexByte(rest[start:], ':')
|
||||||
|
if end < 0 {
|
||||||
|
parts = append(parts, rest)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
parts = append(parts, rest[:start+end])
|
||||||
|
rest = rest[start+end+1:]
|
||||||
|
}
|
||||||
|
if len(parts) > 3 {
|
||||||
|
return VolumeSpec{}, fmt.Errorf("invalid spec: %s: too many colons", spec)
|
||||||
|
}
|
||||||
|
if slices.Contains(parts, "") {
|
||||||
|
return VolumeSpec{}, fmt.Errorf("invalid spec: %s: empty section between colons", spec)
|
||||||
|
}
|
||||||
|
|
||||||
|
volume := VolumeSpec{Type: mount.TypeVolume, Target: parts[0]}
|
||||||
|
if len(parts) > 1 {
|
||||||
|
volume.Source, volume.Target = parts[0], parts[1]
|
||||||
|
if isHostPath(volume.Source) {
|
||||||
|
volume.Type = mount.TypeBind
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(parts) == 3 {
|
||||||
|
for option := range strings.SplitSeq(parts[2], ",") {
|
||||||
|
switch option {
|
||||||
|
case "ro":
|
||||||
|
volume.ReadOnly = true
|
||||||
|
case "rw":
|
||||||
|
volume.ReadOnly = false
|
||||||
|
case "nocopy":
|
||||||
|
volume.NoCopy = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return volume, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func hasDriveLetter(s string) bool {
|
||||||
|
letter, size := utf8.DecodeRuneInString(s)
|
||||||
|
return size < len(s) && s[size] == ':' && unicode.IsLetter(letter)
|
||||||
|
}
|
||||||
|
|
||||||
|
func isHostPath(source string) bool {
|
||||||
|
return strings.ContainsAny(source[:1], "./~") || strings.HasPrefix(source, `\\`) || hasDriveLetter(source)
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
package container
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/moby/moby/api/types/mount"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestParseVolumeReplacesInvalidUTF8LikeTheDaemonSees(t *testing.T) {
|
||||||
|
parsed, err := ParseVolume("/data/\xff\xfe:/mnt:ro")
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, VolumeSpec{Type: mount.TypeBind, Source: "/data/��", Target: "/mnt", ReadOnly: true}, parsed)
|
||||||
|
}
|
||||||
+13
-24
@@ -91,7 +91,7 @@ func readActionImpl(ctx context.Context, step *model.Step, actionDir, actionPath
|
|||||||
if b, err = trampoline.ReadFile("res/trampoline.js"); err != nil {
|
if b, err = trampoline.ReadFile("res/trampoline.js"); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
err2 := writeFile(filepath.Join(actionDir, actionPath, "trampoline.js"), b, 0o400)
|
err2 := writeFile(filepath.Join(actionDir, actionPath, "trampoline.js"), b, 0o644)
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
return nil, err2
|
return nil, err2
|
||||||
}
|
}
|
||||||
@@ -152,11 +152,11 @@ func maybeCopyToActionDir(ctx context.Context, step actionStep, actionDir, actio
|
|||||||
defer unlock()
|
defer unlock()
|
||||||
|
|
||||||
if !rc.Config.NoActionPatch {
|
if !rc.Config.NoActionPatch {
|
||||||
// A concurrent job's prepare resets this directory, so patch under the copy's lock.
|
// Other jobs share the directory, so patch under the copy's lock.
|
||||||
defer patchActions(ctx, actionScriptPaths(filepath.Join(actionDir, actionPath), step.getActionModel()))()
|
defer patchActions(ctx, actionScriptPaths(filepath.Join(actionDir, actionPath), step.getActionModel()))()
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc.JobContainer.CopyDir(containerActionDirCopy, actionDir+"/", rc.Config.UseGitIgnore, true)(ctx)
|
return rc.JobContainer.CopyDir(containerActionDirCopy, actionDir+"/", false, true)(ctx) // an exported commit has no .git to apply gitignore with
|
||||||
}
|
}
|
||||||
|
|
||||||
func runActionImpl(step actionStep, actionDir string, remoteAction *remoteAction) common.Executor {
|
func runActionImpl(step actionStep, actionDir string, remoteAction *remoteAction) common.Executor {
|
||||||
@@ -179,7 +179,7 @@ func runActionImpl(step actionStep, actionDir string, remoteAction *remoteAction
|
|||||||
}
|
}
|
||||||
|
|
||||||
actionLocation := path.Join(actionDir, actionPath)
|
actionLocation := path.Join(actionDir, actionPath)
|
||||||
actionName, containerActionDir := getContainerActionPaths(stepModel, actionLocation, rc)
|
actionName, containerActionDir := getContainerActionPaths(step)
|
||||||
|
|
||||||
logger.Debugf("type=%v actionDir=%s actionPath=%s workdir=%s actionCacheDir=%s actionName=%s containerActionDir=%s", stepModel.Type(), actionDir, actionPath, rc.Config.Workdir, rc.ActionCacheDir(), actionName, containerActionDir)
|
logger.Debugf("type=%v actionDir=%s actionPath=%s workdir=%s actionCacheDir=%s actionName=%s containerActionDir=%s", stepModel.Type(), actionDir, actionPath, rc.Config.Workdir, rc.ActionCacheDir(), actionName, containerActionDir)
|
||||||
|
|
||||||
@@ -509,25 +509,14 @@ func populateEnvsFromInput(ctx context.Context, env *map[string]string, action *
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getContainerActionPaths(step *model.Step, actionDir string, rc *RunContext) (string, string) {
|
func getContainerActionPaths(step actionStep) (string, string) {
|
||||||
actionName := ""
|
rc := step.getRunContext()
|
||||||
containerActionDir := "."
|
if sar, ok := step.(*stepActionRemote); ok { // a copy per action, as its repository's directory is shared
|
||||||
if step.Type() != model.StepTypeUsesActionRemote {
|
actionName := path.Join(sar.containerKey(), sar.remoteAction.Path)
|
||||||
actionName = getOsSafeRelativePath(actionDir, rc.Config.Workdir)
|
return actionName, rc.JobContainer.GetActPath() + "/actions/" + actionName
|
||||||
containerActionDir = rc.JobContainer.ToContainerPath(rc.Config.Workdir) + "/" + actionName
|
|
||||||
actionName = "./" + actionName
|
|
||||||
} else if step.Type() == model.StepTypeUsesActionRemote {
|
|
||||||
actionName = getOsSafeRelativePath(actionDir, rc.ActionCacheDir())
|
|
||||||
containerActionDir = rc.JobContainer.GetActPath() + "/actions/" + actionName
|
|
||||||
}
|
}
|
||||||
|
actionName := getOsSafeRelativePath(filepath.Join(rc.Config.Workdir, step.getStepModel().Uses), rc.Config.Workdir)
|
||||||
if actionName == "" {
|
return "./" + actionName, rc.JobContainer.ToContainerPath(rc.Config.Workdir) + "/" + actionName
|
||||||
actionName = filepath.Base(actionDir)
|
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
actionName = strings.ReplaceAll(actionName, "\\", "/")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return actionName, containerActionDir
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getOsSafeRelativePath(s, prefix string) string {
|
func getOsSafeRelativePath(s, prefix string) string {
|
||||||
@@ -573,13 +562,13 @@ func actionStagePaths(step actionStep) (actionDir, actionPath, actionName, conta
|
|||||||
stepModel := step.getStepModel()
|
stepModel := step.getStepModel()
|
||||||
|
|
||||||
if sar, ok := step.(*stepActionRemote); ok {
|
if sar, ok := step.(*stepActionRemote); ok {
|
||||||
actionDir = sar.actionDir()
|
actionDir = sar.actionDir
|
||||||
actionPath = sar.remoteAction.Path
|
actionPath = sar.remoteAction.Path
|
||||||
} else {
|
} else {
|
||||||
actionDir = filepath.Join(rc.Config.Workdir, stepModel.Uses)
|
actionDir = filepath.Join(rc.Config.Workdir, stepModel.Uses)
|
||||||
}
|
}
|
||||||
|
|
||||||
actionName, containerActionDir = getContainerActionPaths(stepModel, path.Join(actionDir, actionPath), rc)
|
actionName, containerActionDir = getContainerActionPaths(step)
|
||||||
return actionDir, actionPath, actionName, containerActionDir
|
return actionDir, actionPath, actionName, containerActionDir
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,9 +4,9 @@
|
|||||||
package runner
|
package runner
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"gitea.com/gitea/runner/act/common"
|
|
||||||
"gitea.com/gitea/runner/act/common/git"
|
"gitea.com/gitea/runner/act/common/git"
|
||||||
|
|
||||||
"gitea.dev/actionslib/pkg/model"
|
"gitea.dev/actionslib/pkg/model"
|
||||||
@@ -50,7 +50,9 @@ func TestCompositeActionParity(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("propagates pre failures", func(t *testing.T) {
|
t.Run("propagates pre failures", func(t *testing.T) {
|
||||||
setCloneExecutor(t, func(git.NewGitCloneExecutorInput) common.Executor { return common.NewErrorExecutor(assert.AnError) })
|
setFetch(t, func(_ctx context.Context, _input git.NewGitCloneExecutorInput) (string, string, error) {
|
||||||
|
return "", "", assert.AnError
|
||||||
|
})
|
||||||
rc := &RunContext{
|
rc := &RunContext{
|
||||||
Config: &Config{GitHubInstance: "github.com", ActionCacheDir: t.TempDir()},
|
Config: &Config{GitHubInstance: "github.com", ActionCacheDir: t.TempDir()},
|
||||||
Run: &model.Run{JobID: "job", Workflow: &model.Workflow{Jobs: map[string]*model.Job{"job": {}}}},
|
Run: &model.Run{JobID: "job", Workflow: &model.Workflow{Jobs: map[string]*model.Job{"job": {}}}},
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ runs:
|
|||||||
|
|
||||||
writeFile := func(filename string, data []byte, perm fs.FileMode) error {
|
writeFile := func(filename string, data []byte, perm fs.FileMode) error {
|
||||||
assert.Equal(t, "actionDir/actionPath/trampoline.js", filename)
|
assert.Equal(t, "actionDir/actionPath/trampoline.js", filename)
|
||||||
assert.Equal(t, fs.FileMode(0o400), perm)
|
assert.Equal(t, fs.FileMode(0o644), perm)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,7 +178,8 @@ func TestActionRunner(t *testing.T) {
|
|||||||
Using: "node16",
|
Using: "node16",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
env: map[string]string{},
|
env: map[string]string{},
|
||||||
|
remoteAction: mustNewRemoteAction(t, "org/repo/path@ref"),
|
||||||
},
|
},
|
||||||
expectedEnv: map[string]string{"INPUT_KEY": "default value"},
|
expectedEnv: map[string]string{"INPUT_KEY": "default value"},
|
||||||
},
|
},
|
||||||
@@ -217,7 +218,8 @@ func TestActionRunner(t *testing.T) {
|
|||||||
Using: "node16",
|
Using: "node16",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
env: map[string]string{},
|
env: map[string]string{},
|
||||||
|
remoteAction: mustNewRemoteAction(t, "org/repo/path@ref"),
|
||||||
},
|
},
|
||||||
expectedEnv: map[string]string{"STATE_name": "state value"},
|
expectedEnv: map[string]string{"STATE_name": "state value"},
|
||||||
},
|
},
|
||||||
@@ -228,7 +230,8 @@ func TestActionRunner(t *testing.T) {
|
|||||||
ctx := t.Context()
|
ctx := t.Context()
|
||||||
|
|
||||||
cm := &containerMock{}
|
cm := &containerMock{}
|
||||||
cm.On("CopyDir", "/var/run/act/actions/dir/", "dir/", false, true).Return(func(ctx context.Context) error { return nil })
|
containerActionDir := "/var/run/act/actions/" + model.UsesHash("/org/repo/path@ref") + "/"
|
||||||
|
cm.On("CopyDir", containerActionDir, "dir/", false, true).Return(func(ctx context.Context) error { return nil })
|
||||||
|
|
||||||
envMatcher := mock.MatchedBy(func(env map[string]string) bool {
|
envMatcher := mock.MatchedBy(func(env map[string]string) bool {
|
||||||
for k, v := range tt.expectedEnv {
|
for k, v := range tt.expectedEnv {
|
||||||
@@ -239,7 +242,7 @@ func TestActionRunner(t *testing.T) {
|
|||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
cm.On("Exec", []string{"node", "--preserve-symlinks-main", "/var/run/act/actions/dir/path"}, envMatcher, "", "").Return(func(ctx context.Context) error { return nil })
|
cm.On("Exec", []string{"node", "--preserve-symlinks-main", containerActionDir + "path"}, envMatcher, "", "").Return(func(ctx context.Context) error { return nil })
|
||||||
|
|
||||||
tt.step.getRunContext().JobContainer = cm
|
tt.step.getRunContext().JobContainer = cm
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ func reportStepError(ctx context.Context, rc *RunContext, err error) {
|
|||||||
// executor can fetch all of them up front.
|
// executor can fetch all of them up front.
|
||||||
type actionPreparer interface {
|
type actionPreparer interface {
|
||||||
prepareActionExecutor() common.Executor
|
prepareActionExecutor() common.Executor
|
||||||
actionDownloadInfo() (reference, sha string, ok bool)
|
actionDownloadInfo() (reference, sha string)
|
||||||
}
|
}
|
||||||
|
|
||||||
// printPrepareActions downloads every action the job uses before its first step runs and reports
|
// printPrepareActions downloads every action the job uses before its first step runs and reports
|
||||||
@@ -101,15 +101,11 @@ func printPrepareActions(rc *RunContext, preparers []actionPreparer) common.Exec
|
|||||||
reportStepError(ctx, rc, err)
|
reportStepError(ctx, rc, err)
|
||||||
return setupError{err}
|
return setupError{err}
|
||||||
}
|
}
|
||||||
reference, sha, ok := preparer.actionDownloadInfo()
|
reference, sha := preparer.actionDownloadInfo()
|
||||||
if !ok {
|
if sha == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if sha == "" {
|
rawLogger.Infof("Download action repository '%s' (SHA:%s)", reference, sha)
|
||||||
rawLogger.Infof("Download action repository '%s'", reference)
|
|
||||||
} else {
|
|
||||||
rawLogger.Infof("Download action repository '%s' (SHA:%s)", reference, sha)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,7 +118,6 @@ func (sfm *stepFactoryMock) newStep(model *model.Step, rc *RunContext) (step, er
|
|||||||
type actionPreparerMock struct {
|
type actionPreparerMock struct {
|
||||||
reference string
|
reference string
|
||||||
sha string
|
sha string
|
||||||
ok bool
|
|
||||||
err error
|
err error
|
||||||
prepared int
|
prepared int
|
||||||
}
|
}
|
||||||
@@ -130,8 +129,8 @@ func (apm *actionPreparerMock) prepareActionExecutor() common.Executor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (apm *actionPreparerMock) actionDownloadInfo() (string, string, bool) {
|
func (apm *actionPreparerMock) actionDownloadInfo() (string, string) {
|
||||||
return apm.reference, apm.sha, apm.ok
|
return apm.reference, apm.sha
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrintPrepareActionsGolden(t *testing.T) {
|
func TestPrintPrepareActionsGolden(t *testing.T) {
|
||||||
@@ -140,18 +139,15 @@ func TestPrintPrepareActionsGolden(t *testing.T) {
|
|||||||
ctx := common.WithLogger(t.Context(), logger.With("job", "j1"))
|
ctx := common.WithLogger(t.Context(), logger.With("job", "j1"))
|
||||||
|
|
||||||
preparers := []actionPreparer{
|
preparers := []actionPreparer{
|
||||||
&actionPreparerMock{reference: "actions/checkout@v7", sha: "9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0", ok: true},
|
&actionPreparerMock{reference: "actions/checkout@v7", sha: "9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0"},
|
||||||
// A resolved commit is best effort; the ref alone is reported when it is unknown.
|
|
||||||
&actionPreparerMock{reference: "actions/setup-go@v6", ok: true},
|
|
||||||
// A step that downloads nothing, such as the checkout of the workflow's own repository.
|
// A step that downloads nothing, such as the checkout of the workflow's own repository.
|
||||||
&actionPreparerMock{ok: false},
|
&actionPreparerMock{},
|
||||||
}
|
}
|
||||||
require.NoError(t, printPrepareActions(&RunContext{}, preparers)(ctx))
|
require.NoError(t, printPrepareActions(&RunContext{}, preparers)(ctx))
|
||||||
|
|
||||||
want := strings.Join([]string{
|
want := strings.Join([]string{
|
||||||
"[j1] | Prepare all required actions",
|
"[j1] | Prepare all required actions",
|
||||||
"[j1] | Download action repository 'actions/checkout@v7' (SHA:9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0)",
|
"[j1] | Download action repository 'actions/checkout@v7' (SHA:9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0)",
|
||||||
"[j1] | Download action repository 'actions/setup-go@v6'",
|
|
||||||
"",
|
"",
|
||||||
}, "\n")
|
}, "\n")
|
||||||
assert.Equal(t, want, buf.String())
|
assert.Equal(t, want, buf.String())
|
||||||
@@ -173,7 +169,7 @@ func TestPrintPrepareActionsFailsJobOnDownloadError(t *testing.T) {
|
|||||||
|
|
||||||
downloadErr := errors.New("failed to fetch \"actions/checkout\"")
|
downloadErr := errors.New("failed to fetch \"actions/checkout\"")
|
||||||
rc := &RunContext{}
|
rc := &RunContext{}
|
||||||
remaining := &actionPreparerMock{reference: "actions/setup-go@v6", ok: true}
|
remaining := &actionPreparerMock{reference: "actions/setup-go@v6", sha: "sha"}
|
||||||
|
|
||||||
err := printPrepareActions(rc, []actionPreparer{
|
err := printPrepareActions(rc, []actionPreparer{
|
||||||
&actionPreparerMock{err: downloadErr},
|
&actionPreparerMock{err: downloadErr},
|
||||||
@@ -267,7 +263,7 @@ func TestNewJobExecutorDownloadsAllActionsBeforeTheFirstStep(t *testing.T) {
|
|||||||
|
|
||||||
for _, stepModel := range steps {
|
for _, stepModel := range steps {
|
||||||
sm := &stepMock{}
|
sm := &stepMock{}
|
||||||
apm := &actionPreparerMock{reference: "actions/checkout@v" + stepModel.ID, ok: true}
|
apm := &actionPreparerMock{reference: "actions/checkout@v" + stepModel.ID, sha: "sha" + stepModel.ID}
|
||||||
sfm.On("newStep", stepModel, rc).Return(&actionStepMock{stepMock: sm, actionPreparerMock: apm}, nil)
|
sfm.On("newStep", stepModel, rc).Return(&actionStepMock{stepMock: sm, actionPreparerMock: apm}, nil)
|
||||||
|
|
||||||
sm.On("pre").Return(func(ctx context.Context) error {
|
sm.On("pre").Return(func(ctx context.Context) error {
|
||||||
@@ -304,8 +300,8 @@ func TestNewJobExecutorDownloadsAllActionsBeforeTheFirstStep(t *testing.T) {
|
|||||||
}
|
}
|
||||||
assert.Equal(t, []string{
|
assert.Equal(t, []string{
|
||||||
"Prepare all required actions",
|
"Prepare all required actions",
|
||||||
"Download action repository 'actions/checkout@v1'",
|
"Download action repository 'actions/checkout@v1' (SHA:sha1)",
|
||||||
"Download action repository 'actions/checkout@v2'",
|
"Download action repository 'actions/checkout@v2' (SHA:sha2)",
|
||||||
"Complete job name: test",
|
"Complete job name: test",
|
||||||
"Run Pre 1",
|
"Run Pre 1",
|
||||||
"Run Pre 2",
|
"Run Pre 2",
|
||||||
|
|||||||
@@ -200,21 +200,21 @@ func TestPatchedBundleAcrossActions(t *testing.T) {
|
|||||||
// The cache toolkit, in each bundler shape and from a spread of ecosystems, including the
|
// The cache toolkit, in each bundler shape and from a spread of ecosystems, including the
|
||||||
// actions that drive a Go or a Rust cache client of their own.
|
// actions that drive a Go or a Rust cache client of their own.
|
||||||
{"actions/cache", actionsCacheRef, "dist/restore/index.js", true},
|
{"actions/cache", actionsCacheRef, "dist/restore/index.js", true},
|
||||||
{"actions/setup-node", "v7.0.0", "dist/cache-save/index.js", true},
|
{"actions/setup-node", "v7.1.0", "dist/cache-save/index.js", true},
|
||||||
{"actions/setup-python", "v7.0.0", "dist/setup/index.js", true},
|
{"actions/setup-python", "v7.0.0", "dist/setup/index.js", true},
|
||||||
{"actions/setup-go", "v7.0.0", "dist/setup/index.js", true},
|
{"actions/setup-go", "v7.0.0", "dist/setup/index.js", true},
|
||||||
{"actions/setup-java", "v5.7.0", "dist/setup/index.js", true},
|
{"actions/setup-java", "v5.7.0", "dist/setup/index.js", true},
|
||||||
{"ruby/setup-ruby", "v1.321.0", "dist/index.js", true},
|
{"ruby/setup-ruby", "v1.331.0", "dist/index.js", true},
|
||||||
{"pnpm/action-setup", "v6.0.9", "dist/index.js", true},
|
{"pnpm/action-setup", "v6.1.0", "dist/index.js", true},
|
||||||
{"oven-sh/setup-bun", "v2.2.0", "dist/setup/index.js", true},
|
{"oven-sh/setup-bun", "v2.2.0", "dist/setup/index.js", true},
|
||||||
{"Swatinem/rust-cache", "v2.9.1", "dist/restore/index.js", true},
|
{"Swatinem/rust-cache", "v2.9.1", "dist/restore/index.js", true},
|
||||||
{"docker/build-push-action", "v7.3.0", "dist/index.cjs", true},
|
{"docker/build-push-action", "v7.4.0", "dist/index.cjs", true},
|
||||||
// The artifact toolkit, where the gate is a refusal and there is nothing to redirect.
|
// The artifact toolkit, where the gate is a refusal and there is nothing to redirect.
|
||||||
// v4.4.0 is the first release whose gate carries the localhost test this matches; the
|
// v4.4.0 is the first release whose gate carries the localhost test this matches; the
|
||||||
// releases before it refuse in a shape the runner leaves alone.
|
// releases before it refuse in a shape the runner leaves alone.
|
||||||
{"actions/upload-artifact", "v4.4.0", "dist/upload/index.js", true},
|
{"actions/upload-artifact", "v4.4.0", "dist/upload/index.js", true},
|
||||||
{"actions/upload-artifact", "v7.0.1", "dist/upload/index.js", true},
|
{"actions/upload-artifact", "v7.0.2", "dist/upload/index.js", true},
|
||||||
{"actions/download-artifact", "v8.0.1", "dist/index.js", true},
|
{"actions/download-artifact", "v8.0.2", "dist/index.js", true},
|
||||||
// Neither toolkit's gate, so these have to come back byte for byte. sccache-action is the
|
// Neither toolkit's gate, so these have to come back byte for byte. sccache-action is the
|
||||||
// one that exports ACTIONS_CACHE_SERVICE_V2 itself, for the Rust client it installs.
|
// one that exports ACTIONS_CACHE_SERVICE_V2 itself, for the Rust client it installs.
|
||||||
{"actions/checkout", "v7.0.1", "dist/index.js", false},
|
{"actions/checkout", "v7.0.1", "dist/index.js", false},
|
||||||
@@ -297,7 +297,7 @@ func TestUploadArtifactThroughTheResultsService(t *testing.T) {
|
|||||||
token := "e30." + base64.RawURLEncoding.EncodeToString([]byte(`{"scp":"Actions.Results:11:22"}`)) + ".sig"
|
token := "e30." + base64.RawURLEncoding.EncodeToString([]byte(`{"scp":"Actions.Results:11:22"}`)) + ".sig"
|
||||||
defer handler.RegisterJob(token, artifactcache.JobCredential{Repo: "testuser/testrepo", Results: gitea.URL})()
|
defer handler.RegisterJob(token, artifactcache.JobCredential{Repo: "testuser/testrepo", Results: gitea.URL})()
|
||||||
|
|
||||||
upload := patchedAction(t, "actions/upload-artifact", "v7.0.1", "dist/upload/index.js")
|
upload := patchedAction(t, "actions/upload-artifact", "v7.0.2", "dist/upload/index.js")
|
||||||
|
|
||||||
env := jobEnv{
|
env := jobEnv{
|
||||||
workspace: tempDirPath(t),
|
workspace: tempDirPath(t),
|
||||||
@@ -319,7 +319,7 @@ func TestUploadArtifactThroughTheResultsService(t *testing.T) {
|
|||||||
|
|
||||||
// And back down again: listing and downloading go the same way, and the signed URL the
|
// And back down again: listing and downloading go the same way, and the signed URL the
|
||||||
// artifact service hands out is fetched straight from it.
|
// artifact service hands out is fetched straight from it.
|
||||||
download := patchedAction(t, "actions/download-artifact", "v8.0.1", "dist/index.js")
|
download := patchedAction(t, "actions/download-artifact", "v8.0.2", "dist/index.js")
|
||||||
env.workspace = tempDirPath(t)
|
env.workspace = tempDirPath(t)
|
||||||
out = runActionEntrypoint(t, download, env, map[string]string{
|
out = runActionEntrypoint(t, download, env, map[string]string{
|
||||||
"name": "an-artifact", "path": "downloaded", "merge-multiple": "false",
|
"name": "an-artifact", "path": "downloaded", "merge-multiple": "false",
|
||||||
@@ -341,7 +341,7 @@ func TestUploadArtifactThroughTheResultsService(t *testing.T) {
|
|||||||
func TestSetupActionFindsTheCacheService(t *testing.T) {
|
func TestSetupActionFindsTheCacheService(t *testing.T) {
|
||||||
requireHostTools(t, "node", "npm")
|
requireHostTools(t, "node", "npm")
|
||||||
|
|
||||||
setup := patchedAction(t, "actions/setup-node", "v7.0.0", "dist/setup/index.js")
|
setup := patchedAction(t, "actions/setup-node", "v7.1.0", "dist/setup/index.js")
|
||||||
|
|
||||||
handler, err := artifactcache.StartHandler(artifactcache.Options{Dir: filepath.Join(t.TempDir(), "cache"), OutboundIP: "127.0.0.1"})
|
handler, err := artifactcache.StartHandler(artifactcache.Options{Dir: filepath.Join(t.TempDir(), "cache"), OutboundIP: "127.0.0.1"})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|||||||
@@ -223,8 +223,6 @@ func TestActionScriptPaths(t *testing.T) {
|
|||||||
assert.Nil(t, actionScriptPaths("/a", escaping))
|
assert.Nil(t, actionScriptPaths("/a", escaping))
|
||||||
}
|
}
|
||||||
|
|
||||||
// The bundle has to be patched whatever state the shared action directory is in, because a
|
|
||||||
// concurrent job's prepare checks the action out again and resets it.
|
|
||||||
func TestPatchActionsAtTheContainerCopy(t *testing.T) {
|
func TestPatchActionsAtTheContainerCopy(t *testing.T) {
|
||||||
copiedBundle := func(t *testing.T, noPatch bool) string {
|
copiedBundle := func(t *testing.T, noPatch bool) string {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
@@ -234,12 +232,13 @@ func TestPatchActionsAtTheContainerCopy(t *testing.T) {
|
|||||||
Step: &model.Step{Uses: "owner/repo/sub@v1"},
|
Step: &model.Step{Uses: "owner/repo/sub@v1"},
|
||||||
remoteAction: &remoteAction{Org: "owner", Repo: "repo", Path: "sub", Ref: "v1"},
|
remoteAction: &remoteAction{Org: "owner", Repo: "repo", Path: "sub", Ref: "v1"},
|
||||||
action: &model.Action{Runs: model.ActionRuns{Using: "node20", Main: "index.js"}},
|
action: &model.Action{Runs: model.ActionRuns{Using: "node20", Main: "index.js"}},
|
||||||
|
actionDir: t.TempDir(),
|
||||||
RunContext: &RunContext{
|
RunContext: &RunContext{
|
||||||
Config: &Config{ActionCacheDir: t.TempDir(), NoActionPatch: noPatch},
|
Config: &Config{ActionCacheDir: t.TempDir(), NoActionPatch: noPatch},
|
||||||
JobContainer: cm,
|
JobContainer: cm,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
script := filepath.Join(sar.actionDir(), "sub", "index.js")
|
script := filepath.Join(sar.actionDir, "sub", "index.js")
|
||||||
require.NoError(t, os.MkdirAll(filepath.Dir(script), 0o755))
|
require.NoError(t, os.MkdirAll(filepath.Dir(script), 0o755))
|
||||||
require.NoError(t, os.WriteFile(script, []byte(gateTSC), 0o600))
|
require.NoError(t, os.WriteFile(script, []byte(gateTSC), 0o600))
|
||||||
|
|
||||||
@@ -250,7 +249,7 @@ func TestPatchActionsAtTheContainerCopy(t *testing.T) {
|
|||||||
copied = string(body)
|
copied = string(body)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
require.NoError(t, maybeCopyToActionDir(t.Context(), sar, sar.actionDir(), "sub", "/var/run/act/actions/repo/sub"))
|
require.NoError(t, maybeCopyToActionDir(t.Context(), sar, sar.actionDir, "sub", "/var/run/act/actions/repo/sub"))
|
||||||
source, err := os.ReadFile(script)
|
source, err := os.ReadFile(script)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, gateTSC, string(source), "the shared copy is left as it was found")
|
assert.Equal(t, gateTSC, string(source), "the shared copy is left as it was found")
|
||||||
|
|||||||
@@ -209,7 +209,9 @@ func (c Config) withInstanceAuth(input git.NewGitCloneExecutorInput, token strin
|
|||||||
return input
|
return input
|
||||||
}
|
}
|
||||||
input.ClientCertFile, input.ClientKeyFile = c.ClientCertFile, c.ClientKeyFile
|
input.ClientCertFile, input.ClientKeyFile = c.ClientCertFile, c.ClientKeyFile
|
||||||
input.InsecureSkipTLS = c.InsecureSkipTLS && onInstanceHost(u.Host, c.GitHubInstance)
|
if onInstanceHost(u.Host, c.GitHubInstance) {
|
||||||
|
input.InsecureSkipTLS, input.Transport = c.InsecureSkipTLS, c.InstanceTransport
|
||||||
|
}
|
||||||
if u.User == nil {
|
if u.User == nil {
|
||||||
input.Token = token
|
input.Token = token
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -185,8 +185,12 @@ func TestInstanceAuthAndTransportOnlyApplyToTheInstance(t *testing.T) {
|
|||||||
InsecureSkipTLS: true,
|
InsecureSkipTLS: true,
|
||||||
ClientCertFile: "/cert",
|
ClientCertFile: "/cert",
|
||||||
ClientKeyFile: "/key",
|
ClientKeyFile: "/key",
|
||||||
|
InstanceTransport: &http.Transport{},
|
||||||
}
|
}
|
||||||
want := git.NewGitCloneExecutorInput{URL: tt.cloneURL, InsecureSkipTLS: tt.insecure}
|
want := git.NewGitCloneExecutorInput{URL: tt.cloneURL, InsecureSkipTLS: tt.insecure}
|
||||||
|
if tt.insecure {
|
||||||
|
want.Transport = conf.InstanceTransport
|
||||||
|
}
|
||||||
if tt.token {
|
if tt.token {
|
||||||
want.Token = "token"
|
want.Token = "token"
|
||||||
}
|
}
|
||||||
|
|||||||
+39
-15
@@ -22,6 +22,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"runtime/debug"
|
||||||
"slices"
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -35,11 +36,9 @@ import (
|
|||||||
|
|
||||||
"gitea.dev/actionslib/pkg/exprparser"
|
"gitea.dev/actionslib/pkg/exprparser"
|
||||||
"gitea.dev/actionslib/pkg/model"
|
"gitea.dev/actionslib/pkg/model"
|
||||||
"github.com/docker/cli/cli/compose/loader"
|
|
||||||
"github.com/docker/go-connections/nat"
|
"github.com/docker/go-connections/nat"
|
||||||
"github.com/kballard/go-shellquote"
|
"github.com/kballard/go-shellquote"
|
||||||
"github.com/moby/moby/api/types/mount"
|
"github.com/moby/moby/api/types/mount"
|
||||||
"github.com/opencontainers/selinux/go-selinux"
|
|
||||||
"go.yaml.in/yaml/v4"
|
"go.yaml.in/yaml/v4"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
"golang.org/x/text/encoding/unicode"
|
"golang.org/x/text/encoding/unicode"
|
||||||
@@ -83,8 +82,9 @@ type RunContext struct {
|
|||||||
platformImage string // container.image or the runs-on pick, resolved once by isEnabled
|
platformImage string // container.image or the runs-on pick, resolved once by isEnabled
|
||||||
jobIndex, jobTotal int // strategy.job-index and job-total, total 0 when unknown
|
jobIndex, jobTotal int // strategy.job-index and job-total, total 0 when unknown
|
||||||
|
|
||||||
jobEnv map[string]string // workflow and job env as evaluated for the container and service specs
|
jobEnv map[string]string // workflow and job env as evaluated for the container and service specs
|
||||||
dockerActionImages map[*model.Step]string // Dockerfile action images built for this job, removed when it ends
|
dockerActionImages map[*model.Step]string // Dockerfile action images built for this job, removed when it ends
|
||||||
|
actionDownloads map[string]actionDownload // remote action repositories by clone URL and ref, fetched once per job
|
||||||
|
|
||||||
// summaryFileInitialized tracks which per-step summary files (workflow/step-summary-N.md)
|
// summaryFileInitialized tracks which per-step summary files (workflow/step-summary-N.md)
|
||||||
// have already been created on the JobContainer. The runner sets up file-command files
|
// have already been created on the JobContainer. The runner sets up file-command files
|
||||||
@@ -330,13 +330,13 @@ func splitVolumes(specs []string) ([]string, map[string]string, map[string]bool)
|
|||||||
targets := map[string]bool{}
|
targets := map[string]bool{}
|
||||||
|
|
||||||
for _, spec := range specs {
|
for _, spec := range specs {
|
||||||
parsed, err := loader.ParseVolume(spec)
|
parsed, err := container.ParseVolume(spec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
binds = append(binds, spec) // unclassifiable, sanitizeConfig warns and drops it
|
binds = append(binds, spec) // unclassifiable, sanitizeConfig warns and drops it
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
targets[parsed.Target] = true
|
targets[parsed.Target] = true
|
||||||
if parsed.Type == string(mount.TypeVolume) && parsed.Source != "" && !parsed.ReadOnly {
|
if parsed.Type == mount.TypeVolume && parsed.Source != "" && !parsed.ReadOnly {
|
||||||
mounts[parsed.Source] = parsed.Target
|
mounts[parsed.Source] = parsed.Target
|
||||||
} else {
|
} else {
|
||||||
binds = append(binds, spec)
|
binds = append(binds, spec)
|
||||||
@@ -377,7 +377,7 @@ func (rc *RunContext) GetBindsAndMounts(ctx context.Context) ([]string, map[stri
|
|||||||
if runtime.GOOS == "darwin" {
|
if runtime.GOOS == "darwin" {
|
||||||
bindModifiers = ":delegated"
|
bindModifiers = ":delegated"
|
||||||
}
|
}
|
||||||
if selinux.GetEnabled() {
|
if selinuxEnabled() {
|
||||||
bindModifiers = ":z"
|
bindModifiers = ":z"
|
||||||
}
|
}
|
||||||
binds = append(binds, fmt.Sprintf("%s:%s%s", source, target, bindModifiers))
|
binds = append(binds, fmt.Sprintf("%s:%s%s", source, target, bindModifiers))
|
||||||
@@ -718,31 +718,55 @@ func (rc *RunContext) cleanupJobResources(networkName string, createAndDeleteNet
|
|||||||
logger := common.Logger(ctx)
|
logger := common.Logger(ctx)
|
||||||
rc.printServiceLogs(ctx)
|
rc.printServiceLogs(ctx)
|
||||||
errs := []error{rc.closeDockerProxy(ctx)}
|
errs := []error{rc.closeDockerProxy(ctx)}
|
||||||
|
var containers []common.Executor
|
||||||
if rc.JobContainer != nil {
|
if rc.JobContainer != nil {
|
||||||
errs = append(errs, rc.JobContainer.Remove()(ctx))
|
containers = append(containers, rc.JobContainer.Remove())
|
||||||
}
|
}
|
||||||
if len(rc.serviceContainers) > 0 {
|
if len(rc.serviceContainers) > 0 {
|
||||||
logger.Infof("Cleaning up services for job %s", rc.JobName)
|
logger.Infof("Cleaning up services for job %s", rc.JobName)
|
||||||
errs = append(errs, rc.stopServiceContainers()(ctx))
|
containers = append(containers, rc.stopServiceContainers())
|
||||||
}
|
}
|
||||||
|
errs = append(errs, runAll(ctx, containers))
|
||||||
|
ctx, cancel := context.WithTimeout(context.WithoutCancel(ctx), jobCleanupTimeout)
|
||||||
|
defer cancel()
|
||||||
if !common.Dryrun(ctx) && !rc.Config.NoSweep && (preclean || rc.hadDockerProxy) {
|
if !common.Dryrun(ctx) && !rc.Config.NoSweep && (preclean || rc.hadDockerProxy) {
|
||||||
errs = append(errs, container.RemoveDockerJobResources(ctx, rc.jobContainerName()))
|
errs = append(errs, container.RemoveDockerJobResources(ctx, rc.jobContainerName())) // after the containers, whose endpoints would block removing the job networks
|
||||||
}
|
}
|
||||||
|
var rest []common.Executor
|
||||||
if preclean || rc.deferVolumeCleanup == nil {
|
if preclean || rc.deferVolumeCleanup == nil {
|
||||||
errs = append(errs, rc.cleanupJobVolumes(ctx))
|
rest = append(rest, rc.cleanupJobVolumes)
|
||||||
} else {
|
} else {
|
||||||
rc.deferVolumeCleanup(rc.cleanupJobVolumes)
|
rc.deferVolumeCleanup(rc.cleanupJobVolumes)
|
||||||
}
|
}
|
||||||
if createAndDeleteNetwork {
|
if createAndDeleteNetwork {
|
||||||
logger.Infof("Cleaning up network for job %s, and network name is: %s", rc.JobName, networkName)
|
logger.Infof("Cleaning up network for job %s, and network name is: %s", rc.JobName, networkName)
|
||||||
errs = append(errs, container.NewDockerNetworkDisconnectExecutor(networkName, rc.Config.CacheContainer).
|
rest = append(rest, func(ctx context.Context) error {
|
||||||
IfBool(rc.Config.CacheContainer != "")(ctx))
|
return errors.Join(
|
||||||
errs = append(errs, container.NewDockerNetworkRemoveExecutor(networkName)(ctx))
|
container.NewDockerNetworkDisconnectExecutor(networkName, rc.Config.CacheContainer).IfBool(rc.Config.CacheContainer != "")(ctx),
|
||||||
|
container.NewDockerNetworkRemoveExecutor(networkName)(ctx))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
return errors.Join(errs...)
|
return errors.Join(append(errs, runAll(ctx, rest))...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func runAll(ctx context.Context, executors []common.Executor) error {
|
||||||
|
errs := make([]error, len(executors))
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
for i, executor := range executors {
|
||||||
|
wg.Go(func() {
|
||||||
|
defer func() {
|
||||||
|
if recovered := recover(); recovered != nil {
|
||||||
|
errs[i] = fmt.Errorf("panic: %v\n%s", recovered, debug.Stack())
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
errs[i] = executor(ctx)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
return errors.Join(errs...)
|
||||||
|
}
|
||||||
|
|
||||||
func (rc *RunContext) createJobVolumes(ctx context.Context, mounts map[string]string) error {
|
func (rc *RunContext) createJobVolumes(ctx context.Context, mounts map[string]string) error {
|
||||||
runnerUUID := rc.Config.ContainerNetworkCreateOptions.RunnerUUID
|
runnerUUID := rc.Config.ContainerNetworkCreateOptions.RunnerUUID
|
||||||
if runnerUUID == "" || common.Dryrun(ctx) {
|
if runnerUUID == "" || common.Dryrun(ctx) {
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"testing/synctest"
|
"testing/synctest"
|
||||||
"time"
|
"time"
|
||||||
@@ -31,7 +32,6 @@ import (
|
|||||||
|
|
||||||
"gitea.dev/actionslib/pkg/exprparser"
|
"gitea.dev/actionslib/pkg/exprparser"
|
||||||
"gitea.dev/actionslib/pkg/model"
|
"gitea.dev/actionslib/pkg/model"
|
||||||
"github.com/docker/cli/cli/compose/loader"
|
|
||||||
"github.com/moby/moby/api/types/volume"
|
"github.com/moby/moby/api/types/volume"
|
||||||
assert "github.com/stretchr/testify/assert"
|
assert "github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
@@ -605,7 +605,7 @@ func TestRunContext_GetBindsAndMounts(t *testing.T) {
|
|||||||
// volumes must displace the runner's rather than pile up next to them.
|
// volumes must displace the runner's rather than pile up next to them.
|
||||||
targets := map[string]bool{}
|
targets := map[string]bool{}
|
||||||
for _, bind := range gotbind {
|
for _, bind := range gotbind {
|
||||||
parsed, err := loader.ParseVolume(bind)
|
parsed, err := container.ParseVolume(bind)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.NotContains(t, targets, parsed.Target, "%s mounts an already mounted target", bind)
|
assert.NotContains(t, targets, parsed.Target, "%s mounts an already mounted target", bind)
|
||||||
targets[parsed.Target] = true
|
targets[parsed.Target] = true
|
||||||
@@ -775,10 +775,10 @@ func TestRemoveDockerActionImagesByTag(t *testing.T) {
|
|||||||
assert.Equal(t, []string{"act-action-dockeraction:latest-job"}, removed)
|
assert.Equal(t, []string{"act-action-dockeraction:latest-job"}, removed)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCleanupJobResourcesContinuesAfterFailure(t *testing.T) {
|
func TestCleanupJobResources(t *testing.T) {
|
||||||
t.Setenv("TMPDIR", "/tmp")
|
t.Setenv("TMPDIR", "/tmp")
|
||||||
proxyDir := t.TempDir()
|
proxyDir := t.TempDir()
|
||||||
for _, name := range []string{"synchronous", "proxy", "closed proxy", "kept proxy", "deferred", "preclean deferred", "canceled"} {
|
for _, name := range []string{"synchronous", "proxy", "closed proxy", "kept proxy", "deferred", "preclean deferred", "canceled proxy"} {
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
proxy, preclean, deferred := strings.HasSuffix(name, "proxy"), strings.HasPrefix(name, "preclean"), strings.HasSuffix(name, "deferred")
|
proxy, preclean, deferred := strings.HasSuffix(name, "proxy"), strings.HasPrefix(name, "preclean"), strings.HasSuffix(name, "deferred")
|
||||||
removesLabelled := (proxy || preclean) && name != "kept proxy"
|
removesLabelled := (proxy || preclean) && name != "kept proxy"
|
||||||
@@ -787,8 +787,20 @@ func TestCleanupJobResourcesContinuesAfterFailure(t *testing.T) {
|
|||||||
}
|
}
|
||||||
jobError, removeError, closeError := errors.New("remove job"), errors.New("remove service"), errors.New("close service")
|
jobError, removeError, closeError := errors.New("remove job"), errors.New("remove service"), errors.New("close service")
|
||||||
job, service := &containerMock{}, &containerMock{}
|
job, service := &containerMock{}, &containerMock{}
|
||||||
job.On("Remove").Return(func(context.Context) error { return jobError }).Once()
|
removeAlongside := func(started, other chan struct{}, failure error) func(context.Context) error {
|
||||||
service.On("Remove").Return(func(context.Context) error { return removeError }).Once()
|
return func(context.Context) error {
|
||||||
|
close(started)
|
||||||
|
select {
|
||||||
|
case <-other:
|
||||||
|
case <-time.After(10 * time.Second):
|
||||||
|
t.Error("the containers are removed one after the other instead of alongside each other")
|
||||||
|
}
|
||||||
|
return failure
|
||||||
|
}
|
||||||
|
}
|
||||||
|
jobRemoving, serviceRemoving := make(chan struct{}), make(chan struct{})
|
||||||
|
job.On("Remove").Return(removeAlongside(jobRemoving, serviceRemoving, jobError)).Once()
|
||||||
|
service.On("Remove").Return(removeAlongside(serviceRemoving, jobRemoving, removeError)).Once()
|
||||||
service.On("Close").Return(func(context.Context) error { return closeError }).Once()
|
service.On("Close").Return(func(context.Context) error { return closeError }).Once()
|
||||||
rc := &RunContext{
|
rc := &RunContext{
|
||||||
Config: &Config{CacheContainer: "cache-container", NoSweep: name == "kept proxy"},
|
Config: &Config{CacheContainer: "cache-container", NoSweep: name == "kept proxy"},
|
||||||
@@ -825,7 +837,7 @@ func TestCleanupJobResourcesContinuesAfterFailure(t *testing.T) {
|
|||||||
}
|
}
|
||||||
ctx, cancel := context.WithCancel(t.Context())
|
ctx, cancel := context.WithCancel(t.Context())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
if name == "canceled" {
|
if name == "canceled proxy" {
|
||||||
cancel()
|
cancel()
|
||||||
}
|
}
|
||||||
err := rc.cleanupJobResources("job-network", true, preclean)(ctx)
|
err := rc.cleanupJobResources("job-network", true, preclean)(ctx)
|
||||||
@@ -839,14 +851,10 @@ func TestCleanupJobResourcesContinuesAfterFailure(t *testing.T) {
|
|||||||
for _, failure := range []error{jobError, removeError, closeError} {
|
for _, failure := range []error{jobError, removeError, closeError} {
|
||||||
require.ErrorIs(t, err, failure)
|
require.ErrorIs(t, err, failure)
|
||||||
}
|
}
|
||||||
if name == "canceled" {
|
for _, operation := range []string{"DELETE /volumes/" + rc.jobContainerName(), "DELETE /volumes/" + rc.jobContainerName() + "-env", "POST /networks/job-network/disconnect", "GET /networks"} {
|
||||||
require.ErrorIs(t, err, context.Canceled)
|
require.ErrorContains(t, err, operation)
|
||||||
} else {
|
|
||||||
for _, operation := range []string{"DELETE /volumes/" + rc.jobContainerName(), "DELETE /volumes/" + rc.jobContainerName() + "-env", "POST /networks/job-network/disconnect", "GET /networks"} {
|
|
||||||
require.ErrorContains(t, err, operation)
|
|
||||||
}
|
|
||||||
assert.Equal(t, 2, volumeRemovals)
|
|
||||||
}
|
}
|
||||||
|
assert.Equal(t, 2, volumeRemovals)
|
||||||
assert.Equal(t, removesLabelled, strings.Contains(err.Error(), "labelled GET /containers/json"))
|
assert.Equal(t, removesLabelled, strings.Contains(err.Error(), "labelled GET /containers/json"))
|
||||||
if removesLabelled {
|
if removesLabelled {
|
||||||
require.ErrorContains(t, err, "labelled GET /networks")
|
require.ErrorContains(t, err, "labelled GET /networks")
|
||||||
@@ -1360,8 +1368,11 @@ func TestRunContext_cleanupFailedStart(t *testing.T) {
|
|||||||
} {
|
} {
|
||||||
t.Run(testcase.name, func(t *testing.T) {
|
t.Run(testcase.name, func(t *testing.T) {
|
||||||
var operations []string
|
var operations []string
|
||||||
|
var operationsMu sync.Mutex
|
||||||
record := func(operation string, failure error) func(context.Context) error {
|
record := func(operation string, failure error) func(context.Context) error {
|
||||||
return func(context.Context) error {
|
return func(context.Context) error {
|
||||||
|
operationsMu.Lock()
|
||||||
|
defer operationsMu.Unlock()
|
||||||
operations = append(operations, operation)
|
operations = append(operations, operation)
|
||||||
return failure
|
return failure
|
||||||
}
|
}
|
||||||
@@ -1403,7 +1414,7 @@ func TestRunContext_cleanupFailedStart(t *testing.T) {
|
|||||||
ctx := common.WithLogger(common.WithDryrun(t.Context(), true), logger)
|
ctx := common.WithLogger(common.WithDryrun(t.Context(), true), logger)
|
||||||
rc.ExprEval = rc.NewExpressionEvaluator(ctx)
|
rc.ExprEval = rc.NewExpressionEvaluator(ctx)
|
||||||
err = rc.startContainer().Then(rc.stopContainer()).Finally(rc.closeContainer())(ctx)
|
err = rc.startContainer().Then(rc.stopContainer()).Finally(rc.closeContainer())(ctx)
|
||||||
want := "job.Remove service.Remove service.Close service.Pull job.Pull"
|
want := "job.Remove service.Close service.Remove service.Pull job.Pull"
|
||||||
switch {
|
switch {
|
||||||
case testcase.pullError != nil:
|
case testcase.pullError != nil:
|
||||||
require.ErrorIs(t, err, testcase.pullError)
|
require.ErrorIs(t, err, testcase.pullError)
|
||||||
@@ -1418,7 +1429,9 @@ func TestRunContext_cleanupFailedStart(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert.Equal(t, strings.Fields(want+" job.Remove service.Remove service.Close job.Close"), operations)
|
slices.Sort(operations[:3])
|
||||||
|
slices.Sort(operations[len(operations)-4 : len(operations)-1])
|
||||||
|
assert.Equal(t, strings.Fields(want+" job.Remove service.Close service.Remove job.Close"), operations)
|
||||||
assert.Empty(t, rc.Masks)
|
assert.Empty(t, rc.Masks)
|
||||||
assert.Equal(t, testcase.pullError == nil && testcase.health != container.HealthUnhealthy, slices.ContainsFunc(hook.AllRecords(), func(entry logging.Record) bool {
|
assert.Equal(t, testcase.pullError == nil && testcase.health != container.HealthUnhealthy, slices.ContainsFunc(hook.AllRecords(), func(entry logging.Record) bool {
|
||||||
return strings.HasPrefix(entry.Message, "::group::Print service container logs")
|
return strings.HasPrefix(entry.Message, "::group::Print service container logs")
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
package runner
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
|
)
|
||||||
|
|
||||||
|
var selinuxEnabled = sync.OnceValue(func() bool {
|
||||||
|
if !isSELinuxfs("/sys/fs/selinux") && !hasOtherSELinuxfs() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
label, _ := os.ReadFile("/proc/self/attr/current")
|
||||||
|
return strings.TrimSuffix(string(label), "\x00") != "kernel"
|
||||||
|
})
|
||||||
|
|
||||||
|
func hasOtherSELinuxfs() bool {
|
||||||
|
mounts, _ := os.ReadFile("/proc/self/mountinfo")
|
||||||
|
for line := range strings.Lines(string(mounts)) {
|
||||||
|
if strings.Contains(line, " - selinuxfs ") {
|
||||||
|
if fields := strings.Fields(line); len(fields) > 4 && isSELinuxfs(fields[4]) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func isSELinuxfs(mountPoint string) bool {
|
||||||
|
var fs unix.Statfs_t
|
||||||
|
return unix.Statfs(mountPoint, &fs) == nil && uint32(fs.Type) == uint32(unix.SELINUX_MAGIC) && fs.Flags&unix.ST_RDONLY == 0
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
//go:build !linux
|
||||||
|
|
||||||
|
package runner
|
||||||
|
|
||||||
|
func selinuxEnabled() bool { return false }
|
||||||
@@ -47,7 +47,7 @@ func (sal *stepActionLocal) main() common.Executor {
|
|||||||
defer rawLogger.Infof("::endgroup::")
|
defer rawLogger.Infof("::endgroup::")
|
||||||
|
|
||||||
actionDir := filepath.Join(sal.getRunContext().Config.Workdir, sal.Step.Uses)
|
actionDir := filepath.Join(sal.getRunContext().Config.Workdir, sal.Step.Uses)
|
||||||
_, containerActionPath := getContainerActionPaths(sal.Step, path.Join(actionDir, ""), sal.RunContext)
|
_, containerActionPath := getContainerActionPaths(sal)
|
||||||
|
|
||||||
localReader := func(filename string) (io.Reader, io.Closer, error) {
|
localReader := func(filename string) (io.Reader, io.Closer, error) {
|
||||||
spath := path.Join(containerActionPath, filename)
|
spath := path.Join(containerActionPath, filename)
|
||||||
@@ -127,8 +127,7 @@ func (sal *stepActionLocal) getActionModel() *model.Action {
|
|||||||
|
|
||||||
func (sal *stepActionLocal) getCompositeRunContext(ctx context.Context) (*RunContext, error) {
|
func (sal *stepActionLocal) getCompositeRunContext(ctx context.Context) (*RunContext, error) {
|
||||||
if sal.compositeRunContext == nil {
|
if sal.compositeRunContext == nil {
|
||||||
actionDir := filepath.Join(sal.RunContext.Config.Workdir, sal.Step.Uses)
|
_, containerActionDir := getContainerActionPaths(sal)
|
||||||
_, containerActionDir := getContainerActionPaths(sal.getStepModel(), actionDir, sal.RunContext)
|
|
||||||
|
|
||||||
compositeRunContext, err := newCompositeRunContext(ctx, sal.RunContext, sal, containerActionDir)
|
compositeRunContext, err := newCompositeRunContext(ctx, sal.RunContext, sal, containerActionDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -30,13 +30,16 @@ type stepActionRemote struct {
|
|||||||
action *model.Action
|
action *model.Action
|
||||||
env map[string]string
|
env map[string]string
|
||||||
remoteAction *remoteAction
|
remoteAction *remoteAction
|
||||||
resolvedSha string
|
actionDir string // the repository at the resolved commit, shared by the job's actions in it
|
||||||
|
resolvedSha string // set on the step that made the job's download of the repository
|
||||||
}
|
}
|
||||||
|
|
||||||
var stepActionRemoteNewCloneExecutor = git.NewGitCloneExecutor
|
type actionDownload struct {
|
||||||
|
dir string
|
||||||
|
err error
|
||||||
|
}
|
||||||
|
|
||||||
// selfRepoPrefix introduces a self-repository reference: the action lives in the repo holding the file that wrote the `uses:`.
|
var stepActionRemoteFetch = git.FetchAction
|
||||||
const selfRepoPrefix = "$/"
|
|
||||||
|
|
||||||
func (sar *stepActionRemote) prepareActionExecutor() common.Executor {
|
func (sar *stepActionRemote) prepareActionExecutor() common.Executor {
|
||||||
return func(ctx context.Context) error {
|
return func(ctx context.Context) error {
|
||||||
@@ -64,61 +67,57 @@ func (sar *stepActionRemote) prepareActionExecutor() common.Executor {
|
|||||||
common.Logger(ctx).Debugf("Skipping local actions/checkout because workdir was already copied")
|
common.Logger(ctx).Debugf("Skipping local actions/checkout because workdir was already copied")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
actionDir := sar.actionDir()
|
cloneURL := sar.remoteAction.CloneURL(sar.RunContext.Config.DefaultActionURL())
|
||||||
defaultActionURL := sar.RunContext.Config.DefaultActionURL()
|
job := sar.RunContext.topLevelRunContext()
|
||||||
// For Gitea
|
key := cloneURL + "@" + sar.remoteAction.Ref
|
||||||
// github.Token, unlike Config.GetToken, survives the composite config copy, which nils Config.Secrets.
|
download, ok := job.actionDownloads[key]
|
||||||
gitClone := stepActionRemoteNewCloneExecutor(sar.RunContext.Config.withInstanceAuth(git.NewGitCloneExecutorInput{
|
if !ok {
|
||||||
URL: sar.remoteAction.CloneURL(defaultActionURL),
|
// For Gitea
|
||||||
Ref: sar.remoteAction.Ref,
|
// github.Token, unlike Config.GetToken, survives the composite config copy, which nils Config.Secrets.
|
||||||
Dir: actionDir,
|
download.dir, sar.resolvedSha, download.err = stepActionRemoteFetch(ctx, sar.RunContext.Config.withInstanceAuth(git.NewGitCloneExecutorInput{
|
||||||
OfflineMode: sar.RunContext.Config.ActionOfflineMode,
|
URL: cloneURL,
|
||||||
Depth: sar.RunContext.Config.ActionCloneDepth,
|
Ref: sar.remoteAction.Ref,
|
||||||
// printPrepareActions reports the download with its resolved commit.
|
Dir: filepath.Join(sar.RunContext.ActionCacheDir(), model.UsesHash(key)),
|
||||||
Quiet: true,
|
OfflineMode: sar.RunContext.Config.ActionOfflineMode,
|
||||||
}, github.Token))
|
Depth: sar.RunContext.Config.ActionCloneDepth,
|
||||||
if err := gitClone(ctx); err != nil {
|
}, github.Token))
|
||||||
var refErr *git.Error
|
if job.actionDownloads == nil {
|
||||||
switch {
|
job.actionDownloads = map[string]actionDownload{}
|
||||||
case errors.As(err, &refErr) && errors.Is(err, git.ErrShortRef):
|
|
||||||
return fmt.Errorf("unable to resolve action `%s`, the provided ref `%s` is the shortened version of a commit SHA, which is not supported. Please use the full commit SHA `%s` instead",
|
|
||||||
sar.Step.Uses, sar.remoteAction.Ref, refErr.Commit())
|
|
||||||
default:
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
job.actionDownloads[key] = download
|
||||||
}
|
}
|
||||||
|
var refErr *git.Error
|
||||||
|
switch {
|
||||||
|
case errors.As(download.err, &refErr) && errors.Is(download.err, git.ErrShortRef):
|
||||||
|
return fmt.Errorf("unable to resolve action `%s`, the provided ref `%s` is the shortened version of a commit SHA, which is not supported. Please use the full commit SHA `%s` instead",
|
||||||
|
sar.Step.Uses, sar.remoteAction.Ref, refErr.Commit())
|
||||||
|
case download.err != nil:
|
||||||
|
return download.err
|
||||||
|
}
|
||||||
|
sar.actionDir = download.dir
|
||||||
|
|
||||||
unlock, err := git.AcquireCloneLock(ctx, actionDir)
|
unlock, err := git.AcquireCloneLock(ctx, sar.actionDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer unlock()
|
defer unlock()
|
||||||
|
|
||||||
// Best effort: the download report falls back to the ref alone when the commit is unknown.
|
|
||||||
if _, sha, err := git.FindGitRevision(ctx, actionDir); err != nil {
|
|
||||||
common.Logger(ctx).Debugf("unable to resolve the commit of %s: %v", sar.remoteAction.Reference(), err)
|
|
||||||
} else {
|
|
||||||
sar.resolvedSha = sha
|
|
||||||
}
|
|
||||||
|
|
||||||
remoteReader := func(filename string) (io.Reader, io.Closer, error) {
|
remoteReader := func(filename string) (io.Reader, io.Closer, error) {
|
||||||
f, err := os.Open(filepath.Join(actionDir, sar.remoteAction.Path, filename))
|
f, err := os.Open(filepath.Join(sar.actionDir, sar.remoteAction.Path, filename))
|
||||||
return f, f, err
|
return f, f, err
|
||||||
}
|
}
|
||||||
|
|
||||||
actionModel, err := sar.readAction(ctx, sar.Step, actionDir, sar.remoteAction.Path, remoteReader, os.WriteFile)
|
actionModel, err := sar.readAction(ctx, sar.Step, sar.actionDir, sar.remoteAction.Path, remoteReader, os.WriteFile)
|
||||||
sar.action = actionModel
|
sar.action = actionModel
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// actionDownloadInfo reports the action this step downloaded and the commit it resolved to. ok is
|
func (sar *stepActionRemote) actionDownloadInfo() (reference, sha string) { // once per job, as actions/runner reports
|
||||||
// false when nothing was fetched, as for the local checkout of the workflow's own repository.
|
if sar.resolvedSha == "" {
|
||||||
func (sar *stepActionRemote) actionDownloadInfo() (reference, sha string, ok bool) {
|
return "", ""
|
||||||
if sar.remoteAction == nil || sar.action == nil {
|
|
||||||
return "", "", false
|
|
||||||
}
|
}
|
||||||
return sar.remoteAction.Reference(), sar.resolvedSha, true
|
return fmt.Sprintf("%s/%s@%s", sar.remoteAction.Org, sar.remoteAction.Repo, sar.remoteAction.Ref), sar.resolvedSha
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sar *stepActionRemote) pre() common.Executor {
|
func (sar *stepActionRemote) pre() common.Executor {
|
||||||
@@ -147,7 +146,7 @@ func (sar *stepActionRemote) main() common.Executor {
|
|||||||
return sar.RunContext.JobContainer.CopyDir(copyToPath, sar.RunContext.Config.Workdir+string(filepath.Separator)+".", sar.RunContext.Config.UseGitIgnore, false)(ctx)
|
return sar.RunContext.JobContainer.CopyDir(copyToPath, sar.RunContext.Config.Workdir+string(filepath.Separator)+".", sar.RunContext.Config.UseGitIgnore, false)(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
return sar.runAction(sar, sar.actionDir(), sar.remoteAction)(ctx)
|
return sar.runAction(sar, sar.actionDir, sar.remoteAction)(ctx)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -156,13 +155,8 @@ func (sar *stepActionRemote) post() common.Executor {
|
|||||||
return runStepExecutor(sar, stepStagePost, runPostStep(sar)).If(hasPostStep(sar)).If(shouldRunPostStep(sar))
|
return runStepExecutor(sar, stepStagePost, runPostStep(sar)).If(hasPostStep(sar)).If(shouldRunPostStep(sar))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sar *stepActionRemote) actionDir() string {
|
func (sar *stepActionRemote) containerKey() string {
|
||||||
uses := sar.Step.Uses
|
return model.UsesHash(sar.remoteAction.URL + "/" + sar.remoteAction.Reference())
|
||||||
if strings.HasPrefix(uses, selfRepoPrefix) {
|
|
||||||
// The same `$/x` names a different action per enclosing repo, so key the cache on what it resolved to.
|
|
||||||
uses = sar.remoteAction.URL + "/" + sar.remoteAction.Reference()
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("%s/%s", sar.RunContext.ActionCacheDir(), model.UsesHash(uses))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sar *stepActionRemote) getRunContext() *RunContext {
|
func (sar *stepActionRemote) getRunContext() *RunContext {
|
||||||
@@ -213,9 +207,7 @@ func (sar *stepActionRemote) getActionModel() *model.Action {
|
|||||||
|
|
||||||
func (sar *stepActionRemote) getCompositeRunContext(ctx context.Context) (*RunContext, error) {
|
func (sar *stepActionRemote) getCompositeRunContext(ctx context.Context) (*RunContext, error) {
|
||||||
if sar.compositeRunContext == nil {
|
if sar.compositeRunContext == nil {
|
||||||
actionDir := sar.actionDir()
|
_, containerActionDir := getContainerActionPaths(sar)
|
||||||
actionLocation := path.Join(actionDir, sar.remoteAction.Path)
|
|
||||||
_, containerActionDir := getContainerActionPaths(sar.getStepModel(), actionLocation, sar.RunContext)
|
|
||||||
|
|
||||||
compositeRunContext, err := newCompositeRunContext(ctx, sar.RunContext, sar, containerActionDir)
|
compositeRunContext, err := newCompositeRunContext(ctx, sar.RunContext, sar, containerActionDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -31,14 +32,10 @@ type stepActionRemoteMocks struct {
|
|||||||
mock.Mock
|
mock.Mock
|
||||||
}
|
}
|
||||||
|
|
||||||
func actionDirSuffix(suffix string) any {
|
func setFetch(t *testing.T, fetch func(context.Context, git.NewGitCloneExecutorInput) (string, string, error)) {
|
||||||
return mock.MatchedBy(func(actionDir string) bool { return strings.HasSuffix(actionDir, suffix) })
|
original := stepActionRemoteFetch
|
||||||
}
|
stepActionRemoteFetch = fetch
|
||||||
|
t.Cleanup(func() { stepActionRemoteFetch = original })
|
||||||
func setCloneExecutor(t *testing.T, executor func(git.NewGitCloneExecutorInput) common.Executor) {
|
|
||||||
original := stepActionRemoteNewCloneExecutor
|
|
||||||
stepActionRemoteNewCloneExecutor = executor
|
|
||||||
t.Cleanup(func() { stepActionRemoteNewCloneExecutor = original })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestShortSHAActionRejected(t *testing.T) {
|
func TestShortSHAActionRejected(t *testing.T) {
|
||||||
@@ -181,12 +178,10 @@ func TestStepActionRemote(t *testing.T) {
|
|||||||
sarm := &stepActionRemoteMocks{}
|
sarm := &stepActionRemoteMocks{}
|
||||||
|
|
||||||
clonedAction := false
|
clonedAction := false
|
||||||
|
actionDir := t.TempDir()
|
||||||
setCloneExecutor(t, func(input git.NewGitCloneExecutorInput) common.Executor {
|
setFetch(t, func(_ctx context.Context, _input git.NewGitCloneExecutorInput) (string, string, error) {
|
||||||
return func(ctx context.Context) error {
|
clonedAction = true
|
||||||
clonedAction = true
|
return actionDir, "", nil
|
||||||
return nil
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
sar := &stepActionRemote{
|
sar := &stepActionRemote{
|
||||||
@@ -213,10 +208,10 @@ func TestStepActionRemote(t *testing.T) {
|
|||||||
sar.RunContext.ExprEval = sar.RunContext.NewExpressionEvaluator(ctx)
|
sar.RunContext.ExprEval = sar.RunContext.NewExpressionEvaluator(ctx)
|
||||||
|
|
||||||
if tt.mocks.read {
|
if tt.mocks.read {
|
||||||
sarm.On("readAction", sar.Step, actionDirSuffix(sar.Step.UsesHash()), "", mock.Anything, mock.Anything).Return(&model.Action{}, nil)
|
sarm.On("readAction", sar.Step, actionDir, "", mock.Anything, mock.Anything).Return(&model.Action{}, nil)
|
||||||
}
|
}
|
||||||
if tt.mocks.run {
|
if tt.mocks.run {
|
||||||
sarm.On("runAction", sar, actionDirSuffix(sar.Step.UsesHash()), mustNewRemoteAction(t, sar.Step.Uses)).Return(func(ctx context.Context) error { return tt.runError })
|
sarm.On("runAction", sar, actionDir, mustNewRemoteAction(t, sar.Step.Uses)).Return(func(ctx context.Context) error { return tt.runError })
|
||||||
|
|
||||||
cm.On("Copy", "/var/run/act", mock.AnythingOfType("[]*container.FileEntry")).Return(noopExecutor)
|
cm.On("Copy", "/var/run/act", mock.AnythingOfType("[]*container.FileEntry")).Return(noopExecutor)
|
||||||
|
|
||||||
@@ -263,40 +258,60 @@ func TestStepActionRemote(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestStepActionRemotePrepare(t *testing.T) {
|
func TestStepActionRemotePrepare(t *testing.T) {
|
||||||
for _, test := range []struct {
|
var fetched, read []string
|
||||||
name, uses, instance, actionPath, wantURL string
|
setFetch(t, func(_ctx context.Context, input git.NewGitCloneExecutorInput) (string, string, error) {
|
||||||
}{
|
fetched = append(fetched, input.URL+"@"+input.Ref)
|
||||||
{name: "nested action", uses: "org/repo/path@ref", instance: "https://github.com", actionPath: "path", wantURL: "https://github.com/org/repo"},
|
if input.Ref == "missing" {
|
||||||
{name: "instance fallback", uses: "actions/setup-go@v4", instance: "gitea.example", wantURL: "https://gitea.example/actions/setup-go"},
|
return "", "", assert.AnError
|
||||||
} {
|
}
|
||||||
t.Run(test.name, func(t *testing.T) {
|
return filepath.Join(input.Dir, "commit"), "sha-" + input.Ref, nil
|
||||||
var actualURL string
|
})
|
||||||
setCloneExecutor(t, func(input git.NewGitCloneExecutorInput) common.Executor {
|
newJob := func(instance string) *RunContext {
|
||||||
return func(context.Context) error {
|
return &RunContext{
|
||||||
actualURL = input.URL
|
Config: &Config{GitHubInstance: instance, ActionCacheDir: t.TempDir()},
|
||||||
return nil
|
Run: &model.Run{JobID: "1", Workflow: &model.Workflow{Jobs: map[string]*model.Job{"1": {}}}},
|
||||||
}
|
JobContainer: &jobContainerMock{},
|
||||||
})
|
}
|
||||||
|
|
||||||
actionMocks := &stepActionRemoteMocks{}
|
|
||||||
action := &stepActionRemote{
|
|
||||||
Step: &model.Step{Uses: test.uses},
|
|
||||||
RunContext: &RunContext{
|
|
||||||
Config: &Config{GitHubInstance: test.instance, ActionCacheDir: t.TempDir()},
|
|
||||||
Run: &model.Run{JobID: "1", Workflow: &model.Workflow{
|
|
||||||
Jobs: map[string]*model.Job{"1": {}},
|
|
||||||
}},
|
|
||||||
},
|
|
||||||
readAction: actionMocks.readAction,
|
|
||||||
}
|
|
||||||
actionMocks.On("readAction", action.Step, actionDirSuffix(action.Step.UsesHash()), test.actionPath,
|
|
||||||
mock.Anything, mock.Anything).Return(&model.Action{}, nil)
|
|
||||||
|
|
||||||
require.NoError(t, action.prepareActionExecutor()(t.Context()))
|
|
||||||
assert.Equal(t, test.wantURL, actualURL)
|
|
||||||
actionMocks.AssertExpectations(t)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
prepare := func(rc *RunContext, uses string) (*stepActionRemote, error) {
|
||||||
|
sar := &stepActionRemote{Step: &model.Step{Uses: uses}, RunContext: rc, readAction: func(_ctx context.Context, _step *model.Step, _actionDir, actionPath string, _readFile actionYamlReader, _writeFile fileWriter) (*model.Action, error) {
|
||||||
|
read = append(read, actionPath)
|
||||||
|
return &model.Action{}, nil
|
||||||
|
}}
|
||||||
|
return sar, sar.prepareActionExecutor()(t.Context())
|
||||||
|
}
|
||||||
|
|
||||||
|
job := newJob("https://github.com")
|
||||||
|
restore, err := prepare(job, "org/repo/restore@v1")
|
||||||
|
require.NoError(t, err)
|
||||||
|
root, err := prepare(job, "org/repo@v1")
|
||||||
|
require.NoError(t, err)
|
||||||
|
nested, err := prepare(&RunContext{Config: job.Config, Run: job.Run, JobContainer: job.JobContainer, Parent: job}, "org/repo/save@v1")
|
||||||
|
require.NoError(t, err)
|
||||||
|
other, err := prepare(job, "org/repo@v2")
|
||||||
|
require.NoError(t, err)
|
||||||
|
_, err = prepare(newJob("gitea.example"), "org/repo@v1")
|
||||||
|
require.NoError(t, err)
|
||||||
|
for range 2 {
|
||||||
|
_, err = prepare(job, "org/repo@missing")
|
||||||
|
require.ErrorIs(t, err, assert.AnError)
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Equal(t, []string{"https://github.com/org/repo@v1", "https://github.com/org/repo@v2", "https://gitea.example/org/repo@v1", "https://github.com/org/repo@missing"}, fetched)
|
||||||
|
assert.Equal(t, []string{"restore", "", "save", "", ""}, read)
|
||||||
|
assert.Equal(t, root.actionDir, restore.actionDir)
|
||||||
|
assert.Equal(t, root.actionDir, nested.actionDir)
|
||||||
|
assert.NotEqual(t, root.actionDir, other.actionDir)
|
||||||
|
|
||||||
|
reference, sha := restore.actionDownloadInfo()
|
||||||
|
assert.Equal(t, []string{"org/repo@v1", "sha-v1"}, []string{reference, sha})
|
||||||
|
_, sha = root.actionDownloadInfo()
|
||||||
|
assert.Empty(t, sha)
|
||||||
|
|
||||||
|
_, rootContainerDir := getContainerActionPaths(root)
|
||||||
|
_, restoreContainerDir := getContainerActionPaths(restore)
|
||||||
|
assert.NotEqual(t, path.Dir(rootContainerDir), path.Dir(restoreContainerDir))
|
||||||
|
assert.Equal(t, "restore", path.Base(restoreContainerDir))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStepActionRemotePost(t *testing.T) {
|
func TestStepActionRemotePost(t *testing.T) {
|
||||||
@@ -701,17 +716,15 @@ func Test_newRemoteActionSelfRepo(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_stepActionRemoteSelfRepoActionDir(t *testing.T) {
|
func Test_stepActionRemoteSelfRepoContainerKeyDiffersPerRepo(t *testing.T) {
|
||||||
dirFor := func(repo string) string {
|
keyFor := func(repo string) string {
|
||||||
sar := &stepActionRemote{
|
sar := &stepActionRemote{
|
||||||
Step: &model.Step{Uses: "$/.gitea/actions/build"},
|
Step: &model.Step{Uses: "$/.gitea/actions/build"},
|
||||||
RunContext: &RunContext{Config: &Config{ActionCacheDir: "/cache"}},
|
|
||||||
remoteAction: &remoteAction{Org: "owner", Repo: repo, Ref: "v1"},
|
remoteAction: &remoteAction{Org: "owner", Repo: repo, Ref: "v1"},
|
||||||
}
|
}
|
||||||
return sar.actionDir()
|
return sar.containerKey()
|
||||||
}
|
}
|
||||||
// The same `$/x` in two repos must not share a cache directory.
|
assert.NotEqual(t, keyFor("one"), keyFor("two"))
|
||||||
assert.NotEqual(t, dirFor("one"), dirFor("two"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_remoteActionReference(t *testing.T) {
|
func Test_remoteActionReference(t *testing.T) {
|
||||||
@@ -774,37 +787,11 @@ func TestStepActionRemotePreResolvesDownloadedCommit(t *testing.T) {
|
|||||||
|
|
||||||
require.NoError(t, sar.prepareActionExecutor()(t.Context()))
|
require.NoError(t, sar.prepareActionExecutor()(t.Context()))
|
||||||
|
|
||||||
reference, sha, ok := sar.actionDownloadInfo()
|
reference, sha := sar.actionDownloadInfo()
|
||||||
assert.True(t, ok)
|
|
||||||
assert.Equal(t, "actions/setup-go@main", reference)
|
assert.Equal(t, "actions/setup-go@main", reference)
|
||||||
assert.Equal(t, wantSha, sha)
|
assert.Equal(t, wantSha, sha)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStepActionRemoteActionDownloadInfo(t *testing.T) {
|
|
||||||
t.Run("reports the action and its resolved commit", func(t *testing.T) {
|
|
||||||
sar := &stepActionRemote{
|
|
||||||
remoteAction: mustNewRemoteAction(t, "actions/checkout@v7"),
|
|
||||||
action: &model.Action{},
|
|
||||||
resolvedSha: "9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0",
|
|
||||||
}
|
|
||||||
|
|
||||||
reference, sha, ok := sar.actionDownloadInfo()
|
|
||||||
|
|
||||||
assert.True(t, ok)
|
|
||||||
assert.Equal(t, "actions/checkout@v7", reference)
|
|
||||||
assert.Equal(t, "9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0", sha)
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("reports nothing when no action was downloaded", func(t *testing.T) {
|
|
||||||
// The local checkout of the workflow's own repository resolves no action.
|
|
||||||
sar := &stepActionRemote{remoteAction: mustNewRemoteAction(t, "actions/checkout@v7")}
|
|
||||||
|
|
||||||
_, _, ok := sar.actionDownloadInfo()
|
|
||||||
|
|
||||||
assert.False(t, ok)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func Test_safeFilename(t *testing.T) {
|
func Test_safeFilename(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
s string
|
s string
|
||||||
@@ -856,9 +843,10 @@ func TestStepActionRemoteCloneTokenSurvivesNilSecrets(t *testing.T) {
|
|||||||
ctx := t.Context()
|
ctx := t.Context()
|
||||||
|
|
||||||
var capturedToken string
|
var capturedToken string
|
||||||
setCloneExecutor(t, func(input git.NewGitCloneExecutorInput) common.Executor {
|
actionDir := t.TempDir()
|
||||||
|
setFetch(t, func(_ctx context.Context, input git.NewGitCloneExecutorInput) (string, string, error) {
|
||||||
capturedToken = input.Token
|
capturedToken = input.Token
|
||||||
return func(ctx context.Context) error { return nil }
|
return actionDir, "", nil
|
||||||
})
|
})
|
||||||
|
|
||||||
sarm := &stepActionRemoteMocks{}
|
sarm := &stepActionRemoteMocks{}
|
||||||
@@ -886,7 +874,7 @@ func TestStepActionRemoteCloneTokenSurvivesNilSecrets(t *testing.T) {
|
|||||||
}
|
}
|
||||||
sar.RunContext.ExprEval = sar.RunContext.NewExpressionEvaluator(ctx)
|
sar.RunContext.ExprEval = sar.RunContext.NewExpressionEvaluator(ctx)
|
||||||
|
|
||||||
sarm.On("readAction", sar.Step, actionDirSuffix(sar.Step.UsesHash()), "", mock.Anything, mock.Anything).Return(&model.Action{}, nil)
|
sarm.On("readAction", sar.Step, actionDir, "", mock.Anything, mock.Anything).Return(&model.Action{}, nil)
|
||||||
|
|
||||||
err := sar.prepareActionExecutor()(ctx)
|
err := sar.prepareActionExecutor()(ctx)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|||||||
+1
-1
@@ -51,7 +51,7 @@ Job pods mount no service account token unless the template sets `automountServi
|
|||||||
|
|
||||||
## Services
|
## Services
|
||||||
|
|
||||||
Services share the pod's network, so a step reaches one by its id or `localhost`, and two services cannot listen on the same port. An id is lowercased and has characters other than letters, digits and `-` replaced by `-`, so the service `my_db` is reached as `my-db`. Pass secrets to services through `env`, as `command` is visible in the pod spec. Of `options`, only `--health-*` is supported. They become a startup probe with Docker's defaults, which stops a service that fails its retries, so the job fails as on Docker.
|
Services share the pod's network, so a step reaches one by its id or `localhost`, and two services cannot listen on the same port. An id that is not a valid hostname is sanitized, so `my_db` is reached as `my-db`. Pass secrets to services through `env`, as `command` is visible in the pod spec. Of `options`, only `--health-*` is supported. They become a startup probe with Docker's defaults, which stops a service that fails its retries, so the job fails as on Docker.
|
||||||
|
|
||||||
## Unsupported
|
## Unsupported
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
//go:build e2e
|
||||||
|
|
||||||
|
package e2e
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func testMovingActionRef(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
ctx := t.Context()
|
||||||
|
|
||||||
|
api, repo, _ := startIsolatedScenario(t, "action_ref.yml", "e2e-action-ref", runnerOptions{})
|
||||||
|
const actionRepo = "e2e-moving-action"
|
||||||
|
if err := api.CreateRepo(ctx, actionRepo); err != nil {
|
||||||
|
t.Fatalf("create action repo: %v", err)
|
||||||
|
}
|
||||||
|
action, err := os.ReadFile("testdata/actions/moving.yml")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("read action fixture: %v", err)
|
||||||
|
}
|
||||||
|
if err := api.CreateFile(ctx, actionRepo, "action.yml", string(action), "add action"); err != nil {
|
||||||
|
t.Fatalf("push action: %v", err)
|
||||||
|
}
|
||||||
|
branch, err := api.DefaultBranch(ctx, repo)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("get default branch: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var previousID int64
|
||||||
|
for revision := range 3 {
|
||||||
|
name := fmt.Sprintf("revision-%d", revision)
|
||||||
|
if err := api.CreateFile(ctx, actionRepo, name, name, "add "+name); err != nil {
|
||||||
|
t.Fatalf("move the action ref: %v", err)
|
||||||
|
}
|
||||||
|
if err := waitForDispatch(ctx, api, repo, "action_ref.yml", branch, map[string]string{"revision": name}); err != nil {
|
||||||
|
t.Fatalf("dispatch workflow: %v", err)
|
||||||
|
}
|
||||||
|
wfRun := waitForRunAfter(t, api, repo, previousID)
|
||||||
|
requireSuccess(t, api, repo, wfRun.ID)
|
||||||
|
previousID = wfRun.ID
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -31,6 +31,7 @@ func TestCompatibility(t *testing.T) {
|
|||||||
t.Run("cancellation_and_log_streaming", testRunCancellation)
|
t.Run("cancellation_and_log_streaming", testRunCancellation)
|
||||||
t.Run("dispatch", testWorkflowDispatch)
|
t.Run("dispatch", testWorkflowDispatch)
|
||||||
t.Run("builtin_checkout", testBuiltinCheckout)
|
t.Run("builtin_checkout", testBuiltinCheckout)
|
||||||
|
t.Run("moving_action_ref", testMovingActionRef)
|
||||||
t.Run("ephemeral", testEphemeralRunner)
|
t.Run("ephemeral", testEphemeralRunner)
|
||||||
t.Run("kubernetes", testKubernetes)
|
t.Run("kubernetes", testKubernetes)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ func testWorkflowDispatch(t *testing.T) {
|
|||||||
t.Fatalf("get default branch: %v", err)
|
t.Fatalf("get default branch: %v", err)
|
||||||
}
|
}
|
||||||
inputs := map[string]string{"subject": "dispatch-input-value"}
|
inputs := map[string]string{"subject": "dispatch-input-value"}
|
||||||
if err := waitForDispatch(ctx, api, repo, branch, inputs); err != nil {
|
if err := waitForDispatch(ctx, api, repo, "dispatch.yml", branch, inputs); err != nil {
|
||||||
t.Fatalf("dispatch workflow: %v", err)
|
t.Fatalf("dispatch workflow: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,13 +35,13 @@ func testWorkflowDispatch(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Gitea indexes workflows asynchronously after the Contents API commit.
|
// Gitea indexes workflows asynchronously after the Contents API commit.
|
||||||
func waitForDispatch(ctx context.Context, api *GiteaAPI, repo, branch string, inputs map[string]string) error {
|
func waitForDispatch(ctx context.Context, api *GiteaAPI, repo, workflow, branch string, inputs map[string]string) error {
|
||||||
ctx, cancel := context.WithTimeout(ctx, time.Minute)
|
ctx, cancel := context.WithTimeout(ctx, time.Minute)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
var lastErr error
|
var lastErr error
|
||||||
for {
|
for {
|
||||||
lastErr = api.DispatchWorkflow(ctx, repo, "dispatch.yml", branch, inputs)
|
lastErr = api.DispatchWorkflow(ctx, repo, workflow, branch, inputs)
|
||||||
if lastErr == nil {
|
if lastErr == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+9
@@ -0,0 +1,9 @@
|
|||||||
|
name: moving
|
||||||
|
inputs:
|
||||||
|
revision:
|
||||||
|
required: true
|
||||||
|
runs:
|
||||||
|
using: composite
|
||||||
|
steps:
|
||||||
|
- run: test -e "$GITHUB_ACTION_PATH/${{ inputs.revision }}"
|
||||||
|
shell: sh
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
name: action-ref
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
revision:
|
||||||
|
required: true
|
||||||
|
jobs:
|
||||||
|
moving:
|
||||||
|
runs-on: e2e-action-ref
|
||||||
|
steps:
|
||||||
|
- uses: self:e2e-admin/e2e-moving-action@main
|
||||||
|
with:
|
||||||
|
revision: ${{ inputs.revision }}
|
||||||
Vendored
+2
-2
@@ -7,7 +7,7 @@ jobs:
|
|||||||
- run: |
|
- run: |
|
||||||
mkdir -p cached
|
mkdir -p cached
|
||||||
echo "cached-payload" > cached/data.txt
|
echo "cached-payload" > cached/data.txt
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
with:
|
with:
|
||||||
path: cached
|
path: cached
|
||||||
key: e2e-cache-${{ github.run_id }}
|
key: e2e-cache-${{ github.run_id }}
|
||||||
@@ -15,7 +15,7 @@ jobs:
|
|||||||
needs: save
|
needs: save
|
||||||
runs-on: e2e-cache
|
runs-on: e2e-cache
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v6
|
||||||
id: restore
|
id: restore
|
||||||
with:
|
with:
|
||||||
path: cached
|
path: cached
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ jobs:
|
|||||||
NGINX_ENTRYPOINT_QUIET_LOGS: 1
|
NGINX_ENTRYPOINT_QUIET_LOGS: 1
|
||||||
options: --health-cmd "wget -q -O /dev/null http://localhost/" --health-interval 1s
|
options: --health-cmd "wget -q -O /dev/null http://localhost/" --health-interval 1s
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v7
|
||||||
- run: |
|
- run: |
|
||||||
test -f .gitea/workflows/kubernetes.yml
|
test -f .gitea/workflows/kubernetes.yml
|
||||||
echo "FROM_ENV=exported" >> "$GITHUB_ENV"
|
echo "FROM_ENV=exported" >> "$GITHUB_ENV"
|
||||||
|
|||||||
Vendored
+2
-2
@@ -33,7 +33,7 @@ jobs:
|
|||||||
- id: emit
|
- id: emit
|
||||||
run: echo "token=produced-value-42" >> "$GITHUB_OUTPUT"
|
run: echo "token=produced-value-42" >> "$GITHUB_OUTPUT"
|
||||||
- run: echo "artifact content" > payload.txt
|
- run: echo "artifact content" > payload.txt
|
||||||
- uses: actions/upload-artifact@v4
|
- uses: actions/upload-artifact@v7
|
||||||
with:
|
with:
|
||||||
name: payload
|
name: payload
|
||||||
path: payload.txt
|
path: payload.txt
|
||||||
@@ -41,7 +41,7 @@ jobs:
|
|||||||
needs: produce
|
needs: produce
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/download-artifact@v4
|
- uses: actions/download-artifact@v8
|
||||||
with:
|
with:
|
||||||
name: payload
|
name: payload
|
||||||
- run: grep -q 'artifact content' payload.txt
|
- run: grep -q 'artifact content' payload.txt
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ spec:
|
|||||||
claimName: docker-vol
|
claimName: docker-vol
|
||||||
initContainers:
|
initContainers:
|
||||||
- name: docker
|
- name: docker
|
||||||
image: docker:28.2.2-dind
|
image: docker:29.9.1-dind
|
||||||
securityContext:
|
securityContext:
|
||||||
privileged: true
|
privileged: true
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ spec:
|
|||||||
emptyDir: {}
|
emptyDir: {}
|
||||||
initContainers:
|
initContainers:
|
||||||
- name: docker
|
- name: docker
|
||||||
image: docker:28.2.2-dind
|
image: docker:29.9.1-dind
|
||||||
securityContext:
|
securityContext:
|
||||||
privileged: true
|
privileged: true
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
|
|||||||
@@ -2,13 +2,11 @@ module gitea.com/gitea/runner
|
|||||||
|
|
||||||
go 1.27
|
go 1.27
|
||||||
|
|
||||||
toolchain go1.27.2
|
toolchain go1.27.3
|
||||||
|
|
||||||
require (
|
require (
|
||||||
connectrpc.com/connect v1.21.0
|
connectrpc.com/connect v1.21.0
|
||||||
dario.cat/mergo v1.0.2
|
|
||||||
gitea.dev/actionslib v1.4.1
|
gitea.dev/actionslib v1.4.1
|
||||||
github.com/avast/retry-go/v5 v5.0.0
|
|
||||||
github.com/bmatcuk/doublestar/v4 v4.10.2
|
github.com/bmatcuk/doublestar/v4 v4.10.2
|
||||||
github.com/coder/websocket v1.8.15
|
github.com/coder/websocket v1.8.15
|
||||||
github.com/containerd/errdefs v1.0.0
|
github.com/containerd/errdefs v1.0.0
|
||||||
@@ -17,21 +15,15 @@ require (
|
|||||||
github.com/docker/cli v29.8.2+incompatible
|
github.com/docker/cli v29.8.2+incompatible
|
||||||
github.com/docker/go-connections v0.8.1
|
github.com/docker/go-connections v0.8.1
|
||||||
github.com/docker/go-units v0.5.0
|
github.com/docker/go-units v0.5.0
|
||||||
github.com/google/go-cmp v0.7.0
|
|
||||||
github.com/johannesboyne/gofakes3 v1.2.0
|
github.com/johannesboyne/gofakes3 v1.2.0
|
||||||
github.com/joho/godotenv v1.5.1
|
github.com/joho/godotenv v1.5.1
|
||||||
github.com/julienschmidt/httprouter v1.3.0
|
|
||||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
|
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
|
||||||
github.com/mattn/go-isatty v0.0.24
|
|
||||||
github.com/moby/go-archive v0.3.3
|
|
||||||
github.com/moby/moby/api v1.56.1
|
github.com/moby/moby/api v1.56.1
|
||||||
github.com/moby/moby/client v0.6.1
|
github.com/moby/moby/client v0.6.1
|
||||||
github.com/moby/patternmatcher v0.6.1
|
github.com/moby/patternmatcher v0.6.1
|
||||||
github.com/opencontainers/image-spec v1.1.1
|
github.com/opencontainers/image-spec v1.1.1
|
||||||
github.com/opencontainers/selinux v1.15.1
|
|
||||||
github.com/prometheus/client_golang v1.24.1
|
github.com/prometheus/client_golang v1.24.1
|
||||||
github.com/prometheus/client_model v0.6.3
|
github.com/prometheus/client_model v0.6.3
|
||||||
github.com/sirupsen/logrus v1.10.2
|
|
||||||
github.com/spf13/cobra v1.10.2
|
github.com/spf13/cobra v1.10.2
|
||||||
github.com/spf13/pflag v1.0.10
|
github.com/spf13/pflag v1.0.10
|
||||||
github.com/stretchr/testify v1.12.1
|
github.com/stretchr/testify v1.12.1
|
||||||
@@ -42,44 +34,32 @@ require (
|
|||||||
go.opentelemetry.io/otel/sdk v1.47.0
|
go.opentelemetry.io/otel/sdk v1.47.0
|
||||||
go.opentelemetry.io/otel/trace v1.47.0
|
go.opentelemetry.io/otel/trace v1.47.0
|
||||||
go.opentelemetry.io/proto/otlp v1.11.1
|
go.opentelemetry.io/proto/otlp v1.11.1
|
||||||
go.yaml.in/yaml/v4 v4.0.0-rc.6
|
go.yaml.in/yaml/v4 v4.0.0-rc.6.0.20261013184558-04dd63131525
|
||||||
golang.org/x/net v0.60.0
|
golang.org/x/net v0.60.0
|
||||||
golang.org/x/sync v0.24.0
|
golang.org/x/sync v0.24.0
|
||||||
golang.org/x/sys v0.49.0
|
golang.org/x/sys v0.49.0
|
||||||
golang.org/x/term v0.46.0
|
golang.org/x/term v0.46.0
|
||||||
golang.org/x/text v0.42.0
|
golang.org/x/text v0.42.0
|
||||||
google.golang.org/protobuf v1.36.12
|
google.golang.org/protobuf v1.36.12
|
||||||
gotest.tools/v3 v3.5.2
|
|
||||||
tags.cncf.io/container-device-interface v1.1.1
|
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
cyphar.com/go-pathrs v0.2.5 // indirect
|
|
||||||
github.com/Microsoft/go-winio v0.6.2 // indirect
|
github.com/Microsoft/go-winio v0.6.2 // indirect
|
||||||
github.com/beorn7/perks v1.0.1 // indirect
|
github.com/beorn7/perks v1.0.1 // indirect
|
||||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||||
github.com/containerd/errdefs/pkg v0.3.0 // indirect
|
github.com/containerd/errdefs/pkg v0.3.0 // indirect
|
||||||
github.com/containerd/log v0.1.0 // indirect
|
|
||||||
github.com/cyphar/filepath-securejoin v0.7.0 // indirect
|
|
||||||
github.com/docker/docker-credential-helpers v0.9.8 // indirect
|
|
||||||
github.com/felixge/httpsnoop v1.1.0 // indirect
|
github.com/felixge/httpsnoop v1.1.0 // indirect
|
||||||
github.com/go-logr/logr v1.4.4 // indirect
|
github.com/go-logr/logr v1.4.4 // indirect
|
||||||
github.com/go-logr/stdr v1.2.2 // indirect
|
github.com/go-logr/stdr v1.2.2 // indirect
|
||||||
github.com/go-viper/mapstructure/v2 v2.5.0 // indirect
|
|
||||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
|
|
||||||
github.com/google/uuid v1.6.0 // indirect
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||||
github.com/klauspost/compress v1.19.2 // indirect
|
github.com/klauspost/compress v1.19.2 // indirect
|
||||||
github.com/moby/docker-image-spec v1.3.1 // indirect
|
github.com/moby/docker-image-spec v1.3.1 // indirect
|
||||||
github.com/moby/sys/sequential v0.7.0 // indirect
|
|
||||||
github.com/moby/sys/user v0.4.1 // indirect
|
|
||||||
github.com/moby/sys/userns v0.2.0 // indirect
|
|
||||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||||
github.com/opencontainers/go-digest v1.0.0 // indirect
|
github.com/opencontainers/go-digest v1.0.0 // indirect
|
||||||
github.com/prometheus/common v0.70.1 // indirect
|
github.com/prometheus/common v0.70.1 // indirect
|
||||||
github.com/prometheus/procfs v0.21.1 // indirect
|
github.com/prometheus/procfs v0.21.1 // indirect
|
||||||
github.com/ryszard/goskiplist v0.0.0-20150312221310-2dfbae5fcf46 // indirect
|
github.com/ryszard/goskiplist v0.0.0-20150312221310-2dfbae5fcf46 // indirect
|
||||||
github.com/santhosh-tekuri/jsonschema/v6 v6.0.3 // indirect
|
|
||||||
github.com/stretchr/objx v0.5.3 // indirect
|
github.com/stretchr/objx v0.5.3 // indirect
|
||||||
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
|
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
|
||||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.70.0 // indirect
|
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.70.0 // indirect
|
||||||
|
|||||||
@@ -1,17 +1,9 @@
|
|||||||
connectrpc.com/connect v1.21.0 h1:LhqSJt7jHf5NJBo9Jq/t/9FjcYAideif0mg+qe2jCUs=
|
connectrpc.com/connect v1.21.0 h1:LhqSJt7jHf5NJBo9Jq/t/9FjcYAideif0mg+qe2jCUs=
|
||||||
connectrpc.com/connect v1.21.0/go.mod h1:A2ygJrukXwWy32vkCAAHNVguZrqZ+jeZ9rGRnGR4dN4=
|
connectrpc.com/connect v1.21.0/go.mod h1:A2ygJrukXwWy32vkCAAHNVguZrqZ+jeZ9rGRnGR4dN4=
|
||||||
cyphar.com/go-pathrs v0.2.5 h1:SnX9FBvnoyn3lUs1dkMgZ52bAETpirNu3FTRh5HlRik=
|
|
||||||
cyphar.com/go-pathrs v0.2.5/go.mod h1:y8f1EMG7r+hCuFf/rXsKqMJrJAUoADZGNh5/vZPKcGc=
|
|
||||||
dario.cat/mergo v1.0.2 h1:85+piFYR1tMbRrLcDwR18y4UKJ3aH1Tbzi24VRW1TK8=
|
|
||||||
dario.cat/mergo v1.0.2/go.mod h1:E/hbnu0NxMFBjpMIE34DRGLWqDy0g5FuKDhCb31ngxA=
|
|
||||||
gitea.dev/actionslib v1.4.1 h1:DWlUnzDfuuMArQWS6yZ+vwJu9av7sZVMOox7li/kyu4=
|
gitea.dev/actionslib v1.4.1 h1:DWlUnzDfuuMArQWS6yZ+vwJu9av7sZVMOox7li/kyu4=
|
||||||
gitea.dev/actionslib v1.4.1/go.mod h1:RbXaZudZ04YndjBBxZJF9rZAqU6SKGkaSD1sob5lQbE=
|
gitea.dev/actionslib v1.4.1/go.mod h1:RbXaZudZ04YndjBBxZJF9rZAqU6SKGkaSD1sob5lQbE=
|
||||||
github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6 h1:He8afgbRMd7mFxO99hRNu+6tazq8nFF9lIwo9JFroBk=
|
|
||||||
github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8=
|
|
||||||
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
|
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
|
||||||
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
|
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
|
||||||
github.com/avast/retry-go/v5 v5.0.0 h1:kf1Qc2UsTZ4qq8elDymqfbISvkyMuhgRxuJqX2NHP7k=
|
|
||||||
github.com/avast/retry-go/v5 v5.0.0/go.mod h1://d+usmKWio1agtZfS1H/ltTqwtIfBnRq9zEwjc3eH8=
|
|
||||||
github.com/aws/aws-sdk-go-v2 v1.41.5 h1:dj5kopbwUsVUVFgO4Fi5BIT3t4WyqIDjGKCangnV/yY=
|
github.com/aws/aws-sdk-go-v2 v1.41.5 h1:dj5kopbwUsVUVFgO4Fi5BIT3t4WyqIDjGKCangnV/yY=
|
||||||
github.com/aws/aws-sdk-go-v2 v1.41.5/go.mod h1:mwsPRE8ceUUpiTgF7QmQIJ7lgsKUPQOUl3o72QBrE1o=
|
github.com/aws/aws-sdk-go-v2 v1.41.5/go.mod h1:mwsPRE8ceUUpiTgF7QmQIJ7lgsKUPQOUl3o72QBrE1o=
|
||||||
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.8 h1:eBMB84YGghSocM7PsjmmPffTa+1FBUeNvGvFou6V/4o=
|
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.8 h1:eBMB84YGghSocM7PsjmmPffTa+1FBUeNvGvFou6V/4o=
|
||||||
@@ -52,23 +44,15 @@ github.com/containerd/errdefs v1.0.0 h1:tg5yIfIlQIrxYtu9ajqY42W3lpS19XqdxRQeEwYG
|
|||||||
github.com/containerd/errdefs v1.0.0/go.mod h1:+YBYIdtsnF4Iw6nWZhJcqGSg/dwvV7tyJ/kCkyJ2k+M=
|
github.com/containerd/errdefs v1.0.0/go.mod h1:+YBYIdtsnF4Iw6nWZhJcqGSg/dwvV7tyJ/kCkyJ2k+M=
|
||||||
github.com/containerd/errdefs/pkg v0.3.0 h1:9IKJ06FvyNlexW690DXuQNx2KA2cUJXx151Xdx3ZPPE=
|
github.com/containerd/errdefs/pkg v0.3.0 h1:9IKJ06FvyNlexW690DXuQNx2KA2cUJXx151Xdx3ZPPE=
|
||||||
github.com/containerd/errdefs/pkg v0.3.0/go.mod h1:NJw6s9HwNuRhnjJhM7pylWwMyAkmCQvQ4GpJHEqRLVk=
|
github.com/containerd/errdefs/pkg v0.3.0/go.mod h1:NJw6s9HwNuRhnjJhM7pylWwMyAkmCQvQ4GpJHEqRLVk=
|
||||||
github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
|
|
||||||
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
|
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
|
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
|
||||||
github.com/creack/pty v1.1.24 h1:bJrF4RRfyJnbTJqzRLHzcGaZK1NeM5kTC9jGgovnR1s=
|
github.com/creack/pty v1.1.24 h1:bJrF4RRfyJnbTJqzRLHzcGaZK1NeM5kTC9jGgovnR1s=
|
||||||
github.com/creack/pty v1.1.24/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE=
|
github.com/creack/pty v1.1.24/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE=
|
||||||
github.com/cyphar/filepath-securejoin v0.7.0 h1:s0Y3ITPy6sQn5xt54DuYvTF8hu134ooYLUb58DX/HjE=
|
|
||||||
github.com/cyphar/filepath-securejoin v0.7.0/go.mod h1:ymLGms/u3BYaviIiuKFnUx8EkQEZeK6cInNoAPJA3o4=
|
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
|
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
|
||||||
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
|
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
|
||||||
github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI=
|
|
||||||
github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
|
|
||||||
github.com/docker/cli v29.8.2+incompatible h1:2zgdFuoFst2T80oS42vhKGxkd0JRo305eIEKTsxR7pQ=
|
github.com/docker/cli v29.8.2+incompatible h1:2zgdFuoFst2T80oS42vhKGxkd0JRo305eIEKTsxR7pQ=
|
||||||
github.com/docker/cli v29.8.2+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
|
github.com/docker/cli v29.8.2+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
|
||||||
github.com/docker/docker-credential-helpers v0.9.8 h1:bIREROb7So6PRlq6KTtdS9MPEjC29OQRkFNlvK2OX8Q=
|
|
||||||
github.com/docker/docker-credential-helpers v0.9.8/go.mod h1:v1S+hepowrQXITkEfw6o4+BMbGot02wiKpzWhGUZK6c=
|
|
||||||
github.com/docker/go-connections v0.8.1 h1:JibmG5hULs5qXSr/cp/w3Pw5fZuStt4MOHMUExb29/M=
|
github.com/docker/go-connections v0.8.1 h1:JibmG5hULs5qXSr/cp/w3Pw5fZuStt4MOHMUExb29/M=
|
||||||
github.com/docker/go-connections v0.8.1/go.mod h1:no1qkHdjq7kLMGUXYAduOhYPSJxxvgWBh7ogVvptn3Q=
|
github.com/docker/go-connections v0.8.1/go.mod h1:no1qkHdjq7kLMGUXYAduOhYPSJxxvgWBh7ogVvptn3Q=
|
||||||
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
|
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
|
||||||
@@ -80,12 +64,8 @@ github.com/go-logr/logr v1.4.4 h1:tG4xh9yMsRCAiodLVTxyrkzSZ9+o0L1Kg/+cPVcbP/8=
|
|||||||
github.com/go-logr/logr v1.4.4/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
github.com/go-logr/logr v1.4.4/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||||
github.com/go-viper/mapstructure/v2 v2.5.0 h1:vM5IJoUAy3d7zRSVtIwQgBj7BiWtMPfmPEgAXnvj1Ro=
|
|
||||||
github.com/go-viper/mapstructure/v2 v2.5.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
|
|
||||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
|
|
||||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
|
|
||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||||
@@ -94,44 +74,26 @@ github.com/johannesboyne/gofakes3 v1.2.0 h1:I9VEzPWvvAUAGzDlhYFoZjF0AXMlkcEyZlmB
|
|||||||
github.com/johannesboyne/gofakes3 v1.2.0/go.mod h1:UHhRZRod9rENGFrUWTYnQHZqlNgSmjOq8DaD/ATQYRM=
|
github.com/johannesboyne/gofakes3 v1.2.0/go.mod h1:UHhRZRod9rENGFrUWTYnQHZqlNgSmjOq8DaD/ATQYRM=
|
||||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||||
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
|
|
||||||
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
|
|
||||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
|
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
|
||||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
|
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
|
||||||
github.com/klauspost/compress v1.19.2 h1:hMRETovs/pu/dVWN7zIT1PGG8t509MwT6bO7XSi26R8=
|
github.com/klauspost/compress v1.19.2 h1:hMRETovs/pu/dVWN7zIT1PGG8t509MwT6bO7XSi26R8=
|
||||||
github.com/klauspost/compress v1.19.2/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ=
|
github.com/klauspost/compress v1.19.2/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ=
|
||||||
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
|
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
|
||||||
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
|
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
|
||||||
github.com/mattn/go-isatty v0.0.24 h1:tGZZoVgT/KiqK1c8ocVLeDS8BSWMRd47J3Lbz7vsReI=
|
|
||||||
github.com/mattn/go-isatty v0.0.24/go.mod h1:nMCL3Zebbrt45jsMDgnfIwz6ydEQApk5oEI3HqDio6A=
|
|
||||||
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
|
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
|
||||||
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
|
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
|
||||||
github.com/moby/go-archive v0.3.3 h1:OxxR9paxsluYi+zDUEXTTaIxtkK3viymW+Ka7vRhhME=
|
|
||||||
github.com/moby/go-archive v0.3.3/go.mod h1:Npdv43fFqlhZW7Xo8fbm3ZMYFvAGNviUPqX21VERbcE=
|
|
||||||
github.com/moby/moby/api v1.56.1 h1:PpWkvVPB7Fr/No8w+TfyJ/I6rWZ2YPZhT3JorIg+06c=
|
github.com/moby/moby/api v1.56.1 h1:PpWkvVPB7Fr/No8w+TfyJ/I6rWZ2YPZhT3JorIg+06c=
|
||||||
github.com/moby/moby/api v1.56.1/go.mod h1:sZ+THbVWkjOmBPPfbnzdD/G1LuIexWhqlSHHPTDQ1Uk=
|
github.com/moby/moby/api v1.56.1/go.mod h1:sZ+THbVWkjOmBPPfbnzdD/G1LuIexWhqlSHHPTDQ1Uk=
|
||||||
github.com/moby/moby/client v0.6.1 h1:gvfKmdcWw+9MzXYP0vAUKQtBTGu1L8475K2nsmL7O98=
|
github.com/moby/moby/client v0.6.1 h1:gvfKmdcWw+9MzXYP0vAUKQtBTGu1L8475K2nsmL7O98=
|
||||||
github.com/moby/moby/client v0.6.1/go.mod h1:XHgTFqz9NCgS/VuoxXMmEDVmVgXQ4vFEc15wsCIwb24=
|
github.com/moby/moby/client v0.6.1/go.mod h1:XHgTFqz9NCgS/VuoxXMmEDVmVgXQ4vFEc15wsCIwb24=
|
||||||
github.com/moby/patternmatcher v0.6.1 h1:qlhtafmr6kgMIJjKJMDmMWq7WLkKIo23hsrpR3x084U=
|
github.com/moby/patternmatcher v0.6.1 h1:qlhtafmr6kgMIJjKJMDmMWq7WLkKIo23hsrpR3x084U=
|
||||||
github.com/moby/patternmatcher v0.6.1/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc=
|
github.com/moby/patternmatcher v0.6.1/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc=
|
||||||
github.com/moby/sys/mount v0.3.5 h1:eS3fsZTjHaBihwjp4/+5Z3jxqLXYsbwxqpVSfFv3M00=
|
|
||||||
github.com/moby/sys/mount v0.3.5/go.mod h1:WUQDO+/uCiCIkIztx8SrwIDVn2dtMFRBebRhpDFT71M=
|
|
||||||
github.com/moby/sys/mountinfo v0.7.2 h1:1shs6aH5s4o5H2zQLn796ADW1wMrIwHsyJ2v9KouLrg=
|
|
||||||
github.com/moby/sys/mountinfo v0.7.2/go.mod h1:1YOa8w8Ih7uW0wALDUgT1dTTSBrZ+HiBLGws92L2RU4=
|
|
||||||
github.com/moby/sys/sequential v0.7.0 h1:ASQNGNROJSuOO6LL6bPHbKvuZu6NU8P4ldPWk31zj/8=
|
|
||||||
github.com/moby/sys/sequential v0.7.0/go.mod h1:NfSTAp6V3fw4tmkD62PEcOKeZKquXT8VKCkf7aVR79o=
|
|
||||||
github.com/moby/sys/user v0.4.1 h1:RgjRlaDKi/Xmyrz4t8lyzXT6v2ooFeO/7xtchmhVWE0=
|
|
||||||
github.com/moby/sys/user v0.4.1/go.mod h1:E9QsW5WRe1kUAf7kW8hXKwu1uhsZEAdPLYHYSDudF4Y=
|
|
||||||
github.com/moby/sys/userns v0.2.0 h1:nEtDtp7NCV/6dutSklNe8FrENPwFdc4mXnZqC/JWgXM=
|
|
||||||
github.com/moby/sys/userns v0.2.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28=
|
|
||||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
|
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
|
||||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
|
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
|
||||||
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
|
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
|
||||||
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
|
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
|
||||||
github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040=
|
github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040=
|
||||||
github.com/opencontainers/image-spec v1.1.1/go.mod h1:qpqAh3Dmcf36wStyyWU+kCeDgrGnAve2nCC8+7h8Q0M=
|
github.com/opencontainers/image-spec v1.1.1/go.mod h1:qpqAh3Dmcf36wStyyWU+kCeDgrGnAve2nCC8+7h8Q0M=
|
||||||
github.com/opencontainers/selinux v1.15.1 h1:ERxeh5caJvCzNAKdI8WQbJmB1LDTn4BuaAg8wihLBpA=
|
|
||||||
github.com/opencontainers/selinux v1.15.1/go.mod h1:LenyElirjUHszfxrjuFqC85HIeXZKumHcKMQtnaDlQQ=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/prometheus/client_golang v1.24.1 h1:JnJkREXzWxUdCuPFpIWZiPispT9xVV59uiuyR2bPlnU=
|
github.com/prometheus/client_golang v1.24.1 h1:JnJkREXzWxUdCuPFpIWZiPispT9xVV59uiuyR2bPlnU=
|
||||||
github.com/prometheus/client_golang v1.24.1/go.mod h1:F+oSRECHg4sse5ucfYpYDeIv/hu68Zo0uoHKetWnzcE=
|
github.com/prometheus/client_golang v1.24.1/go.mod h1:F+oSRECHg4sse5ucfYpYDeIv/hu68Zo0uoHKetWnzcE=
|
||||||
@@ -144,10 +106,6 @@ github.com/prometheus/procfs v0.21.1/go.mod h1:aB55Cww9pdSJVHk0hUf0inxWyyjPogFIj
|
|||||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
github.com/ryszard/goskiplist v0.0.0-20150312221310-2dfbae5fcf46 h1:GHRpF1pTW19a8tTFrMLUcfWwyC0pnifVo2ClaLq+hP8=
|
github.com/ryszard/goskiplist v0.0.0-20150312221310-2dfbae5fcf46 h1:GHRpF1pTW19a8tTFrMLUcfWwyC0pnifVo2ClaLq+hP8=
|
||||||
github.com/ryszard/goskiplist v0.0.0-20150312221310-2dfbae5fcf46/go.mod h1:uAQ5PCi+MFsC7HjREoAz1BU+Mq60+05gifQSsHSDG/8=
|
github.com/ryszard/goskiplist v0.0.0-20150312221310-2dfbae5fcf46/go.mod h1:uAQ5PCi+MFsC7HjREoAz1BU+Mq60+05gifQSsHSDG/8=
|
||||||
github.com/santhosh-tekuri/jsonschema/v6 v6.0.3 h1:1EYB5IzjZawrrnELUi78f9fPu57HuXjmddZPjrls/28=
|
|
||||||
github.com/santhosh-tekuri/jsonschema/v6 v6.0.3/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU=
|
|
||||||
github.com/sirupsen/logrus v1.10.2 h1:G2SED73/qrAu6YwbdxOD6peLkCBI3z7L+ykJFTXJBBo=
|
|
||||||
github.com/sirupsen/logrus v1.10.2/go.mod h1:SLEg8TqYulVKKfIGHldVp2K2aYz2DKSVBq4g/H5bR7Q=
|
|
||||||
github.com/spf13/afero v1.2.1 h1:qgMbHoJbPbw579P+1zVY+6n4nIFuIchaIjzZ/I/Yq8M=
|
github.com/spf13/afero v1.2.1 h1:qgMbHoJbPbw579P+1zVY+6n4nIFuIchaIjzZ/I/Yq8M=
|
||||||
github.com/spf13/afero v1.2.1/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
|
github.com/spf13/afero v1.2.1/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
|
||||||
github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU=
|
github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU=
|
||||||
@@ -200,8 +158,8 @@ go.yaml.in/yaml/v2 v2.4.4/go.mod h1:gMZqIpDtDqOfM0uNfy0SkpRhvUryYH0Z6wdMYcacYXQ=
|
|||||||
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
|
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
|
||||||
go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw=
|
go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw=
|
||||||
go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg=
|
go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg=
|
||||||
go.yaml.in/yaml/v4 v4.0.0-rc.6 h1:1h7H1ohdUh93/FyE4YaDa1Zh64K6VVbjF4K6WUxMtH4=
|
go.yaml.in/yaml/v4 v4.0.0-rc.6.0.20261013184558-04dd63131525 h1:FtzHH3s777Nx50YcPAcodAPm1mNakc228nMYbr3f+90=
|
||||||
go.yaml.in/yaml/v4 v4.0.0-rc.6/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0=
|
go.yaml.in/yaml/v4 v4.0.0-rc.6.0.20261013184558-04dd63131525/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0=
|
||||||
golang.org/x/net v0.60.0 h1:79p50tfZlm0J9YfoDsSi639qSXNGVwEzOPLCxM2FsYU=
|
golang.org/x/net v0.60.0 h1:79p50tfZlm0J9YfoDsSi639qSXNGVwEzOPLCxM2FsYU=
|
||||||
golang.org/x/net v0.60.0/go.mod h1:2DA/G1UfVbCpQPeWTmMPGY7Cs2PkBkwu743bVX5PIVg=
|
golang.org/x/net v0.60.0/go.mod h1:2DA/G1UfVbCpQPeWTmMPGY7Cs2PkBkwu743bVX5PIVg=
|
||||||
golang.org/x/sync v0.24.0 h1:iqiDrGoDgyuvAKrhLQthUEzU/R378N78gXbBjxed7oA=
|
golang.org/x/sync v0.24.0 h1:iqiDrGoDgyuvAKrhLQthUEzU/R378N78gXbBjxed7oA=
|
||||||
@@ -227,5 +185,3 @@ gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
|
|||||||
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
|
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
|
||||||
pgregory.net/rapid v1.2.0 h1:keKAYRcjm+e1F0oAuU5F5+YPAWcyxNNRK2wud503Gnk=
|
pgregory.net/rapid v1.2.0 h1:keKAYRcjm+e1F0oAuU5F5+YPAWcyxNNRK2wud503Gnk=
|
||||||
pgregory.net/rapid v1.2.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04=
|
pgregory.net/rapid v1.2.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04=
|
||||||
tags.cncf.io/container-device-interface v1.1.1 h1:YPwQz4xg8PlQ0yT/baR0BtLpTQROe4l6M1yuRgAu1vc=
|
|
||||||
tags.cncf.io/container-device-interface v1.1.1/go.mod h1:S1PSJWYPD4Iom0/39mvr/VVFCfG0Yt14j20d0OYrY2M=
|
|
||||||
+18
-19
@@ -33,9 +33,8 @@ import (
|
|||||||
|
|
||||||
"connectrpc.com/connect"
|
"connectrpc.com/connect"
|
||||||
runnerv1 "gitea.dev/actionslib/runner/v1"
|
runnerv1 "gitea.dev/actionslib/runner/v1"
|
||||||
"github.com/avast/retry-go/v5"
|
|
||||||
"github.com/mattn/go-isatty"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"golang.org/x/term"
|
||||||
)
|
)
|
||||||
|
|
||||||
func runDaemon(ctx context.Context, daemArgs *daemonArgs, configFile *string) func(cmd *cobra.Command, args []string) error {
|
func runDaemon(ctx context.Context, daemArgs *daemonArgs, configFile *string) func(cmd *cobra.Command, args []string) error {
|
||||||
@@ -189,22 +188,22 @@ func runDaemon(ctx context.Context, daemArgs *daemonArgs, configFile *string) fu
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
// declare the labels of the runner before fetching tasks
|
// declare the labels of the runner before fetching tasks
|
||||||
resp, err := retry.NewWithData[*connect.Response[runnerv1.DeclareResponse]](
|
var resp *connect.Response[runnerv1.DeclareResponse]
|
||||||
retry.Context(ctx),
|
for attempt := 0; ; attempt++ {
|
||||||
retry.UntilSucceeded(),
|
resp, err = runner.Declare(ctx, ls.Names())
|
||||||
retry.Delay(declareRetryDelay),
|
if err == nil || !shouldRetryDeclare(err) || ctx.Err() != nil {
|
||||||
retry.DelayType(retry.FixedDelay),
|
break
|
||||||
retry.RetryIf(shouldRetryDeclare),
|
}
|
||||||
retry.OnRetry(func(attempt uint, err error) {
|
if attempt == 0 {
|
||||||
if attempt == 0 {
|
logging.WithError(err).Warn("fail to invoke Declare, retrying until Gitea is reachable")
|
||||||
logging.WithError(err).Warn("fail to invoke Declare, retrying until Gitea is reachable")
|
} else {
|
||||||
} else {
|
logging.WithError(err).Debug("fail to invoke Declare, retrying")
|
||||||
logging.WithError(err).Debug("fail to invoke Declare, retrying")
|
}
|
||||||
}
|
select {
|
||||||
}),
|
case <-time.After(declareRetryDelay):
|
||||||
).Do(func() (*connect.Response[runnerv1.DeclareResponse], error) {
|
case <-ctx.Done():
|
||||||
return runner.Declare(ctx, ls.Names())
|
}
|
||||||
})
|
}
|
||||||
switch {
|
switch {
|
||||||
case err != nil && ctx.Err() != nil && !client.IsRegistrationRejected(err):
|
case err != nil && ctx.Err() != nil && !client.IsRegistrationRejected(err):
|
||||||
return nil
|
return nil
|
||||||
@@ -340,7 +339,7 @@ func initLogging(cfg *config.Config) {
|
|||||||
return funcname, filename
|
return funcname, filename
|
||||||
}
|
}
|
||||||
|
|
||||||
isTerm := isatty.IsTerminal(os.Stdout.Fd())
|
isTerm := term.IsTerminal(int(os.Stdout.Fd()))
|
||||||
logging.SetTextFormat(logging.TextOptions{
|
logging.SetTextFormat(logging.TextOptions{
|
||||||
DisableColors: !isTerm,
|
DisableColors: !isTerm,
|
||||||
FullTimestamp: true,
|
FullTimestamp: true,
|
||||||
|
|||||||
@@ -188,10 +188,3 @@ func TestShouldRetryDeclare(t *testing.T) {
|
|||||||
require.Equal(t, tc.retry, shouldRetryDeclare(tc.err), tc.err.Error())
|
require.Equal(t, tc.retry, shouldRetryDeclare(tc.err), tc.err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// A dependency that reconfigures logrus's global logger when it is loaded makes its own log lines
|
|
||||||
// show up twice or not at all, so this fails when upgrading one starts doing that. It does not
|
|
||||||
// cover a dependency that does so later, while running.
|
|
||||||
func TestLogrusBridgeSurvivesDependencies(t *testing.T) {
|
|
||||||
require.True(t, logging.LogrusBridgeIntact())
|
|
||||||
}
|
|
||||||
@@ -24,15 +24,15 @@ import (
|
|||||||
"connectrpc.com/connect"
|
"connectrpc.com/connect"
|
||||||
pingv1 "gitea.dev/actionslib/ping/v1"
|
pingv1 "gitea.dev/actionslib/ping/v1"
|
||||||
runnerv1 "gitea.dev/actionslib/runner/v1"
|
runnerv1 "gitea.dev/actionslib/runner/v1"
|
||||||
"github.com/mattn/go-isatty"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"golang.org/x/term"
|
||||||
)
|
)
|
||||||
|
|
||||||
// runRegister registers a runner to the server
|
// runRegister registers a runner to the server
|
||||||
func runRegister(ctx context.Context, regArgs *registerArgs, configFile *string) func(*cobra.Command, []string) error {
|
func runRegister(ctx context.Context, regArgs *registerArgs, configFile *string) func(*cobra.Command, []string) error {
|
||||||
return func(cmd *cobra.Command, args []string) error {
|
return func(cmd *cobra.Command, args []string) error {
|
||||||
logging.SetReportCaller(false)
|
logging.SetReportCaller(false)
|
||||||
isTerm := isatty.IsTerminal(os.Stdout.Fd())
|
isTerm := term.IsTerminal(int(os.Stdout.Fd()))
|
||||||
logging.SetTextFormat(logging.TextOptions{
|
logging.SetTextFormat(logging.TextOptions{
|
||||||
DisableColors: !isTerm,
|
DisableColors: !isTerm,
|
||||||
DisableTimestamp: true,
|
DisableTimestamp: true,
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import (
|
|||||||
"gitea.com/gitea/runner/internal/pkg/config"
|
"gitea.com/gitea/runner/internal/pkg/config"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"gotest.tools/v3/assert"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRegisterNonInteractiveReturnsLabelValidationError(t *testing.T) {
|
func TestRegisterNonInteractiveReturnsLabelValidationError(t *testing.T) {
|
||||||
@@ -23,7 +22,7 @@ func TestRegisterNonInteractiveReturnsLabelValidationError(t *testing.T) {
|
|||||||
Token: "token",
|
Token: "token",
|
||||||
InstanceAddr: "http://localhost:3000",
|
InstanceAddr: "http://localhost:3000",
|
||||||
})
|
})
|
||||||
assert.ErrorContains(t, err, "empty label")
|
require.ErrorContains(t, err, "empty label")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRegisterInputsValidate(t *testing.T) {
|
func TestRegisterInputsValidate(t *testing.T) {
|
||||||
@@ -262,6 +261,6 @@ func TestDoRegisterReturnsPingErrorWithoutRetrying(t *testing.T) {
|
|||||||
cfg := &config.Config{}
|
cfg := &config.Config{}
|
||||||
cfg.Runner.File = filepath.Join(t.TempDir(), ".runner")
|
cfg.Runner.File = filepath.Join(t.TempDir(), ".runner")
|
||||||
err := doRegister(t.Context(), cfg, ®isterInputs{InstanceAddr: server.URL, RunnerName: "runner"})
|
err := doRegister(t.Context(), cfg, ®isterInputs{InstanceAddr: server.URL, RunnerName: "runner"})
|
||||||
assert.ErrorContains(t, err, "cannot ping the Gitea instance server")
|
require.ErrorContains(t, err, "cannot ping the Gitea instance server")
|
||||||
assert.Equal(t, int32(1), requests.Load())
|
require.Equal(t, int32(1), requests.Load())
|
||||||
}
|
}
|
||||||
@@ -157,6 +157,8 @@ var removeOrphanJobVolumes = container.RemoveOrphanJobVolumes
|
|||||||
|
|
||||||
var removeOrphanKubernetesResources = container.RemoveOrphanKubernetesResources
|
var removeOrphanKubernetesResources = container.RemoveOrphanKubernetesResources
|
||||||
|
|
||||||
|
const orphanDockerResourceAge = 10 * time.Minute // spares the network and volumes of a job still starting its first container
|
||||||
|
|
||||||
// OnIdle performs lightweight maintenance during polling idle windows.
|
// OnIdle performs lightweight maintenance during polling idle windows.
|
||||||
// It runs synchronously on the poller goroutine; shouldRunIdleCleanup
|
// It runs synchronously on the poller goroutine; shouldRunIdleCleanup
|
||||||
// throttles invocations to runner.idle_cleanup_interval so the impact on
|
// throttles invocations to runner.idle_cleanup_interval so the impact on
|
||||||
@@ -189,10 +191,12 @@ func (r *Runner) OnIdle(ctx context.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Runner) cleanupOrphanDockerResources(ctx context.Context) {
|
func (r *Runner) cleanupOrphanDockerResources(ctx context.Context) {
|
||||||
|
ctx, cancel := context.WithTimeout(ctx, time.Minute)
|
||||||
|
defer cancel()
|
||||||
if r.uuid == "" || (!r.requiresDocker() && !dockerReachable(ctx)) {
|
if r.uuid == "" || (!r.requiresDocker() && !dockerReachable(ctx)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
cutoff := r.now().Add(-r.cfg.Runner.WorkdirCleanupAge)
|
cutoff := r.now().Add(-orphanDockerResourceAge)
|
||||||
if err := removeOrphanNetworks(ctx, r.uuid, r.isolatedCacheContainer(), cutoff); err != nil {
|
if err := removeOrphanNetworks(ctx, r.uuid, r.isolatedCacheContainer(), cutoff); err != nil {
|
||||||
logging.Warnf("failed to clean up networks left behind by earlier jobs: %v", err)
|
logging.Warnf("failed to clean up networks left behind by earlier jobs: %v", err)
|
||||||
}
|
}
|
||||||
@@ -497,9 +501,11 @@ func (r *Runner) run(ctx context.Context, task *runnerv1.Task, reporter *report.
|
|||||||
_ = job.RawServices.Decode(&services) // a whole-value expression names no service before evaluation
|
_ = job.RawServices.Decode(&services) // a whole-value expression names no service before evaluation
|
||||||
serviceNames := slices.Sorted(maps.Keys(services))
|
serviceNames := slices.Sorted(maps.Keys(services))
|
||||||
if strings.HasPrefix(platform, labels.SchemeKubernetes+"://") {
|
if strings.HasPrefix(platform, labels.SchemeKubernetes+"://") {
|
||||||
for index, name := range serviceNames {
|
var hostnames []string
|
||||||
serviceNames[index] = container.KubernetesServiceName(name)
|
for _, name := range serviceNames {
|
||||||
|
hostnames = append(hostnames, container.KubernetesServiceHostnames(name)...)
|
||||||
}
|
}
|
||||||
|
serviceNames = hostnames
|
||||||
}
|
}
|
||||||
proxyEnv := JobProxyEnv(envs, cacheURL, serviceNames)
|
proxyEnv := JobProxyEnv(envs, cacheURL, serviceNames)
|
||||||
maps.Copy(envs, proxyEnv)
|
maps.Copy(envs, proxyEnv)
|
||||||
|
|||||||
@@ -317,7 +317,9 @@ func TestRunnerOnIdleRemovesOrphanNetworks(t *testing.T) {
|
|||||||
var sweptVolumes []string
|
var sweptVolumes []string
|
||||||
var sweptCutoff time.Time
|
var sweptCutoff time.Time
|
||||||
origRemoveOrphanNetworks := removeOrphanNetworks
|
origRemoveOrphanNetworks := removeOrphanNetworks
|
||||||
removeOrphanNetworks = func(_ context.Context, runnerUUID, detach string, createdBefore time.Time) error {
|
removeOrphanNetworks = func(ctx context.Context, runnerUUID, detach string, createdBefore time.Time) error {
|
||||||
|
_, hasDeadline := ctx.Deadline()
|
||||||
|
assert.True(t, hasDeadline)
|
||||||
swept = append(swept, runnerUUID)
|
swept = append(swept, runnerUUID)
|
||||||
detached = append(detached, detach)
|
detached = append(detached, detach)
|
||||||
sweptCutoff = createdBefore
|
sweptCutoff = createdBefore
|
||||||
@@ -327,7 +329,7 @@ func TestRunnerOnIdleRemovesOrphanNetworks(t *testing.T) {
|
|||||||
origRemoveOrphanJobVolumes := removeOrphanJobVolumes
|
origRemoveOrphanJobVolumes := removeOrphanJobVolumes
|
||||||
removeOrphanJobVolumes = func(_ context.Context, runnerUUID string, createdBefore time.Time) error {
|
removeOrphanJobVolumes = func(_ context.Context, runnerUUID string, createdBefore time.Time) error {
|
||||||
sweptVolumes = append(sweptVolumes, runnerUUID)
|
sweptVolumes = append(sweptVolumes, runnerUUID)
|
||||||
assert.Equal(t, now.Add(-24*time.Hour), createdBefore)
|
assert.Equal(t, now.Add(-orphanDockerResourceAge), createdBefore)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
t.Cleanup(func() { removeOrphanJobVolumes = origRemoveOrphanJobVolumes })
|
t.Cleanup(func() { removeOrphanJobVolumes = origRemoveOrphanJobVolumes })
|
||||||
@@ -350,7 +352,7 @@ func TestRunnerOnIdleRemovesOrphanNetworks(t *testing.T) {
|
|||||||
assert.Equal(t, []string{"runner-1"}, swept)
|
assert.Equal(t, []string{"runner-1"}, swept)
|
||||||
assert.Equal(t, swept, sweptVolumes)
|
assert.Equal(t, swept, sweptVolumes)
|
||||||
// a network of a job starting during the pass is younger than this and so out of scope
|
// a network of a job starting during the pass is younger than this and so out of scope
|
||||||
assert.Equal(t, now.Add(-24*time.Hour), sweptCutoff)
|
assert.Equal(t, now.Add(-orphanDockerResourceAge), sweptCutoff)
|
||||||
|
|
||||||
// a host-only runner has no daemon to sweep
|
// a host-only runner has no daemon to sweep
|
||||||
origDockerReachable := dockerReachable
|
origDockerReachable := dockerReachable
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import (
|
|||||||
runnerv1 "gitea.dev/actionslib/runner/v1"
|
runnerv1 "gitea.dev/actionslib/runner/v1"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"go.yaml.in/yaml/v4"
|
"go.yaml.in/yaml/v4"
|
||||||
"gotest.tools/v3/assert"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_generateWorkflow(t *testing.T) {
|
func Test_generateWorkflow(t *testing.T) {
|
||||||
@@ -58,7 +57,7 @@ jobs:
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
assert: func(t *testing.T, wf *model.Workflow) {
|
assert: func(t *testing.T, wf *model.Workflow) {
|
||||||
assert.DeepEqual(t, wf.GetJob("job9").Needs(), []string{"job1", "job2"})
|
require.Equal(t, []string{"job1", "job2"}, wf.GetJob("job9").Needs())
|
||||||
},
|
},
|
||||||
want1: "job9",
|
want1: "job9",
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
@@ -83,8 +82,8 @@ jobs:
|
|||||||
},
|
},
|
||||||
assert: func(t *testing.T, wf *model.Workflow) {
|
assert: func(t *testing.T, wf *model.Workflow) {
|
||||||
job := wf.GetJob("test")
|
job := wf.GetJob("test")
|
||||||
assert.DeepEqual(t, job.Needs(), []string{})
|
require.Equal(t, []string{}, job.Needs())
|
||||||
assert.Equal(t, len(job.Steps), 2)
|
require.Len(t, job.Steps, 2)
|
||||||
},
|
},
|
||||||
want1: "test",
|
want1: "test",
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
@@ -125,9 +124,9 @@ jobs:
|
|||||||
assert: func(t *testing.T, wf *model.Workflow) {
|
assert: func(t *testing.T, wf *model.Workflow) {
|
||||||
job := wf.GetJob("deploy")
|
job := wf.GetJob("deploy")
|
||||||
needs := job.Needs()
|
needs := job.Needs()
|
||||||
assert.DeepEqual(t, needs, []string{"build", "lint", "test"})
|
require.Equal(t, []string{"build", "lint", "test"}, needs)
|
||||||
assert.Equal(t, wf.Jobs["test"].Outputs["coverage"], "80%")
|
require.Equal(t, "80%", wf.Jobs["test"].Outputs["coverage"])
|
||||||
assert.Equal(t, wf.Jobs["lint"].Result, "failure")
|
require.Equal(t, "failure", wf.Jobs["lint"].Result)
|
||||||
},
|
},
|
||||||
want1: "deploy",
|
want1: "deploy",
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
@@ -165,11 +164,11 @@ jobs:
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
assert: func(t *testing.T, wf *model.Workflow) {
|
assert: func(t *testing.T, wf *model.Workflow) {
|
||||||
assert.Equal(t, wf.Name, "Complex workflow")
|
require.Equal(t, "Complex workflow", wf.Name)
|
||||||
assert.Equal(t, wf.Env["NODE_ENV"], "production")
|
require.Equal(t, "production", wf.Env["NODE_ENV"])
|
||||||
assert.Equal(t, wf.Env["CI"], "true")
|
require.Equal(t, "true", wf.Env["CI"])
|
||||||
job := wf.GetJob("build")
|
job := wf.GetJob("build")
|
||||||
assert.Equal(t, len(job.Steps), 4)
|
require.Len(t, job.Steps, 4)
|
||||||
},
|
},
|
||||||
want1: "build",
|
want1: "build",
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
@@ -200,8 +199,8 @@ jobs:
|
|||||||
assert: func(t *testing.T, wf *model.Workflow) {
|
assert: func(t *testing.T, wf *model.Workflow) {
|
||||||
job := wf.GetJob("integration")
|
job := wf.GetJob("integration")
|
||||||
container := job.Container()
|
container := job.Container()
|
||||||
assert.Equal(t, container.Image, "node:18")
|
require.Equal(t, "node:18", container.Image)
|
||||||
assert.Equal(t, job.Services["postgres"].Image, "postgres:15")
|
require.Equal(t, "postgres:15", job.Services["postgres"].Image)
|
||||||
},
|
},
|
||||||
want1: "integration",
|
want1: "integration",
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
@@ -231,7 +230,7 @@ jobs:
|
|||||||
job := wf.GetJob("test")
|
job := wf.GetJob("test")
|
||||||
matrixes, err := job.GetMatrixes()
|
matrixes, err := job.GetMatrixes()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, len(matrixes), 2)
|
require.Len(t, matrixes, 2)
|
||||||
},
|
},
|
||||||
want1: "test",
|
want1: "test",
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
@@ -245,9 +244,9 @@ jobs:
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
assert: func(t *testing.T, wf *model.Workflow) {
|
assert: func(t *testing.T, wf *model.Workflow) {
|
||||||
assert.Equal(t, wf.Name, "Special: characters & test")
|
require.Equal(t, "Special: characters & test", wf.Name)
|
||||||
job := wf.GetJob("test")
|
job := wf.GetJob("test")
|
||||||
assert.Equal(t, len(job.Steps), 3)
|
require.Len(t, job.Steps, 3)
|
||||||
},
|
},
|
||||||
want1: "test",
|
want1: "test",
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
@@ -283,7 +282,7 @@ jobs:
|
|||||||
}
|
}
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
tt.assert(t, got)
|
tt.assert(t, got)
|
||||||
assert.Equal(t, got1, tt.want1)
|
require.Equal(t, tt.want1, got1)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -301,7 +300,7 @@ func Test_yamlV4NodeRoundTrip(t *testing.T) {
|
|||||||
|
|
||||||
out, err := yaml.Marshal(&node)
|
out, err := yaml.Marshal(&node)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, string(out), "- a\n- b\n- c\n")
|
require.Equal(t, "- a\n- b\n- c\n", string(out))
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("unmarshal and re-marshal workflow", func(t *testing.T) {
|
t.Run("unmarshal and re-marshal workflow", func(t *testing.T) {
|
||||||
@@ -310,7 +309,7 @@ func Test_yamlV4NodeRoundTrip(t *testing.T) {
|
|||||||
var wf map[string]any
|
var wf map[string]any
|
||||||
err := yaml.Unmarshal(input, &wf)
|
err := yaml.Unmarshal(input, &wf)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, wf["name"], "test")
|
require.Equal(t, "test", wf["name"])
|
||||||
|
|
||||||
out, err := yaml.Marshal(wf)
|
out, err := yaml.Marshal(wf)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@@ -318,7 +317,7 @@ func Test_yamlV4NodeRoundTrip(t *testing.T) {
|
|||||||
var wf2 map[string]any
|
var wf2 map[string]any
|
||||||
err = yaml.Unmarshal(out, &wf2)
|
err = yaml.Unmarshal(out, &wf2)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, wf2["name"], "test")
|
require.Equal(t, "test", wf2["name"])
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("node kind constants", func(t *testing.T) {
|
t.Run("node kind constants", func(t *testing.T) {
|
||||||
|
|||||||
@@ -61,9 +61,9 @@ runner:
|
|||||||
#workdir_cleanup_age: 24h
|
#workdir_cleanup_age: 24h
|
||||||
# Cadence for the idle cleanup pass. Besides the directories above, on runners that use
|
# Cadence for the idle cleanup pass. Besides the directories above, on runners that use
|
||||||
# docker it removes the per-job networks and volumes of jobs this runner did not live to
|
# docker it removes the per-job networks and volumes of jobs this runner did not live to
|
||||||
# tear down, which would otherwise hold a subnet of the daemon address pool and the job's
|
# tear down once unused and 10 minutes old, which would otherwise hold a subnet of the
|
||||||
# workspace contents until the host is rebuilt. On runners with kubernetes labels it
|
# daemon address pool and the job's workspace contents until the host is rebuilt. On
|
||||||
# removes such jobs' pods and Secrets.
|
# runners with kubernetes labels it removes such jobs' pods and Secrets.
|
||||||
#idle_cleanup_interval: 10m
|
#idle_cleanup_interval: 10m
|
||||||
# The base interval for periodic log flush to the Gitea instance.
|
# The base interval for periodic log flush to the Gitea instance.
|
||||||
# Logs may be sent earlier if the buffer reaches log_report_batch_size
|
# Logs may be sent earlier if the buffer reaches log_report_batch_size
|
||||||
@@ -76,6 +76,9 @@ runner:
|
|||||||
# Flush logs immediately when the buffer reaches this many rows.
|
# Flush logs immediately when the buffer reaches this many rows.
|
||||||
# This ensures bursty output (e.g., npm install) is delivered promptly.
|
# This ensures bursty output (e.g., npm install) is delivered promptly.
|
||||||
#log_report_batch_size: 100
|
#log_report_batch_size: 100
|
||||||
|
# The lowest severity of the runner's own messages (not step output) that are sent to the
|
||||||
|
# job log between steps: trace, debug, info, warn, error. Default if omitted: follow log.level.
|
||||||
|
#log_report_level: info
|
||||||
# The interval for reporting task state (step status, timing) to the Gitea instance.
|
# The interval for reporting task state (step status, timing) to the Gitea instance.
|
||||||
# State is also reported on step transitions (start/stop) and after each log flush.
|
# State is also reported on step transitions (start/stop) and after each log flush.
|
||||||
#state_report_interval: 5s
|
#state_report_interval: 5s
|
||||||
@@ -88,11 +91,12 @@ runner:
|
|||||||
# it replaces https://github.com with the value here, which is useful for some special network environments.
|
# it replaces https://github.com with the value here, which is useful for some special network environments.
|
||||||
#github_mirror: ''
|
#github_mirror: ''
|
||||||
# Extra HTTP headers for runner API requests to Gitea, e.g. reverse proxy authentication.
|
# Extra HTTP headers for runner API requests to Gitea, e.g. reverse proxy authentication.
|
||||||
# Not used for action clones, artifacts, job summaries or jobs. Runner headers take precedence.
|
# Not used for action downloads, artifacts, job summaries or jobs. Runner headers take precedence.
|
||||||
# Dropped on redirects to another hostname, or to HTTP if the instance URL uses HTTPS.
|
# Dropped on redirects to another hostname, or to HTTP if the instance URL uses HTTPS.
|
||||||
#extra_headers:
|
#extra_headers:
|
||||||
# X-Proxy-Token: 'example'
|
# X-Proxy-Token: 'example'
|
||||||
# When true (the default), fetch only the requested ref of an action repository (e.g. actions/checkout@v4) at depth 1 instead of cloning every branch's full history.
|
# When true (the default), clone only the requested ref at depth 1 instead of every branch's full history. Actions download as
|
||||||
|
# archives, so this applies to reusable workflows and to actions whose host serves no archive of them.
|
||||||
# Set to false to clone the full history.
|
# Set to false to clone the full history.
|
||||||
#action_shallow_clone: true
|
#action_shallow_clone: true
|
||||||
# When true (the default), inject the ACT=true environment variable into jobs.
|
# When true (the default), inject the ACT=true environment variable into jobs.
|
||||||
|
|||||||
@@ -71,16 +71,17 @@ type Runner struct {
|
|||||||
FetchTimeout time.Duration `yaml:"fetch_timeout"` // FetchTimeout specifies the timeout duration for fetching resources.
|
FetchTimeout time.Duration `yaml:"fetch_timeout"` // FetchTimeout specifies the timeout duration for fetching resources.
|
||||||
FetchInterval time.Duration `yaml:"fetch_interval"` // FetchInterval specifies the interval duration for fetching resources.
|
FetchInterval time.Duration `yaml:"fetch_interval"` // FetchInterval specifies the interval duration for fetching resources.
|
||||||
FetchIntervalMax time.Duration `yaml:"fetch_interval_max"` // FetchIntervalMax specifies the maximum backoff interval when idle.
|
FetchIntervalMax time.Duration `yaml:"fetch_interval_max"` // FetchIntervalMax specifies the maximum backoff interval when idle.
|
||||||
WorkdirCleanupAge time.Duration `yaml:"workdir_cleanup_age"` // WorkdirCleanupAge removes stale bind-workdir task directories, orphaned host-mode scratch dirs and orphaned docker and Kubernetes job resources older than this duration during idle cleanup.
|
WorkdirCleanupAge time.Duration `yaml:"workdir_cleanup_age"` // WorkdirCleanupAge removes stale bind-workdir task directories, orphaned host-mode scratch dirs and orphaned Kubernetes job resources older than this duration during idle cleanup.
|
||||||
IdleCleanupInterval time.Duration `yaml:"idle_cleanup_interval"` // IdleCleanupInterval runs the idle cleanup (stale directories, orphaned docker networks and volumes, orphaned job pods) periodically while the runner is idle. Set to 0 to disable cleanup cadence.
|
IdleCleanupInterval time.Duration `yaml:"idle_cleanup_interval"` // IdleCleanupInterval runs the idle cleanup (stale directories, orphaned docker networks and volumes, orphaned job pods) periodically while the runner is idle. Set to 0 to disable cleanup cadence.
|
||||||
LogReportInterval time.Duration `yaml:"log_report_interval"` // LogReportInterval specifies the base interval for periodic log flush.
|
LogReportInterval time.Duration `yaml:"log_report_interval"` // LogReportInterval specifies the base interval for periodic log flush.
|
||||||
LogReportMaxLatency time.Duration `yaml:"log_report_max_latency"` // LogReportMaxLatency specifies the max time a log row can wait before being sent.
|
LogReportMaxLatency time.Duration `yaml:"log_report_max_latency"` // LogReportMaxLatency specifies the max time a log row can wait before being sent.
|
||||||
LogReportBatchSize int `yaml:"log_report_batch_size"` // LogReportBatchSize triggers immediate log flush when buffer reaches this size.
|
LogReportBatchSize int `yaml:"log_report_batch_size"` // LogReportBatchSize triggers immediate log flush when buffer reaches this size.
|
||||||
|
LogReportLevel string `yaml:"log_report_level"` // LogReportLevel is the lowest level of the runner's own messages sent to the job log between steps. Empty, the default, follows log.level.
|
||||||
StateReportInterval time.Duration `yaml:"state_report_interval"` // StateReportInterval specifies the interval for state reporting.
|
StateReportInterval time.Duration `yaml:"state_report_interval"` // StateReportInterval specifies the interval for state reporting.
|
||||||
ReportCloseTimeout time.Duration `yaml:"report_close_timeout"` // ReportCloseTimeout caps each RPC attempt when flushing the final logs and task state at job completion, on a detached context so a server cancel can't block the acknowledgement.
|
ReportCloseTimeout time.Duration `yaml:"report_close_timeout"` // ReportCloseTimeout caps each RPC attempt when flushing the final logs and task state at job completion, on a detached context so a server cancel can't block the acknowledgement.
|
||||||
Labels []string `yaml:"labels"` // Labels specify the labels of the runner. Labels are declared on each startup
|
Labels []string `yaml:"labels"` // Labels specify the labels of the runner. Labels are declared on each startup
|
||||||
GithubMirror string `yaml:"github_mirror"` // GithubMirror defines what mirrors should be used when using github
|
GithubMirror string `yaml:"github_mirror"` // GithubMirror defines what mirrors should be used when using github
|
||||||
ActionShallowClone *bool `yaml:"action_shallow_clone"` // ActionShallowClone fetches only the requested ref of an action repository at depth 1 instead of cloning every branch's full history. It is a pointer to distinguish between false and not set; if not set, it defaults to true.
|
ActionShallowClone *bool `yaml:"action_shallow_clone"` // ActionShallowClone clones only the requested ref at depth 1 instead of every branch's full history, for reusable workflows and actions without an archive. It is a pointer to distinguish between false and not set; if not set, it defaults to true.
|
||||||
SetActEnv *bool `yaml:"set_act_env"` // SetActEnv controls whether the ACT=true environment variable is injected into jobs. It is a pointer to distinguish between false and not set; if not set, it defaults to true. Set it to false so workflows gated on `if: ${{ !env.ACT }}` behave like on GitHub.
|
SetActEnv *bool `yaml:"set_act_env"` // SetActEnv controls whether the ACT=true environment variable is injected into jobs. It is a pointer to distinguish between false and not set; if not set, it defaults to true. Set it to false so workflows gated on `if: ${{ !env.ACT }}` behave like on GitHub.
|
||||||
PatchActions *bool `yaml:"patch_actions"` // PatchActions applies compatibility patches to the actions a job runs, so actions written for GitHub work against Gitea, see act/runner/patch_actions.go. It is a pointer to distinguish between false and not set; if not set, it defaults to true. Set it to false to run every action exactly as published, at the price of the artifact actions refusing.
|
PatchActions *bool `yaml:"patch_actions"` // PatchActions applies compatibility patches to the actions a job runs, so actions written for GitHub work against Gitea, see act/runner/patch_actions.go. It is a pointer to distinguish between false and not set; if not set, it defaults to true. Set it to false to run every action exactly as published, at the price of the artifact actions refusing.
|
||||||
AllocatePTY bool `yaml:"allocate_pty"` // AllocatePTY allocates a pseudo-TTY for each step's process. Default is false, matching GitHub's actions/runner. Enable only for jobs that need an interactive terminal; tools like docker build emit redrawing progress frames into the captured log when a TTY is present. Applies to both host and docker backends.
|
AllocatePTY bool `yaml:"allocate_pty"` // AllocatePTY allocates a pseudo-TTY for each step's process. Default is false, matching GitHub's actions/runner. Enable only for jobs that need an interactive terminal; tools like docker build emit redrawing progress frames into the captured log when a TTY is present. Applies to both host and docker backends.
|
||||||
@@ -348,6 +349,11 @@ func LoadDefault(file string) (*Config, error) {
|
|||||||
if !slices.Contains(ToolCacheModes, cfg.Runner.ToolCacheMode) {
|
if !slices.Contains(ToolCacheModes, cfg.Runner.ToolCacheMode) {
|
||||||
return nil, fmt.Errorf("invalid runner.tool_cache_mode %q: must be one of %q", cfg.Runner.ToolCacheMode, ToolCacheModes)
|
return nil, fmt.Errorf("invalid runner.tool_cache_mode %q: must be one of %q", cfg.Runner.ToolCacheMode, ToolCacheModes)
|
||||||
}
|
}
|
||||||
|
if cfg.Runner.LogReportLevel != "" {
|
||||||
|
if _, err := logging.ParseLevel(cfg.Runner.LogReportLevel); err != nil {
|
||||||
|
return nil, fmt.Errorf("invalid runner.log_report_level: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
if err := validateExtraHeaders(cfg.Runner.ExtraHeaders); err != nil {
|
if err := validateExtraHeaders(cfg.Runner.ExtraHeaders); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -172,6 +172,11 @@ func TestLoadDefault_ToolCacheMode(t *testing.T) {
|
|||||||
assert.Contains(t, err.Error(), "tool_cache_mode")
|
assert.Contains(t, err.Error(), "tool_cache_mode")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLoadDefault_RejectsInvalidLogReportLevel(t *testing.T) {
|
||||||
|
_, err := LoadDefault(write(t, "runner:\n log_report_level: loud\n"))
|
||||||
|
require.ErrorContains(t, err, "runner.log_report_level")
|
||||||
|
}
|
||||||
|
|
||||||
func TestLoadDefault_LoadsExtraHeaders(t *testing.T) {
|
func TestLoadDefault_LoadsExtraHeaders(t *testing.T) {
|
||||||
path := filepath.Join(t.TempDir(), "config.yaml")
|
path := filepath.Join(t.TempDir(), "config.yaml")
|
||||||
require.NoError(t, os.WriteFile(path, []byte("runner:\n extra_headers:\n X-Proxy-Token: proxy-token\n"), 0o600))
|
require.NoError(t, os.WriteFile(path, []byte("runner:\n extra_headers:\n X-Proxy-Token: proxy-token\n"), 0o600))
|
||||||
|
|||||||
@@ -312,29 +312,9 @@ func allScalars(nodes []*yaml.Node) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// quoteLeadingNewlines keeps a scalar starting with a newline out of block style, whose indentation indicator the encoder drops.
|
// encodeYAML never wraps lines, re-encoding must not reflow long values.
|
||||||
// TODO: remove once https://github.com/yaml/go-yaml/pull/396 is released.
|
|
||||||
func quoteLeadingNewlines(node *yaml.Node) {
|
|
||||||
if node.Kind == yaml.ScalarNode && strings.HasPrefix(node.Value, "\n") {
|
|
||||||
node.Style = yaml.DoubleQuotedStyle
|
|
||||||
}
|
|
||||||
for _, child := range node.Content {
|
|
||||||
quoteLeadingNewlines(child)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func encodeYAML(node *yaml.Node) ([]byte, error) {
|
func encodeYAML(node *yaml.Node) ([]byte, error) {
|
||||||
quoteLeadingNewlines(node)
|
return yaml.Dump(node, yaml.WithV3Defaults(), yaml.WithIndent(2), yaml.WithLineWidth(-1))
|
||||||
var buf bytes.Buffer
|
|
||||||
encoder := yaml.NewEncoder(&buf)
|
|
||||||
encoder.SetIndent(2)
|
|
||||||
if err := encoder.Encode(node); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := encoder.Close(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return buf.Bytes(), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// restoreLayout re-applies the spacing the encoder drops: the blank lines between
|
// restoreLayout re-applies the spacing the encoder drops: the blank lines between
|
||||||
|
|||||||
@@ -280,6 +280,12 @@ func TestEditValuesPreservesFileText(t *testing.T) {
|
|||||||
edit: func(file string) error { return SetValue(file, "runner.capacity", "4") },
|
edit: func(file string) error { return SetValue(file, "runner.capacity", "4") },
|
||||||
added: "runner:\n capacity: 4\n",
|
added: "runner:\n capacity: 4\n",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "folded scalar with a long more-indented line",
|
||||||
|
content: []byte("runner:\n envs:\n FOLDED: >\n begin\n a more-indented line that is long enough for an encoder wrapping at 80 columns to break\n end\n"),
|
||||||
|
edit: func(file string) error { return SetValue(file, "runner.capacity", "4") },
|
||||||
|
added: " capacity: 4\n",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range tests {
|
for _, tc := range tests {
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"gotest.tools/v3/assert"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestParse(t *testing.T) {
|
func TestParse(t *testing.T) {
|
||||||
@@ -77,7 +76,7 @@ func TestParse(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.DeepEqual(t, got, tt.want)
|
require.Equal(t, tt.want, got)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,11 @@
|
|||||||
package process
|
package process
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"runtime"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -64,3 +67,15 @@ func (t *TreeKill) Capture(p *os.Process) (*Killer, error) {
|
|||||||
t.killer.Store(k)
|
t.killer.Store(k)
|
||||||
return k, nil
|
return k, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wait is cmd.Wait, but like GitHub's runner a leftover holding a successful command's output does not fail it, and is killed only on Windows.
|
||||||
|
func (t *TreeKill) Wait(ctx context.Context, cmd *exec.Cmd) error {
|
||||||
|
err := cmd.Wait()
|
||||||
|
if !errors.Is(err, exec.ErrWaitDelay) || ctx.Err() != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
_ = t.killer.Load().Kill()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -4,8 +4,12 @@
|
|||||||
package process
|
package process
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"io"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
@@ -20,6 +24,41 @@ func TestNewTreeKillConfiguresCommand(t *testing.T) {
|
|||||||
require.NoError(t, cmd.Cancel())
|
require.NoError(t, cmd.Cancel())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTreeKillWaitWithLeftoverHoldingOutput(t *testing.T) {
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
t.Skip("uses POSIX shell")
|
||||||
|
}
|
||||||
|
for _, tc := range []struct {
|
||||||
|
name string
|
||||||
|
timeout time.Duration
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
{name: "succeeds", timeout: time.Minute},
|
||||||
|
{name: "fails once the context is done", timeout: 10 * time.Millisecond, wantErr: true},
|
||||||
|
} {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
ctx, cancel := context.WithTimeout(t.Context(), tc.timeout)
|
||||||
|
defer cancel()
|
||||||
|
cmd := exec.CommandContext(ctx, "sh", "-c", "sleep 30 &")
|
||||||
|
cmd.Stdout = io.Discard
|
||||||
|
cmd.SysProcAttr = SysProcAttr("", false)
|
||||||
|
tk := NewTreeKill(cmd)
|
||||||
|
cmd.WaitDelay = 50 * time.Millisecond
|
||||||
|
require.NoError(t, cmd.Start())
|
||||||
|
killer, err := tk.Capture(cmd.Process)
|
||||||
|
require.NoError(t, err)
|
||||||
|
t.Cleanup(func() { _ = killer.Kill() })
|
||||||
|
|
||||||
|
err = tk.Wait(ctx, cmd)
|
||||||
|
if tc.wantErr {
|
||||||
|
require.Error(t, err)
|
||||||
|
} else {
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestTreeKillCaptureStoresKiller(t *testing.T) {
|
func TestTreeKillCaptureStoresKiller(t *testing.T) {
|
||||||
cmd := exec.CommandContext(t.Context(), "sleep", "10")
|
cmd := exec.CommandContext(t.Context(), "sleep", "10")
|
||||||
cmd.SysProcAttr = SysProcAttr("", false)
|
cmd.SysProcAttr = SysProcAttr("", false)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/rand/v2"
|
||||||
"regexp"
|
"regexp"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -24,7 +25,6 @@ import (
|
|||||||
"connectrpc.com/connect"
|
"connectrpc.com/connect"
|
||||||
"gitea.dev/actionslib/pkg/model"
|
"gitea.dev/actionslib/pkg/model"
|
||||||
runnerv1 "gitea.dev/actionslib/runner/v1"
|
runnerv1 "gitea.dev/actionslib/runner/v1"
|
||||||
"github.com/avast/retry-go/v5"
|
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
"google.golang.org/protobuf/types/known/timestamppb"
|
"google.golang.org/protobuf/types/known/timestamppb"
|
||||||
)
|
)
|
||||||
@@ -89,6 +89,7 @@ type Reporter struct {
|
|||||||
logReportInterval time.Duration
|
logReportInterval time.Duration
|
||||||
logReportMaxLatency time.Duration
|
logReportMaxLatency time.Duration
|
||||||
logBatchSize int
|
logBatchSize int
|
||||||
|
logReportLevel logging.Level
|
||||||
stateReportInterval time.Duration
|
stateReportInterval time.Duration
|
||||||
// closeTimeout bounds each RPC attempt in the final flush, on a context
|
// closeTimeout bounds each RPC attempt in the final flush, on a context
|
||||||
// detached from r.ctx so a server cancel can't abort the acknowledgement.
|
// detached from r.ctx so a server cancel can't abort the acknowledgement.
|
||||||
@@ -133,6 +134,7 @@ func NewReporter(ctx context.Context, cancel context.CancelFunc, client client.C
|
|||||||
logReportInterval: cfg.Runner.LogReportInterval,
|
logReportInterval: cfg.Runner.LogReportInterval,
|
||||||
logReportMaxLatency: cfg.Runner.LogReportMaxLatency,
|
logReportMaxLatency: cfg.Runner.LogReportMaxLatency,
|
||||||
logBatchSize: cfg.Runner.LogReportBatchSize,
|
logBatchSize: cfg.Runner.LogReportBatchSize,
|
||||||
|
logReportLevel: logging.GetLevel(),
|
||||||
stateReportInterval: cfg.Runner.StateReportInterval,
|
stateReportInterval: cfg.Runner.StateReportInterval,
|
||||||
closeTimeout: cfg.Runner.ReportCloseTimeout,
|
closeTimeout: cfg.Runner.ReportCloseTimeout,
|
||||||
logNotify: make(chan struct{}, 1),
|
logNotify: make(chan struct{}, 1),
|
||||||
@@ -146,6 +148,10 @@ func NewReporter(ctx context.Context, cancel context.CancelFunc, client client.C
|
|||||||
jobLog: openJobLog(cfg.Log.Job, task.Id, time.Now()),
|
jobLog: openJobLog(cfg.Log.Job, task.Id, time.Now()),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if level, err := logging.ParseLevel(cfg.Runner.LogReportLevel); err == nil { // unset keeps log.level
|
||||||
|
rv.logReportLevel = level
|
||||||
|
}
|
||||||
|
|
||||||
rv.daemonWait = 6 * rv.effectiveCloseTimeout()
|
rv.daemonWait = 6 * rv.effectiveCloseTimeout()
|
||||||
|
|
||||||
registerGlobalMasks(rv)
|
registerGlobalMasks(rv)
|
||||||
@@ -771,7 +777,23 @@ func (r *Reporter) Close(lastWords string) error {
|
|||||||
func (r *Reporter) flushFinal(fn func() error) error {
|
func (r *Reporter) flushFinal(fn func() error) error {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 3*r.effectiveCloseTimeout())
|
ctx, cancel := context.WithTimeout(context.Background(), 3*r.effectiveCloseTimeout())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
return retry.New(retry.Context(ctx)).Do(fn)
|
var errs []error
|
||||||
|
for attempt := range 10 {
|
||||||
|
err := fn()
|
||||||
|
if err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
errs = append(errs, err)
|
||||||
|
if attempt == 9 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
case <-time.After(100*time.Millisecond<<attempt + rand.N(100*time.Millisecond)):
|
||||||
|
case <-ctx.Done():
|
||||||
|
return errors.Join(append(errs, ctx.Err())...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return errors.Join(errs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// effectiveCloseTimeout returns closeTimeout, or 10s when unset, so a zero
|
// effectiveCloseTimeout returns closeTimeout, or 10s when unset, so a zero
|
||||||
@@ -954,9 +976,9 @@ func (r *Reporter) duringSteps() bool {
|
|||||||
|
|
||||||
// shouldAppendLogRow reports whether a non-raw_output entry should be written
|
// shouldAppendLogRow reports whether a non-raw_output entry should be written
|
||||||
// to the job log: only when we are between steps and the entry's level is
|
// to the job log: only when we are between steps and the entry's level is
|
||||||
// within the globally configured log level.
|
// within runner.log_report_level.
|
||||||
func (r *Reporter) shouldAppendLogRow(entry logging.Record) bool {
|
func (r *Reporter) shouldAppendLogRow(entry logging.Record) bool {
|
||||||
return !r.duringSteps() && entry.Level >= logging.GetLevel()
|
return !r.duringSteps() && entry.Level >= r.logReportLevel
|
||||||
}
|
}
|
||||||
|
|
||||||
var stringToResult = map[string]runnerv1.Result{
|
var stringToResult = map[string]runnerv1.Result{
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"testing"
|
"testing"
|
||||||
|
"testing/synctest"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitea.com/gitea/runner/act/common/logging"
|
"gitea.com/gitea/runner/act/common/logging"
|
||||||
@@ -309,7 +310,10 @@ func TestReporter_LogLevelFiltering(t *testing.T) {
|
|||||||
taskCtx, err := structpb.NewStruct(map[string]any{})
|
taskCtx, err := structpb.NewStruct(map[string]any{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
cfg, _ := config.LoadDefault("")
|
cfg, _ := config.LoadDefault("")
|
||||||
|
cfg.Runner.LogReportLevel = "warn"
|
||||||
reporter := NewReporter(ctx, cancel, client, &runnerv1.Task{Context: taskCtx}, cfg)
|
reporter := NewReporter(ctx, cancel, client, &runnerv1.Task{Context: taskCtx}, cfg)
|
||||||
|
assert.False(t, reporter.shouldAppendLogRow(logging.Record{Level: logging.LevelInfo}))
|
||||||
|
assert.True(t, reporter.shouldAppendLogRow(logging.Record{Level: logging.LevelWarn}))
|
||||||
reporter.RunDaemon()
|
reporter.RunDaemon()
|
||||||
defer func() {
|
defer func() {
|
||||||
require.NoError(t, reporter.Close(""))
|
require.NoError(t, reporter.Close(""))
|
||||||
@@ -1158,6 +1162,19 @@ func TestReporter_EffectiveCloseTimeout(t *testing.T) {
|
|||||||
assert.Equal(t, 5*time.Second, (&Reporter{closeTimeout: 5 * time.Second}).effectiveCloseTimeout())
|
assert.Equal(t, 5*time.Second, (&Reporter{closeTimeout: 5 * time.Second}).effectiveCloseTimeout())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestReporter_FlushFinalRetriesUntilSuccess(t *testing.T) {
|
||||||
|
synctest.Test(t, func(t *testing.T) {
|
||||||
|
calls := 0
|
||||||
|
require.NoError(t, (&Reporter{}).flushFinal(func() error {
|
||||||
|
if calls++; calls < 3 {
|
||||||
|
return errors.New("unavailable")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}))
|
||||||
|
assert.Equal(t, 3, calls)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestReporter_ParseResult(t *testing.T) {
|
func TestReporter_ParseResult(t *testing.T) {
|
||||||
r := &Reporter{}
|
r := &Reporter{}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
|
"math/rand/v2"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
@@ -26,7 +27,6 @@ import (
|
|||||||
|
|
||||||
"gitea.dev/actionslib/pkg/model"
|
"gitea.dev/actionslib/pkg/model"
|
||||||
runnerv1 "gitea.dev/actionslib/runner/v1"
|
runnerv1 "gitea.dev/actionslib/runner/v1"
|
||||||
"github.com/avast/retry-go/v5"
|
|
||||||
"github.com/docker/go-connections/tlsconfig"
|
"github.com/docker/go-connections/tlsconfig"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"go.opentelemetry.io/otel/attribute"
|
"go.opentelemetry.io/otel/attribute"
|
||||||
@@ -226,10 +226,10 @@ func (c *client) upload(ctx context.Context, data proto.Message) error {
|
|||||||
}
|
}
|
||||||
ctx, cancel := context.WithTimeout(ctx, c.timeout)
|
ctx, cancel := context.WithTimeout(ctx, c.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
return retry.New(retry.Context(ctx), retry.Attempts(5), retry.LastErrorOnly(true), retry.DelayType(retryDelay)).Do(func() error {
|
for attempt := 1; ; attempt++ {
|
||||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.endpoint, bytes.NewReader(body))
|
req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.endpoint, bytes.NewReader(body))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return retry.Unrecoverable(err)
|
return err
|
||||||
}
|
}
|
||||||
req.Header = c.headers.Clone()
|
req.Header = c.headers.Clone()
|
||||||
req.Header.Set("Content-Type", "application/x-protobuf")
|
req.Header.Set("Content-Type", "application/x-protobuf")
|
||||||
@@ -237,33 +237,39 @@ func (c *client) upload(ctx context.Context, data proto.Message) error {
|
|||||||
req.Header.Set("Content-Encoding", "gzip")
|
req.Header.Set("Content-Encoding", "gzip")
|
||||||
}
|
}
|
||||||
resp, err := c.httpClient.Do(req)
|
resp, err := c.httpClient.Do(req)
|
||||||
if err != nil {
|
if err == nil {
|
||||||
|
_, _ = io.Copy(io.Discard, resp.Body)
|
||||||
|
_ = resp.Body.Close()
|
||||||
|
if resp.StatusCode < http.StatusMultipleChoices {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
err = &statusError{resp.Status, resp.Header.Get("Retry-After")}
|
||||||
|
if !slices.Contains([]int{http.StatusTooManyRequests, http.StatusBadGateway, http.StatusServiceUnavailable, http.StatusGatewayTimeout}, resp.StatusCode) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if attempt == 5 {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, _ = io.Copy(io.Discard, resp.Body)
|
select {
|
||||||
_ = resp.Body.Close()
|
case <-time.After(retryDelay(attempt, err)):
|
||||||
if resp.StatusCode < http.StatusMultipleChoices {
|
case <-ctx.Done():
|
||||||
return nil
|
return ctx.Err()
|
||||||
}
|
}
|
||||||
err = &statusError{resp.Status, resp.Header.Get("Retry-After")}
|
}
|
||||||
if slices.Contains([]int{http.StatusTooManyRequests, http.StatusBadGateway, http.StatusServiceUnavailable, http.StatusGatewayTimeout}, resp.StatusCode) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return retry.Unrecoverable(err)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type statusError struct{ status, retryAfter string }
|
type statusError struct{ status, retryAfter string }
|
||||||
|
|
||||||
func (e *statusError) Error() string { return "OTLP export failed: " + e.status }
|
func (e *statusError) Error() string { return "OTLP export failed: " + e.status }
|
||||||
|
|
||||||
func retryDelay(attempt uint, err error, config retry.DelayContext) time.Duration {
|
func retryDelay(attempt int, err error) time.Duration {
|
||||||
if status := (*statusError)(nil); errors.As(err, &status) {
|
if status := (*statusError)(nil); errors.As(err, &status) {
|
||||||
if seconds, err := strconv.ParseUint(status.retryAfter, 10, 31); err == nil {
|
if seconds, err := strconv.ParseUint(status.retryAfter, 10, 31); err == nil {
|
||||||
return time.Duration(seconds) * time.Second
|
return time.Duration(seconds) * time.Second
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return retry.CombineDelay(retry.BackOffDelay, retry.RandomDelay)(attempt, err, config)
|
return 100*time.Millisecond<<(attempt-1) + rand.N(100*time.Millisecond)
|
||||||
}
|
}
|
||||||
|
|
||||||
func StartJob(ctx context.Context, task *runnerv1.Task) (context.Context, func(runnerv1.Result)) {
|
func StartJob(ctx context.Context, task *runnerv1.Task) (context.Context, func(runnerv1.Result)) {
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ func TestExportRetriesAndMatchesOTLP(t *testing.T) {
|
|||||||
<-traceBodies
|
<-traceBodies
|
||||||
var tracesData tracepb.TracesData
|
var tracesData tracepb.TracesData
|
||||||
require.NoError(t, proto.Unmarshal(gunzip(<-traceBodies), &tracesData))
|
require.NoError(t, proto.Unmarshal(gunzip(<-traceBodies), &tracesData))
|
||||||
assert.Equal(t, 2*time.Second, retryDelay(1, &statusError{"429 Too Many Requests", "2"}, nil))
|
assert.Equal(t, 2*time.Second, retryDelay(1, &statusError{"429 Too Many Requests", "2"}))
|
||||||
assert.Equal(t, "op", tracesData.GetResourceSpans()[0].GetScopeSpans()[0].GetSpans()[0].GetName())
|
assert.Equal(t, "op", tracesData.GetResourceSpans()[0].GetScopeSpans()[0].GetSpans()[0].GetName())
|
||||||
|
|
||||||
resourceMetrics := metricsData.GetResourceMetrics()[0]
|
resourceMetrics := metricsData.GetResourceMetrics()[0]
|
||||||
|
|||||||
Reference in new issue
Block a user