mirror of
https://github.com/ebrianne/adguard-exporter.git
synced 2024-12-22 07:57:35 +01:00
Added docker file
Added docker-compose method and secrets Added master action and added arm64 build Added badge and updated workflows Removed gox in workflow, added upx Fixes conditional if in UPX workflow
This commit is contained in:
parent
7142f174e4
commit
b591f09028
110
.github/workflows/master.yml
vendored
Normal file
110
.github/workflows/master.yml
vendored
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
name: Build/Push (master)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- 'master'
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- 'master'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- uses: actions/setup-go@v1
|
||||||
|
with:
|
||||||
|
go-version: 1.14
|
||||||
|
|
||||||
|
- name: Install go dependencies
|
||||||
|
run: go get -t -v ./...
|
||||||
|
|
||||||
|
- name: Run go tests
|
||||||
|
run: go test -v -cover -race ./...
|
||||||
|
|
||||||
|
build-docker:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: test
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v1
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v1
|
||||||
|
|
||||||
|
- name: Login to DockerHub
|
||||||
|
uses: docker/login-action@v1
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
|
||||||
|
- name: Build and push docker image
|
||||||
|
id: docker_build
|
||||||
|
uses: docker/build-push-action@v2
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: ./Dockerfile
|
||||||
|
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
|
||||||
|
push: true
|
||||||
|
tags: ebrianne/adguard-exporter:latest
|
||||||
|
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: test
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- os: linux
|
||||||
|
arch: 386
|
||||||
|
- os: linux
|
||||||
|
arch: amd64
|
||||||
|
- os: linux
|
||||||
|
arch: arm
|
||||||
|
- os: linux
|
||||||
|
arch: arm64
|
||||||
|
- os: darwin
|
||||||
|
arch: 386
|
||||||
|
- os: darwin
|
||||||
|
arch: amd64
|
||||||
|
- os: freebsd
|
||||||
|
arch: 386
|
||||||
|
- os: freebsd
|
||||||
|
arch: amd64
|
||||||
|
- os: windows
|
||||||
|
arch: 386
|
||||||
|
extension: '.exe'
|
||||||
|
- os: windows
|
||||||
|
arch: amd64
|
||||||
|
extension: '.exe'
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
go-version: 1.14
|
||||||
|
|
||||||
|
- name: Download go dependencies
|
||||||
|
run: go get -t -v ./...
|
||||||
|
|
||||||
|
- name: Install the needed vendors
|
||||||
|
run: GO111MODULE=on go mod vendor
|
||||||
|
|
||||||
|
- name: Create release (${{ matrix.os }}-${{ matrix.arch }})
|
||||||
|
run: CGO_ENABLED=0 GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build -a -ldflags '-s -w' -o adguard_exporter-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.extension }} ./
|
||||||
|
|
||||||
|
- if: matrix.os != 'freebsd'
|
||||||
|
name: Run UPX (${{ matrix.os }}-${{ matrix.arch }})
|
||||||
|
uses: crazy-max/ghaction-upx@v1
|
||||||
|
with:
|
||||||
|
version: latest
|
||||||
|
file: ./adguard_exporter-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.extension }}
|
||||||
|
args: -fq --brute
|
66
.github/workflows/tag.yml
vendored
66
.github/workflows/tag.yml
vendored
@ -8,15 +8,49 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
go_version: [ '1.12', '1.13', '1.14' ]
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- uses: actions/setup-go@v2
|
- uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: ${{ matrix.go_version }}
|
go-version: 1.14
|
||||||
|
|
||||||
- run: go get -t -v ./...
|
- run: go get -t -v ./...
|
||||||
|
- run: go test -v -race ./...
|
||||||
|
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: test
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v1
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v1
|
||||||
|
|
||||||
|
- name: Login to DockerHub
|
||||||
|
uses: docker/login-action@v1
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
|
||||||
|
- name: Get the version
|
||||||
|
id: get_version
|
||||||
|
run: echo ::set-output name=TAG_NAME::${GITHUB_REF/refs\/tags\//}
|
||||||
|
|
||||||
|
- name: Build and push docker image
|
||||||
|
id: docker_build
|
||||||
|
uses: docker/build-push-action@v2
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: ./Dockerfile
|
||||||
|
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
|
||||||
|
push: true
|
||||||
|
tags: ebrianne/adguard-exporter:${{ steps.get_version.outputs.TAG_NAME }}
|
||||||
|
|
||||||
release:
|
release:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@ -47,6 +81,8 @@ jobs:
|
|||||||
arch: amd64
|
arch: amd64
|
||||||
- os: linux
|
- os: linux
|
||||||
arch: arm
|
arch: arm
|
||||||
|
- os: linux
|
||||||
|
arch: arm64
|
||||||
- os: darwin
|
- os: darwin
|
||||||
arch: 386
|
arch: 386
|
||||||
- os: darwin
|
- os: darwin
|
||||||
@ -62,7 +98,9 @@ jobs:
|
|||||||
arch: amd64
|
arch: amd64
|
||||||
extension: '.exe'
|
extension: '.exe'
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- uses: actions/setup-go@v2
|
- uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: 1.14
|
go-version: 1.14
|
||||||
@ -70,12 +108,20 @@ jobs:
|
|||||||
- name: Download go dependencies
|
- name: Download go dependencies
|
||||||
run: go get -t -v ./...
|
run: go get -t -v ./...
|
||||||
|
|
||||||
- name: Install mitchellh/gox to create platform specific releases
|
- name: Install the needed vendors
|
||||||
run: go install github.com/mitchellh/gox
|
run: GO111MODULE=on go mod vendor
|
||||||
|
|
||||||
- name: Create release
|
- name: Create release (${{ matrix.os }}-${{ matrix.arch }})
|
||||||
run: gox -ldflags "-s -w" -os="${{ matrix.os }}" -arch="${{ matrix.arch }}" -output="adguard_exporter-{{.OS}}-{{.Arch}}" -verbose ./...
|
run: CGO_ENABLED=0 GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build -a -ldflags '-s -w' -o adguard_exporter-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.extension }} ./
|
||||||
|
|
||||||
|
- if: matrix.os != 'freebsd'
|
||||||
|
name: Run UPX (${{ matrix.os }}-${{ matrix.arch }})
|
||||||
|
uses: crazy-max/ghaction-upx@v1
|
||||||
|
with:
|
||||||
|
version: latest
|
||||||
|
file: ./adguard_exporter-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.extension }}
|
||||||
|
args: -fq --brute
|
||||||
|
|
||||||
- name: Upload release assets
|
- name: Upload release assets
|
||||||
id: upload-release-asset
|
id: upload-release-asset
|
||||||
uses: actions/upload-release-asset@v1
|
uses: actions/upload-release-asset@v1
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@ vendor
|
|||||||
debug
|
debug
|
||||||
adguard_exporter
|
adguard_exporter
|
||||||
.git/
|
.git/
|
||||||
|
.env
|
19
Dockerfile
Normal file
19
Dockerfile
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
FROM --platform=$BUILDPLATFORM golang:1.14-alpine AS build
|
||||||
|
ARG TARGETOS
|
||||||
|
ARG TARGETARCH
|
||||||
|
|
||||||
|
WORKDIR /tmp/adguard_exporter
|
||||||
|
|
||||||
|
RUN apk update && apk --no-cache add git alpine-sdk upx
|
||||||
|
COPY . .
|
||||||
|
RUN GO111MODULE=on go mod vendor
|
||||||
|
RUN CGO_ENABLED=0 GOOS=$OS GOARCH=$ARCH go build -ldflags '-s -w' -o adguard_exporter ./
|
||||||
|
RUN upx -f --brute adguard_exporter
|
||||||
|
|
||||||
|
FROM scratch
|
||||||
|
LABEL name="adguard-exporter"
|
||||||
|
|
||||||
|
WORKDIR /root
|
||||||
|
COPY --from=build /tmp/adguard_exporter/adguard_exporter adguard_exporter
|
||||||
|
|
||||||
|
CMD ["./adguard_exporter"]
|
96
README.md
96
README.md
@ -1,5 +1,6 @@
|
|||||||
# AdguardHome Prometheus Exporter
|
# AdguardHome Prometheus Exporter
|
||||||
|
|
||||||
|
![Build/Push (master)](https://github.com/ebrianne/adguard-exporter/workflows/Build/Push%20(master)/badge.svg?branch=master)
|
||||||
[![GoDoc](https://godoc.org/github.com/ebrianne/adguard-exporter?status.png)](https://godoc.org/github.com/ebrianne/adguard-exporter)
|
[![GoDoc](https://godoc.org/github.com/ebrianne/adguard-exporter?status.png)](https://godoc.org/github.com/ebrianne/adguard-exporter)
|
||||||
[![GoReportCard](https://goreportcard.com/badge/github.com/ebrianne/adguard-exporter)](https://goreportcard.com/report/github.com/ebrianne/adguard-exporter)
|
[![GoReportCard](https://goreportcard.com/badge/github.com/ebrianne/adguard-exporter)](https://goreportcard.com/report/github.com/ebrianne/adguard-exporter)
|
||||||
|
|
||||||
@ -56,6 +57,101 @@ Then, build the binary (here, an example to run on Raspberry PI ARM architecture
|
|||||||
$ GOOS=linux GOARCH=arm GOARM=7 go build -o adguard_exporter .
|
$ GOOS=linux GOARCH=arm GOARM=7 go build -o adguard_exporter .
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Using Docker
|
||||||
|
|
||||||
|
The exporter has been made available as a docker image. You can simply run it by the following command and pass the configuration with environment variables:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run \
|
||||||
|
-e 'adguard_protocol=http' \
|
||||||
|
-e 'adguard_hostname=192.168.10.252' \
|
||||||
|
-e 'adguard_username=admin' \
|
||||||
|
-e 'adguard_password=mypassword' \
|
||||||
|
-e 'interval=10s' \
|
||||||
|
-e 'log_limit=10000' \
|
||||||
|
-e 'server_port=9617' \
|
||||||
|
-p 9617:9617 \
|
||||||
|
ebrianne/adguard_exporter:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
If you prefer you can use an .env file where the environment variables are defined and using the command:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run --env-file=.env -p 9617:9617 \
|
||||||
|
ebrianne/adguard_exporter:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also use docker-compose passing the environment file or using secrets locally
|
||||||
|
### Local with environment file
|
||||||
|
|
||||||
|
```yml
|
||||||
|
version: "3.7"
|
||||||
|
|
||||||
|
services:
|
||||||
|
adguard_exporter:
|
||||||
|
image: ebrianne/adguard_exporter:latest
|
||||||
|
restart: always
|
||||||
|
ports:
|
||||||
|
- "9617:9617"
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
|
```
|
||||||
|
### Local with secret file (compose version 3 minimum)
|
||||||
|
|
||||||
|
```yml
|
||||||
|
version: "3.7"
|
||||||
|
|
||||||
|
secrets:
|
||||||
|
my-adguard-pass:
|
||||||
|
file: ./my-adguard-pass.txt
|
||||||
|
|
||||||
|
services:
|
||||||
|
adguard_exporter:
|
||||||
|
image: ebrianne/adguard_exporter:latest
|
||||||
|
restart: always
|
||||||
|
secrets:
|
||||||
|
- my-adguard-pass
|
||||||
|
ports:
|
||||||
|
- "9617:9617"
|
||||||
|
environment:
|
||||||
|
- adguard_protocol=http
|
||||||
|
- adguard_hostname=192.168.10.252
|
||||||
|
- adguard_username=admin
|
||||||
|
- adguard_password=/run/secrets/my-adguard-pass
|
||||||
|
- interval=10s
|
||||||
|
- log_limit=10000
|
||||||
|
```
|
||||||
|
### Swarm mode (docker swarm init)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
echo "mypassword" | docker secret create my-adguard-pass -
|
||||||
|
```
|
||||||
|
Here is an example of docker-compose file.
|
||||||
|
|
||||||
|
```yml
|
||||||
|
version: "3.7"
|
||||||
|
|
||||||
|
secrets:
|
||||||
|
my-adguard-pass:
|
||||||
|
external: true
|
||||||
|
|
||||||
|
services:
|
||||||
|
adguard_exporter:
|
||||||
|
image: ebrianne/adguard_exporter:latest
|
||||||
|
restart: always
|
||||||
|
secrets:
|
||||||
|
- my-adguard-pass
|
||||||
|
ports:
|
||||||
|
- "9617:9617"
|
||||||
|
environment:
|
||||||
|
- adguard_protocol=http
|
||||||
|
- adguard_hostname=192.168.10.252
|
||||||
|
- adguard_username=admin
|
||||||
|
- adguard_password=/run/secrets/my-adguard-pass
|
||||||
|
- interval=10s
|
||||||
|
- log_limit=10000
|
||||||
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
In order to run the exporter, type the following command (arguments are optional):
|
In order to run the exporter, type the following command (arguments are optional):
|
||||||
|
Loading…
Reference in New Issue
Block a user