Skip to content

Commit 067382d

Browse files
LucasRoesleralexellis
authored andcommitted
Add script to manage go.mod and modules.txt
**What** - Add scripting that handles copying the function's go.mod to the function root. This requires several mutations to handle renaming the module and dealig with local replacements of the function - Add scriptin to handle the vendor/modules.txt. It also handles mutations to deal with the local replacement of the function code Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
1 parent 71255a6 commit 067382d

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

template/golang-http/Dockerfile

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,43 @@ ARG GOFLAGS=""
2525
RUN cat function/GO_REPLACE.txt >> ./go.mod || exit 0
2626
RUN if [ -d ./function/vendor ]; then \
2727
echo "moving handler vendor" && \
28-
mv -f ./function/vendor .; \
28+
mv -f ./function/vendor .;\
2929
else \
30-
echo "using modules or vendor not found "; \
30+
echo "vendor not found "; \
31+
fi
32+
33+
RUN if [ "${GO111MODULE}" == 'on' ]; then \
34+
# copy the user's go.mod
35+
mv -f ./function/go.mod . && \
36+
mv -f ./function/go.sum . && \
37+
# clean up the go.mod,
38+
# remove any local require for the handler/function, this can exist _if_ the
39+
# developer has subpackages in their handler. It is ok to just remove it
40+
# because we will replace it later
41+
grep -v "handler/function" go.mod > gomod2; mv gomod2 go.mod && \
42+
# now update the go.mod
43+
# first, replace handler/function to point at the local code
44+
# second, we need to rename the module to handler to match our main
45+
go mod edit \
46+
-replace=handler/function=./function \
47+
-module handler && \
48+
cat go.mod && \
49+
if [ -d ./vendor ]; then \
50+
# when vendored, we need to do similar edits to the vendor/modules.txt
51+
# first we need to replace any possible copy of the handler code
52+
rm -rf vendor/handler && \
53+
# in modules.txt, we remove existing references to the handler/function
54+
# these are replaced later with the new structure
55+
grep -v "handler/function" ./vendor/modules.txt> modulestext; mv modulestext ./vendor/modules.txt && \
56+
# add the mising replace to the vendor/modules.txt
57+
echo "## explicit" >> ./vendor/modules.txt && \
58+
echo "# handler/function => ./function" >> ./vendor/modules.txt && \
59+
cat ./vendor/modules.txt; \
60+
else \
61+
echo "skip adding replace to ' ./vendor/modules.txt'"; \
62+
fi \
63+
else \
64+
echo "skip go.mod handling"; \
3165
fi
3266

3367
# Run a gofmt and exclude all vendored code.

0 commit comments

Comments
 (0)