Skip to content

Commit

Permalink
feat: Update volume endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmoysrt committed Jan 28, 2025
1 parent 4982747 commit 64060de
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 168 deletions.
2 changes: 1 addition & 1 deletion agent/dns_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func startDnsServer() {
}
_ = w.WriteMsg(m)
})
server := &dns.Server{Addr: "10.0.1.1:53", Net: "udp"}
server := &dns.Server{Addr: "127.0.0.1:5353", Net: "udp"}
log.Printf("Starting DNS server at %s\n", server.Addr)
if err := server.ListenAndServe(); err != nil {
log.Fatalf("Failed to start DNS server: %s\n ", err)
Expand Down
164 changes: 0 additions & 164 deletions agent/file_utils.go

This file was deleted.

8 changes: 8 additions & 0 deletions agent/volume_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ func (v *Volume) Create() error {
if err := v.Validate(); err != nil {
return err
}
// Check if the volume already exists
exists, err := ExistsVolume(v.UUID)
if err != nil {
return err
}
if exists {
return fmt.Errorf("volume already exists")
}
// Create the record
if err := rwDB.Create(v).Error; err != nil {
return err
Expand Down
8 changes: 5 additions & 3 deletions agent/volume_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"fmt"
"os"
"path/filepath"

"github.com/docker/docker/api/types/volume"
Expand All @@ -11,7 +12,7 @@ import (
var volumeBindsDefaultPath string

func init() {
volumePath, err := filepath.Abs("./volumes")
volumePath, err := filepath.Abs("/home/tanmoy/docker-volumes")
if err != nil {
fmt.Println("Failed to get absolute path for volumes directory")
panic(err)
Expand Down Expand Up @@ -45,7 +46,7 @@ func (v *Volume) RemoveVolume(deleteDirectory bool) error {
// Remove volume directory
if v.Type == LocalVolume && deleteDirectory {
path := v.LocalVolumeFullPath()
RemovePath(path)
_ = os.RemoveAll(path)
}
return nil
}
Expand Down Expand Up @@ -79,7 +80,7 @@ func (v *Volume) Restore(downloadUrl string) error {

func createLocalVolume(v *Volume) error {
// create volume directory
err := CreateDirectoryWithOptions(v.LocalVolumeFullPath(), false, 0755)
err := os.MkdirAll(v.LocalVolumeFullPath(), 0755)
if err != nil {
return err
}
Expand All @@ -88,6 +89,7 @@ func createLocalVolume(v *Volume) error {
Name: v.UUID,
Driver: "local",
DriverOpts: map[string]string{
"type": "volume",
"o": "bind",
"device": v.LocalVolumeFullPath(),
},
Expand Down

0 comments on commit 64060de

Please sign in to comment.