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:
Eldwan Brianne 2020-12-22 11:45:08 +01:00
parent 7142f174e4
commit b591f09028
5 changed files with 282 additions and 10 deletions

110
.github/workflows/master.yml vendored Normal file
View 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

View File

@ -8,15 +8,49 @@ on:
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
go_version: [ '1.12', '1.13', '1.14' ]
steps:
- uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go_version }}
go-version: 1.14
- 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:
runs-on: ubuntu-latest
@ -47,6 +81,8 @@ jobs:
arch: amd64
- os: linux
arch: arm
- os: linux
arch: arm64
- os: darwin
arch: 386
- os: darwin
@ -62,7 +98,9 @@ jobs:
arch: amd64
extension: '.exe'
steps:
- uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: 1.14
@ -70,11 +108,19 @@ jobs:
- name: Download go dependencies
run: go get -t -v ./...
- name: Install mitchellh/gox to create platform specific releases
run: go install github.com/mitchellh/gox
- name: Install the needed vendors
run: GO111MODULE=on go mod vendor
- name: Create release
run: gox -ldflags "-s -w" -os="${{ matrix.os }}" -arch="${{ matrix.arch }}" -output="adguard_exporter-{{.OS}}-{{.Arch}}" -verbose ./...
- 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
- name: Upload release assets
id: upload-release-asset

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ vendor
debug
adguard_exporter
.git/
.env

19
Dockerfile Normal file
View 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"]

View File

@ -1,5 +1,6 @@
# 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)
[![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 .
```
## 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
In order to run the exporter, type the following command (arguments are optional):