Skip to content

Commit

Permalink
Added Makefile and Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
oscaromeu committed Feb 28, 2021
1 parent 349edc5 commit e3dc984
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 2 deletions.
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)
42 changes: 42 additions & 0 deletions examples/influxdb/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
4 changes: 2 additions & 2 deletions examples/influxdb/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
general:
meteocat_api_key: "ksajclksajclaskjwo32cmsdsmadlqwlkewqñl"
meteocat_api_key: "my_apikey"
meteocat_codi_estacio: ""
meteocat_codi_variable: ""
database:
Expand All @@ -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"


22 changes: 22 additions & 0 deletions examples/influxdb/go.mod
Original file line number Diff line number Diff line change
@@ -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
)

0 comments on commit e3dc984

Please sign in to comment.