diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2398262 --- /dev/null +++ b/Makefile @@ -0,0 +1,22 @@ +GOCMD = go +GOBUILD = $(GOCMD) build +GOGET = $(GOCMD) get -v +GOCLEAN = $(GOCMD) clean +GOINSTALL = $(GOCMD) install +GOTEST = $(GOCMD) test + +.PHONY: all + +all: test + +.PHONY: test +test: + $(GOTEST) -v -covermode=count -coverprofile=coverage.out ./... + +.PHONY: build +build: test + $(GOBUILD) + +.PHONY: install +install: test + $(GOINSTALL) diff --git a/examples/influxdb/Dockerfile b/examples/influxdb/Dockerfile new file mode 100644 index 0000000..806acfc --- /dev/null +++ b/examples/influxdb/Dockerfile @@ -0,0 +1,42 @@ +ARG BUILDER_IMAGE=golang:buster +ARG DISTROLESS_IMAGE=gcr.io/distroless/base +############################ +# STEP 1 build executable binary +############################ + +# syntax = docker/dockerfile:1-experimental + +FROM --platform=${BUILDPLATFORM} ${BUILDER_IMAGE} AS base +WORKDIR /src +ENV CGO_ENABLED=0 +COPY go.* . +RUN --mount=type=cache,target=/go/pkg/mod \ + go mod download + +FROM base AS build +ARG TARGETOS +ARG TARGETARCH +# Ensure ca-certficates are up to date +RUN update-ca-certificates +WORKDIR /src +COPY . . +RUN --mount=target=. \ + --mount=type=cache,target=/go/pkg/mod \ + --mount=type=cache,target=/root/.cache/go-build \ + GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-w -s" -a -installsuffix cgo -o /go/bin/meteocat/example/influxdb . + + +############################ +# STEP 2 build a small image +############################ +# using base nonroot image +# user:group is nobody:nobody, uid:gid = 65534:65534 +FROM ${DISTROLESS_IMAGE} + +# Copy our config file and static executable +COPY config.yml $GOPATH/src/meteocat/example/influxdb/ +COPY --from=build /go/bin/meteocat/example/influxdb /go/bin/meteocat/example/influxdb +WORKDIR $GOPATH/src/meteocat/example/influxdb/ +ENV LOG_DEBUG=true +# Run main +ENTRYPOINT ["/go/bin/meteocat/example/influxdb"] diff --git a/examples/influxdb/config.yml b/examples/influxdb/config.yml index fc24c38..2abb7ec 100644 --- a/examples/influxdb/config.yml +++ b/examples/influxdb/config.yml @@ -1,5 +1,5 @@ general: - meteocat_api_key: "ksajclksajclaskjwo32cmsdsmadlqwlkewqñl" + meteocat_api_key: "my_apikey" meteocat_codi_estacio: "" meteocat_codi_variable: "" database: @@ -8,6 +8,6 @@ database: influx_bucket: "meteocat-testing" influx_measurement: "meteocat_all_by_station" influx_org: "Testing" - influx_token: "5dYxum3y8db1ZZ4uCYkEjpt4C0AscasñlckasñlcaksñclsakMDv9GJewEHiLF6FjCQnqTDjrS-90ZLwFCLQBg==" + influx_token: "my_token" diff --git a/examples/influxdb/go.mod b/examples/influxdb/go.mod new file mode 100644 index 0000000..5776262 --- /dev/null +++ b/examples/influxdb/go.mod @@ -0,0 +1,22 @@ +module influxdb + +go 1.15 + +require ( + github.com/deepmap/oapi-codegen v1.5.1 // indirect + github.com/fatih/color v1.10.0 // indirect + github.com/ilyakaznacheev/cleanenv v1.2.5 + github.com/influxdata/influxdb-client-go/v2 v2.2.2 + github.com/influxdata/line-protocol v0.0.0-20210219174132-3da7e03c5204 // indirect + github.com/kr/text v0.2.0 // indirect + github.com/magefile/mage v1.11.0 // indirect + github.com/oscaromeu/meteocat v0.0.0-20210221173235-349edc505962 + github.com/sirupsen/logrus v1.8.0 + github.com/stretchr/testify v1.7.0 // indirect + golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 // indirect + golang.org/x/sys v0.0.0-20210228012217-479acdf4ea46 // indirect + gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect + gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect + olympos.io/encoding/edn v0.0.0-20201019073823-d3554ca0b0a3 // indirect +)