diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..86082d3 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,16 @@ +version: 2 + +updates: + - package-ecosystem: gomod + directory: / + labels: + - dependencies + schedule: + interval: daily + + - package-ecosystem: "github-actions" + directory: "/" + labels: + - dependencies + schedule: + interval: "daily" diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index c80d518..ebccdd5 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -1,5 +1,5 @@ name: Go - + on: push: branches: @@ -12,10 +12,11 @@ jobs: build: name: Build runs-on: ubuntu-latest + environment: docker strategy: fail-fast: true matrix: - go: ["1.19.x"] + go: ["1.20.x"] steps: - name: Set up Go ${{ matrix.go }} @@ -36,9 +37,36 @@ jobs: restore-keys: | ${{ runner.os }}-go-${{ matrix.go-version }}- - - name: Build - run: | - make - make docker - make push - if [[ -n "${{ github.ref }}" ]]; then make crossbuild release; fi \ No newline at end of file + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v4 + with: + # either 'goreleaser' (default) or 'goreleaser-pro' + distribution: goreleaser + version: latest + args: release --snapshot + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push Docker image to docker.io + uses: mr-smithers-excellent/docker-build-push@v6.2 + with: + registry: docker.io + image: sophos/nginx-vtx-exporter + multiPlatform: true + addLatest: false + directory: . + dockerfile: Dockerfile + username: ${{ secrets.DOCKER_USER }} + password: ${{ secrets.DOCKER_PASS }} + + - name: Build and push Docker image to ghcr.io + uses: mr-smithers-excellent/docker-build-push@v6.2 + with: + registry: ghcr.io + image: nginx-vtx-exporter + multiPlatform: true + addLatest: false + directory: . + dockerfile: Dockerfile + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..00061c6 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,69 @@ +name: Go + +on: + push: + tags: + - "v**" + +jobs: + build: + name: Build + runs-on: ubuntu-latest + environment: docker + strategy: + fail-fast: true + matrix: + go: ["1.20.x"] + + steps: + - name: Set up Go ${{ matrix.go }} + uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.go }} + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v3.3.0 + + - uses: actions/cache@v3 + with: + path: | + ~/go/pkg/mod + ~/.cache/go-build + key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go-${{ matrix.go-version }}- + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v4 + with: + # either 'goreleaser' (default) or 'goreleaser-pro' + distribution: goreleaser + version: latest + args: release --release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push Docker image to docker.io + uses: mr-smithers-excellent/docker-build-push@v6.2 + with: + registry: docker.io + image: sophos/nginx-vtx-exporter + multiPlatform: true + addLatest: true + directory: . + dockerfile: Dockerfile + username: ${{ secrets.DOCKER_USER }} + password: ${{ secrets.DOCKER_PASS }} + + - name: Build and push Docker image to ghcr.io + uses: mr-smithers-excellent/docker-build-push@v6.2 + with: + registry: nginx-vtx-exporter + image: ghcr.io + multiPlatform: true + addLatest: true + directory: . + dockerfile: Dockerfile + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.promu.yml b/.promu.yml deleted file mode 100644 index 4af6d40..0000000 --- a/.promu.yml +++ /dev/null @@ -1,21 +0,0 @@ -repository: - path: github.com/hnlq715/nginx-vts-exporter -build: - flags: -a -tags netgo - ldflags: | - -X {{repoPath}}/vendor/github.com/prometheus/common/version.Version={{.Version}} - -X {{repoPath}}/vendor/github.com/prometheus/common/version.Revision={{.Revision}} - -X {{repoPath}}/vendor/github.com/prometheus/common/version.Branch={{.Branch}} - -X {{repoPath}}/vendor/github.com/prometheus/common/version.BuildUser={{user}}@{{host}} - -X {{repoPath}}/vendor/github.com/prometheus/common/version.BuildDate={{date "20060102-15:04:05"}} -tarball: - files: - - LICENSE -crossbuild: - platforms: - - linux/amd64 - - linux/386 - - darwin/amd64 - - darwin/386 - - windows/amd64 - - windows/386 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 87fcaf1..0000000 --- a/.travis.yml +++ /dev/null @@ -1,18 +0,0 @@ -sudo: required - -services: - - docker - -language: go - -go: -- 1.13.6 - -env: -- GO111MODULE=on - -after_success: - - make - - make docker - - make push - - if [[ -n "$TRAVIS_TAG" ]]; then make crossbuild release; fi diff --git a/Dockerfile b/Dockerfile index 7e05305..ba3761e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM quay.io/prometheus/busybox:latest -MAINTAINER Sophos +LABEL Sophos -COPY nginx-vts-exporter /bin/nginx-vts-exporter +COPY ./dist/nginx-vtx-exporter_linux_amd64_v1/nginx-vtx-exporter /bin/nginx-vts-exporter COPY docker-entrypoint.sh /bin/docker-entrypoint.sh ENV NGINX_HOST "http://localhost" diff --git a/Makefile b/Makefile deleted file mode 100644 index 9c45fb6..0000000 --- a/Makefile +++ /dev/null @@ -1,78 +0,0 @@ -GO := GO111MODULE=on go -PROMU := $(GOPATH)/bin/promu -pkgs = $(shell $(GO) list ./...) - -PREFIX ?= $(shell pwd) -BIN_DIR ?= $(shell pwd) -DOCKER_IMAGE_NAME ?= nginx-vts-exporter -DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD)) -TAG := $(shell echo `if [ "$(TRAVIS_BRANCH)" = "master" ] || [ "$(TRAVIS_BRANCH)" = "" ] ; then echo "latest"; else echo $(TRAVIS_BRANCH) ; fi`) - -all: format build test - -info: - @echo ">> show project info" - @$(PROMU) info - -style: - @echo ">> checking code style" - @! gofmt -d $(shell find . -path ./vendor -prune -o -name '*.go' -print) | grep '^' - -test: - @echo ">> running tests" - @$(GO) test -short $(pkgs) - -format: - @echo ">> formatting code" - @$(GO) fmt $(pkgs) - -vet: - @echo ">> vetting code" - @$(GO) vet $(pkgs) - -build: promu - @echo ">> building binaries" - @$(PROMU) build --prefix $(PREFIX) - -crossbuild: promu - @echo ">> crossbuilding binaries" - @$(PROMU) crossbuild - -tarball: promu - @echo ">> building release tarball" - @$(PROMU) tarball --prefix $(PREFIX) $(BIN_DIR) - -docker: - @echo ">> building docker image" - @docker build -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" . - -rpm: - @echo ">> building rpm package" - @$(PREFIX)/rpm/makerpm.sh rpm - -srpm: - @echo ">> building rpm package" - @$(PREFIX)/rpm/makerpm.sh srpm - -push: - @echo ">> pushing docker image, $(DOCKER_USER),$(DOCKER_IMAGE_NAME),$(TAG)" - @echo $(DOCKER_PASS) | docker login -u "$(DOCKER_USER)" --password-stdin - @docker tag "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" "$(DOCKER_USER)/$(DOCKER_IMAGE_NAME):$(TAG)" - @docker push "$(DOCKER_USER)/$(DOCKER_IMAGE_NAME):$(TAG)" - -release: promu github-release - @echo ">> pushing binary to github with ghr" - @$(PROMU) crossbuild tarballs - @$(PROMU) release .tarballs - -promu: - @GOOS=$(shell uname -s | tr A-Z a-z) \ - GOARCH=$(subst x86_64,amd64,$(patsubst i%86,386,$(shell uname -m))) \ - $(GO) install github.com/prometheus/promu@latest - -github-release: - @GOOS=$(shell uname -s | tr A-Z a-z) \ - GOARCH=$(subst x86_64,amd64,$(patsubst i%86,386,$(shell uname -m))) \ - $(GO) install github.com/aktau/github-release@latest - -.PHONY: all style format build test vet tarball docker promu rpm srpm diff --git a/README.md b/README.md index 15863b6..52e96f4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # nginx-vts-exporter -[![Build Status](https://travis-ci.org/hnlq715/nginx-vts-exporter.svg?branch=master)](https://travis-ci.org/hnlq715/nginx-vts-exporter) +[![Go](https://github.com/hnlq715/nginx-vts-exporter/actions/workflows/go.yml/badge.svg)](https://github.com/hnlq715/nginx-vts-exporter/actions/workflows/go.yml) [![Docker Pulls](https://img.shields.io/docker/pulls/sophos/nginx-vts-exporter.svg)](https://hub.docker.com/r/sophos/nginx-vts-exporter) [![Github All Releases](https://img.shields.io/github/downloads/hnlq715/nginx-vts-exporter/total.svg)](https://github.com/hnlq715/nginx-vts-exporter) [![GitHub release](https://img.shields.io/github/release/hnlq715/nginx-vts-exporter.svg)](https://github.com/hnlq715/nginx-vts-exporter) diff --git a/VERSION b/VERSION deleted file mode 100644 index 2d993c4..0000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -0.10.7 diff --git a/goreleaser.yml b/goreleaser.yml new file mode 100644 index 0000000..106e796 --- /dev/null +++ b/goreleaser.yml @@ -0,0 +1,9 @@ +project_name: nginx-vtx-exporter + +builds: + - main: . + id: "nginx-vtx-exporter" + binary: nginx-vtx-exporter + goos: + - linux + goarch: [amd64, arm64]