MCPcopy
hub / github.com/nektos/act / createBuildContext

Function createBuildContext

pkg/container/docker_build.go:78–123  ·  view source on GitHub ↗
(ctx context.Context, contextDir string, relDockerfile string)

Source from the content-addressed store, hash-verified

76 }
77}
78func createBuildContext(ctx context.Context, contextDir string, relDockerfile string) (io.ReadCloser, error) {
79 common.Logger(ctx).Debugf("Creating archive for build context dir '%s' with relative dockerfile '%s'", contextDir, relDockerfile)
80
81 // And canonicalize dockerfile name to a platform-independent one
82 relDockerfile = filepath.ToSlash(relDockerfile)
83
84 f, err := os.Open(filepath.Join(contextDir, ".dockerignore"))
85 if err != nil && !os.IsNotExist(err) {
86 return nil, err
87 }
88 defer f.Close()
89
90 var excludes []string
91 if err == nil {
92 excludes, err = ignorefile.ReadAll(f)
93 if err != nil {
94 return nil, err
95 }
96 }
97
98 // If .dockerignore mentions .dockerignore or the Dockerfile
99 // then make sure we send both files over to the daemon
100 // because Dockerfile is, obviously, needed no matter what, and
101 // .dockerignore is needed to know if either one needs to be
102 // removed. The daemon will remove them for us, if needed, after it
103 // parses the Dockerfile. Ignore errors here, as they will have been
104 // caught by validateContextDirectory above.
105 var includes = []string{"."}
106 keepThem1, _ := patternmatcher.Matches(".dockerignore", excludes)
107 keepThem2, _ := patternmatcher.Matches(relDockerfile, excludes)
108 if keepThem1 || keepThem2 {
109 includes = append(includes, ".dockerignore", relDockerfile)
110 }
111
112 compression := archive.Uncompressed
113 buildCtx, err := archive.TarWithOptions(contextDir, &archive.TarOptions{
114 Compression: compression,
115 ExcludePatterns: excludes,
116 IncludeFiles: includes,
117 })
118 if err != nil {
119 return nil, err
120 }
121
122 return buildCtx, nil
123}

Callers 1

NewDockerBuildExecutorFunction · 0.85

Calls 3

LoggerFunction · 0.92
OpenMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…