skel finally works \o/
ci/woodpecker/push/woodpecker Pipeline failed Details

why
Johannes Bülow 2024-01-30 21:24:31 +01:00
parent 7361f5a805
commit c991ef7295
Signed by untrusted user who does not match committer: jmb
GPG Key ID: B56971CF7B8F83A6
4 changed files with 40 additions and 28 deletions

View File

@ -5,3 +5,4 @@
5533801d-70e3-4c21-9942-82d20930c789
5533801d-70e3-4c21-9942-82d20930c789
5533801d-70e3-4c21-9942-82d20930c789
5533801d-70e3-4c21-9942-82d20930c789

1
Vagrantfile vendored
View File

@ -116,6 +116,7 @@ Vagrant.configure("2") do |config|
rm go.tar.gz
echo 'export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin' >> /etc/profile
echo 'CGO_ENABLED=1' >>/etc/profile
echo 'alias cleanpods="podman stop -a && podman rm -a"' >> /etc/profile
echo 'CGO_ENABLED=1' >>/root/.bashrc
export PATH=$PATH:/usr/local/go/bin
go install github.com/cosmtrek/air@latest

View File

@ -3,6 +3,7 @@ package pods
import (
"context"
"log"
"net"
"time"
"github.com/containers/podman/v4/pkg/bindings"
@ -13,6 +14,7 @@ import (
)
var Socket context.Context
var rawSocket net.Conn
func socketConnection() context.Context {
uri := "unix:///run/podman/podman.sock"
@ -23,12 +25,19 @@ func socketConnection() context.Context {
return conn
}
func TestPodman() {
_ = socketConnection()
func rawConnection() net.Conn {
connection, err := net.Dial("unix", "unix:///run/podman/podman.sock")
if err != nil {
log.Println(
"Could not establish raw UNIX socket connection, certain features will not work properly",
)
}
return connection
}
func ConnectSocket() {
Socket = socketConnection()
rawSocket = rawConnection()
}
func PullImage() error {

View File

@ -1,54 +1,55 @@
package pods
import (
"bytes"
"log"
"net/http"
"net/url"
"os"
"github.com/containers/podman/v4/pkg/bindings/containers"
"github.com/containers/podman/v4/pkg/bindings"
"github.com/spf13/viper"
)
// CopySkelToContainer copies an Archive into the containers home directory
// (Assumes the use of a Webtop container)
func CopySkelToContainer(id string) error {
trueVar := true
log.Println("Copying skel Archive to container")
var buf bytes.Buffer
var err error
conn, err := bindings.GetClient(Socket)
if err != nil {
return err
}
file, err := os.Open(viper.GetString("skel"))
if err != nil {
log.Println("Could not open skel archive", err)
return err
}
fileInfo, err := os.Stat(viper.GetString("skel"))
log.Println("Skel Archive is ", fileInfo.Size(), "b")
defer file.Close()
// Use 'FileInfo' to get the size of the file
fileInfo, err := file.Stat()
params := url.Values{}
params.Set("path", "/config")
response, err := conn.DoRequest(
Socket,
file,
http.MethodPut,
"/containers/%s/archive",
params,
nil,
id,
)
if err != nil {
log.Println("Could not get size of skel archive", err)
return err
}
// 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)
if response.StatusCode != http.StatusOK {
log.Println("Error putting archive into container: ")
return err
}
log.Println("Writing file from buffer to container")
copyOptions := &containers.CopyOptions{
Chown: &trueVar,
}
_, err = containers.CopyFromArchiveWithOptions(Socket, id, "/config/", &buf, copyOptions)
if err != nil {
log.Print("Error copying to Container: ", err)
}
return err
log.Println(response.StatusCode, response.Body)
return response.Process(nil)
}