simple skel no work :c
ci/woodpecker/push/woodpecker Pipeline failed Details

why
Johannes Bülow 2024-01-30 19:41:10 +01:00
parent f48a4fc108
commit 7361f5a805
Signed by untrusted user who does not match committer: jmb
GPG Key ID: B56971CF7B8F83A6
4 changed files with 36 additions and 55 deletions

View File

@ -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 5533801d-70e3-4c21-9942-82d20930c789
5533801d-70e3-4c21-9942-82d20930c789
5533801d-70e3-4c21-9942-82d20930c789

View File

@ -1,5 +1,5 @@
.PHONY: release dev deps install .PHONY: release dev deps install skel
release: deps release: deps
CGO_ENABLED=1 go build -buildvcs=true . CGO_ENABLED=1 go build -buildvcs=true .
@ -22,3 +22,7 @@ install:
cp -n podterminal.service /etc/systemd/system/ cp -n podterminal.service /etc/systemd/system/
systemctl daemon-reload systemctl daemon-reload
systemctl enable --now podterminal systemctl enable --now podterminal
skel:
echo "Taring up /etc/podterminal/skel/"
tar -czvf /etc/podterminal/skel.tar.gz -C /etc/podterminal/skel .

View File

@ -2,78 +2,53 @@ package pods
import ( import (
"bytes" "bytes"
"io"
"log" "log"
"os"
buildahCopyah "github.com/containers/buildah/copier"
"github.com/containers/podman/v4/pkg/bindings/containers" "github.com/containers/podman/v4/pkg/bindings/containers"
"github.com/containers/podman/v4/pkg/copy"
"github.com/spf13/viper" "github.com/spf13/viper"
"golang.org/x/sync/errgroup"
) )
// CopySkelToContainer copies an Archive into the containers home directory // CopySkelToContainer copies an Archive into the containers home directory
// (Assumes the use of a Webtop container) // (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 { func CopySkelToContainer(id string) error {
log.Println("Copying skel directory to container") trueVar := true
var errorGroup errgroup.Group log.Println("Copying skel Archive to container")
var buf bytes.Buffer var buf bytes.Buffer
var err error var err error
_, err = copy.ResolveHostPath(viper.GetString("skel"))
file, err := os.Open(viper.GetString("skel"))
if err != nil { if err != nil {
log.Println("Could not find skel Directory", err) log.Println("Could not open skel archive", err)
return err return err
} }
reader, writer := io.Pipe() defer file.Close()
// Create Function for copying from host to pipe // Use 'FileInfo' to get the size of the file
hostCopy := func() error { fileInfo, err := file.Stat()
getOptions := buildahCopyah.GetOptions{ if err != nil {
KeepDirectoryNames: true, log.Println("Could not get size of skel archive", err)
} return err
err := buildahCopyah.Get("/", "", getOptions, []string{viper.GetString("skel")}, &buf)
if err != nil {
log.Print("Error copying from Host: ", err)
}
//defer closeAndLogWriter(writer)
return nil
} }
// create function to copy from pipe to container // Create a buffer with the size of the file
containerCopy := func() error { buffer := bytes.NewBuffer(make([]byte, 0, fileInfo.Size()))
_, err := containers.CopyFromArchive(Socket, id, "/config/", &buf)
if err != nil { // Copy the file contents to the buffer
log.Print("Error copying to Container: ", err) _, err = buffer.ReadFrom(file)
} if err != nil {
//defer closeAndLogReader(reader) log.Println("Could not get read in skel archive", err)
return nil return err
} }
errorGroup.Go(hostCopy) log.Println("Writing file from buffer to container")
errorGroup.Go(containerCopy) copyOptions := &containers.CopyOptions{
Chown: &trueVar,
if err := errorGroup.Wait(); err != nil {
log.Println("Could not Copy Skel", err)
} }
closeAndLogReader(reader) _, err = containers.CopyFromArchiveWithOptions(Socket, id, "/config/", &buf, copyOptions)
closeAndLogWriter(writer) if err != nil {
log.Print("Error copying to Container: ", err)
}
return 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)
}
}

View File

@ -16,7 +16,7 @@ func readConfigFile() {
viper.SetDefault("maxAge", 10800) viper.SetDefault("maxAge", 10800)
viper.SetDefault("dri", false) viper.SetDefault("dri", false)
viper.SetDefault("dir_node", "/dev/dri/renderD128") 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("block_filebrowser", false)
viper.SetDefault("envvars", viper.SetDefault("envvars",
map[string]string{ map[string]string{