Skip to content

feat: upgrade to go 1.18 and use workspaces to manage the handler #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
build
test
test.yml
.DS_STORE
.DS_STORE
.vscode
6 changes: 6 additions & 0 deletions go.work
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
go 1.18

use (
./template/golang-http
./template/golang-middleware
)
8 changes: 3 additions & 5 deletions template/golang-http/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM --platform=${TARGETPLATFORM:-linux/amd64} ghcr.io/openfaas/of-watchdog:0.9.3 as watchdog
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.17-alpine3.15 as build
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.18-alpine3.15 as build

ARG TARGETPLATFORM
ARG BUILDPLATFORM
Expand All @@ -11,7 +11,6 @@ RUN apk --no-cache add git
COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog
RUN chmod +x /usr/bin/fwatchdog

ENV CGO_ENABLED=0

RUN mkdir -p /go/src/handler
WORKDIR /go/src/handler
Expand All @@ -20,10 +19,9 @@ COPY . .
ARG GO111MODULE="on"
ARG GOPROXY=""
ARG GOFLAGS=""
ARG DEBUG=0
ARG CGO_ENABLED=0
ENV CGO_ENABLED=${CGO_ENABLED}

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

# Run a gofmt and exclude all vendored code.
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; }
Expand Down
3 changes: 3 additions & 0 deletions template/golang-http/function/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module handler/function

go 1.18
4 changes: 1 addition & 3 deletions template/golang-http/go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module handler

go 1.16

replace handler/function => ./function
go 1.18

require github.com/openfaas/templates-sdk v0.0.0-20200723092016-0ebf61253625
6 changes: 6 additions & 0 deletions template/golang-http/go.work
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
go 1.18

use (
.
./function
)
149 changes: 0 additions & 149 deletions template/golang-http/modules-cleanup.sh

This file was deleted.

11 changes: 4 additions & 7 deletions template/golang-middleware/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM --platform=${TARGETPLATFORM:-linux/amd64} ghcr.io/openfaas/of-watchdog:0.9.3 as watchdog
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.17-alpine3.15 as build
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.18-alpine3.15 as build

ARG TARGETPLATFORM
ARG BUILDPLATFORM
Expand All @@ -11,7 +11,6 @@ RUN apk --no-cache add git
COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog
RUN chmod +x /usr/bin/fwatchdog

ENV CGO_ENABLED=0

RUN mkdir -p /go/src/handler
WORKDIR /go/src/handler
Expand All @@ -20,10 +19,8 @@ COPY . .
ARG GO111MODULE="on"
ARG GOPROXY=""
ARG GOFLAGS=""
ARG DEBUG=0

# Lift the vendor and go.mod to the main package, cleanup any relative references
RUN sh modules-cleanup.sh
ARG CGO_ENABLED=0
ENV CGO_ENABLED=${CGO_ENABLED}

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

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

FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.14
Expand Down
3 changes: 3 additions & 0 deletions template/golang-middleware/function/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module handler/function

go 1.18
4 changes: 1 addition & 3 deletions template/golang-middleware/go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module handler

go 1.16

replace handler/function => ./function
go 1.18
6 changes: 6 additions & 0 deletions template/golang-middleware/go.work
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
go 1.18

use (
.
./function
)
Loading