diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..eb4bfe6e --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "gomod" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "daily" diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..0d2ae725 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,68 @@ +name: goreleaser + +on: + push: + # not not consider simplec commit + branches: + - '!*' + # consider only release and pre-release tags + tags: + - 'v[0-9]+.[0-9]+.[0-9]+' + - 'v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+' + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: set up go + uses: actions/setup-go@v2 + with: + go-version: 1.18 + + - name: cache go modules + uses: actions/cache@v1 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: tests modules + run: | + go mod vendor + if [ ! -z "$(git status --porcelain)" ]; then + echo "::error::vendor directory if not synched with go.mod, please run go mod vendor" + exit 1 + fi + + go mod tidy + if [ ! -z "$(git status --porcelain)" ]; then + echo "::error::modules are not tidy, please run go mod tidy" + exit 1 + fi + + - name: tests + run: | + go test -v ./... + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: run goreleaser + uses: goreleaser/goreleaser-action@v2 + if: success() && startsWith(github.ref, 'refs/tags/') + with: + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + USER: github-actions + diff --git a/.gitignore b/.gitignore index 121f4107..b51ba41d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,3 @@ -/.build -/.release -/.tarballs +/dist /cf_exporter *.tar.gz -*.test -*-stamp diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 00000000..db6c619d --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,97 @@ +project_name: cf_exporter + +builds: + - id: binary + dir: . + main: ./main.go + binary: cf_exporter + env: + - CGO_ENABLED=0 + ldflags: + - -s + - -w + - -X github.com/prometheus/common/version.Version={{.Version}} + - -X github.com/prometheus/common/version.Revision={{.FullCommit}} + - -X github.com/prometheus/common/version.Branch={{.Branch}} + - -X github.com/prometheus/common/version.BuildUser={{.Env.USER}} + - -X github.com/prometheus/common/version.BuildDate={{.Date}} + - -X code.cloudfoundry.org/cli/version/binaryVersion={{.Version}} + goos: + - linux + - darwin + - windows + goarch: + - amd64 + - 386 + - arm + - arm64 + - ppc64 + - ppc64le + goarm: [5,6,7] + ignore: + - goos: darwin + goarch: arm + - goos: darwin + goarch: arm64 + - goos: darwin + goarch: ppc64 + - goos: darwin + goarch: ppc64le + - goos: darwin + goarch: 386 + - goos: windows + goarch: arm + - goos: windows + goarch: arm64 + - goos: windows + goarch: ppc64 + - goos: windows + goarch: ppc64le + +archives: + - id: archives + builds: [binary] + format: "tar.gz" + name_template: '{{ .ProjectName }}_{{ .Version }}.{{ .Os }}-{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}' + wrap_in_directory: true + files: + - LICENSE + - NOTICE + - README* + - CHANGELOG* + - docs/* + format_overrides: + - goos: windows + format: zip + +changelog: + sort: asc + use: github + filters: + exclude: + - 'docs' + - '\.md' + +checksum: + name_template: checksums.txt + algorithm: sha256 + +dockers: + - goos: linux + goarch: amd64 + dockerfile: ./packages/docker/Dockerfile + image_templates: + - "boshprometheus/cf-exporter:latest" + - "boshprometheus/cf-exporter:{{ .Tag }}" + - "boshprometheus/cf-exporter:v{{ .Major }}" + - "boshprometheus/cf-exporter:v{{ .Major }}.{{ .Minor }}" + build_flag_templates: + - "--label=org.opencontainers.image.created={{ .Date }}" + - "--label=org.opencontainers.image.title={{ .ProjectName }}" + - "--label=org.opencontainers.image.revision={{ .FullCommit }}" + - "--label=org.opencontainers.image.version={{ .Version }}" + - "--label=org.opencontainers.image.source={{ .GitURL }}" + +release: + prerelease: auto + name_template: '{{.Tag}}' diff --git a/.promu.yml b/.promu.yml deleted file mode 100644 index 7a256f0a..00000000 --- a/.promu.yml +++ /dev/null @@ -1,29 +0,0 @@ -verbose: false -go: - cgo: false - version: 1.15 -repository: - path: github.com/bosh-prometheus/cf_exporter -build: - flags: -mod=vendor -a -tags 'netgo static_build' - ldflags: | - -X github.com/prometheus/common/version.Version={{.Version}} - -X github.com/prometheus/common/version.Revision={{.Revision}} - -X github.com/prometheus/common/version.Branch={{.Branch}} - -X github.com/prometheus/common/version.BuildUser={{user}}@{{host}} - -X github.com/prometheus/common/version.BuildDate={{date "20060102-15:04:05"}} -tarball: - files: - - LICENSE - - NOTICE -crossbuild: - platforms: - - darwin/amd64 - - linux/386 - - linux/amd64 - - linux/arm - - linux/arm64 - - linux/ppc64 - - linux/ppc64le - - windows/386 - - windows/amd64 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 1c29fc24..00000000 --- a/.travis.yml +++ /dev/null @@ -1,42 +0,0 @@ -sudo: required - -language: go - -go: - - 1.15.x - -go_import_path: github.com/bosh-prometheus/cf_exporter - -services: - - docker - - -jobs: - include: - - stage: Run tests - script: make test - - - stage: Build docker image - env: - - DOCKER_IMAGE_NAME=boshprometheus/cf-exporter - - secure: mKWGE1/len9O5n5qtR3tJ2w7sWGVpV+6W46qQKt1u1cI5BiNKe/wfIhBz52OWYFVK1ZDs3qqU5Nb187vJscIB1VETZ4gNKRYA21+iplo/cctcmN0C2oKjp7iVkVyhJdd0ywM9c/yafN2DHmWmECQ+W4OXDbkXdYE6z4i65u1dIb7JlYvlmmQWZBgdnCqjONp6gDFD3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dHP52yXKVQfkKnesIvbG1WBHrlDzgq62ybjjZ8KIoaxe5orihubcp82aIU//N0RFaBemwCOMT6nbYHa+yv1rkEJZE69MIE7b9HJZs= - script: - - make crossbuild - - ln -s .build/linux-amd64/cf_exporter cf_exporter - - | - if [ -n "$TRAVIS_TAG" ]; then - make docker DOCKER_IMAGE_NAME=$DOCKER_IMAGE_NAME DOCKER_IMAGE_TAG=$TRAVIS_TAG - else - make docker DOCKER_IMAGE_NAME=$DOCKER_IMAGE_NAME DOCKER_IMAGE_TAG=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then echo $TRAVIS_BRANCH; else echo $TRAVIS_PULL_REQUEST_BRANCH; fi) - fi - - | - if [[ "$TRAVIS_TAG" =~ ^v[0-9]+(\.[0-9]+){2}$ ]]; then - docker tag "$DOCKER_IMAGE_NAME:$TRAVIS_TAG" "$DOCKER_IMAGE_NAME:latest" - fi - - docker images - - | - if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then - docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD - docker push $DOCKER_IMAGE_NAME - fi diff --git a/Makefile b/Makefile deleted file mode 100644 index e4d4b4d0..00000000 --- a/Makefile +++ /dev/null @@ -1,64 +0,0 @@ -GO := go -GINKGO := ginkgo -PROMU := $(GOPATH)/bin/promu -pkgs = $(shell $(GO) list ./... | grep -v /vendor/) - -PREFIX ?= $(shell pwd) -BIN_DIR ?= $(shell pwd) -TARBALLS_DIR ?= $(shell pwd)/.tarballs -DOCKER_IMAGE_NAME ?= cf-exporter -DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD)) - -all: format build test - -deps: - @$(GO) get github.com/onsi/ginkgo/ginkgo - @$(GO) get github.com/onsi/gomega - -format: - @echo ">> formatting code" - @$(GO) fmt $(pkgs) - -style: - @echo ">> checking code style" - @! gofmt -d $(shell find . -path ./vendor -prune -o -name '*.go' -print) | grep '^' - -vet: - @echo ">> vetting code" - @$(GO) vet $(pkgs) - -test: deps - @echo ">> running tests" - @$(GINKGO) version - @$(GINKGO) -r -race . - -promu: - @GOOS=$(shell uname -s | tr A-Z a-z) \ - GOARCH=$(subst x86_64,amd64,$(patsubst i%86,386,$(shell uname -m))) \ - $(GO) get -u github.com/prometheus/promu - -build: promu - @echo ">> building binaries" - @$(PROMU) build --prefix $(PREFIX) - -crossbuild: promu - @echo ">> building cross-platform binaries" - @$(PROMU) crossbuild - -tarball: build - @echo ">> building release tarball" - @$(PROMU) tarball --prefix $(PREFIX) $(BIN_DIR) - -tarballs: crossbuild - @echo ">> building release tarballs" - @$(PROMU) crossbuild tarballs - -release: promu - @echo ">> uploading tarballs to the Github release" - @$(PROMU) release ${TARBALLS_DIR} - -docker: - @echo ">> building docker image" - @docker build -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" . - -.PHONY: all deps format style vet test promu build crossbuild tarball tarballs release docker diff --git a/Procfile b/Procfile deleted file mode 100644 index 4aaaa5a1..00000000 --- a/Procfile +++ /dev/null @@ -1 +0,0 @@ -web: cf_exporter --web.listen-address=":$PORT" diff --git a/VERSION b/VERSION deleted file mode 100644 index 57121573..00000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -0.10.1 diff --git a/packages/docker/Dockerfile b/packages/docker/Dockerfile index 47dc20ca..8cf637b3 100644 --- a/packages/docker/Dockerfile +++ b/packages/docker/Dockerfile @@ -1,7 +1,7 @@ FROM quay.io/prometheus/busybox:latest MAINTAINER Ferran Rodenas -COPY cf_exporter /bin/cf_exporter +ADD cf_exporter /bin/cf_exporter ENTRYPOINT ["/bin/cf_exporter"] -EXPOSE 9193 \ No newline at end of file +EXPOSE 9193