Compare commits

...

25 commits

Author SHA1 Message Date
qwerty287 b9f16c111c
Merge 060c713ea5 into 325b1b5e57 2024-04-28 10:57:40 +02:00
renovate[bot] 325b1b5e57
chore(deps): update dependency trim to v1 (#3658) 2024-04-28 10:50:39 +02:00
Robert Kaussow 4b1ff6d1a7
Compare to pipeline created timestamp while using before/after filter (#3654) 2024-04-28 10:32:31 +02:00
renovate[bot] 2c3cd83402
chore(deps): update dependency got to v14 (#3657) 2024-04-28 10:16:25 +02:00
renovate[bot] a230e88c3a
chore(deps): lock file maintenance (#3656)
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Update | Change |
|---|---|
| lockFileMaintenance | All locks refreshed |

🔧 This Pull Request updates lock files to use the latest dependency
versions.

---

### Configuration

📅 **Schedule**: Branch creation - "before 4am on Monday" (UTC),
Automerge - "before 4am" (UTC).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get
[config help](https://togithub.com/renovatebot/renovate/discussions) if
that's undesired.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/woodpecker-ci/woodpecker).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zMjEuMiIsInVwZGF0ZWRJblZlciI6IjM3LjMyMS4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiLCJkb2N1bWVudGF0aW9uIiwidWkiXX0=-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-28 08:18:02 +02:00
qwerty287 060c713ea5
Merge branch 'main' into rework-entry 2024-04-19 16:58:43 +02:00
qwerty287 e963f8197b
prettier 2024-04-18 08:58:32 +02:00
qwerty287 aec353a554
add test case 2024-04-18 08:45:26 +02:00
qwerty287 536b98edcb
Fix missing schema 2024-04-18 08:43:35 +02:00
qwerty287 79da53152f
Merge branch 'main' into rework-entry 2024-04-18 08:08:11 +02:00
qwerty287 ac08d056e7
Merge branch 'main' into rework-entry 2024-04-17 09:05:20 +02:00
qwerty287 c0b0a71e74
Merge branch 'main' into rework-entry 2024-04-16 07:53:21 +02:00
qwerty287 a8bd4f2136
Merge branch 'main' into rework-entry 2024-04-15 08:01:01 +02:00
qwerty287 1a1dd207f6
Merge branch 'main' into rework-entry 2024-04-10 13:05:01 +02:00
qwerty287 0b7837e66e
Merge branch 'main' into rework-entry 2024-04-09 16:09:50 +02:00
qwerty287 53967dfce7
Merge branch 'main' into rework-entry 2024-04-03 08:10:01 +02:00
qwerty287 5d48799841
Merge branch 'main' into rework-entry 2024-03-29 09:41:58 +01:00
qwerty287 59b73df9fe
Merge branch 'main' into rework-entry 2024-03-28 20:24:15 +01:00
qwerty287 6e0658b9af
Merge branch 'main' into rework-entry 2024-03-28 08:54:12 +01:00
qwerty287 75310a6321
More docs 2024-03-25 15:49:30 +01:00
qwerty287 8ed3643de2
fix test 2024-03-25 15:47:31 +01:00
qwerty287 95bdacca88
Fix entrypoint without commands
Co-authored-by: Thomas Anderson <127358482+zc-devs@users.noreply.github.com>
2024-03-25 08:13:15 +01:00
qwerty287 e2cca422c9
Fix tests 2024-03-24 16:17:07 +01:00
qwerty287 e506db203f
fix test 2024-03-24 15:36:39 +01:00
qwerty287 0b3c3a4299
Rework entrypoints 2024-03-24 15:33:53 +01:00
14 changed files with 898 additions and 945 deletions

View file

@ -161,6 +161,9 @@ Only build steps can define commands. You cannot use commands with plugins or se
Allows you to specify the entrypoint for containers. Note that this must be a list of the command and its arguments (e.g. `["/bin/sh", "-c"]`).
If you define [`commands`](#commands), the default entrypoint will be `["/bin/sh", "-c", "echo $CI_SCRIPT | base64 -d | /bin/sh -e"]`.
You can also use a custom shell with `CI_SCRIPT` (Base64-encoded) if you set `commands`.
### `environment`
Woodpecker provides the ability to pass environment variables to individual steps.

View file

@ -53,8 +53,8 @@
},
"pnpm": {
"overrides": {
"trim": "^0.0.3",
"got": "^11.8.5"
"trim": "^1.0.0",
"got": "^14.0.0"
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -18,21 +18,19 @@ import (
"encoding/base64"
)
func GenerateContainerConf(commands []string, goos string) (env map[string]string, entry []string, cmd string) {
func GenerateContainerConf(commands []string, goos string) (env map[string]string, entry []string) {
env = make(map[string]string)
if goos == "windows" {
env["CI_SCRIPT"] = base64.StdEncoding.EncodeToString([]byte(generateScriptWindows(commands)))
env["HOME"] = "c:\\root"
env["SHELL"] = "powershell.exe"
entry = []string{"powershell", "-noprofile", "-noninteractive", "-command"}
cmd = "[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Env:CI_SCRIPT)) | iex"
entry = []string{"powershell", "-noprofile", "-noninteractive", "-command", "[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Env:CI_SCRIPT)) | iex"}
} else {
env["CI_SCRIPT"] = base64.StdEncoding.EncodeToString([]byte(generateScriptPosix(commands)))
env["HOME"] = "/root"
env["SHELL"] = "/bin/sh"
entry = []string{"/bin/sh", "-c"}
cmd = "echo $CI_SCRIPT | base64 -d | /bin/sh -e"
entry = []string{"/bin/sh", "-c", "echo $CI_SCRIPT | base64 -d | /bin/sh -e"}
}
return env, entry, cmd
return env, entry
}

View file

@ -12,16 +12,14 @@ const (
)
func TestGenerateContainerConf(t *testing.T) {
gotEnv, gotEntry, gotCmd := GenerateContainerConf([]string{"echo hello world"}, "windows")
gotEnv, gotEntry := GenerateContainerConf([]string{"echo hello world"}, "windows")
assert.Equal(t, windowsScriptBase64, gotEnv["CI_SCRIPT"])
assert.Equal(t, "c:\\root", gotEnv["HOME"])
assert.Equal(t, "powershell.exe", gotEnv["SHELL"])
assert.Equal(t, []string{"powershell", "-noprofile", "-noninteractive", "-command"}, gotEntry)
assert.Equal(t, "[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Env:CI_SCRIPT)) | iex", gotCmd)
gotEnv, gotEntry, gotCmd = GenerateContainerConf([]string{"echo hello world"}, "linux")
assert.Equal(t, []string{"powershell", "-noprofile", "-noninteractive", "-command", "[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Env:CI_SCRIPT)) | iex"}, gotEntry)
gotEnv, gotEntry = GenerateContainerConf([]string{"echo hello world"}, "linux")
assert.Equal(t, posixScriptBase64, gotEnv["CI_SCRIPT"])
assert.Equal(t, "/root", gotEnv["HOME"])
assert.Equal(t, "/bin/sh", gotEnv["SHELL"])
assert.Equal(t, []string{"/bin/sh", "-c"}, gotEntry)
assert.Equal(t, "echo $CI_SCRIPT | base64 -d | /bin/sh -e", gotCmd)
assert.Equal(t, []string{"/bin/sh", "-c", "echo $CI_SCRIPT | base64 -d | /bin/sh -e"}, gotEntry)
}

View file

@ -45,16 +45,15 @@ func (e *docker) toConfig(step *types.Step) *container.Config {
configEnv := make(map[string]string)
maps.Copy(configEnv, step.Environment)
if len(step.Commands) != 0 {
env, entry, cmd := common.GenerateContainerConf(step.Commands, e.info.OSType)
if len(step.Commands) > 0 {
env, entry := common.GenerateContainerConf(step.Commands, e.info.OSType)
for k, v := range env {
configEnv[k] = v
}
if len(step.Entrypoint) > 0 {
entry = step.Entrypoint
}
config.Entrypoint = entry
config.Cmd = []string{cmd}
}
if len(step.Entrypoint) > 0 {
config.Entrypoint = step.Entrypoint
}
if len(configEnv) != 0 {

View file

@ -105,8 +105,7 @@ func TestToConfigSmall(t *testing.T) {
assert.EqualValues(t, &container.Config{
AttachStdout: true,
AttachStderr: true,
Cmd: []string{"echo $CI_SCRIPT | base64 -d | /bin/sh -e"},
Entrypoint: []string{"/bin/sh", "-c"},
Entrypoint: []string{"/bin/sh", "-c", "echo $CI_SCRIPT | base64 -d | /bin/sh -e"},
Labels: map[string]string{
"wp_step": "test",
"wp_uuid": "09238932",
@ -163,8 +162,7 @@ func TestToConfigFull(t *testing.T) {
WorkingDir: "/src/abc",
AttachStdout: true,
AttachStderr: true,
Cmd: []string{"echo $CI_SCRIPT | base64 -d | /bin/sh -e"},
Entrypoint: []string{"/bin/sh", "-c"},
Entrypoint: []string{"/bin/sh", "-c", "echo $CI_SCRIPT | base64 -d | /bin/sh -e"},
Labels: map[string]string{
"wp_step": "test",
"wp_uuid": "09238932",

View file

@ -147,15 +147,14 @@ func podContainer(step *types.Step, podName, goos string, options BackendOptions
container.ImagePullPolicy = v1.PullAlways
}
if len(step.Commands) != 0 {
scriptEnv, command, args := common.GenerateContainerConf(step.Commands, goos)
if len(step.Entrypoint) > 0 {
command = step.Entrypoint
}
if len(step.Commands) > 0 {
scriptEnv, command := common.GenerateContainerConf(step.Commands, goos)
container.Command = command
container.Args = []string{args}
maps.Copy(step.Environment, scriptEnv)
}
if len(step.Entrypoint) > 0 {
container.Command = step.Entrypoint
}
container.Env = mapToEnvVars(step.Environment)

View file

@ -90,9 +90,7 @@ func TestTinyPod(t *testing.T) {
"image": "gradle:8.4.0-jdk21",
"command": [
"/bin/sh",
"-c"
],
"args": [
"-c",
"echo $CI_SCRIPT | base64 -d | /bin/sh -e"
],
"workingDir": "/woodpecker/src",
@ -183,9 +181,6 @@ func TestFullPod(t *testing.T) {
"/bin/sh",
"-c"
],
"args": [
"echo $CI_SCRIPT | base64 -d | /bin/sh -e"
],
"workingDir": "/woodpecker/src",
"ports": [
{
@ -415,3 +410,49 @@ func TestPodPrivilege(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, true, *pod.Spec.SecurityContext.RunAsNonRoot)
}
func TestScratchPod(t *testing.T) {
expected := `
{
"metadata": {
"name": "wp-01he8bebctabr3kgk0qj36d2me-0",
"namespace": "woodpecker",
"creationTimestamp": null,
"labels": {
"step": "curl-google"
}
},
"spec": {
"containers": [
{
"name": "wp-01he8bebctabr3kgk0qj36d2me-0",
"image": "quay.io/curl/curl",
"command": [
"/usr/bin/curl",
"-v",
"google.com"
],
"resources": {}
}
],
"restartPolicy": "Never"
},
"status": {}
}`
pod, err := mkPod(&types.Step{
Name: "curl-google",
Image: "quay.io/curl/curl",
Entrypoint: []string{"/usr/bin/curl", "-v", "google.com"},
}, &config{
Namespace: "woodpecker",
}, "wp-01he8bebctabr3kgk0qj36d2me-0", "linux/amd64", BackendOptions{})
assert.NoError(t, err)
podJSON, err := json.Marshal(pod)
assert.NoError(t, err)
ja := jsonassert.New(t)
t.Log(string(podJSON))
ja.Assertf(string(podJSON), expected)
}

View file

@ -14,6 +14,14 @@ steps:
image: golang
commands: go test
entrypoint:
image: alpine
entrypoint: ['some_entry', '--some-flag']
singla-entrypoint:
image: alpine
entrypoint: some_entry
commands:
privileged: true
image: golang

View file

@ -371,6 +371,21 @@
},
"backend_options": {
"$ref": "#/definitions/step_backend_options"
},
"entrypoint": {
"description": "Defines container entrypoint.",
"oneOf": [
{
"type": "array",
"minLength": 1,
"items": {
"type": "string"
}
},
{
"type": "string"
}
]
}
}
},

View file

@ -59,11 +59,11 @@ func (s storage) GetPipelineList(repo *model.Repo, p *model.ListOptions, f *mode
if f != nil {
if f.After != 0 {
cond = cond.And(builder.Gt{"pipeline_started": f.After})
cond = cond.And(builder.Gt{"pipeline_created": f.After})
}
if f.Before != 0 {
cond = cond.And(builder.Lt{"pipeline_started": f.Before})
cond = cond.And(builder.Lt{"pipeline_created": f.Before})
}
}

View file

@ -231,21 +231,19 @@ func TestPipelines(t *testing.T) {
})
g.It("Should get filtered pipelines", func() {
dt1, _ := time.Parse(time.RFC3339, "2023-01-15T15:00:00Z")
pipeline1 := &model.Pipeline{
RepoID: repo.ID,
Started: dt1.Unix(),
RepoID: repo.ID,
}
dt2, _ := time.Parse(time.RFC3339, "2023-01-15T16:30:00Z")
pipeline2 := &model.Pipeline{
RepoID: repo.ID,
Started: dt2.Unix(),
RepoID: repo.ID,
}
err1 := store.CreatePipeline(pipeline1, []*model.Step{}...)
g.Assert(err1).IsNil()
time.Sleep(1 * time.Second)
before := time.Now().Unix()
err2 := store.CreatePipeline(pipeline2, []*model.Step{}...)
g.Assert(err2).IsNil()
pipelines, err3 := store.GetPipelineList(&model.Repo{ID: 1}, &model.ListOptions{Page: 1, PerPage: 50}, &model.PipelineFilter{Before: dt2.Unix()})
pipelines, err3 := store.GetPipelineList(&model.Repo{ID: 1}, &model.ListOptions{Page: 1, PerPage: 50}, &model.PipelineFilter{Before: before})
g.Assert(err3).IsNil()
g.Assert(len(pipelines)).Equal(1)
g.Assert(pipelines[0].ID).Equal(pipeline1.ID)

File diff suppressed because it is too large Load diff