Skip to content

Commit 9d8dfdf

Browse files
authored
feat: dagger runner context support (#516)
Signed-off-by: Miguel Martinez Trivino <[email protected]>
1 parent 02aa275 commit 9d8dfdf

File tree

9 files changed

+212
-50
lines changed

9 files changed

+212
-50
lines changed

app/cli/internal/action/workflow_run_list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ func humanizedRunnerType(in v1.CraftingSchema_Runner_RunnerType) string {
117117
*v1.CraftingSchema_Runner_AZURE_PIPELINE.Enum(): "Azure Pipeline",
118118
*v1.CraftingSchema_Runner_JENKINS_JOB.Enum(): "Jenkins Job",
119119
*v1.CraftingSchema_Runner_CIRCLECI_BUILD.Enum(): "CircleCI Build",
120+
*v1.CraftingSchema_Runner_DAGGER_PIPELINE.Enum(): "Dagger Pipeline",
120121
}
121122

122123
hrt, ok := mapping[in]

app/cli/internal/action/workflow_run_list_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ func (s *workflowRunListSuite) TestHumanizedRunnerType() {
5252
name: "jenkins runner",
5353
testInput: v1.CraftingSchema_Runner_JENKINS_JOB,
5454
expectedOutput: "Jenkins Job",
55+
}, {
56+
name: "dagger runner",
57+
testInput: v1.CraftingSchema_Runner_DAGGER_PIPELINE,
58+
expectedOutput: "Dagger Pipeline",
5559
}, {
5660
name: "circleci runner",
5761
testInput: v1.CraftingSchema_Runner_CIRCLECI_BUILD,

app/controlplane/api/gen/frontend/workflowcontract/v1/crafting_schema.ts

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/api/workflowcontract/v1/crafting_schema.pb.go

Lines changed: 46 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/api/workflowcontract/v1/crafting_schema.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ message CraftingSchema {
4646
AZURE_PIPELINE = 3;
4747
JENKINS_JOB = 4;
4848
CIRCLECI_BUILD = 5;
49+
DAGGER_PIPELINE = 6;
4950
}
5051
}
5152

extras/dagger/main.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@ import (
77
"time"
88
)
99

10-
const (
11-
// https://github.com/chainloop-dev/chainloop/releases/tag/v0.60.0
12-
// providing a sha triggers a no-sec hardcoded credentials false positive
13-
//nolint:gosec
14-
clImage = "ghcr.io/chainloop-dev/chainloop/cli@sha256:4e0bc402f71f4877a1ae8d6df5eb4e666a0efa0e7d43ab4f97f21c0e46ae0a59"
15-
)
10+
const chainloopVersion = "v0.60.0"
1611

1712
type Chainloop struct {
1813
Token *Secret
@@ -148,7 +143,8 @@ func (m *Chainloop) AttestationReset(ctx context.Context,
148143

149144
func (m *Chainloop) cliImage() *Container {
150145
return dag.Container().
151-
From(clImage).
146+
From(fmt.Sprintf("ghcr.io/chainloop-dev/chainloop/cli:%s", chainloopVersion)).
152147
WithSecretVariable("CHAINLOOP_ROBOT_ACCOUNT", m.Token).
153-
WithEnvVariable("CACHEBUSTER", time.Now().String())
148+
WithEnvVariable("CACHEBUSTER", time.Now().String()).
149+
WithEnvVariable("CHAINLOOP_DAGGER_CLIENT", chainloopVersion)
154150
}

internal/attestation/crafter/runner.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ func NewRunner(t schemaapi.CraftingSchema_Runner_RunnerType) supportedRunner {
5252
return runners.NewJenkinsJob()
5353
case schemaapi.CraftingSchema_Runner_CIRCLECI_BUILD:
5454
return runners.NewCircleCIBuild()
55+
case schemaapi.CraftingSchema_Runner_DAGGER_PIPELINE:
56+
return runners.NewDaggerPipeline()
5557
default:
5658
return runners.NewGeneric()
5759
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//
2+
// Copyright 2024 The Chainloop Authors.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
package runners
17+
18+
import "os"
19+
20+
type DaggerPipeline struct{}
21+
22+
const DaggerPipelineID = "dagger-pipeline"
23+
24+
func NewDaggerPipeline() *DaggerPipeline {
25+
return &DaggerPipeline{}
26+
}
27+
28+
func (r *DaggerPipeline) CheckEnv() bool {
29+
for _, envVarName := range []string{"CHAINLOOP_DAGGER_CLIENT"} {
30+
if os.Getenv(envVarName) == "" {
31+
return false
32+
}
33+
}
34+
35+
return true
36+
}
37+
38+
func (r *DaggerPipeline) ListEnvVars() []*EnvVarDefinition {
39+
return []*EnvVarDefinition{
40+
// Version of the Chainloop Client
41+
{"CHAINLOOP_DAGGER_CLIENT", false},
42+
}
43+
}
44+
45+
func (r *DaggerPipeline) String() string {
46+
return DaggerPipelineID
47+
}
48+
49+
// TODO: figure out an URL and or more useful information
50+
func (r *DaggerPipeline) RunURI() string {
51+
return ""
52+
}
53+
54+
func (r *DaggerPipeline) ResolveEnvVars() (map[string]string, []*error) {
55+
return resolveEnvVars(r.ListEnvVars())
56+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
//
2+
// Copyright 2024 The Chainloop Authors.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
package runners
17+
18+
import (
19+
"os"
20+
"testing"
21+
22+
"github.com/stretchr/testify/assert"
23+
"github.com/stretchr/testify/suite"
24+
)
25+
26+
type daggerPipelineSuite struct {
27+
suite.Suite
28+
runner *DaggerPipeline
29+
}
30+
31+
func (s *daggerPipelineSuite) TestCheckEnv() {
32+
testCases := []struct {
33+
name string
34+
env map[string]string
35+
want bool
36+
}{
37+
{
38+
name: "empty",
39+
env: map[string]string{},
40+
want: false,
41+
},
42+
{
43+
name: "present",
44+
env: map[string]string{
45+
"CHAINLOOP_DAGGER_CLIENT": "v1.0.0",
46+
},
47+
want: true,
48+
},
49+
}
50+
51+
for _, tc := range testCases {
52+
s.T().Run(tc.name, func(t *testing.T) {
53+
os.Unsetenv("CHAINLOOP_DAGGER_CLIENT")
54+
55+
for k, v := range tc.env {
56+
t.Setenv(k, v)
57+
}
58+
59+
s.Equal(tc.want, s.runner.CheckEnv())
60+
})
61+
}
62+
}
63+
64+
func (s *daggerPipelineSuite) TestListEnvVars() {
65+
assert.Equal(s.T(), []*EnvVarDefinition{{"CHAINLOOP_DAGGER_CLIENT", false}}, s.runner.ListEnvVars())
66+
}
67+
68+
func (s *daggerPipelineSuite) TestResolveEnvVars() {
69+
resolvedEnvVars, errors := s.runner.ResolveEnvVars()
70+
s.Empty(errors)
71+
s.Equal(map[string]string{"CHAINLOOP_DAGGER_CLIENT": "v0.6.0"}, resolvedEnvVars)
72+
}
73+
74+
func (s *daggerPipelineSuite) TestRunURI() {
75+
s.Equal("", s.runner.RunURI())
76+
}
77+
78+
func (s *daggerPipelineSuite) TestRunnerName() {
79+
s.Equal("dagger-pipeline", s.runner.String())
80+
}
81+
82+
// Run before each test
83+
func (s *daggerPipelineSuite) SetupTest() {
84+
s.runner = NewDaggerPipeline()
85+
t := s.T()
86+
t.Setenv("CHAINLOOP_DAGGER_CLIENT", "v0.6.0")
87+
}
88+
89+
// Run the tests
90+
func TestDaggerPipelineRunner(t *testing.T) {
91+
suite.Run(t, new(daggerPipelineSuite))
92+
}

0 commit comments

Comments
 (0)