Skip to content

Commit 181c36a

Browse files
committed
add sbom creation and vulnerability scan
1 parent b6dfe30 commit 181c36a

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

ci/main.go

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,14 @@ func (m *Ci) Lint(ctx context.Context, dir *dagger.Directory) (string, error) {
4040

4141
// Returns the Sast report as a file
4242
func (m *Ci) Sast(ctx context.Context, directory *dagger.Directory) *dagger.File {
43-
return dag.Container().
44-
From("presidentbeef/brakeman:latest").
45-
WithMountedDirectory("/app", directory).
46-
WithWorkdir("/app").
47-
WithExec([]string{"/usr/src/app/bin/brakeman", }).
48-
File("/app/brakeman-output.tabs")
43+
return dag.Container().
44+
From("presidentbeef/brakeman:latest").
45+
WithMountedDirectory("/app", directory).
46+
WithWorkdir("/app").
47+
WithExec([]string{"/usr/src/app/bin/brakeman"}).
48+
File("/app/brakeman-output.tabs")
4949
}
5050

51-
5251
// Creates a PostgreSQL service for local testing based on the official image with the provided version. If no version is provided, 'latest' will be used.
5352
func (m *Ci) Postgres(
5453
_ context.Context,
@@ -79,19 +78,41 @@ func (m *Ci) Memcached(
7978

8079
// Executes the test suite for the Rails application in the provided Directory
8180
func (m *Ci) Test(ctx context.Context, dir *dagger.Directory) *dagger.Container {
82-
return m.Build(ctx, dir).From("ruby:latest").
81+
return dag.Container().From("ruby:latest").
82+
WithMountedDirectory("/app", dir).
83+
WithWorkdir("/app").
8384
WithEnvVariable("RAILS_TEST_DB_NAME", "postgres").
8485
WithEnvVariable("RAILS_TEST_DB_USERNAME", "postgres").
8586
WithEnvVariable("RAILS_TEST_DB_PASSWORD", "postgres").
8687
WithEnvVariable("RAILS_ENV", "test").
8788
WithEnvVariable("CI", "true").
8889
WithEnvVariable("PGDATESTYLE", "German").
89-
WithExec([]string{"sudo", "apt-get", "-yqq", "update"}).
90-
WithExec([]string{"sudo", "apt-get", "-yqq", "install", "libpq-dev", "libvips-dev"}).
91-
WithExec([]string{"gem", "install", "bundler", "--version", "'~> 2'"}).
90+
WithExec([]string{"apt-get", "-yqq", "update"}).
91+
WithExec([]string{"apt-get", "-yqq", "install", "libpq-dev", "libvips-dev"}).
92+
WithExec([]string{"gem", "install", "bundler"}).
9293
WithExec([]string{"bundle", "install", "--jobs", "4", "--retry", "3"}).
9394
WithExec([]string{"bundle", "exec", "rails", "db:create"}).
9495
WithExec([]string{"bundle", "exec", "rails", "db:migrate"}).
9596
WithExec([]string{"bundle", "exec", "rails", "assets:precompile"}).
9697
WithExec([]string{"bundle", "exec", "rails", "test"})
9798
}
99+
100+
func (m *Ci) Sbom(ctx context.Context, container *dagger.Container) *dagger.File {
101+
trivy := dag.Trivy(dagger.TrivyOpts{
102+
DatabaseRepository: "public.ecr.aws/aquasecurity/trivy-db",
103+
})
104+
105+
sbom := trivy.Container(container).
106+
Report("spdx-json").
107+
WithName("spdx.json")
108+
109+
return sbom
110+
}
111+
112+
func (m *Ci) Vulnscan(ctx context.Context, sbom *dagger.File) *dagger.File {
113+
trivy := dag.Trivy(dagger.TrivyOpts{
114+
DatabaseRepository: "public.ecr.aws/aquasecurity/trivy-db",
115+
})
116+
117+
return trivy.Sbom(sbom).Report("json")
118+
}

dagger.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,12 @@
22
"name": "ci",
33
"engineVersion": "v0.14.0",
44
"sdk": "go",
5+
"dependencies": [
6+
{
7+
"name": "trivy",
8+
"source": "github.com/sagikazarmark/daggerverse/trivy@trivy/v0.5.0",
9+
"pin": "5b826062b6bc1bfbd619aa5d0fba117190c85aba"
10+
}
11+
],
512
"source": "ci"
613
}

0 commit comments

Comments
 (0)