This commit is contained in:
cangui 2025-08-18 19:04:02 +02:00
parent 102a48fa12
commit 9cdb2a3a8d
2 changed files with 33 additions and 38 deletions

View File

@ -1,19 +1,19 @@
FROM golang:1.24 # ----- build -----
FROM golang:1.22 AS builder
WORKDIR /app WORKDIR /src
# Copie les fichiers de dépendances Go
COPY go.mod go.sum ./ COPY go.mod go.sum ./
RUN go mod download RUN go mod download
# Copie tout le reste (code + web + assets)
COPY . . COPY . .
# Si ton main est à la racine (main.go), garde ./ ; sinon mets le chemin du main
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /out/shelfy .
# Build de ton binaire # ----- runtime -----
RUN go build -o shelfy . FROM alpine:3.20
# sh est présent (utile pour le "tee")
# Expose les ports nécessaires RUN adduser -D -u 10001 appuser
EXPOSE 8080 2121 WORKDIR /app
COPY --from=builder /out/shelfy /app/shelfy
# Commande de lancement RUN chmod +x /app/shelfy && mkdir -p /app/data /app/upload /var/log/shelfy && chown -R appuser:appuser /app
CMD ["./shelfy"] USER appuser
ENTRYPOINT ["/bin/sh","-c","/app/shelfy 2>&1 | tee -a /var/log/shelfy/shelfy.log"]

41
main.go
View File

@ -253,30 +253,25 @@ func startHTTP() {
_ = app.Run(":8080") _ = app.Run(":8080")
} }
// ---------- Main ----------
func main() { func main() {
// SFTP sur 2222 (root = ./upload)
go startSFTPServer(SFTPBaseDir) go startSFTPServer(SFTPBaseDir)
// HTTP normal
// Serveur HTTP Gin startHTTP()
bd := db.InitDB() }
app := gin.Default() func loadOrCreateRSAHostKey(path string) (ssh.Signer, error) {
if _, err := os.Stat(path); err == nil {
api := app.Group("/api/v1") b, err := os.ReadFile(path)
routes.AddRoutes(api, bd) if err != nil { return nil, err }
utils.CreateDefaultFolder(bd) return ssh.ParsePrivateKey(b)
}
app.Static("/static", "./web") // Génère une clé RSA 2048
app.NoRoute(func(c *gin.Context) { priv, err := rsa.GenerateKey(rand.Reader, 2048)
if strings.HasPrefix(c.Request.URL.Path, "/api/") { if err != nil { return nil, err }
c.JSON(404, gin.H{"error": "Not found"}) // Encode en PEM "RSA PRIVATE KEY" (PKCS#1)
return pkcs1 := x509.MarshalPKCS1PrivateKey(priv)
} pemBytes := pem.EncodeToMemory(&pem.Block{Type: "RSA PRIVATE KEY", Bytes: pkcs1})
c.File("./web/index.html") if err := os.WriteFile(path, pemBytes, 0o600); err != nil { return nil, err }
}) return ssh.ParsePrivateKey(pemBytes)
log.Println("[HTTP] Serveur Gin sur http://localhost:8080")
app.Run(":8080")
} }