Skip to content

Commit 2268390

Browse files
committed
Improve output, migrate to Go 1.18
* Improves output for connector invocations with duration * Updates connector-sdk, and Go to 1.18 Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent f981570 commit 2268390

File tree

8 files changed

+180
-615
lines changed

8 files changed

+180
-615
lines changed

Dockerfile

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
FROM teamserverless/license-check:0.3.9 as license-check
1+
FROM ghcr.io/openfaas/license-check:0.4.0 as license-check
22

3-
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.15 as build
3+
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.18 as build
44

55
ARG TARGETPLATFORM
66
ARG BUILDPLATFORM
@@ -9,6 +9,7 @@ ARG TARGETARCH
99

1010
ENV CGO_ENABLED=0
1111
ENV GO111MODULE=on
12+
# ENV GOFLAGS=-mod=vendor
1213

1314
COPY --from=license-check /license-check /usr/bin/
1415

@@ -27,7 +28,7 @@ RUN VERSION=$(git describe --all --exact-match `git rev-parse HEAD` | grep tags
2728
-X github.com/openfaas/cron-connector/version.Version=${VERSION}" \
2829
-a -installsuffix cgo -o cron-connector .
2930

30-
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.14 as ship
31+
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.16.1 as ship
3132
LABEL org.label-schema.license="MIT" \
3233
org.label-schema.vcs-url="https://github.com/openfaas/cron-connector" \
3334
org.label-schema.vcs-type="Git" \

Makefile

+20-24
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
1-
.PHONY: build push manifest test verify-codegen charts
2-
TAG?=latest
1+
IMG_NAME?=cron-connector
32

4-
# docker manifest command will work with Docker CLI 18.03 or newer
5-
# but for now it's still experimental feature so we need to enable that
6-
export DOCKER_CLI_EXPERIMENTAL=enabled
7-
8-
build:
9-
docker build -t openfaas/cron-connector:$(TAG)-amd64 . -f Dockerfile
10-
docker build --build-arg OPTS="GOARCH=arm64" -t openfaas/cron-connector:$(TAG)-arm64 . -f Dockerfile
11-
docker build --build-arg OPTS="GOARCH=arm GOARM=6" -t openfaas/cron-connector:$(TAG)-armhf . -f Dockerfile
3+
TAG?=dev
4+
PLATFORMS?=linux/amd64,linux/arm/v7,linux/arm64
5+
OWNER?=alexellis2
6+
SERVER?=docker.io
127

13-
push:
14-
docker push openfaas/cron-connector:$(TAG)-amd64
15-
docker push openfaas/cron-connector:$(TAG)-arm64
16-
docker push openfaas/cron-connector:$(TAG)-armhf
8+
VERSION := $(shell git describe --tags --dirty)
9+
GIT_COMMIT := $(shell git rev-parse HEAD)
1710

18-
manifest:
19-
docker manifest create --amend openfaas/cron-connector:$(TAG) \
20-
openfaas/cron-connector:$(TAG)-amd64 \
21-
openfaas/cron-connector:$(TAG)-arm64 \
22-
openfaas/cron-connector:$(TAG)-armhf
23-
docker manifest annotate openfaas/cron-connector:$(TAG) openfaas/cron-connector:$(TAG)-arm64 --os linux --arch arm64
24-
docker manifest annotate openfaas/cron-connector:$(TAG) openfaas/cron-connector:$(TAG)-armhf --os linux --arch arm --variant v6
25-
docker manifest push -p openfaas/cron-connector:$(TAG)
11+
export DOCKER_CLI_EXPERIMENTAL=enabled
12+
export DOCKER_BUILDKIT=1
2613

27-
test:
28-
go test ./...
14+
.PHONY: publish-buildx-all
15+
publish-buildx-all:
16+
@echo $(SERVER)/$(OWNER)/$(IMG_NAME):$(TAG) && \
17+
docker buildx create --use --name=multiarch --node=multiarch && \
18+
docker buildx build \
19+
--platform $(PLATFORMS) \
20+
--push=true \
21+
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
22+
--build-arg VERSION=$(VERSION) \
23+
--tag $(SERVER)/$(OWNER)/$(IMG_NAME):$(TAG) \
24+
.

config.go

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"time"
7+
8+
"github.com/openfaas/connector-sdk/types"
9+
)
10+
11+
func getControllerConfig() (*types.ControllerConfig, error) {
12+
gURL, ok := os.LookupEnv("gateway_url")
13+
14+
if !ok {
15+
return nil, fmt.Errorf("gateway_url environment variable not set")
16+
}
17+
18+
asynchronousInvocation := false
19+
if val, exists := os.LookupEnv("asynchronous_invocation"); exists {
20+
asynchronousInvocation = (val == "1" || val == "true")
21+
}
22+
23+
contentType := "text/plain"
24+
if v, exists := os.LookupEnv("content_type"); exists && len(v) > 0 {
25+
contentType = v
26+
}
27+
28+
var printResponseBody bool
29+
if val, exists := os.LookupEnv("print_response_body"); exists {
30+
printResponseBody = (val == "1" || val == "true")
31+
}
32+
33+
rebuildInterval := time.Second * 10
34+
35+
if val, exists := os.LookupEnv("rebuild_interval"); exists {
36+
d, err := time.ParseDuration(val)
37+
if err != nil {
38+
return nil, err
39+
}
40+
rebuildInterval = d
41+
}
42+
43+
return &types.ControllerConfig{
44+
RebuildInterval: rebuildInterval,
45+
GatewayURL: gURL,
46+
AsyncFunctionInvocation: asynchronousInvocation,
47+
ContentType: contentType,
48+
PrintResponse: true,
49+
PrintResponseBody: printResponseBody,
50+
PrintRequestBody: false,
51+
}, nil
52+
}

go.mod

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
module github.com/openfaas/cron-connector
22

3-
go 1.16
3+
go 1.18
44

55
require (
6-
github.com/openfaas/connector-sdk v0.6.1
7-
github.com/openfaas/faas-cli v0.0.0-20210617112918-72816d486cf7
8-
github.com/openfaas/faas-provider v0.18.5
9-
github.com/pkg/errors v0.9.1
6+
github.com/openfaas/connector-sdk v0.6.7
7+
github.com/openfaas/faas-cli v0.0.0-20220806094027-3534df71572f
8+
github.com/openfaas/faas-provider v0.19.0
109
github.com/robfig/cron/v3 v3.0.1
1110
)
11+
12+
require (
13+
github.com/drone/envsubst v1.0.3 // indirect
14+
github.com/kr/text v0.2.0 // indirect
15+
github.com/mitchellh/go-homedir v1.1.0 // indirect
16+
github.com/openfaas/faas/gateway v0.0.0-20220805080331-b87b96ae456e // indirect
17+
github.com/ryanuber/go-glob v1.0.0 // indirect
18+
gopkg.in/yaml.v2 v2.4.0 // indirect
19+
)

0 commit comments

Comments
 (0)