Skip to content

Commit

Permalink
ci: Add Hadolint and update main.go
Browse files Browse the repository at this point in the history
  • Loading branch information
softwaredevelop committed Mar 12, 2024
1 parent 74151f5 commit 81cee84
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .hadolint.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
---
trustedRegistries:
- docker.io

ignored:
- DL3008
- DL3018
48 changes: 48 additions & 0 deletions cc/linting/h.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//revive:disable:package-comments,exported
package linting

import (
"cc/util"
"context"
"path/filepath"

"dagger.io/dagger"
)

func Hadolint(dir string, c *dagger.Client, id dagger.ContainerID, mountedDir string) error {
ctx := context.Background()

p := filepath.Join(dir, "..")
file := c.Host().
Directory(p).
File(".hadolint.yaml")

id, err := util.MountedHostDirectory(c, id, p, mountedDir).
ID(ctx)
if err != nil {
return err
}

_, err = H(c, id).
WithWorkdir(mountedDir).
WithMountedFile("/.config/.hadolint.yaml", file).
WithExec([]string{"sh", "-c", "/hadolint --config /.config/.hadolint.yaml $(find . -type f \\( -name Dockerfile -o -name Dockerfile.* \\))"}).
Stdout(ctx)
if err != nil {
return err
}
return nil
}

func H(c *dagger.Client, id dagger.ContainerID) *dagger.Container {
return h(c, id)
}

func h(c *dagger.Client, id dagger.ContainerID) *dagger.Container {
hadolint := c.
Container().
From("hadolint/hadolint:latest-alpine")

return c.Container(dagger.ContainerOpts{ID: id}).
WithFile("/", hadolint.File("/bin/hadolint"))
}
12 changes: 11 additions & 1 deletion cc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func main() {
c = c.Pipeline("code_quality")
id, err := c.
Container().
From("busybox:uclibc").
WithMountedTemp("/mountedtmp").
ID(ctx)
if err != nil {
Expand All @@ -47,10 +48,19 @@ func main() {
}

var wg sync.WaitGroup
wg.Add(6)
wg.Add(7)

runtime.GOMAXPROCS(runtime.NumCPU())

go func() {
defer wg.Done()
f := c.Pipeline("hadolint")
err = linting.Hadolint(dir, f, id, mountedDir)
if err != nil {
panic(err)
}
}()

go func() {
defer wg.Done()
f := c.Pipeline("shellcheck")
Expand Down

0 comments on commit 81cee84

Please sign in to comment.