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 <[email protected]>
  • Loading branch information
matejvasek committed Mar 9, 2023
1 parent afad45e commit faae74b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion 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,12 @@ func (b *Builder) Build(ctx context.Context, f fn.Function) (err error) {
return nil
}

p = filepath.ToSlash(p)

if exclude.MatchString(p) {
return nil
}

lnk := ""
if fi.Mode()&fs.ModeSymlink != 0 {
lnk, err = os.Readlink(path)
Expand All @@ -241,7 +251,7 @@ func (b *Builder) Build(ctx context.Context, f fn.Function) (err error) {
if err != nil {
return fmt.Errorf("cannot create tar header: %w", err)
}
hdr.Name = filepath.ToSlash(p)
hdr.Name = p

err = tw.WriteHeader(hdr)
if err != nil {
Expand Down

0 comments on commit faae74b

Please sign in to comment.