Skip to content

Commit 193d979

Browse files
LucasRoesleralexellis
authored andcommitted
feat: upgrade to go 1.18 and use workspaces to manage the handler
Replace the custom bash script with a Go workspace, to handle setting the correct imports and replacements during the Go builds. This is simpler and uses offical Go tooling. Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
1 parent eb793ff commit 193d979

File tree

12 files changed

+35
-322
lines changed

12 files changed

+35
-322
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
build
22
test
33
test.yml
4-
.DS_STORE
4+
.DS_STORE
5+
.vscode

go.work

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
go 1.18
2+
3+
use (
4+
./template/golang-http
5+
./template/golang-middleware
6+
)

template/golang-http/Dockerfile

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FROM --platform=${TARGETPLATFORM:-linux/amd64} ghcr.io/openfaas/of-watchdog:0.9.3 as watchdog
2-
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.17-alpine3.15 as build
2+
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.18-alpine3.15 as build
33

44
ARG TARGETPLATFORM
55
ARG BUILDPLATFORM
@@ -11,7 +11,6 @@ RUN apk --no-cache add git
1111
COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog
1212
RUN chmod +x /usr/bin/fwatchdog
1313

14-
ENV CGO_ENABLED=0
1514

1615
RUN mkdir -p /go/src/handler
1716
WORKDIR /go/src/handler
@@ -20,10 +19,9 @@ COPY . .
2019
ARG GO111MODULE="on"
2120
ARG GOPROXY=""
2221
ARG GOFLAGS=""
23-
ARG DEBUG=0
22+
ARG CGO_ENABLED=0
23+
ENV CGO_ENABLED=${CGO_ENABLED}
2424

25-
# Lift the vendor and go.mod to the main package, cleanup any relative references
26-
RUN sh modules-cleanup.sh
2725

2826
# Run a gofmt and exclude all vendored code.
2927
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; }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module handler/function
2+
3+
go 1.18

template/golang-http/go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
module handler
22

3-
go 1.16
4-
5-
replace handler/function => ./function
3+
go 1.18
64

75
require github.com/openfaas/templates-sdk v0.0.0-20200723092016-0ebf61253625

template/golang-http/go.work

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
go 1.18
2+
3+
use (
4+
.
5+
./function
6+
)

template/golang-http/modules-cleanup.sh

Lines changed: 0 additions & 149 deletions
This file was deleted.

template/golang-middleware/Dockerfile

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FROM --platform=${TARGETPLATFORM:-linux/amd64} ghcr.io/openfaas/of-watchdog:0.9.3 as watchdog
2-
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.17-alpine3.15 as build
2+
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.18-alpine3.15 as build
33

44
ARG TARGETPLATFORM
55
ARG BUILDPLATFORM
@@ -11,7 +11,6 @@ RUN apk --no-cache add git
1111
COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog
1212
RUN chmod +x /usr/bin/fwatchdog
1313

14-
ENV CGO_ENABLED=0
1514

1615
RUN mkdir -p /go/src/handler
1716
WORKDIR /go/src/handler
@@ -20,10 +19,8 @@ COPY . .
2019
ARG GO111MODULE="on"
2120
ARG GOPROXY=""
2221
ARG GOFLAGS=""
23-
ARG DEBUG=0
24-
25-
# Lift the vendor and go.mod to the main package, cleanup any relative references
26-
RUN sh modules-cleanup.sh
22+
ARG CGO_ENABLED=0
23+
ENV CGO_ENABLED=${CGO_ENABLED}
2724

2825
# Run a gofmt and exclude all vendored code.
2926
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; }
@@ -33,7 +30,7 @@ WORKDIR /go/src/handler/function
3330
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} go test ./... -cover
3431

3532
WORKDIR /go/src/handler
36-
RUN CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
33+
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
3734
go build --ldflags "-s -w" -a -installsuffix cgo -o handler .
3835

3936
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.14
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module handler/function
2+
3+
go 1.18

template/golang-middleware/go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
module handler
22

3-
go 1.16
4-
5-
replace handler/function => ./function
3+
go 1.18

0 commit comments

Comments
 (0)