This commit is contained in:
51
.gitea/workflows/register.yml
Normal file
51
.gitea/workflows/register.yml
Normal file
@@ -0,0 +1,51 @@
|
||||
name: release-tag
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'main'
|
||||
jobs:
|
||||
release-image:
|
||||
runs-on: ubuntu-fast
|
||||
env:
|
||||
DOCKER_ORG: ${{ vars.DOCKER_ORG }}
|
||||
DOCKER_LATEST: latest
|
||||
RUNNER_TOOL_CACHE: /toolcache
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v2
|
||||
|
||||
- name: Set up Docker BuildX
|
||||
uses: docker/setup-buildx-action@v2
|
||||
with: # replace it with your local IP
|
||||
config-inline: |
|
||||
[registry."${{ vars.DOCKER_REGISTRY }}"]
|
||||
http = true
|
||||
insecure = true
|
||||
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
registry: ${{ vars.DOCKER_REGISTRY }} # replace it with your local IP
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
|
||||
- name: Get Meta
|
||||
id: meta
|
||||
run: |
|
||||
echo REPO_NAME=$(echo ${GITHUB_REPOSITORY} | awk -F"/" '{print $2}') >> $GITHUB_OUTPUT
|
||||
echo REPO_VERSION=$(git describe --tags --always | sed 's/^v//') >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
platforms: |
|
||||
linux/amd64
|
||||
push: true
|
||||
tags: | # replace it with your local IP and tags
|
||||
${{ vars.DOCKER_REGISTRY }}/${{ env.DOCKER_ORG }}/${{ steps.meta.outputs.REPO_NAME }}:${{ steps.meta.outputs.REPO_VERSION }}
|
||||
${{ vars.DOCKER_REGISTRY }}/${{ env.DOCKER_ORG }}/${{ steps.meta.outputs.REPO_NAME }}:${{ env.DOCKER_LATEST }}
|
26
Dockerfile
Normal file
26
Dockerfile
Normal file
@@ -0,0 +1,26 @@
|
||||
# -------- Dockerfile (Multi-Stage Build) --------
|
||||
# 1. Builder-Stage
|
||||
FROM golang:1.24-alpine AS builder
|
||||
|
||||
WORKDIR /app
|
||||
COPY go.* ./
|
||||
RUN go mod download
|
||||
COPY . .
|
||||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /bin/ipblock-api
|
||||
|
||||
# 2. Runtime-Stage
|
||||
FROM alpine:3.20
|
||||
|
||||
# HTTPS-Callouts in Alpine brauchen ca-certificates
|
||||
RUN apk add --no-cache ca-certificates
|
||||
|
||||
COPY --from=builder /bin/ipblock-api /bin/ipblock-api
|
||||
|
||||
# Default listens on :8080 – siehe main.go
|
||||
EXPOSE 8080
|
||||
|
||||
# Environment defaults; können per compose überschrieben werden
|
||||
ENV REDIS_ADDR=redis:6379 \
|
||||
TTL_HOURS=720
|
||||
|
||||
ENTRYPOINT ["/bin/ipblock-api"]
|
49
main.go
49
main.go
@@ -24,6 +24,7 @@ package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -577,17 +578,18 @@ type target struct {
|
||||
const (
|
||||
indexTemplateHTML = `<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head><meta charset="utf-8"><title>IPv64 Blocklists</title>
|
||||
<head><meta charset="utf-8"><title>IP Blocklists</title>
|
||||
<style>body{font-family:system-ui, sans-serif;margin:2rem}table{border-collapse:collapse}td,th{padding:4px 8px;border:1px solid #ddd}</style></head>
|
||||
<body>
|
||||
<h1>IPv64 Blocklists</h1>
|
||||
<p>Es sind {{len .Files}} Dateien verfügbar (letztes Update: {{.Updated}}).</p>
|
||||
<h1>IP Blocklists</h1>
|
||||
<p>There are {{len .Files}} files available (last Update: {{.Updated}}).</p>
|
||||
<table>
|
||||
<tr><th>Datei</th><th>Größe</th><th>Zuletzt geändert</th></tr>
|
||||
<tr><th>File</th><th>Row Count</th><th>Last Changed</th></tr>
|
||||
{{range .Files}}
|
||||
<tr><td><a href="/lists/{{.Name}}">{{.Name}}</a></td><td align="right">{{.Size}}</td><td>{{.ModTime}}</td></tr>
|
||||
{{end}}
|
||||
</table>
|
||||
<p><a href="/lists.json">/lists.json</a> - Full list as JSON</p>
|
||||
</body>
|
||||
</html>`
|
||||
)
|
||||
@@ -647,6 +649,16 @@ func main() {
|
||||
tmpl.Execute(w, data)
|
||||
})
|
||||
|
||||
// JSON API – /lists.json
|
||||
http.HandleFunc("/lists.json", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
enc := json.NewEncoder(w)
|
||||
enc.SetIndent("", " ")
|
||||
if err := enc.Encode(defaultLists); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
})
|
||||
|
||||
log.Printf("HTTP server listening on %s, serving %s", *listenAddr, *outDir)
|
||||
log.Fatal(http.ListenAndServe(*listenAddr, nil))
|
||||
}
|
||||
@@ -722,6 +734,35 @@ func fetchAndSave(client *http.Client, t target, outDir string) error {
|
||||
return os.Rename(tmp, dst)
|
||||
}
|
||||
|
||||
// ──────────────────────────────────────────────────────────────────────────────
|
||||
// Helpers
|
||||
// ──────────────────────────────────────────────────────────────────────────────
|
||||
// ExportListJSON schreibt die Map als prettified JSON‑Datei.
|
||||
func ExportListJSON(path string, m map[string]string) error {
|
||||
f, err := os.Create(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
enc := json.NewEncoder(f)
|
||||
enc.SetIndent("", " ")
|
||||
return enc.Encode(m)
|
||||
}
|
||||
|
||||
// ImportListJSON liest eine JSON‑Datei und gibt map[string]string zurück.
|
||||
func ImportListJSON(path string) (map[string]string, error) {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
var m map[string]string
|
||||
if err := json.NewDecoder(f).Decode(&m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// buildIndexData assembles a directory listing for the /index route.
|
||||
func buildIndexData(dir string) (struct {
|
||||
Files []fileInfo
|
||||
|
Reference in New Issue
Block a user