Skip to content

Commit

Permalink
Merge pull request #51 from janboll/update-golang
Browse files Browse the repository at this point in the history
Refactorings for aws-resource-exporter
  • Loading branch information
janboll authored Sep 6, 2022
2 parents 135776a + 321bc05 commit 9214743
Show file tree
Hide file tree
Showing 446 changed files with 40 additions and 147,447 deletions.
8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
FROM registry.centos.org/centos/centos:7
FROM quay.io/app-sre/golang:1.18.5 as builder
WORKDIR /build
COPY . .
RUN make build

COPY aws-resource-exporter /bin/aws-resource-exporter
FROM registry.access.redhat.com/ubi8-minimal
COPY --from=builder /build/aws-resource-exporter /bin/aws-resource-exporter

EXPOSE 9115
ENTRYPOINT [ "/bin/aws-resource-exporter" ]
44 changes: 15 additions & 29 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
.PHONY: all build image check vendor dependencies
NAME := aws-resource-exporter
REPO := quay.io/app-sre/$(NAME)
TAG := $(shell git rev-parse --short HEAD)

PKGS := $(shell go list ./... | grep -v -E '/vendor/|/test')
FIRST_GOPATH := $(firstword $(subst :, ,$(shell go env GOPATH)))
GOLANGCI_LINT_BIN := $(FIRST_GOPATH)/bin/golangci-lint
CONTAINER_ENGINE ?= $(shell which podman >/dev/null 2>&1 && echo podman || echo docker)

ifneq (,$(wildcard $(CURDIR)/.docker))
DOCKER_CONF := $(CURDIR)/.docker
Expand All @@ -14,7 +13,7 @@ else
endif

.PHONY: all
all: build
all: test image

.PHONY: clean
clean:
Expand All @@ -25,32 +24,24 @@ clean:
# Building #
############

.PHONY: build
build:
go build -o $(NAME) .

vendor:
go mod tidy
go mod vendor
go mod verify

image: build
docker build -t $(REPO):$(TAG) .
.PHONY: image
image:
$(CONTAINER_ENGINE) build -t $(REPO):$(TAG) .

.PHONY: image-push
image-push:
docker tag $(REPO):$(TAG) $(REPO):latest
docker --config=$(DOCKER_CONF) push $(REPO):$(TAG)
docker --config=$(DOCKER_CONF) push $(REPO):latest
$(CONTAINER_ENGINE) tag $(REPO):$(TAG) $(REPO):latest
$(CONTAINER_ENGINE) --config=$(DOCKER_CONF) push $(REPO):$(TAG)
$(CONTAINER_ENGINE) --config=$(DOCKER_CONF) push $(REPO):latest

##############
# Formatting #
##############

.PHONY: lint
lint: $(GOLANGCI_LINT_BIN)
# megacheck fails to respect build flags, causing compilation failure during linting.
# instead, use the unused, gosimple, and staticcheck linters directly
$(GOLANGCI_LINT_BIN) run -D megacheck -E unused,gosimple,staticcheck

.PHONY: format
format: go-fmt

Expand All @@ -62,19 +53,14 @@ go-fmt:
# Testing #
###########

.PHONY: vet
vet:
go vet ./...

.PHONY: test
test: test-unit
test: vet test-unit

.PHONY: test-unit
test-unit:
go test -race -short $(PKGS) -count=1

############
# Binaries #
############

dependencies: $(GOLANGCI_LINT_BIN)

$(GOLANGCI_LINT_BIN):
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(FIRST_GOPATH)/bin v1.16.0

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Then:

### Using the container image

docker run --rm -d -p 9115:9115 \
podman run --rm -d -p 9115:9115 \
--name aws-resource-exporter \
--env AWS_ACCESS_KEY_ID=AAA \
--env AWS_SECRET_ACCESS_KEY=AAA \
Expand All @@ -50,7 +50,7 @@ Then:

make build

### Building docker image
### Building container image

make image image-push

Expand Down
21 changes: 17 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
module github.com/app-sre/aws-resource-exporter

go 1.12
go 1.18

require (
github.com/aws/aws-sdk-go v1.29.2
github.com/go-kit/kit v0.9.0
github.com/golang/protobuf v1.3.3 // indirect
github.com/prometheus/client_golang v1.4.1
github.com/prometheus/common v0.9.1
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4 // indirect
golang.org/x/text v0.3.2 // indirect
gopkg.in/alecthomas/kingpin.v2 v2.2.6
gopkg.in/yaml.v2 v2.2.5
)

require (
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/go-logfmt/logfmt v0.4.0 // indirect
github.com/golang/protobuf v1.3.3 // indirect
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/procfs v0.0.8 // indirect
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4 // indirect
)
5 changes: 0 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnf
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -100,10 +99,6 @@ golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4 h1:sfkvUWPNGwSV+8/fNqctR5lS2AqCSqYwXdrjCxp/dXo=
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
Expand Down
27 changes: 0 additions & 27 deletions vendor/github.com/alecthomas/template/LICENSE

This file was deleted.

25 changes: 0 additions & 25 deletions vendor/github.com/alecthomas/template/README.md

This file was deleted.

Loading

0 comments on commit 9214743

Please sign in to comment.