Skip to content

Commit

Permalink
Improve output, migrate to Go 1.18
Browse files Browse the repository at this point in the history
* Improves output for connector invocations with duration
* Updates connector-sdk, and Go to 1.18

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
  • Loading branch information
alexellis committed Aug 13, 2022
1 parent f981570 commit 2268390
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 615 deletions.
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM teamserverless/license-check:0.3.9 as license-check
FROM ghcr.io/openfaas/license-check:0.4.0 as license-check

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

ARG TARGETPLATFORM
ARG BUILDPLATFORM
Expand All @@ -9,6 +9,7 @@ ARG TARGETARCH

ENV CGO_ENABLED=0
ENV GO111MODULE=on
# ENV GOFLAGS=-mod=vendor

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

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

FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.14 as ship
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.16.1 as ship
LABEL org.label-schema.license="MIT" \
org.label-schema.vcs-url="https://github.com/openfaas/cron-connector" \
org.label-schema.vcs-type="Git" \
Expand Down
44 changes: 20 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
.PHONY: build push manifest test verify-codegen charts
TAG?=latest
IMG_NAME?=cron-connector

# docker manifest command will work with Docker CLI 18.03 or newer
# but for now it's still experimental feature so we need to enable that
export DOCKER_CLI_EXPERIMENTAL=enabled

build:
docker build -t openfaas/cron-connector:$(TAG)-amd64 . -f Dockerfile
docker build --build-arg OPTS="GOARCH=arm64" -t openfaas/cron-connector:$(TAG)-arm64 . -f Dockerfile
docker build --build-arg OPTS="GOARCH=arm GOARM=6" -t openfaas/cron-connector:$(TAG)-armhf . -f Dockerfile
TAG?=dev
PLATFORMS?=linux/amd64,linux/arm/v7,linux/arm64
OWNER?=alexellis2
SERVER?=docker.io

push:
docker push openfaas/cron-connector:$(TAG)-amd64
docker push openfaas/cron-connector:$(TAG)-arm64
docker push openfaas/cron-connector:$(TAG)-armhf
VERSION := $(shell git describe --tags --dirty)
GIT_COMMIT := $(shell git rev-parse HEAD)

manifest:
docker manifest create --amend openfaas/cron-connector:$(TAG) \
openfaas/cron-connector:$(TAG)-amd64 \
openfaas/cron-connector:$(TAG)-arm64 \
openfaas/cron-connector:$(TAG)-armhf
docker manifest annotate openfaas/cron-connector:$(TAG) openfaas/cron-connector:$(TAG)-arm64 --os linux --arch arm64
docker manifest annotate openfaas/cron-connector:$(TAG) openfaas/cron-connector:$(TAG)-armhf --os linux --arch arm --variant v6
docker manifest push -p openfaas/cron-connector:$(TAG)
export DOCKER_CLI_EXPERIMENTAL=enabled
export DOCKER_BUILDKIT=1

test:
go test ./...
.PHONY: publish-buildx-all
publish-buildx-all:
@echo $(SERVER)/$(OWNER)/$(IMG_NAME):$(TAG) && \
docker buildx create --use --name=multiarch --node=multiarch && \
docker buildx build \
--platform $(PLATFORMS) \
--push=true \
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
--build-arg VERSION=$(VERSION) \
--tag $(SERVER)/$(OWNER)/$(IMG_NAME):$(TAG) \
.
52 changes: 52 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package main

import (
"fmt"
"os"
"time"

"github.com/openfaas/connector-sdk/types"
)

func getControllerConfig() (*types.ControllerConfig, error) {
gURL, ok := os.LookupEnv("gateway_url")

if !ok {
return nil, fmt.Errorf("gateway_url environment variable not set")
}

asynchronousInvocation := false
if val, exists := os.LookupEnv("asynchronous_invocation"); exists {
asynchronousInvocation = (val == "1" || val == "true")
}

contentType := "text/plain"
if v, exists := os.LookupEnv("content_type"); exists && len(v) > 0 {
contentType = v
}

var printResponseBody bool
if val, exists := os.LookupEnv("print_response_body"); exists {
printResponseBody = (val == "1" || val == "true")
}

rebuildInterval := time.Second * 10

if val, exists := os.LookupEnv("rebuild_interval"); exists {
d, err := time.ParseDuration(val)
if err != nil {
return nil, err
}
rebuildInterval = d
}

return &types.ControllerConfig{
RebuildInterval: rebuildInterval,
GatewayURL: gURL,
AsyncFunctionInvocation: asynchronousInvocation,
ContentType: contentType,
PrintResponse: true,
PrintResponseBody: printResponseBody,
PrintRequestBody: false,
}, nil
}
18 changes: 13 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
module github.com/openfaas/cron-connector

go 1.16
go 1.18

require (
github.com/openfaas/connector-sdk v0.6.1
github.com/openfaas/faas-cli v0.0.0-20210617112918-72816d486cf7
github.com/openfaas/faas-provider v0.18.5
github.com/pkg/errors v0.9.1
github.com/openfaas/connector-sdk v0.6.7
github.com/openfaas/faas-cli v0.0.0-20220806094027-3534df71572f
github.com/openfaas/faas-provider v0.19.0
github.com/robfig/cron/v3 v3.0.1
)

require (
github.com/drone/envsubst v1.0.3 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/openfaas/faas/gateway v0.0.0-20220805080331-b87b96ae456e // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
Loading

0 comments on commit 2268390

Please sign in to comment.