Skip to content

Commit 38a865d

Browse files
committed
Migrate to Go modules and Go 1.13
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent 14776ab commit 38a865d

18 files changed

+117
-181
lines changed

.vscode/launch.json

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

.vscode/settings.json

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

.vscode/tasks.json

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

Dockerfile

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,55 @@
1-
FROM golang:1.11
1+
FROM teamserverless/license-check:0.3.9 as license-check
22

3-
RUN mkdir -p /go/src/github.com/openfaas-incubator/cron-connector/
3+
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.13 as build
44

5-
WORKDIR /go/src/github.com/openfaas-incubator/cron-connector
5+
ARG TARGETPLATFORM
6+
ARG BUILDPLATFORM
7+
ARG TARGETOS
8+
ARG TARGETARCH
69

10+
ENV CGO_ENABLED=0
11+
ENV GO111MODULE=on
12+
ENV GOFLAGS=-mod=vendor
13+
14+
COPY --from=license-check /license-check /usr/bin/
15+
16+
WORKDIR /go/src/github.com/openfaas/cron-connector
717
COPY . .
818

9-
ARG OPTS
19+
RUN license-check -path /go/src/github.com/openfaas/cron-connector/ --verbose=false "Alex Ellis" "OpenFaaS Author(s)"
20+
RUN gofmt -l -d $(find . -type f -name '*.go' -not -path "./vendor/*")
21+
RUN CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH} go test -v ./...
22+
23+
RUN VERSION=$(git describe --all --exact-match `git rev-parse HEAD` | grep tags | sed 's/tags\///') \
24+
&& GIT_COMMIT=$(git rev-list -1 HEAD) \
25+
&& GOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=${CGO_ENABLED} go build \
26+
--ldflags "-s -w \
27+
-X github.com/openfaas/cron-connector/version.GitCommit=${GIT_COMMIT}\
28+
-X github.com/openfaas/cron-connector/version.Version=${VERSION}" \
29+
-a -installsuffix cgo -o cron-connector .
30+
31+
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.12 as ship
32+
LABEL org.label-schema.license="MIT" \
33+
org.label-schema.vcs-url="https://github.com/openfaas/cron-connector" \
34+
org.label-schema.vcs-type="Git" \
35+
org.label-schema.name="openfaas/cron-connector" \
36+
org.label-schema.vendor="openfaas" \
37+
org.label-schema.docker.schema-version="1.0"
38+
39+
RUN apk --no-cache add \
40+
ca-certificates
1041

11-
RUN gofmt -l -d $(find . -type f -name '*.go' -not -path "./vendor/*") && \
12-
go test -v ./ && \
13-
VERSION=$(git describe --all --exact-match `git rev-parse HEAD` | grep tags | sed 's/tags\///') && \
14-
GIT_COMMIT=$(git rev-list -1 HEAD) && \
15-
env ${OPTS} CGO_ENABLED=0 GOOS=linux go build -ldflags "-s -w \
16-
-X github.com/openfaas-incubator/cron-connector/pkg/version.Release=${VERSION} \
17-
-X github.com/openfaas-incubator/cron-connector/pkg/version.SHA=${GIT_COMMIT}" \
18-
-a -installsuffix cgo -o cron-connector . && \
19-
addgroup --system app && \
20-
adduser --system --ingroup app app && \
21-
mkdir /scratch-tmp
42+
RUN addgroup -S app \
43+
&& adduser -S -g app app
2244

23-
# we can't add user in next stage because it's from scratch
24-
# ca-certificates and tmp folder are also missing in scratch
25-
# so we add all of it here and copy files in next stage
45+
WORKDIR /home/app
2646

27-
FROM scratch
47+
ENV http_proxy ""
48+
ENV https_proxy ""
2849

29-
COPY --from=0 /etc/passwd /etc/group /etc/
30-
COPY --from=0 /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
31-
COPY --from=0 --chown=app:app /scratch-tmp /tmp/
32-
COPY --from=0 /go/src/github.com/openfaas-incubator/cron-connector/cron-connector .
50+
COPY --from=build /go/src/github.com/openfaas/cron-connector/cron-connector .
51+
RUN chown -R app:app ./
3352

3453
USER app
3554

36-
ENTRYPOINT ["./cron-connector"]
55+
CMD ["./cron-connector"]

Gopkg.lock

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

Gopkg.toml

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

LICENSE

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
Copyright 2019 Rishabh Gupta
2-
Copyright 2019 OpenFaaS Author(s)
1+
Copyright 2020 OpenFaaS Author(s)
32

43
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
54

Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,3 @@ manifest:
2626

