Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6d2a78a266 | ||
|
|
8a765b2ab0 | ||
|
|
806a85a871 | ||
|
|
c898454997 | ||
|
|
753eaeab10 | ||
|
|
8e215b2574 | ||
|
|
e4ec84ea31 |
+36
-83
@@ -1,100 +1,53 @@
|
|||||||
---
|
|
||||||
kind: pipeline
|
kind: pipeline
|
||||||
name: test
|
type: kubernetes
|
||||||
|
name: default
|
||||||
|
|
||||||
steps:
|
node_selector:
|
||||||
- name: test
|
zone: dev
|
||||||
image: golang:1.21
|
|
||||||
environment:
|
|
||||||
VERSION: ${DRONE_TAG:-${DRONE_COMMIT}}
|
|
||||||
commands:
|
|
||||||
- make test
|
|
||||||
|
|
||||||
- name: check
|
|
||||||
image: iamthefij/drone-pre-commit:personal
|
|
||||||
|
|
||||||
---
|
|
||||||
kind: pipeline
|
|
||||||
name: publish
|
|
||||||
|
|
||||||
depends_on:
|
|
||||||
- test
|
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
event:
|
event:
|
||||||
- push
|
- push
|
||||||
- tag
|
- tag
|
||||||
refs:
|
|
||||||
- refs/heads/master
|
workspace:
|
||||||
- refs/tags/v*
|
path: /drone/src
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: build all binaries
|
- name: pull image to dockerhub
|
||||||
image: golang:1.21
|
image: docker.io/owncloudci/drone-docker-buildx:4
|
||||||
environment:
|
privileged: true
|
||||||
VERSION: ${DRONE_TAG:-${DRONE_COMMIT}}
|
|
||||||
commands:
|
|
||||||
- make all
|
|
||||||
|
|
||||||
- name: compress binaries for release
|
|
||||||
image: ubuntu
|
|
||||||
commands:
|
|
||||||
- find ./dist -type f -executable -execdir tar -czvf {}.tar.gz {} \;
|
|
||||||
when:
|
|
||||||
event: tag
|
|
||||||
|
|
||||||
- name: upload gitea release
|
|
||||||
image: plugins/gitea-release
|
|
||||||
settings:
|
settings:
|
||||||
title: ${DRONE_TAG}
|
cache-from: [ "safebox/minitor" ]
|
||||||
files: dist/*.tar.gz
|
repo: safebox/minitor
|
||||||
checksum:
|
tags: latest
|
||||||
- md5
|
username:
|
||||||
- sha1
|
from_secret: dockerhub-username
|
||||||
- sha256
|
password:
|
||||||
- sha512
|
from_secret: dockerhub-password
|
||||||
base_url:
|
|
||||||
from_secret: gitea_base_url
|
|
||||||
api_key:
|
|
||||||
from_secret: gitea_token
|
|
||||||
when:
|
|
||||||
event: tag
|
|
||||||
|
|
||||||
- name: Build and publish docker images
|
|
||||||
image: thegeeklab/drone-docker-buildx
|
|
||||||
settings:
|
|
||||||
repo: iamthefij/minitor-go
|
|
||||||
auto_tag: true
|
|
||||||
platforms:
|
platforms:
|
||||||
- linux/amd64
|
- linux/amd64
|
||||||
- linux/arm64
|
- linux/arm64
|
||||||
- linux/arm
|
when:
|
||||||
username:
|
event:
|
||||||
from_secret: docker_username
|
- tag
|
||||||
password:
|
|
||||||
from_secret: docker_password
|
|
||||||
|
|
||||||
---
|
- name: build multiarch from dev
|
||||||
kind: pipeline
|
image: docker.io/owncloudci/drone-docker-buildx:4
|
||||||
name: notify
|
privileged: true
|
||||||
|
|
||||||
depends_on:
|
|
||||||
- test
|
|
||||||
- publish
|
|
||||||
|
|
||||||
trigger:
|
|
||||||
status:
|
|
||||||
- failure
|
|
||||||
|
|
||||||
steps:
|
|
||||||
|
|
||||||
- name: notify
|
|
||||||
image: drillster/drone-email
|
|
||||||
settings:
|
settings:
|
||||||
host:
|
cache-from: [ "registry.dev.format.hu/minitor" ]
|
||||||
from_secret: SMTP_HOST # pragma: whitelist secret
|
registry: registry.dev.format.hu
|
||||||
|
repo: registry.dev.format.hu/minitor
|
||||||
|
tags: latest
|
||||||
|
dockerfile: Dockerfile
|
||||||
username:
|
username:
|
||||||
from_secret: SMTP_USER # pragma: whitelist secret
|
from_secret: dev-hu-registry-username
|
||||||
password:
|
password:
|
||||||
from_secret: SMTP_PASS # pragma: whitelist secret
|
from_secret: dev-hu-registry-password
|
||||||
from: drone@iamthefij.com
|
platforms:
|
||||||
|
- linux/amd64
|
||||||
|
- linux/arm64
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
- push
|
||||||
@@ -1,111 +0,0 @@
|
|||||||
name: ci
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
tags:
|
|
||||||
- "v*"
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
tests:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
|
|
||||||
- name: Set up Go
|
|
||||||
uses: actions/setup-go@v6
|
|
||||||
with:
|
|
||||||
go-version-file: go.mod
|
|
||||||
|
|
||||||
- name: Run tests
|
|
||||||
run: make test
|
|
||||||
|
|
||||||
lint:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
|
|
||||||
- name: Set up Go
|
|
||||||
uses: actions/setup-go@v6
|
|
||||||
with:
|
|
||||||
go-version-file: go.mod
|
|
||||||
|
|
||||||
- name: Set up Python
|
|
||||||
uses: actions/setup-python@v6
|
|
||||||
|
|
||||||
- name: Run pre-commit
|
|
||||||
uses: https://git.iamthefij.com/iamthefij/pre-commit-action@v3.0.2
|
|
||||||
|
|
||||||
release:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: test
|
|
||||||
if: "${{ github.event_name != 'pull_request' }}"
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
|
|
||||||
- name: Set up Go
|
|
||||||
uses: actions/setup-go@v6
|
|
||||||
with:
|
|
||||||
go-version-file: go.mod
|
|
||||||
|
|
||||||
- name: Build binaries
|
|
||||||
env:
|
|
||||||
VERSION: "${{ github.REF_NAME }}"
|
|
||||||
run: make all
|
|
||||||
|
|
||||||
# Package binaries and create release if this is a tagged build
|
|
||||||
- name: Compress binaries
|
|
||||||
if: "${{ github.ref_type == 'tag' }}"
|
|
||||||
run: find ./dist -type f -executable -execdir tar -czvf {}.tar.gz {} \;
|
|
||||||
|
|
||||||
- name: Upload release
|
|
||||||
uses: https://gitea.com/actions/gitea-release-action@v1
|
|
||||||
if: "${{ github.ref_type == 'tag' }}"
|
|
||||||
with:
|
|
||||||
files: |-
|
|
||||||
dist/*.tar.gz
|
|
||||||
md5sum: true
|
|
||||||
sha256sum: true
|
|
||||||
|
|
||||||
- name: Docker meta
|
|
||||||
id: meta
|
|
||||||
uses: docker/metadata-action@v5
|
|
||||||
with:
|
|
||||||
# list of Docker images to use as base name for tags
|
|
||||||
images: |
|
|
||||||
${{ github.REPOSITORY }}
|
|
||||||
# generate Docker tags based on the following events/attributes
|
|
||||||
tags: |
|
|
||||||
type=ref,event=branch
|
|
||||||
type=ref,event=pr
|
|
||||||
type=semver,pattern={{version}}
|
|
||||||
type=semver,pattern={{major}}.{{minor}}
|
|
||||||
type=semver,pattern={{major}}
|
|
||||||
|
|
||||||
- name: Login to Docker Hub
|
|
||||||
uses: docker/login-action@v3
|
|
||||||
if: "${{ github.event_name != 'pull_request' }}"
|
|
||||||
with:
|
|
||||||
username: ${{ secrets.DOCKER_USERNAME }}
|
|
||||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
|
||||||
|
|
||||||
- name: Set up QEMU
|
|
||||||
uses: docker/setup-qemu-action@v3
|
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
|
|
||||||
- name: Build and push
|
|
||||||
uses: docker/build-push-action@v6
|
|
||||||
with:
|
|
||||||
# Use path context so we can access pre-compiled binaries
|
|
||||||
context: .
|
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
|
||||||
platforms: |
|
|
||||||
linux/amd64
|
|
||||||
linux/arm64
|
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
|
||||||
+111
-6
@@ -1,8 +1,117 @@
|
|||||||
FROM alpine:3.23
|
FROM golang:1.25 AS gomail-builder
|
||||||
|
ARG TARGETARCH=amd64
|
||||||
|
ARG TARGETOS=linux
|
||||||
|
WORKDIR /gomail
|
||||||
|
RUN { \
|
||||||
|
echo 'package main'; \
|
||||||
|
echo ''; \
|
||||||
|
echo 'import ('; \
|
||||||
|
echo ' "fmt"'; \
|
||||||
|
echo ' "io"'; \
|
||||||
|
echo ' "net/mail"'; \
|
||||||
|
echo ' "net/smtp"'; \
|
||||||
|
echo ' "os"'; \
|
||||||
|
echo ' "strings"'; \
|
||||||
|
echo ')'; \
|
||||||
|
echo ''; \
|
||||||
|
echo 'func main() {'; \
|
||||||
|
echo ' readHeaders := strings.Contains(strings.Join(os.Args[1:], " "), "-t")'; \
|
||||||
|
echo ' recipients := []string{}'; \
|
||||||
|
echo ' for _, arg := range os.Args[1:] {'; \
|
||||||
|
echo ' if !strings.HasPrefix(arg, "-") {'; \
|
||||||
|
echo ' recipients = append(recipients, arg)'; \
|
||||||
|
echo ' }'; \
|
||||||
|
echo ' }'; \
|
||||||
|
echo ''; \
|
||||||
|
echo ' body, err := io.ReadAll(os.Stdin)'; \
|
||||||
|
echo ' if err != nil {'; \
|
||||||
|
echo ' fmt.Fprintln(os.Stderr, err)'; \
|
||||||
|
echo ' os.Exit(1)'; \
|
||||||
|
echo ' }'; \
|
||||||
|
echo ''; \
|
||||||
|
echo ' if readHeaders {'; \
|
||||||
|
echo ' msg, parseErr := mail.ReadMessage(strings.NewReader(string(body)))'; \
|
||||||
|
echo ' if parseErr != nil {'; \
|
||||||
|
echo ' fmt.Fprintln(os.Stderr, parseErr)'; \
|
||||||
|
echo ' os.Exit(1)'; \
|
||||||
|
echo ' }'; \
|
||||||
|
echo ' for _, hdr := range []string{"To", "Cc", "Bcc"} {'; \
|
||||||
|
echo ' if val := msg.Header.Get(hdr); val != "" {'; \
|
||||||
|
echo ' addrs, addrErr := mail.ParseAddressList(val)'; \
|
||||||
|
echo ' if addrErr != nil {'; \
|
||||||
|
echo ' fmt.Fprintln(os.Stderr, addrErr)'; \
|
||||||
|
echo ' os.Exit(1)'; \
|
||||||
|
echo ' }'; \
|
||||||
|
echo ' for _, addr := range addrs {'; \
|
||||||
|
echo ' recipients = append(recipients, addr.Address)'; \
|
||||||
|
echo ' }'; \
|
||||||
|
echo ' }'; \
|
||||||
|
echo ' }'; \
|
||||||
|
echo ' }'; \
|
||||||
|
echo ''; \
|
||||||
|
echo ' if len(recipients) == 0 {'; \
|
||||||
|
echo ' fmt.Fprintln(os.Stderr, "usage: sendmail [-t] recipient...")'; \
|
||||||
|
echo ' os.Exit(1)'; \
|
||||||
|
echo ' }'; \
|
||||||
|
echo ''; \
|
||||||
|
echo ' relay := os.Getenv("SMTP_RELAY")'; \
|
||||||
|
echo ' if relay == "" {'; \
|
||||||
|
echo ' relay = "172.17.0.2"'; \
|
||||||
|
echo ' }'; \
|
||||||
|
echo ''; \
|
||||||
|
echo ' port := os.Getenv("SMTP_PORT")'; \
|
||||||
|
echo ' if port == "" {'; \
|
||||||
|
echo ' port = "25"'; \
|
||||||
|
echo ' }'; \
|
||||||
|
echo ''; \
|
||||||
|
echo ' sender := os.Getenv("EMAIL_FROM")'; \
|
||||||
|
echo ' if sender == "" {'; \
|
||||||
|
echo ' fmt.Fprintln(os.Stderr, "[sendmail] EMAIL_FROM is not set, skipping")'; \
|
||||||
|
echo ' os.Exit(0)'; \
|
||||||
|
echo ' }'; \
|
||||||
|
echo ''; \
|
||||||
|
echo ' debug := os.Getenv("DEBUG") != ""'; \
|
||||||
|
echo ' if debug {'; \
|
||||||
|
echo ' fmt.Fprintln(os.Stderr, fmt.Sprintf("[sendmail] relay=%s port=%s sender=%s recipients=%v", relay, port, sender, recipients))'; \
|
||||||
|
echo ' fmt.Fprintln(os.Stderr, "[sendmail] body:")'; \
|
||||||
|
echo ' fmt.Fprintln(os.Stderr, string(body))'; \
|
||||||
|
echo ' }'; \
|
||||||
|
echo ''; \
|
||||||
|
echo ' if err = smtp.SendMail(relay+":"+port, nil, sender, recipients, body); err != nil {'; \
|
||||||
|
echo ' fmt.Fprintln(os.Stderr, err)'; \
|
||||||
|
echo ' os.Exit(1)'; \
|
||||||
|
echo ' }'; \
|
||||||
|
echo ' if debug {'; \
|
||||||
|
echo ' fmt.Fprintln(os.Stderr, "[sendmail] sent successfully")'; \
|
||||||
|
echo ' }'; \
|
||||||
|
echo '}'; \
|
||||||
|
} > main.go
|
||||||
|
RUN go mod init gomail && \
|
||||||
|
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o /usr/local/bin/sendmail .
|
||||||
|
|
||||||
|
|
||||||
|
FROM golang:1.25 AS builder
|
||||||
|
WORKDIR /app
|
||||||
|
COPY ./go.mod ./go.sum /app/
|
||||||
|
RUN go mod download
|
||||||
|
COPY ./*.go /app/
|
||||||
|
RUN rm -f /app/gomail.go
|
||||||
|
|
||||||
|
ARG TARGETARCH=amd64
|
||||||
|
ARG TARGETOS=linux
|
||||||
|
ARG VERSION=dev
|
||||||
|
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags "-X main.version=${VERSION}" -a -installsuffix nocgo -o minitor .
|
||||||
|
|
||||||
|
FROM alpine:3.23
|
||||||
RUN mkdir /app
|
RUN mkdir /app
|
||||||
WORKDIR /app/
|
WORKDIR /app/
|
||||||
|
|
||||||
|
# Copy minitor in
|
||||||
|
COPY --from=builder /app/minitor .
|
||||||
|
|
||||||
|
# Copy sendmail (gomail) in
|
||||||
|
COPY --from=gomail-builder /usr/local/bin/sendmail /usr/local/bin/sendmail
|
||||||
|
|
||||||
# Add common checking tools
|
# Add common checking tools
|
||||||
# hadolint ignore=DL3018
|
# hadolint ignore=DL3018
|
||||||
RUN apk --no-cache add bash=~5 curl=~8 jq=~1 bind-tools=~9 tzdata
|
RUN apk --no-cache add bash=~5 curl=~8 jq=~1 bind-tools=~9 tzdata
|
||||||
@@ -12,13 +121,9 @@ RUN addgroup -S minitor && adduser -S minitor -G minitor
|
|||||||
|
|
||||||
# Copy scripts
|
# Copy scripts
|
||||||
COPY ./scripts /app/scripts
|
COPY ./scripts /app/scripts
|
||||||
|
COPY default_config.hcl /app/config.hcl
|
||||||
RUN chmod -R 755 /app/scripts
|
RUN chmod -R 755 /app/scripts
|
||||||
|
|
||||||
# Copy minitor in
|
|
||||||
ARG TARGETOS
|
|
||||||
ARG TARGETARCH
|
|
||||||
COPY ./dist/minitor-${TARGETOS}-${TARGETARCH} ./minitor
|
|
||||||
|
|
||||||
# Drop to non-root user
|
# Drop to non-root user
|
||||||
USER minitor
|
USER minitor
|
||||||
|
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
FROM golang:1.25 AS builder
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
COPY ./go.mod ./go.sum /app/
|
|
||||||
RUN go mod download
|
|
||||||
|
|
||||||
COPY ./*.go /app/
|
|
||||||
|
|
||||||
ARG TARGETOS
|
|
||||||
ARG TARGETARCH
|
|
||||||
ARG VERSION=dev
|
|
||||||
ENV CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=${TARGETARCH}
|
|
||||||
RUN go build -ldflags "-X main.version=${VERSION}" -a -installsuffix nocgo -o minitor .
|
|
||||||
|
|
||||||
FROM alpine:3.23
|
|
||||||
RUN mkdir /app
|
|
||||||
WORKDIR /app/
|
|
||||||
|
|
||||||
# Copy minitor in
|
|
||||||
COPY --from=builder /app/minitor .
|
|
||||||
|
|
||||||
# Add common checking tools
|
|
||||||
# hadolint ignore=DL3018
|
|
||||||
RUN apk --no-cache add bash=~5 curl=~8 jq=~1 bind-tools=~9 tzdata
|
|
||||||
|
|
||||||
# Add minitor user for running as non-root
|
|
||||||
RUN addgroup -S minitor && adduser -S minitor -G minitor
|
|
||||||
|
|
||||||
# Copy scripts
|
|
||||||
COPY ./scripts /app/scripts
|
|
||||||
RUN chmod -R 755 /app/scripts
|
|
||||||
|
|
||||||
# Drop to non-root user
|
|
||||||
USER minitor
|
|
||||||
|
|
||||||
ENTRYPOINT [ "./minitor" ]
|
|
||||||
|
|
||||||
# vim: set filetype=dockerfile:
|
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
check_interval = "1s"
|
||||||
|
|
||||||
|
monitor "mdstat_raid" {
|
||||||
|
command = [
|
||||||
|
"sh",
|
||||||
|
"-c",
|
||||||
|
"grep -q '\\[U_\\|_U\\]' /host_proc/mdstat && exit 1 || exit 0"
|
||||||
|
]
|
||||||
|
check_interval = "30s"
|
||||||
|
alert_after = 1
|
||||||
|
alert_every = 0
|
||||||
|
|
||||||
|
alert_down = ["email_alert"]
|
||||||
|
alert_up = ["email_recovery"]
|
||||||
|
}
|
||||||
|
alert "email_alert" {
|
||||||
|
command = [
|
||||||
|
"sh",
|
||||||
|
"-c",
|
||||||
|
"EMAIL=$EMAIL_RECIPIENT; printf 'Subject: RAID ALERT\nTo: %s\n\nRAID degraded\n' \"$EMAIL\" | /usr/local/bin/sendmail -t || true"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
alert "email_recovery" {
|
||||||
|
command = [
|
||||||
|
"sh",
|
||||||
|
"-c",
|
||||||
|
"EMAIL=$EMAIL_RECIPIENT; printf 'Subject: RAID ALERT\nTo: %s\n\nRAID clean\n' \"$EMAIL\" | /usr/local/bin/sendmail -t || true"
|
||||||
|
]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user