File tree Expand file tree Collapse file tree 4 files changed +76
-7
lines changed Expand file tree Collapse file tree 4 files changed +76
-7
lines changed Original file line number Diff line number Diff line change @@ -20,20 +20,24 @@ ARG GO111MODULE="on"
20
20
ARG GOPROXY=""
21
21
ARG GOFLAGS=""
22
22
ARG CGO_ENABLED=0
23
- ENV CGO_ENABLED=${CGO_ENABLED}
23
+ ARG DEBUG=0
24
24
25
+ ENV DEBUG=${DEBUG}
26
+ ENV CGO_ENABLED=${CGO_ENABLED}
27
+ ENV GOOS=${TARGETOS}
28
+ ENV GOARCH=${TARGETARCH}
29
+ ENV GO=/go/src/handler/go.sh
25
30
26
31
# Run a gofmt and exclude all vendored code.
27
32
RUN test -z "$(gofmt -l $(find . -type f -name '*.go' -not -path " ./vendor/*" -not -path " ./function/vendor/*"))" || { echo "Run \" gofmt -s -w\" on your Golang code" ; exit 1; }
28
33
29
34
WORKDIR /go/src/handler/function
30
35
RUN mkdir -p /go/src/handler/function/static
31
36
32
- RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} go test ./... -cover
37
+ RUN ${GO} test ./... -cover
33
38
34
39
WORKDIR /go/src/handler
35
- RUN CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
36
- go build --ldflags "-s -w" -a -installsuffix cgo -o handler .
40
+ RUN ${GO} build --ldflags "-s -w" -a -installsuffix cgo -o handler .
37
41
38
42
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.15
39
43
# Add non root user and certs
Original file line number Diff line number Diff line change
1
+ #! /bin/sh
2
+ # go.sh is a wrapper for the Go command that will
3
+ # automatically set the required module related flags
4
+ # when a vendor folder is detected.
5
+ #
6
+ # Currently, in Go 1.18, Go Workspaces are incompatible
7
+ # with vendored modules. As a result, we must disable
8
+ # Go modules and use GOPATH mode.
9
+
10
+ # We use this bash script to wrap Go commands because
11
+ # there is no clear way to set an env variable from the
12
+ # a script in a Dockerfile.
13
+ # It is possible to use `go env -w` but, but env varaibles
14
+ # have precedence and if it is set as an arg/env variable,
15
+ # then it will be ignored by the `go env -w`.
16
+
17
+ # if the function/vendor folder exists
18
+ # then we set the env variables for
19
+ # GO111MODULE=off
20
+ if [ -d " /go/src/handler/function/vendor" ]; then
21
+ echo " Setting vendor mode env variables"
22
+ export GO111MODULE=off
23
+ fi
24
+
25
+ # if DEBUG env is 1, print the go env
26
+ if [ " ${DEBUG:- 0} " = " 1" ]; then
27
+ go env
28
+ fi
29
+
30
+ go " $@ "
Original file line number Diff line number Diff line change @@ -20,19 +20,24 @@ ARG GO111MODULE="on"
20
20
ARG GOPROXY=""
21
21
ARG GOFLAGS=""
22
22
ARG CGO_ENABLED=0
23
+ ARG DEBUG=0
24
+
25
+ ENV DEBUG=${DEBUG}
23
26
ENV CGO_ENABLED=${CGO_ENABLED}
27
+ ENV GOOS=${TARGETOS}
28
+ ENV GOARCH=${TARGETARCH}
29
+ ENV GO=/go/src/handler/go.sh
24
30
25
31
# Run a gofmt and exclude all vendored code.
26
32
RUN test -z "$(gofmt -l $(find . -type f -name '*.go' -not -path " ./vendor/*" -not -path " ./function/vendor/*"))" || { echo "Run \" gofmt -s -w\" on your Golang code" ; exit 1; }
27
33
28
34
WORKDIR /go/src/handler/function
29
35
RUN mkdir -p /go/src/handler/function/static
30
36
31
- RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} go test ./... -cover
37
+ RUN ${GO} test ./... -cover
32
38
33
39
WORKDIR /go/src/handler
34
- RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
35
- go build --ldflags "-s -w" -a -installsuffix cgo -o handler .
40
+ RUN ${GO} build --ldflags "-s -w" -a -installsuffix cgo -o handler .
36
41
37
42
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.15 as ship
38
43
Original file line number Diff line number Diff line change
1
+ #! /bin/sh
2
+ # go.sh is a wrapper for the Go command that will
3
+ # automatically set the required module related flags
4
+ # when a vendor folder is detected.
5
+ #
6
+ # Currently, in Go 1.18, Go Workspaces are incompatible
7
+ # with vendored modules. As a result, we must disable
8
+ # Go modules and use GOPATH mode.
9
+
10
+ # We use this bash script to wrap Go commands because
11
+ # there is no clear way to set an env variable from the
12
+ # a script in a Dockerfile.
13
+ # It is possible to use `go env -w` but, but env varaibles
14
+ # have precedence and if it is set as an arg/env variable,
15
+ # then it will be ignored by the `go env -w`.
16
+
17
+ # if the function/vendor folder exists
18
+ # then we set the env variables for
19
+ # GO111MODULE=off
20
+ if [ -d " /go/src/handler/function/vendor" ]; then
21
+ echo " Setting vendor mode env variables"
22
+ export GO111MODULE=off
23
+ fi
24
+
25
+ # if DEBUG env is 1, print the go env
26
+ if [ " ${DEBUG:- 0} " = " 1" ]; then
27
+ go env
28
+ fi
29
+
30
+ go " $@ "
You can’t perform that action at this time.
0 commit comments