simple skel no work :c
ci/woodpecker/push/woodpecker Pipeline failed
Details
ci/woodpecker/push/woodpecker Pipeline failed
Details
parent
f48a4fc108
commit
7361f5a805
|
@ -3,3 +3,5 @@
|
|||
5533801d-70e3-4c21-9942-82d20930c789
|
||||
5533801d-70e3-4c21-9942-82d20930c789
|
||||
5533801d-70e3-4c21-9942-82d20930c789
|
||||
5533801d-70e3-4c21-9942-82d20930c789
|
||||
5533801d-70e3-4c21-9942-82d20930c789
|
||||
|
|
6
Makefile
6
Makefile
|
@ -1,5 +1,5 @@
|
|||
|
||||
.PHONY: release dev deps install
|
||||
.PHONY: release dev deps install skel
|
||||
|
||||
release: deps
|
||||
CGO_ENABLED=1 go build -buildvcs=true .
|
||||
|
@ -22,3 +22,7 @@ install:
|
|||
cp -n podterminal.service /etc/systemd/system/
|
||||
systemctl daemon-reload
|
||||
systemctl enable --now podterminal
|
||||
|
||||
skel:
|
||||
echo "Taring up /etc/podterminal/skel/"
|
||||
tar -czvf /etc/podterminal/skel.tar.gz -C /etc/podterminal/skel .
|
||||
|
|
81
pods/skel.go
81
pods/skel.go
|
@ -2,78 +2,53 @@ package pods
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
buildahCopyah "github.com/containers/buildah/copier"
|
||||
"github.com/containers/podman/v4/pkg/bindings/containers"
|
||||
"github.com/containers/podman/v4/pkg/copy"
|
||||
"github.com/spf13/viper"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
// CopySkelToContainer copies an Archive into the containers home directory
|
||||
// (Assumes the use of a Webtop container)
|
||||
// This Function is heavily inspired by https://github.com/containers/podman/blob/main/cmd/podman/containers/cp.go#L337
|
||||
func CopySkelToContainer(id string) error {
|
||||
log.Println("Copying skel directory to container")
|
||||
var errorGroup errgroup.Group
|
||||
trueVar := true
|
||||
log.Println("Copying skel Archive to container")
|
||||
var buf bytes.Buffer
|
||||
var err error
|
||||
_, err = copy.ResolveHostPath(viper.GetString("skel"))
|
||||
|
||||
file, err := os.Open(viper.GetString("skel"))
|
||||
if err != nil {
|
||||
log.Println("Could not find skel Directory", err)
|
||||
log.Println("Could not open skel archive", err)
|
||||
return err
|
||||
}
|
||||
reader, writer := io.Pipe()
|
||||
defer file.Close()
|
||||
|
||||
// Create Function for copying from host to pipe
|
||||
hostCopy := func() error {
|
||||
getOptions := buildahCopyah.GetOptions{
|
||||
KeepDirectoryNames: true,
|
||||
}
|
||||
err := buildahCopyah.Get("/", "", getOptions, []string{viper.GetString("skel")}, &buf)
|
||||
if err != nil {
|
||||
log.Print("Error copying from Host: ", err)
|
||||
}
|
||||
|
||||
//defer closeAndLogWriter(writer)
|
||||
return nil
|
||||
// Use 'FileInfo' to get the size of the file
|
||||
fileInfo, err := file.Stat()
|
||||
if err != nil {
|
||||
log.Println("Could not get size of skel archive", err)
|
||||
return err
|
||||
}
|
||||
|
||||
// create function to copy from pipe to container
|
||||
containerCopy := func() error {
|
||||
_, err := containers.CopyFromArchive(Socket, id, "/config/", &buf)
|
||||
if err != nil {
|
||||
log.Print("Error copying to Container: ", err)
|
||||
}
|
||||
//defer closeAndLogReader(reader)
|
||||
return nil
|
||||
// Create a buffer with the size of the file
|
||||
buffer := bytes.NewBuffer(make([]byte, 0, fileInfo.Size()))
|
||||
|
||||
// Copy the file contents to the buffer
|
||||
_, err = buffer.ReadFrom(file)
|
||||
if err != nil {
|
||||
log.Println("Could not get read in skel archive", err)
|
||||
return err
|
||||
}
|
||||
|
||||
errorGroup.Go(hostCopy)
|
||||
errorGroup.Go(containerCopy)
|
||||
|
||||
if err := errorGroup.Wait(); err != nil {
|
||||
log.Println("Could not Copy Skel", err)
|
||||
log.Println("Writing file from buffer to container")
|
||||
copyOptions := &containers.CopyOptions{
|
||||
Chown: &trueVar,
|
||||
}
|
||||
closeAndLogReader(reader)
|
||||
closeAndLogWriter(writer)
|
||||
_, err = containers.CopyFromArchiveWithOptions(Socket, id, "/config/", &buf, copyOptions)
|
||||
if err != nil {
|
||||
log.Print("Error copying to Container: ", err)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// closeAndLogReader takes a reader and closes it, logging any error
|
||||
func closeAndLogReader(reader *io.PipeReader) {
|
||||
err := reader.Close()
|
||||
if err != nil {
|
||||
log.Println("Could not close reader: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
// closeAndLogWriter takes a writer and closes it, logging any error
|
||||
func closeAndLogWriter(writer *io.PipeWriter) {
|
||||
err := writer.Close()
|
||||
if err != nil {
|
||||
log.Println("Could not close writer: ", err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ func readConfigFile() {
|
|||
viper.SetDefault("maxAge", 10800)
|
||||
viper.SetDefault("dri", false)
|
||||
viper.SetDefault("dir_node", "/dev/dri/renderD128")
|
||||
viper.SetDefault("skel", "/etc/podterminal/skel/")
|
||||
viper.SetDefault("skel", "/etc/podterminal/skel.tar.gz")
|
||||
viper.SetDefault("block_filebrowser", false)
|
||||
viper.SetDefault("envvars",
|
||||
map[string]string{
|
||||
|
|
Loading…
Reference in New Issue