Skip to content

Commit

Permalink
Migrate to Go modules and Go 1.13
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
  • Loading branch information
alexellis committed Nov 17, 2020
1 parent 14776ab commit 38a865d
Show file tree
Hide file tree
Showing 18 changed files with 117 additions and 181 deletions.
21 changes: 0 additions & 21 deletions .vscode/launch.json

This file was deleted.

3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

32 changes: 0 additions & 32 deletions .vscode/tasks.json

This file was deleted.

67 changes: 43 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,36 +1,55 @@
FROM golang:1.11
FROM teamserverless/license-check:0.3.9 as license-check

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

WORKDIR /go/src/github.com/openfaas-incubator/cron-connector
ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG TARGETOS
ARG TARGETARCH

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

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

WORKDIR /go/src/github.com/openfaas/cron-connector
COPY . .

ARG OPTS
RUN license-check -path /go/src/github.com/openfaas/cron-connector/ --verbose=false "Alex Ellis" "OpenFaaS Author(s)"
RUN gofmt -l -d $(find . -type f -name '*.go' -not -path "./vendor/*")
RUN CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH} go test -v ./...

RUN VERSION=$(git describe --all --exact-match `git rev-parse HEAD` | grep tags | sed 's/tags\///') \
&& GIT_COMMIT=$(git rev-list -1 HEAD) \
&& GOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=${CGO_ENABLED} go build \
--ldflags "-s -w \
-X github.com/openfaas/cron-connector/version.GitCommit=${GIT_COMMIT}\
-X github.com/openfaas/cron-connector/version.Version=${VERSION}" \
-a -installsuffix cgo -o cron-connector .

FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.12 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" \
org.label-schema.name="openfaas/cron-connector" \
org.label-schema.vendor="openfaas" \
org.label-schema.docker.schema-version="1.0"

RUN apk --no-cache add \
ca-certificates

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

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

FROM scratch
ENV http_proxy ""
ENV https_proxy ""

COPY --from=0 /etc/passwd /etc/group /etc/
COPY --from=0 /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=0 --chown=app:app /scratch-tmp /tmp/
COPY --from=0 /go/src/github.com/openfaas-incubator/cron-connector/cron-connector .
COPY --from=build /go/src/github.com/openfaas/cron-connector/cron-connector .
RUN chown -R app:app ./

USER app

ENTRYPOINT ["./cron-connector"]
CMD ["./cron-connector"]
54 changes: 0 additions & 54 deletions Gopkg.lock

This file was deleted.

34 changes: 0 additions & 34 deletions Gopkg.toml

This file was deleted.

3 changes: 1 addition & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Copyright 2019 Rishabh Gupta
Copyright 2019 OpenFaaS Author(s)
Copyright 2020 OpenFaaS Author(s)

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:

Expand Down
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,3 @@ manifest:

test:
go test ./...

verify-codegen:
./hack/verify-codegen.sh
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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.

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

## How to Use

Expand Down
12 changes: 12 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module github.com/openfaas/cron-connector

go 1.13

