skel finally works \o/
ci/woodpecker/push/woodpecker Pipeline failed
Details
ci/woodpecker/push/woodpecker Pipeline failed
Details
parent
7361f5a805
commit
c991ef7295
|
@ -5,3 +5,4 @@
|
||||||
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
|
||||||
|
|
|
@ -116,6 +116,7 @@ Vagrant.configure("2") do |config|
|
||||||
rm go.tar.gz
|
rm go.tar.gz
|
||||||
echo 'export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin' >> /etc/profile
|
echo 'export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin' >> /etc/profile
|
||||||
echo 'CGO_ENABLED=1' >>/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
|
echo 'CGO_ENABLED=1' >>/root/.bashrc
|
||||||
export PATH=$PATH:/usr/local/go/bin
|
export PATH=$PATH:/usr/local/go/bin
|
||||||
go install github.com/cosmtrek/air@latest
|
go install github.com/cosmtrek/air@latest
|
||||||
|
|
|
@ -3,6 +3,7 @@ package pods
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containers/podman/v4/pkg/bindings"
|
"github.com/containers/podman/v4/pkg/bindings"
|
||||||
|
@ -13,6 +14,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var Socket context.Context
|
var Socket context.Context
|
||||||
|
var rawSocket net.Conn
|
||||||
|
|
||||||
func socketConnection() context.Context {
|
func socketConnection() context.Context {
|
||||||
uri := "unix:///run/podman/podman.sock"
|
uri := "unix:///run/podman/podman.sock"
|
||||||
|
@ -23,12 +25,19 @@ func socketConnection() context.Context {
|
||||||
return conn
|
return conn
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPodman() {
|
func rawConnection() net.Conn {
|
||||||
_ = socketConnection()
|
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() {
|
func ConnectSocket() {
|
||||||
Socket = socketConnection()
|
Socket = socketConnection()
|
||||||
|
rawSocket = rawConnection()
|
||||||
}
|
}
|
||||||
|
|
||||||
func PullImage() error {
|
func PullImage() error {
|
||||||
|
|
53
pods/skel.go
53
pods/skel.go
|
@ -1,54 +1,55 @@
|
||||||
package pods
|
package pods
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"log"
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/containers/podman/v4/pkg/bindings/containers"
|
"github.com/containers/podman/v4/pkg/bindings"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 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)
|
||||||
func CopySkelToContainer(id string) error {
|
func CopySkelToContainer(id string) error {
|
||||||
trueVar := true
|
|
||||||
log.Println("Copying skel Archive to container")
|
log.Println("Copying skel Archive to container")
|
||||||
var buf bytes.Buffer
|
|
||||||
var err error
|
var err error
|
||||||
|
conn, err := bindings.GetClient(Socket)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
file, err := os.Open(viper.GetString("skel"))
|
file, err := os.Open(viper.GetString("skel"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Could not open skel archive", err)
|
log.Println("Could not open skel archive", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fileInfo, err := os.Stat(viper.GetString("skel"))
|
||||||
|
log.Println("Skel Archive is ", fileInfo.Size(), "b")
|
||||||
|
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
// Use 'FileInfo' to get the size of the file
|
params := url.Values{}
|
||||||
fileInfo, err := file.Stat()
|
params.Set("path", "/config")
|
||||||
|
|
||||||
|
response, err := conn.DoRequest(
|
||||||
|
Socket,
|
||||||
|
file,
|
||||||
|
http.MethodPut,
|
||||||
|
"/containers/%s/archive",
|
||||||
|
params,
|
||||||
|
nil,
|
||||||
|
id,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Could not get size of skel archive", err)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a buffer with the size of the file
|
if response.StatusCode != http.StatusOK {
|
||||||
buffer := bytes.NewBuffer(make([]byte, 0, fileInfo.Size()))
|
log.Println("Error putting archive into container: ")
|
||||||
|
|
||||||
// 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
|
return err
|
||||||
}
|
}
|
||||||
|
log.Println(response.StatusCode, response.Body)
|
||||||
log.Println("Writing file from buffer to container")
|
return response.Process(nil)
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue