Skip to content

Commit 02aa275

Browse files
authored
feat(dagger): support attestation of git repositories (#517)
Signed-off-by: Miguel Martinez Trivino <[email protected]>
1 parent dcf1380 commit 02aa275

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

extras/dagger/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ Initialize an attestation using the Chainloop token stored in the `CHAINLOOP_TOK
2121
2222
```sh
2323
dagger call -m github.com/chainloop-dev/chainloop/extras/dagger \
24-
--token env:CHAINLOOP_TOKEN attestation-init
24+
--token env:CHAINLOOP_TOKEN attestation-init \
25+
--repository /path/to/repo \ # optional flag to automatically attest a Git repository
26+
--contract-revision 1 # optional flag to specify the revision of the Workflow Contract (default `latest`)
2527
```
2628

2729
The result of this command will be an `attestation-id` that you will use in the next steps.

extras/dagger/main.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,28 @@ func New(token *Secret) *Chainloop {
2323
}
2424

2525
// Start the attestation crafting process
26-
func (m *Chainloop) AttestationInit(ctx context.Context) (string, error) {
27-
info, err := m.cliImage().WithExec([]string{"attestation", "init", "--remote-state", "-o", "json"}).Stdout(ctx)
26+
func (m *Chainloop) AttestationInit(
27+
ctx context.Context,
28+
// Workflow Contract revision, default is the latest
29+
// +optional
30+
contractRevision string,
31+
// Path to the git repository to be attested
32+
// +optional
33+
repository *Directory,
34+
) (string, error) {
35+
// Append the contract revision to the args if provided
36+
args := []string{"attestation", "init", "--remote-state", "-o", "json"}
37+
if contractRevision != "" {
38+
args = append(args, "--contract-revision", contractRevision)
39+
}
40+
41+
// Mount the repository path if provided
42+
c := m.cliImage()
43+
if repository != nil {
44+
c = c.WithDirectory(".", repository)
45+
}
46+
47+
info, err := c.WithExec(args).Stdout(ctx)
2848
if err != nil {
2949
return "", fmt.Errorf("running attestation init: %w", err)
3050
}

0 commit comments

Comments
 (0)