require (
github.com/ewilde/faas-federation v0.0.0-20200206161705-23d8f6d639f1 // indirect
github.com/openfaas-incubator/connector-sdk v0.0.0-20190125151851-d722c9f72ad0
github.com/openfaas/faas v0.0.0-20190104165101-a65df4795bc6
github.com/openfaas/faas-provider v0.0.0-20181216160432-220324e98f5d // indirect
github.com/pkg/errors v0.8.1
gopkg.in/robfig/cron.v2 v2.0.0-20150107220207-be2e0b0deed5
)
11 changes: 11 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
github.com/ewilde/faas-federation v0.0.0-20200206161705-23d8f6d639f1/go.mod h1:KUZSQ/D7+BBykfBCx2cPn8LZdvRLPHwBLhKxF94jRWw=
github.com/openfaas-incubator/connector-sdk v0.0.0-20190125151851-d722c9f72ad0 h1:K7UydMie+pPYUtyA/Ele4xMst5q2D8yYPNg5NU2cs3U=
github.com/openfaas-incubator/connector-sdk v0.0.0-20190125151851-d722c9f72ad0/go.mod h1:jHCtd1HCZwhuwdPy4OB8CQU7ZqzxBdWNhIhH/khCJqQ=
github.com/openfaas/cron-connector v0.2.2/go.mod h1:G+g/i/KXbkd3A/W0FogoRnGxG0uOOhOkshPhuWWdUnQ=
github.com/openfaas/faas v0.0.0-20190104165101-a65df4795bc6 h1:eCf/7VwjpIOfLecWQoO0W9UMu1g5g9Ocwp+Sg7jkGzg=
github.com/openfaas/faas v0.0.0-20190104165101-a65df4795bc6/go.mod h1:E0m2rLup0Vvxg53BKxGgaYAGcZa3Xl+vvL7vSi5yQ14=
github.com/openfaas/faas-provider v0.0.0-20181216160432-220324e98f5d h1:mPAUhyVGlBfGVQQUngtyGEH9uidFUzq9R5QkrpqGJug=
github.com/openfaas/faas-provider v0.0.0-20181216160432-220324e98f5d/go.mod h1:W4OIp33RUOpR7wW+omJB/7GhIydRmYXvKf/VqUKI4yM=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
gopkg.in/robfig/cron.v2 v2.0.0-20150107220207-be2e0b0deed5 h1:E846t8CnR+lv5nE+VuiKTDG/v1U2stad0QzddfJC7kY=
gopkg.in/robfig/cron.v2 v2.0.0-20150107220207-be2e0b0deed5/go.mod h1:hiOFpYm0ZJbusNj2ywpbrXowU3G8U6GIQzqn2mw1UIE=
8 changes: 6 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Rishabh Gupta 2019. All rights reserved.
// Copyright (c) OpenFaaS Author(s) 2020. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

package main
Expand All @@ -11,7 +11,8 @@ import (
"time"

"github.com/openfaas-incubator/connector-sdk/types"
cfunction "github.com/openfaas-incubator/cron-connector/types"
cfunction "github.com/openfaas/cron-connector/types"
"github.com/openfaas/cron-connector/version"
"github.com/openfaas/faas/gateway/requests"
)

Expand All @@ -23,6 +24,9 @@ func main() {
panic(err)
}

sha, ver := version.GetReleaseInfo()
log.Printf("Version: %s\tCommit: %s", sha, ver)

controller := types.NewController(creds, config)
cronScheduler := cfunction.NewScheduler()
topic := "cron-function"
Expand Down
4 changes: 2 additions & 2 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) Rishabh Gupta 2019. All rights reserved.
// Copyright (c) OpenFaaS Author(s) 2020. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
package main

import (
"testing"

cfunction "github.com/openfaas-incubator/cron-connector/types"
cfunction "github.com/openfaas/cron-connector/types"
"github.com/openfaas/faas/gateway/requests"
)

Expand Down
2 changes: 1 addition & 1 deletion types/cron_function.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Rishabh Gupta 2019. All rights reserved.
// Copyright (c) OpenFaaS Author(s) 2020. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

package types
Expand Down
2 changes: 1 addition & 1 deletion types/lookup_builder.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Rishabh Gupta 2019. All rights reserved.
// Copyright (c) OpenFaaS Author(s) 2020. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

package types
Expand Down
2 changes: 1 addition & 1 deletion types/scheduler.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Rishabh Gupta 2019. All rights reserved.
// Copyright (c) OpenFaaS Author(s) 2020. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

package types
Expand Down
10 changes: 10 additions & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# github.com/openfaas-incubator/connector-sdk v0.0.0-20190125151851-d722c9f72ad0
github.com/openfaas-incubator/connector-sdk/types
# github.com/openfaas/faas v0.0.0-20190104165101-a65df4795bc6
github.com/openfaas/faas/gateway/requests
# github.com/openfaas/faas-provider v0.0.0-20181216160432-220324e98f5d
github.com/openfaas/faas-provider/auth
# github.com/pkg/errors v0.8.1
github.com/pkg/errors
# gopkg.in/robfig/cron.v2 v2.0.0-20150107220207-be2e0b0deed5
gopkg.in/robfig/cron.v2
28 changes: 28 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2020 OpenFaaS Author(s)
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

package version

var (
// Version release version of the provider
Version string

// GitCommit SHA of the last git commit
GitCommit string

// DevVersion string for the development version
DevVersion = "dev"
)

// BuildVersion returns current version of the provider
func BuildVersion() string {
if len(Version) == 0 {
return DevVersion
}
return Version
}

// GetReleaseInfo includes the SHA and the release version
func GetReleaseInfo() (sha, release string) {
return GitCommit, BuildVersion()
}

0 comments on commit 38a865d

Please sign in to comment.