Skip to content

Commit ba8b631

Browse files
committed
Move GetTemplate from vendor to local file
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent e87bda4 commit ba8b631

File tree

3 files changed

+38
-109
lines changed

3 files changed

+38
-109
lines changed

builder/build.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,48 @@ import (
3030
// Can also be passed as a build arg hence needs to be accessed from commands
3131
const AdditionalPackageBuildArg = "ADDITIONAL_PACKAGE"
3232

33+
func getTemplate(lang string) (string, *stack.LanguageTemplate, error) {
34+
35+
cwd, err := os.Getwd()
36+
if err != nil {
37+
return "", nil, fmt.Errorf("can't get current working directory: %w", err)
38+
}
39+
40+
templateDir := filepath.Join(cwd, "template")
41+
if _, err := os.Stat(templateDir); err != nil {
42+
return "", nil, fmt.Errorf("template directory not found")
43+
}
44+
45+
files, err := os.ReadDir(templateDir)
46+
if err != nil {
47+
return "", nil, fmt.Errorf("can't read template directory: %w", err)
48+
}
49+
50+
found := ""
51+
for _, file := range files {
52+
if file.IsDir() {
53+
if file.Name() == lang {
54+
found = filepath.Join(templateDir, file.Name())
55+
break
56+
}
57+
}
58+
}
59+
60+
if len(found) == 0 {
61+
return "", nil, fmt.Errorf("template %s not found", lang)
62+
}
63+
parsed, err := stack.ParseYAMLForLanguageTemplate(filepath.Join(found, "template.yml"))
64+
if err != nil {
65+
return "", nil, fmt.Errorf("can't parse template: %w", err)
66+
}
67+
return found, parsed, nil
68+
}
69+
3370
// BuildImage construct Docker image from function parameters
3471
// TODO: refactor signature to a struct to simplify the length of the method header
3572
func BuildImage(image string, handler string, functionName string, language string, nocache bool, squash bool, shrinkwrap bool, buildArgMap map[string]string, buildOptions []string, tagFormat schema.BuildFormat, buildLabelMap map[string]string, quietBuild bool, copyExtraPaths []string, remoteBuilder, payloadSecretPath string, forcePull bool) error {
3673

37-
_, langTemplate, err := stack.GetTemplate(language)
74+
_, langTemplate, err := getTemplate(language)
3875
if err != nil {
3976
return fmt.Errorf("language template: %s not supported, build a custom Dockerfile, error: %w", language, err)
4077
}

vendor/github.com/openfaas/go-sdk/stack/language_template.go

Lines changed: 0 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
# dario.cat/mergo v1.0.0
2-
## explicit; go 1.13
31
# github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c
42
## explicit; go 1.16
53
github.com/Azure/go-ansiterm
64
github.com/Azure/go-ansiterm/winterm
75
# github.com/Masterminds/semver v1.5.0
86
## explicit
97
github.com/Masterminds/semver
10-
# github.com/Microsoft/go-winio v0.6.2
11-
## explicit; go 1.21
12-
# github.com/ProtonMail/go-crypto v1.1.6
13-
## explicit; go 1.17
148
# github.com/VividCortex/ewma v1.2.0
159
## explicit; go 1.12
1610
github.com/VividCortex/ewma
@@ -27,27 +21,17 @@ github.com/alexellis/go-execute/v2
2721
# github.com/alexellis/hmac/v2 v2.0.0
2822
## explicit; go 1.16
2923
github.com/alexellis/hmac/v2
30-
# github.com/beorn7/perks v1.0.1
31-
## explicit; go 1.11
3224
# github.com/bep/debounce v1.2.1
3325
## explicit
3426
github.com/bep/debounce
35-
# github.com/cespare/xxhash/v2 v2.3.0
36-
## explicit; go 1.11
3727
# github.com/cheggaaa/pb/v3 v3.1.7
3828
## explicit; go 1.18
3929
github.com/cheggaaa/pb/v3
4030
github.com/cheggaaa/pb/v3/termutil
41-
# github.com/cloudflare/circl v1.6.1
42-
## explicit; go 1.22.0
4331
# github.com/containerd/stargz-snapshotter/estargz v0.17.0
4432
## explicit; go 1.23.0
4533
github.com/containerd/stargz-snapshotter/estargz
4634
github.com/containerd/stargz-snapshotter/estargz/errorutil
47-
# github.com/cyphar/filepath-securejoin v0.4.1
48-
## explicit; go 1.18
49-
# github.com/distribution/reference v0.6.0
50-
## explicit; go 1.20
5135
# github.com/docker/cli v28.3.3+incompatible
5236
## explicit
5337
github.com/docker/cli/cli/config
@@ -62,15 +46,11 @@ github.com/docker/distribution/registry/client/auth/challenge
6246
## explicit; go 1.21
6347
github.com/docker/docker-credential-helpers/client
6448
github.com/docker/docker-credential-helpers/credentials
65-
# github.com/docker/go-units v0.5.0
66-
## explicit
6749
# github.com/drone/envsubst v1.0.3
6850
## explicit; go 1.13
6951
github.com/drone/envsubst
7052
github.com/drone/envsubst/parse
7153
github.com/drone/envsubst/path
72-
# github.com/emirpasic/gods v1.18.1
73-
## explicit; go 1.2
7454
# github.com/fatih/color v1.18.0
7555
## explicit; go 1.17
7656
github.com/fatih/color
@@ -93,10 +73,6 @@ github.com/go-git/go-git/v5/internal/path_util
9373
github.com/go-git/go-git/v5/plumbing/format/config
9474
github.com/go-git/go-git/v5/plumbing/format/gitignore
9575
github.com/go-git/go-git/v5/utils/ioutil
96-
# github.com/gogo/protobuf v1.3.2
97-
## explicit; go 1.15
98-
# github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8
99-
## explicit; go 1.20
10076
# github.com/google/go-cmp v0.7.0
10177
## explicit; go 1.21
10278
github.com/google/go-cmp/cmp
@@ -134,16 +110,12 @@ github.com/google/go-containerregistry/pkg/v1/remote/transport
134110
github.com/google/go-containerregistry/pkg/v1/stream
135111
github.com/google/go-containerregistry/pkg/v1/tarball
136112
github.com/google/go-containerregistry/pkg/v1/types
137-
# github.com/gorilla/mux v1.8.1
138-
## explicit; go 1.20
139113
# github.com/inconshreveable/mousetrap v1.1.0
140114
## explicit; go 1.18
141115
github.com/inconshreveable/mousetrap
142116
# github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99
143117
## explicit
144118
github.com/jbenet/go-context/io
145-
# github.com/kevinburke/ssh_config v1.2.0
146-
## explicit
147119
# github.com/klauspost/compress v1.18.0
148120
## explicit; go 1.22
149121
github.com/klauspost/compress
@@ -154,8 +126,6 @@ github.com/klauspost/compress/internal/le
154126
github.com/klauspost/compress/internal/snapref
155127
github.com/klauspost/compress/zstd
156128
github.com/klauspost/compress/zstd/internal/xxhash
157-
# github.com/magefile/mage v1.14.0
158-
## explicit; go 1.12
159129
# github.com/mattn/go-colorable v0.1.14
160130
## explicit; go 1.18
161131
github.com/mattn/go-colorable
@@ -178,16 +148,6 @@ github.com/moby/term/windows
178148
# github.com/morikuni/aec v1.0.0
179149
## explicit
180150
github.com/morikuni/aec
181-
# github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822
182-
## explicit
183-
# github.com/nats-io/nats.go v1.37.0
184-
## explicit; go 1.20
185-
# github.com/nats-io/nkeys v0.4.8
186-
## explicit; go 1.20
187-
# github.com/nats-io/nuid v1.0.1
188-
## explicit
189-
# github.com/nats-io/stan.go v0.10.4
190-
## explicit; go 1.14
191151
# github.com/olekukonko/cat v0.0.0-20250817074551-3280053e4e00
192152
## explicit; go 1.21
193153
github.com/olekukonko/cat
@@ -228,40 +188,18 @@ github.com/openfaas/go-sdk
228188
github.com/openfaas/go-sdk/builder
229189
github.com/openfaas/go-sdk/internal/httpclient
230190
github.com/openfaas/go-sdk/stack
231-
# github.com/openfaas/nats-queue-worker v0.0.0-20231219105451-b94918cb8a24
232-
## explicit; go 1.20
233-
# github.com/otiai10/copy v1.14.1
234-
## explicit; go 1.18
235-
# github.com/otiai10/mint v1.6.3
236-
## explicit; go 1.18
237-
# github.com/pjbgf/sha1cd v0.3.2
238-
## explicit; go 1.21
239191
# github.com/pkg/errors v0.9.1
240192
## explicit
241193
github.com/pkg/errors
242-
# github.com/prometheus/client_golang v1.20.5
243-
## explicit; go 1.20
244-
# github.com/prometheus/client_model v0.6.1
245-
## explicit; go 1.19
246-
# github.com/prometheus/common v0.62.0
247-
## explicit; go 1.21
248-
# github.com/prometheus/procfs v0.15.1
249-
## explicit; go 1.20
250194
# github.com/rivo/uniseg v0.4.7
251195
## explicit; go 1.18
252196
github.com/rivo/uniseg
253197
# github.com/ryanuber/go-glob v1.0.0
254198
## explicit
255199
github.com/ryanuber/go-glob
256-
# github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3
257-
## explicit; go 1.13
258-
# github.com/sethvargo/go-password v0.3.1
259-
## explicit; go 1.21
260200
# github.com/sirupsen/logrus v1.9.3
261201
## explicit; go 1.13
262202
github.com/sirupsen/logrus
263-
# github.com/skeema/knownhosts v1.3.1
264-
## explicit; go 1.22
265203
# github.com/spf13/cobra v1.9.1
266204
## explicit; go 1.15
267205
github.com/spf13/cobra
@@ -271,12 +209,6 @@ github.com/spf13/pflag
271209
# github.com/vbatts/tar-split v0.12.1
272210
## explicit; go 1.17
273211
github.com/vbatts/tar-split/archive/tar
274-
# github.com/xanzy/ssh-agent v0.3.3
275-
## explicit; go 1.16
276-
# golang.org/x/crypto v0.41.0
277-
## explicit; go 1.23.0
278-
# golang.org/x/mod v0.27.0
279-
## explicit; go 1.23.0
280212
# golang.org/x/net v0.43.0
281213
## explicit; go 1.23.0
282214
golang.org/x/net/context
@@ -287,8 +219,6 @@ golang.org/x/sync/errgroup
287219
## explicit; go 1.23.0
288220
golang.org/x/sys/unix
289221
golang.org/x/sys/windows
290-
# google.golang.org/protobuf v1.36.4
291-
## explicit; go 1.21
292222
# gopkg.in/warnings.v0 v0.1.2
293223
## explicit
294224
gopkg.in/warnings.v0

0 commit comments

Comments
 (0)