feat: Add auth flow (#146)

This adds a simple way to incorporate a centralized authentication flow.

The idea is to have the user, API and SSH (for machine authentication)
all in one place using `openauthjs` + `SST`

We also have a database now :)

> We are using InstantDB as it allows us to authenticate a use with just
the email. Plus it is super simple simple to use _of course after the
initial fumbles trying to design the db and relationships_
This commit is contained in:
Wanjohi
2025-01-04 00:02:28 +03:00
committed by GitHub
parent 33895974a7
commit fc5a755408
136 changed files with 3512 additions and 1914 deletions

View File

@@ -0,0 +1,72 @@
package session
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"github.com/docker/docker/api/types/container"
)
// detectGPU checks for available GPU type
func detectGPU() GPUType {
// First check for NVIDIA
cmd := exec.Command("nvidia-smi")
if err := cmd.Run(); err == nil {
return GPUNvidia
}
// Check for Intel/AMD GPU by looking for DRI devices
if _, err := os.Stat("/dev/dri"); err == nil {
return GPUIntelAMD
}
return GPUNone
}
// getGPUDeviceRequests returns appropriate device configuration based on GPU type
func getGPUDeviceRequests(gpuType GPUType) ([]container.DeviceRequest, error) {
switch gpuType {
case GPUNvidia:
return []container.DeviceRequest{
{
Driver: "nvidia",
Count: 1,
DeviceIDs: []string{"0"},
Capabilities: [][]string{{"gpu"}},
},
}, nil
case GPUIntelAMD:
return []container.DeviceRequest{}, nil // Empty as we'll handle this in Devices
default:
return nil, fmt.Errorf("no supported GPU detected")
}
}
// getGPUDevices returns appropriate device mappings based on GPU type
func getGPUDevices(gpuType GPUType) []container.DeviceMapping {
if gpuType == GPUIntelAMD {
devices := []container.DeviceMapping{}
// Only look for card and renderD nodes
for _, pattern := range []string{"card[0-9]*", "renderD[0-9]*"} {
matches, err := filepath.Glob(fmt.Sprintf("/dev/dri/%s", pattern))
if err != nil {
continue
}
for _, match := range matches {
// Verify it's a device file
if info, err := os.Stat(match); err == nil && (info.Mode()&os.ModeDevice) != 0 {
devices = append(devices, container.DeviceMapping{
PathOnHost: match,
PathInContainer: match,
CgroupPermissions: "rwm",
})
}
}
}
return devices
}
return nil
}