2727
test:
2828
go test ./...
29-
30-
verify-codegen:
31-
./hack/verify-codegen.sh

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This is a cron event connector for OpenFaaS. This was built to provide a timer interface to trigger OpenFaaS functions. Also checkout [OpenFaaS docs on cron](https://docs.openfaas.com/reference/cron/) for other methods on how you can run functions triggered by cron.
44

5-
This project was forked from [zeerorg/cron-connector](https://github.com/openfaas-incubator/cron-connector) to enable prompt updates and patches for end-users.
5+
This project was forked from [zeerorg/cron-connector](https://github.com/openfaas/cron-connector) to enable prompt updates and patches for end-users.
66

77
## How to Use
88

go.mod

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module github.com/openfaas/cron-connector
2+
3+
go 1.13
4+
5+
require (
6+
github.com/ewilde/faas-federation v0.0.0-20200206161705-23d8f6d639f1 // indirect
7+
github.com/openfaas-incubator/connector-sdk v0.0.0-20190125151851-d722c9f72ad0
8+
github.com/openfaas/faas v0.0.0-20190104165101-a65df4795bc6
9+
github.com/openfaas/faas-provider v0.0.0-20181216160432-220324e98f5d // indirect
10+
github.com/pkg/errors v0.8.1
11+
gopkg.in/robfig/cron.v2 v2.0.0-20150107220207-be2e0b0deed5
12+
)

go.sum

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
github.com/ewilde/faas-federation v0.0.0-20200206161705-23d8f6d639f1/go.mod h1:KUZSQ/D7+BBykfBCx2cPn8LZdvRLPHwBLhKxF94jRWw=
2+
github.com/openfaas-incubator/connector-sdk v0.0.0-20190125151851-d722c9f72ad0 h1:K7UydMie+pPYUtyA/Ele4xMst5q2D8yYPNg5NU2cs3U=
3+
github.com/openfaas-incubator/connector-sdk v0.0.0-20190125151851-d722c9f72ad0/go.mod h1:jHCtd1HCZwhuwdPy4OB8CQU7ZqzxBdWNhIhH/khCJqQ=
4+
github.com/openfaas/cron-connector v0.2.2/go.mod h1:G+g/i/KXbkd3A/W0FogoRnGxG0uOOhOkshPhuWWdUnQ=
5+
github.com/openfaas/faas v0.0.0-20190104165101-a65df4795bc6 h1:eCf/7VwjpIOfLecWQoO0W9UMu1g5g9Ocwp+Sg7jkGzg=
6+
github.com/openfaas/faas v0.0.0-20190104165101-a65df4795bc6/go.mod h1:E0m2rLup0Vvxg53BKxGgaYAGcZa3Xl+vvL7vSi5yQ14=
7+
github.com/openfaas/faas-provider v0.0.0-20181216160432-220324e98f5d h1:mPAUhyVGlBfGVQQUngtyGEH9uidFUzq9R5QkrpqGJug=
8+
github.com/openfaas/faas-provider v0.0.0-20181216160432-220324e98f5d/go.mod h1:W4OIp33RUOpR7wW+omJB/7GhIydRmYXvKf/VqUKI4yM=
9+
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
10+
gopkg.in/robfig/cron.v2 v2.0.0-20150107220207-be2e0b0deed5 h1:E846t8CnR+lv5nE+VuiKTDG/v1U2stad0QzddfJC7kY=
11+
gopkg.in/robfig/cron.v2 v2.0.0-20150107220207-be2e0b0deed5/go.mod h1:hiOFpYm0ZJbusNj2ywpbrXowU3G8U6GIQzqn2mw1UIE=

main.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Rishabh Gupta 2019. All rights reserved.
1+
// Copyright (c) OpenFaaS Author(s) 2020. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
package main
@@ -11,7 +11,8 @@ import (
1111
"time"
1212

1313
"github.com/openfaas-incubator/connector-sdk/types"
14-
cfunction "github.com/openfaas-incubator/cron-connector/types"
14+
cfunction "github.com/openfaas/cron-connector/types"
15+
"github.com/openfaas/cron-connector/version"
1516
"github.com/openfaas/faas/gateway/requests"
1617
)
1718

@@ -23,6 +24,9 @@ func main() {
2324
panic(err)
2425
}
2526

27+
sha, ver := version.GetReleaseInfo()
28+
log.Printf("Version: %s\tCommit: %s", sha, ver)
29+
2630
controller := types.NewController(creds, config)
2731
cronScheduler := cfunction.NewScheduler()
2832
topic := "cron-function"

main_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// Copyright (c) Rishabh Gupta 2019. All rights reserved.
1+
// Copyright (c) OpenFaaS Author(s) 2020. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33
package main
44

55
import (
66
"testing"
77

8-
cfunction "github.com/openfaas-incubator/cron-connector/types"
8+
cfunction "github.com/openfaas/cron-connector/types"
99
"github.com/openfaas/faas/gateway/requests"
1010
)
1111

types/cron_function.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Rishabh Gupta 2019. All rights reserved.
1+
// Copyright (c) OpenFaaS Author(s) 2020. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
package types

types/lookup_builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Rishabh Gupta 2019. All rights reserved.
1+
// Copyright (c) OpenFaaS Author(s) 2020. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
package types

types/scheduler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Rishabh Gupta 2019. All rights reserved.
1+
// Copyright (c) OpenFaaS Author(s) 2020. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
package types

vendor/modules.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# github.com/openfaas-incubator/connector-sdk v0.0.0-20190125151851-d722c9f72ad0
2+
github.com/openfaas-incubator/connector-sdk/types
3+
# github.com/openfaas/faas v0.0.0-20190104165101-a65df4795bc6
4+
github.com/openfaas/faas/gateway/requests
5+
# github.com/openfaas/faas-provider v0.0.0-20181216160432-220324e98f5d
6+
github.com/openfaas/faas-provider/auth
7+
# github.com/pkg/errors v0.8.1
8+
github.com/pkg/errors
9+
# gopkg.in/robfig/cron.v2 v2.0.0-20150107220207-be2e0b0deed5
10+
gopkg.in/robfig/cron.v2

version/version.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2020 OpenFaaS Author(s)
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
package version
5+
6+
var (
7+
// Version release version of the provider
8+
Version string
9+
10+
// GitCommit SHA of the last git commit
11+
GitCommit string
12+
13+
// DevVersion string for the development version
14+
DevVersion = "dev"
15+
)
16+
17+
// BuildVersion returns current version of the provider
18+
func BuildVersion() string {
19+
if len(Version) == 0 {
20+
return DevVersion
21+
}
22+
return Version
23+
}
24+
25+
// GetReleaseInfo includes the SHA and the release version
26+
func GetReleaseInfo() (sha, release string) {
27+
return GitCommit, BuildVersion()
28+
}

0 commit comments

Comments
 (0)