Skip to content

Commit

Permalink
feat: initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
maxime1907 committed Sep 20, 2024
1 parent 3074411 commit 2fdc9a9
Show file tree
Hide file tree
Showing 17 changed files with 747 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work
go.work.sum

# env file
.env

# Custom part
ovh-exporter
vendor
16 changes: 16 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: 2
updates:
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "weekly"
labels:
- "dependencies"
- "bot"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
labels:
- "dependencies"
- "bot"
131 changes: 131 additions & 0 deletions .github/workflows/build_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
name: Build and release

on:
push:
branches:
- main
tags:
- 'v*.*.*'
pull_request:
branches:
- main

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
BINARY_NAME: ovh-exporter

jobs:
golang:
name: Golang
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-24.04
include:
- os: ubuntu-24.04
platform: linux
arch: amd64
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.23.1'

- name: Install packages
run: |
sudo apt-get update
sudo apt install -yq --no-install-recommends make
- name: Build
env:
GOOS: ${{ matrix.platform }}
GOARCH: ${{ matrix.arch }}
run: make build

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ env.BINARY_NAME }}-${{ matrix.platform }}-${{ matrix.arch }}
path: ${{ env.BINARY_NAME }}
if-no-files-found: error

container:
name: Containerfile
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-24.04
include:
- os: ubuntu-24.04
platform: linux
arch: amd64
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata
uses: docker/metadata-action@v5
id: metadata
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build image
uses: docker/build-push-action@v6
with:
context: .
file: Containerfile
push: ${{ github.event_name != 'pull_request' }}
platforms: ${{ matrix.platform }}/${{ matrix.arch }}
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}

release:
runs-on: ubuntu-24.04
needs:
- golang
- container
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Download artifacts
uses: actions/download-artifact@v4

- name: Package
run: |
for folder in ./*; do
if [ -d "$folder" ]; then
echo "Processing folder: $folder"
cd $folder
tar -czf ../$folder.tar.gz -T <(\ls -1)
cd ..
sha256sum $folder.tar.gz > $folder.tar.gz.sha256
fi
done
- name: Release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: '*.tar.gz*'
tag: ${{ github.ref }}
file_glob: true
22 changes: 22 additions & 0 deletions .github/workflows/compliance.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Compliance

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
commit:
name: Commit
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Conventional commit check
uses: cocogitto/[email protected]
33 changes: 33 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Lint

on:
pull_request:
branches:
- main

jobs:
golang:
name: Golang
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.23.1'

- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.61

container:
name: Containerfile
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: hadolint/[email protected]
with:
dockerfile: Containerfile
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ go.work.sum

# env file
.env

# Custom part
ovh-exporter
vendor
25 changes: 25 additions & 0 deletions Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM golang:1.23-alpine AS build

ENV CGO_ENABLED=0
ENV GOOS=linux
ENV GOARCH=amd64

ARG JQ_VERSION=1.7

# hadolint ignore=DL3018
RUN apk update && apk add --no-cache bash git make binutils wget \
&& wget --progress=dot:giga "https://github.com/jqlang/jq/releases/download/jq-${JQ_VERSION}/jq-${GOOS}-${GOARCH}" -O /usr/bin/jq \
&& chmod +x /usr/bin/jq

WORKDIR $GOPATH/src/github.com/wiremind/ovh-exporter

COPY . .

RUN make ovh-exporter && mv ovh-exporter /usr/bin/


FROM busybox:stable AS runtime

COPY --from=build /usr/bin/ovh-exporter /usr/bin/ovh-exporter

ENTRYPOINT ["/usr/bin/ovh-exporter"]
49 changes: 49 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
GO?=go

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif

BINARY_NAME=ovh-exporter
# TODO less bruteforce ?
BINARY_FILES=$(shell find ${PWD} -type f -name "*.go")
GOFMT_FILES?=$(shell find . -not -path "./vendor/*" -type f -name '*.go')

VERSION ?= $(shell git describe --match 'v[0-9]*' --dirty='.m' --always)
REVISION=$(shell git rev-parse HEAD)$(shell if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi)
PKG=github.com/wiremind/ovh-exporter

# Control if static or dynamically linked (static by default)
export CGO_ENABLED:=0

GO_GCFLAGS?=
GO_LDFLAGS=-ldflags '-X $(PKG)/version.Version=$(VERSION) -X $(PKG)/version.Revision=$(REVISION) -X $(PKG)/version.Package=$(PKG)'

.PHONY: build
build: ${BINARY_NAME}

${BINARY_NAME}: ${BINARY_FILES}
${GO} build ${GO_GCFLAGS} ${GO_LDFLAGS} -o $@ cmd/${BINARY_NAME}/*.go
strip -x $@

## Lints all the go code in the application.
.PHONY: lint
lint: dependencies
gofmt -w $(GOFMT_FILES)
$(GOBIN)/goimports -w $(GOFMT_FILES)
$(GOBIN)/gofumpt -l -w $(GOFMT_FILES)
$(GOBIN)/gci write $(GOFMT_FILES) --skip-generated
$(GOBIN)/golangci-lint run

## Loads all the dependencies to vendor directory
.PHONY: dependencies
dependencies:
go install golang.org/x/tools/cmd/[email protected]
go install mvdan.cc/[email protected]
go install github.com/daixiang0/[email protected]
go install github.com/golangci/golangci-lint/cmd/[email protected]
go mod vendor
go mod tidy
3 changes: 3 additions & 0 deletions cog.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ignore_merge_commits = true
from_latest_tag = true
tag_prefix = "v"
28 changes: 28 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module github.com/wiremind/ovh-exporter

go 1.23.1

require (
github.com/ovh/go-ovh v1.6.0
github.com/prometheus/client_golang v1.20.4
github.com/rs/zerolog v1.33.0
github.com/urfave/cli v1.22.15
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sys v0.22.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
)
Loading

0 comments on commit 2fdc9a9

Please sign in to comment.