feat: basic volume plugin commands

This commit is contained in:
Nicolas Meienberger
2025-08-09 12:36:16 +02:00
parent 8d86f56b87
commit e7463d34ef
13 changed files with 222 additions and 9 deletions

50
main.go
View File

@@ -1,20 +1,52 @@
package main
import (
"fmt"
"ironmount/internal/driver"
"log"
"net"
"net/http"
"os"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Hello, World!")
const volumeRoot = "/tmp/ironmount"
type Volume struct {
Name string
Path string
}
var volumes = map[string]Volume{}
func main() {
http.HandleFunc("/", handler)
fmt.Println("Server is running on http://localhost:8080")
err := http.ListenAndServe(":8080", nil)
if err != nil {
fmt.Println("Error starting server:", err)
if err := os.MkdirAll("/run/docker/plugins", 0755); err != nil {
log.Fatalf("Failed to create plugin directory: %v", err)
}
if err := os.MkdirAll(volumeRoot, 0755); err != nil {
log.Fatalf("Failed to create volume root: %v", err)
}
if err := os.MkdirAll("/run/docker/plugins", 0755); err != nil {
log.Fatalf("Failed to create plugin directory: %v", err)
}
socketPath := "/run/docker/plugins/ironmount.sock"
if err := os.RemoveAll(socketPath); err != nil {
log.Fatalf("Failed to remove existing socket: %v", err)
}
http.HandleFunc("/Plugin.Activate", driver.Activate)
http.HandleFunc("/VolumeDriver.Create", driver.Create)
http.HandleFunc("/VolumeDriver.Remove", driver.Remove)
http.HandleFunc("/VolumeDriver.Mount", driver.Mount)
http.HandleFunc("/VolumeDriver.Unmount", driver.Unmount)
http.HandleFunc("/VolumeDriver.Path", driver.Path)
listener, err := net.Listen("unix", socketPath)
if err != nil {
log.Fatalf("Failed to listen on socket: %v", err)
}
log.Printf("Irounmount plugin started, listening on %s", socketPath)
log.Fatal(http.Serve(listener, nil))
}