shit: slopped from bun into a (I hope) light go shit
Build and Publish Docker Image / build-and-push (push) Failing after 22s
Build and Publish Docker Image / build-and-push (push) Failing after 22s
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
name: Build and Publish Docker Image
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
env:
|
||||
REGISTRY: git.reloia.uk
|
||||
IMAGE_NAME: ${{ github.repository }}
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: catthehacker/ubuntu:act-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Log in to Gitea Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
|
||||
password: ${{ secrets.LOGIN_TOKEN }}
|
||||
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
|
||||
platforms: linux/arm64
|
||||
tags: |
|
||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
FROM --platform=$BUILDPLATFORM golang:1.22-alpine AS builder
|
||||
|
||||
ARG TARGETOS
|
||||
ARG TARGETARCH
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY go.mod ./
|
||||
COPY main.go ./
|
||||
|
||||
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o debugghttpy .
|
||||
|
||||
FROM scratch
|
||||
LABEL authors="reloia"
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY --from=builder /app/debugghttpy .
|
||||
|
||||
ENV PORT=3000
|
||||
ENV DOMAIN="*"
|
||||
|
||||
CMD ["./debugghttpy"]
|
||||
@@ -0,0 +1,116 @@
|
||||
package debugghttpy
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
port := os.Getenv("PORT")
|
||||
if port == "" {
|
||||
port = "3000"
|
||||
}
|
||||
allowedOrigin := os.Getenv("DOMAIN")
|
||||
if allowedOrigin == "" {
|
||||
allowedOrigin = "*"
|
||||
}
|
||||
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Access-Control-Allow-Origin", allowedOrigin)
|
||||
|
||||
if r.Method == http.MethodOptions {
|
||||
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS")
|
||||
w.Header().Set("Access-Control-Allow-Headers", "*")
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
ip, portStr, err := net.SplitHostPort(r.RemoteAddr)
|
||||
if err != nil {
|
||||
ip = r.RemoteAddr
|
||||
portStr = "unknown"
|
||||
}
|
||||
family := "IPv4"
|
||||
if strings.Contains(ip, ":") {
|
||||
family = "IPv6"
|
||||
}
|
||||
|
||||
headers := make(map[string]string)
|
||||
for k, v := range r.Header {
|
||||
headers[strings.ToLower(k)] = strings.Join(v, ", ")
|
||||
}
|
||||
|
||||
searchParams := make(map[string]string)
|
||||
for k, v := range r.URL.Query() {
|
||||
searchParams[k] = v[0]
|
||||
}
|
||||
|
||||
var cookiesData interface{}
|
||||
if r.URL.Query().Has("cookies") {
|
||||
cookiesMap := make(map[string]string)
|
||||
for _, c := range r.Cookies() {
|
||||
cookiesMap[c.Name] = c.Value
|
||||
}
|
||||
cookiesData = cookiesMap
|
||||
} else {
|
||||
cookiesData = "disabled, add ?cookies to query to see cookies"
|
||||
delete(headers, "cookie")
|
||||
}
|
||||
|
||||
tlsInfo := "none"
|
||||
if r.TLS != nil {
|
||||
tlsInfo = fmt.Sprintf("TLS (Version: %x)", r.TLS.Version)
|
||||
}
|
||||
|
||||
getValOrNil := func(val string) interface{} {
|
||||
if val == "" {
|
||||
return nil
|
||||
}
|
||||
return val
|
||||
}
|
||||
|
||||
debugInfo := map[string]interface{}{
|
||||
"app": "debugghttpy",
|
||||
"rawSocket": map[string]interface{}{
|
||||
"ip": ip,
|
||||
"family": family,
|
||||
"port": portStr,
|
||||
},
|
||||
"request": map[string]interface{}{
|
||||
"method": r.Method,
|
||||
"url": r.URL.RequestURI(),
|
||||
"pathname": r.URL.Path,
|
||||
"searchParams": searchParams,
|
||||
"protocol": r.Proto,
|
||||
"host": r.Host,
|
||||
"contentLength": r.ContentLength,
|
||||
"tls": tlsInfo,
|
||||
},
|
||||
"quickIps": map[string]interface{}{
|
||||
"x-forwarded-for": getValOrNil(headers["x-forwarded-for"]),
|
||||
"x-real-ip": getValOrNil(headers["x-real-ip"]),
|
||||
"cf-connecting-ip": getValOrNil(headers["cf-connecting-ip"]),
|
||||
"true-client-ip": getValOrNil(headers["true-client-ip"]),
|
||||
},
|
||||
"headers": headers,
|
||||
"cookies": cookiesData,
|
||||
}
|
||||
|
||||
enc := json.NewEncoder(w)
|
||||
enc.SetIndent("", " ")
|
||||
if err := enc.Encode(debugInfo); err != nil {
|
||||
log.Printf("Error encoding JSON: %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
log.Printf("🚀 debugghttpy listening on port %s\n", port)
|
||||
log.Printf("🔒 CORS Allowed Origin: %s\n", allowedOrigin)
|
||||
log.Fatal(http.ListenAndServe(":"+port, nil))
|
||||
}
|
||||
Reference in New Issue
Block a user