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
|
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
|
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 .
|
||||||
|
|
73
pods/skel.go
73
pods/skel.go
|
@ -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{
|
|
||||||
KeepDirectoryNames: true,
|
|
||||||
}
|
|
||||||
err := buildahCopyah.Get("/", "", getOptions, []string{viper.GetString("skel")}, &buf)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print("Error copying from Host: ", err)
|
log.Println("Could not get size of skel archive", err)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
//defer closeAndLogWriter(writer)
|
// Create a buffer with the size of the file
|
||||||
return nil
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
// create function to copy from pipe to container
|
log.Println("Writing file from buffer to container")
|
||||||
containerCopy := func() error {
|
copyOptions := &containers.CopyOptions{
|
||||||
_, err := containers.CopyFromArchive(Socket, id, "/config/", &buf)
|
Chown: &trueVar,
|
||||||
|
}
|
||||||
|
_, err = containers.CopyFromArchiveWithOptions(Socket, id, "/config/", &buf, copyOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print("Error copying to Container: ", err)
|
log.Print("Error copying to Container: ", err)
|
||||||
}
|
}
|
||||||
//defer closeAndLogReader(reader)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
errorGroup.Go(hostCopy)
|
|
||||||
errorGroup.Go(containerCopy)
|
|
||||||
|
|
||||||
if err := errorGroup.Wait(); err != nil {
|
|
||||||
log.Println("Could not Copy Skel", err)
|
|
||||||
}
|
|
||||||
closeAndLogReader(reader)
|
|
||||||
closeAndLogWriter(writer)
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -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{
|
||||||
|
|
Loading…
Reference in New Issue