Skip to content

Commit

Permalink
updated dagger functions
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-hermann-sva committed Nov 4, 2024
1 parent 61543d5 commit 0ee9a47
Showing 1 changed file with 47 additions and 4 deletions.
51 changes: 47 additions & 4 deletions dagger.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,60 @@ dagger call -m github.com/jpadams/daggerverse/[email protected] scan-image --image-re
```


## CREATE A PIPELINE
## FUNCTIONS

### INIT PIPELINE
### CREATE A NEW FUNCTION

```bash
dagger init --sdk=go --source=./dagger
```

### CALL A FUNCTION
### CREATE FUNCTION WITH RETURN

the following function is using a golang base image and builds a binary

```go
// dagger call build --progress plain --src ./ export --path build (returned dir(path))
func (m *Clusterbook) Build(ctx context.Context, src *dagger.Directory) *dagger.Directory {

// get `golang` image
golang := dag.Container().From("golang:latest")

// mount cloned repository into `golang` image
golang = golang.WithDirectory("/src", src).WithWorkdir("/src")

// define the application build command
path := "build/"
golang = golang.WithExec([]string{"env", "GOOS=linux", "GOARCH=amd64", "go", "build", "-o", path, "./main.go"})
}
```

### CALL FUNCTION

```bash
dagger functions
dagger call container-echo --string-arg world
dagger call build --progress plain --src ./ export --path build
```

### CREATE FUNCTION WHICH IS BASED ON A IMPORT WITHOUT A RETURN

```go
func (m *Clusterbook) Scan(ctx context.Context, image string) {

golang := dag.Container().From(image)

scanResult, _ := dag.Trivy().ScanContainer(ctx, golang, dagger.TrivyScanContainerOpts{
TrivyImageTag: trivyImageTag,
Severity: "HIGH,CRITICAL",
Format: "table",
ExitCode: 0,
})

fmt.Println(scanResult)
}
```

```
dagger install github.com/jpadams/daggerverse/trivy
dagger call scan --progress plain --image nginx:latest
```

0 comments on commit 0ee9a47

Please sign in to comment.