mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-07-26 01:17:39 +00:00
Fixes https://gitea.com/gitea/runner/issues/667 Fixes https://gitea.com/gitea/runner/pulls/1103 `container.options` is parsed with docker/cli's `addFlags`, which omits the flags docker/cli registers on the `create` and `run` commands themselves. Those were rejected as unknown — most visibly `--platform`. | Flag | Behavior | Why | | --- | --- | --- | | `--platform` | overrides the runner-wide container architecture | the only way to pick an image architecture per job, e.g. across a matrix | | `--pull always\|missing\|never` | `always` forces a pull, `never` skips it | `force_pull` is runner-wide config today, with no per-job control | Both are resolved in `NewContainer` because the image pull runs before the container is created and the two have to agree. `--name`, `--quiet` and `--disable-content-trust` are now accepted and ignored, and `--use-api-socket` is rejected pointing at `container.docker_host`, so a valid `docker create` line no longer fails outright. <sub>Written by Claude (Opus 4.8).</sub> --------- Co-authored-by: bircni <bircni@icloud.com> Reviewed-on: https://gitea.com/gitea/runner/pulls/1104 Reviewed-by: bircni <bircni@icloud.com> Co-authored-by: silverwind <me@silverwind.io>
62 lines
1.7 KiB
Go
62 lines
1.7 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package container
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestCreateFlagsFromOptions(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
options string
|
|
platform string
|
|
pull string
|
|
}{
|
|
{"", "", pullPolicyMissing},
|
|
{"-v /a:/b --platform=linux/arm64 --pull always", "linux/arm64", pullPolicyAlways},
|
|
{"--platform linux/arm/v7 --pull never", "linux/arm/v7", pullPolicyNever},
|
|
{`--platform "linux/amd64`, "", pullPolicyMissing}, // malformed, defaults kept
|
|
} {
|
|
t.Run(tc.options, func(t *testing.T) {
|
|
cf := createFlagsFromOptions(tc.options)
|
|
assert.Equal(t, tc.platform, cf.platform)
|
|
assert.Equal(t, tc.pull, cf.pull)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestCreateFlagsValidate(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
options string
|
|
wantErr string
|
|
}{
|
|
{"--quiet --disable-content-trust --name mine", ""},
|
|
{"--pull sometimes", `invalid --pull option "sometimes"`},
|
|
{"--use-api-socket", "--use-api-socket is not supported"},
|
|
} {
|
|
t.Run(tc.options, func(t *testing.T) {
|
|
err := createFlagsFromOptions(tc.options).validate()
|
|
if tc.wantErr == "" {
|
|
require.NoError(t, err)
|
|
return
|
|
}
|
|
require.ErrorContains(t, err, tc.wantErr)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestNewContainerAppliesCreateFlags(t *testing.T) {
|
|
input := &NewContainerInput{Platform: "linux/amd64", Options: "--platform linux/arm64 --pull never"}
|
|
cr := NewContainer(input).(*containerReference)
|
|
assert.Equal(t, "linux/arm64", input.Platform)
|
|
assert.Equal(t, pullPolicyNever, cr.pullPolicy)
|
|
|
|
kept := &NewContainerInput{Platform: "linux/amd64", Options: "--privileged"}
|
|
NewContainer(kept)
|
|
assert.Equal(t, "linux/amd64", kept.Platform)
|
|
}
|