Skip to content

Commit

Permalink
fix: node s2i build when node_modules present
Browse files Browse the repository at this point in the history
This is workaround for two bug in another components:
* The s2i CLI/library is not honoring the `--exclude` flag when used with
  the `--as-dockerfile` flag.
* The node s2i image is not working if project contains `node_modules`
  directory with NodeJS modules.

If only one of the bugs above were fixed this commit wouldn't be
necessary.

Signed-off-by: Matej Vasek <mvasek@redhat.com>
  • Loading branch information
matejvasek committed Mar 9, 2023
1 parent afad45e commit e521d72
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/builders/s2i/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/url"
"os"
"path/filepath"
"regexp"
"strings"

"github.com/docker/docker/api/types"
Expand Down Expand Up @@ -204,6 +205,9 @@ func (b *Builder) Build(ctx context.Context, f fn.Function) (err error) {

pr, pw := io.Pipe()

// s2i apparently is not excluding the files in --as-dockerfile mode
exclude := regexp.MustCompile(cfg.ExcludeRegExp)

const up = ".." + string(os.PathSeparator)
go func() {
tw := tar.NewWriter(pw)
Expand All @@ -220,6 +224,10 @@ func (b *Builder) Build(ctx context.Context, f fn.Function) (err error) {
return nil
}

if exclude.MatchString(p) {
return nil
}

lnk := ""
if fi.Mode()&fs.ModeSymlink != 0 {
lnk, err = os.Readlink(path)
Expand Down

0 comments on commit e521d72

Please sign in to comment.