Updated build to be able to build from OCI repositories and some housecleaning
This commit is contained in:
36
cmd/wwbuild/vnfs-local.go
Normal file
36
cmd/wwbuild/vnfs-local.go
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
func vnfsLocalBuild(vnfsPath string, wg *sync.WaitGroup) {
|
||||||
|
defer wg.Done()
|
||||||
|
|
||||||
|
if _, err := os.Stat(vnfsPath); err == nil {
|
||||||
|
// TODO: Build VNFS to temporary file and move to real location when complete atomically
|
||||||
|
// TODO: Check time stamps of sourcedir and build file to see if we need to rebuild or skip
|
||||||
|
|
||||||
|
vnfsDestination := fmt.Sprintf("%s/provision/vnfs/%s.img.gz", LocalStateDir, path.Base(vnfsPath))
|
||||||
|
|
||||||
|
fmt.Printf("Building local Container: %s\n", vnfsPath)
|
||||||
|
|
||||||
|
err := os.MkdirAll(path.Dir(vnfsDestination), 0755)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("ERROR: %s\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = buildVnfs(vnfsPath, vnfsDestination)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("ERROR: %s\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
fmt.Printf("SKIPPING VNFS: (bad path) %s\n", vnfsPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
66
cmd/wwbuild/vnfs-oci.go
Normal file
66
cmd/wwbuild/vnfs-oci.go
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/oci"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
func vnfsOciBuild(OciPath string, wg *sync.WaitGroup) {
|
||||||
|
vnfsDestination := fmt.Sprintf("%s/provision/vnfs/%s.img.gz", LocalStateDir, path.Base(OciPath))
|
||||||
|
defer wg.Done()
|
||||||
|
|
||||||
|
log.Printf("Building OCI Container: %s\n", OciPath)
|
||||||
|
c, err := oci.NewCache(oci.OptSetCachePath("/var/warewulf/oci"))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("ERROR: %s\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
sourcePath, err := c.Pull(context.Background(), OciPath, nil)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("ERROR: %s\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
ociDestination := fmt.Sprintf("%s/oci/vnfs/%s", LocalStateDir, path.Base(sourcePath))
|
||||||
|
|
||||||
|
name, err := os.Readlink(vnfsDestination)
|
||||||
|
if err == nil {
|
||||||
|
if name == ociDestination {
|
||||||
|
log.Printf("Container already built, no changes from upstream\n")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.MkdirAll(path.Dir(ociDestination), 0755)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("ERROR: %s\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = os.MkdirAll(path.Dir(vnfsDestination), 0755)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("ERROR: %s\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = buildVnfs(sourcePath, ociDestination)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("ERROR: %s\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.Symlink(ociDestination, vnfsDestination+"-link")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("ERROR: %s\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
err = os.Rename(vnfsDestination+"-link", vnfsDestination)
|
||||||
|
|
||||||
|
log.Printf("Completed building VNFS: %s\n", path.Base(OciPath))
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
14
cmd/wwbuild/vnfs.go
Normal file
14
cmd/wwbuild/vnfs.go
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os/exec"
|
||||||
|
)
|
||||||
|
|
||||||
|
func buildVnfs(source string, dest string) error {
|
||||||
|
cmd := fmt.Sprintf("cd %s; find . | cpio --quiet -o -H newc | gzip -c > \"%s\"", source, dest)
|
||||||
|
|
||||||
|
err := exec.Command("/bin/sh", "-c", cmd).Run()
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
@@ -1,45 +1,18 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/hpcng/warewulf/internal/pkg/assets"
|
"github.com/hpcng/warewulf/internal/pkg/assets"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const LocalStateDir = "/var/warewulf"
|
const LocalStateDir = "/var/warewulf"
|
||||||
|
|
||||||
func vnfsBuild(vnfsPath string, wg *sync.WaitGroup) {
|
|
||||||
defer wg.Done()
|
|
||||||
if _, err := os.Stat(vnfsPath); err == nil {
|
|
||||||
// TODO: Build VNFS to temporary file and move to real location when complete atomically
|
|
||||||
// TODO: Check time stamps of sourcedir and build file to see if we need to rebuild or skip
|
|
||||||
vnfsDestination := fmt.Sprintf("%s/provision/vnfs/%s.img.gz", LocalStateDir, path.Base(vnfsPath))
|
|
||||||
|
|
||||||
err := os.MkdirAll(path.Dir(vnfsDestination), 0755)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("ERROR: %s\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("BUILDING VNFS: %s\n", vnfsPath)
|
|
||||||
|
|
||||||
cmd := fmt.Sprintf("cd %s; find . | cpio --quiet -o -H newc | gzip -c > \"%s\"", vnfsPath, vnfsDestination)
|
|
||||||
err = exec.Command("/bin/sh", "-c", cmd).Run()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("ERROR: %s\n", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
fmt.Printf("SKIPPING VNFS: (bad path) %s\n", vnfsPath)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
if len(os.Args) < 2 {
|
if len(os.Args) < 2 {
|
||||||
@@ -68,10 +41,16 @@ func main() {
|
|||||||
set[node.Vnfs] = true
|
set[node.Vnfs] = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for entry := range set {
|
for entry := range set {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go vnfsBuild(entry, &wg)
|
if strings.HasPrefix(entry, "/") {
|
||||||
|
vnfsLocalBuild(entry, &wg)
|
||||||
|
} else {
|
||||||
|
vnfsOciBuild(entry, &wg)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(1000 * time.Millisecond)
|
time.Sleep(1000 * time.Millisecond)
|
||||||
fmt.Printf("Waiting for build(s) to complete...\n")
|
fmt.Printf("Waiting for build(s) to complete...\n")
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
@@ -161,9 +140,9 @@ func main() {
|
|||||||
|
|
||||||
wg.Add(2)
|
wg.Add(2)
|
||||||
overlayRuntime(node, replace, &wg)
|
overlayRuntime(node, replace, &wg)
|
||||||
overlaySystem(node, replace, &wg)
|
overlaySystem(node, replace, &wg)
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ func (c *Cache) checkEntry(id string) (string, error) {
|
|||||||
|
|
||||||
func (c *Cache) createEntry(id string) (string, error) {
|
func (c *Cache) createEntry(id string) (string, error) {
|
||||||
path := filepath.Join(c.rootfsDir(), id)
|
path := filepath.Join(c.rootfsDir(), id)
|
||||||
if err := os.MkdirAll(path, 700); err != nil {
|
if err := os.MkdirAll(path, 755); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ func NewCache(opts ...CacheOpt) (*Cache, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := os.MkdirAll(s.path, 0700); err != nil {
|
if err := os.MkdirAll(s.path, 0755); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user