Skip to content

Commit

Permalink
export files, add docu
Browse files Browse the repository at this point in the history
  • Loading branch information
RetGal committed Nov 13, 2024
1 parent c65e996 commit e4c5270
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions ci/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@ import (
"context"
"dagger/ci/internal/dagger"
"fmt"
"sync"
"sync"
)

type Ci struct{}

type Results struct {
LintOutput string
SecurityScan *dagger.File
// haml-lint output as json
LintOutput *dagger.File
// brakeman output as plain text
SecurityScan *dagger.File
// trivy results as json
VulnerabilityScan *dagger.File
Image *dagger.Container
// the built image
Image *dagger.Container
}

// Returns a Container built from the Dockerfile in the provided Directory
Expand All @@ -36,14 +40,14 @@ func (m *Ci) Build(_ context.Context, dir *dagger.Directory) *dagger.Container {
}

// Returns the result of haml-lint run against the sources in the provided Directory
func (m *Ci) Lint(ctx context.Context, dir *dagger.Directory) (string, error) {
func (m *Ci) Lint(ctx context.Context, dir *dagger.Directory) *dagger.File {
return dag.Container().
From("ruby:latest").
WithMountedDirectory("/mnt", dir).
WithWorkdir("/mnt").
WithExec([]string{"gem", "install", "haml-lint"}).
WithExec([]string{"haml-lint", "-r", "json", "."}).
Stdout(ctx)
WithExec([]string{"sh", "-c", "haml-lint -r json . > lint.json || true"}).
File("lint.json")
}

// Returns the Sast report as a file
Expand Down Expand Up @@ -151,7 +155,7 @@ func (m *Ci) Vulnscan(sbom *dagger.File) *dagger.File {

// Executes all the steps and returns a Results object
func (m *Ci) Ci(ctx context.Context, dir *dagger.Directory) *Results {
lintOutput, _ := m.Lint(ctx, dir)
lintOutput := m.Lint(ctx, dir)
securityScan := m.Sast(ctx, dir)
image := m.Build(ctx, dir)
sbom := m.Sbom(image)
Expand All @@ -170,9 +174,9 @@ func (m *Ci) CiIntegration(ctx context.Context, dir *dagger.Directory) *Results
var wg sync.WaitGroup
wg.Add(3)

var lintOutput, _ = func() (string, error) {
var lintOutput = func() *dagger.File {
defer wg.Done()
return "empty", error(nil) //m.Lint(ctx, dir)
return m.Lint(ctx, dir)
}()

var securityScan = func() *dagger.File {
Expand All @@ -188,12 +192,12 @@ func (m *Ci) CiIntegration(ctx context.Context, dir *dagger.Directory) *Results
}()

// This Blocks the execution until its counter become 0
wg.Wait()
wg.Wait()

return &Results{
LintOutput: lintOutput,
SecurityScan: securityScan,
// VulnerabilityScan: vulnerabilityScan,
Image: image,
LintOutput: lintOutput,
SecurityScan: securityScan,
// VulnerabilityScan: vulnerabilityScan,
Image: image,
}
}

0 comments on commit e4c5270

Please sign in to comment.