Skip to content

Commit

Permalink
add libpod/go-systemd deps
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulh committed Jul 19, 2023
1 parent 2ceeeb8 commit 8606029
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 24 deletions.
Binary file modified calaos-container
Binary file not shown.
24 changes: 0 additions & 24 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,8 @@ import (
"github.com/fatih/color"
cli "github.com/jawher/mow.cli"
"github.com/sirupsen/logrus"
// "github.com/containers/podman/v4/pkg/bindings"
// "github.com/containers/podman/v4/pkg/bindings/images"
//
// "github.com/coreos/go-systemd/v22/dbus"
// godbus "github.com/godbus/dbus/v5"
)

/*
Podman API Docs:
https://pkg.go.dev/github.com/containers/podman/[email protected]/pkg/bindings#section-readme
*/
/*
func main() {
conn, err := bindings.NewConnection(context.Background(), "unix://run/podman/podman.sock")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
_, err = images.Pull(conn, "ghcr.io/calaos/calaos_home", nil)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
*/

const (
DefaultConfigFilename = "/etc/calaos-container.toml"

Expand Down
37 changes: 37 additions & 0 deletions models/models.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package models

import (
"context"
"fmt"
"os"

logger "github.com/calaos/calaos-container/log"

"github.com/sirupsen/logrus"

"github.com/containers/podman/v4/pkg/bindings"
"github.com/containers/podman/v4/pkg/bindings/images"
"github.com/coreos/go-systemd/v22/dbus"
)

var (
Expand All @@ -24,3 +32,32 @@ func Init() (err error) {
func Shutdown() {

}

/*
Podman API Docs:
https://pkg.go.dev/github.com/containers/podman/[email protected]/pkg/bindings#section-readme
*/

func Pull(image string) (err error) {
conn, err := bindings.NewConnection(context.Background(), "unix://run/podman/podman.sock")
if err != nil {
fmt.Println(err)
os.Exit(1)
}

_, err = images.Pull(conn, "ghcr.io/calaos/calaos_home", nil)
if err != nil {
fmt.Println(err)
}

return err
}

func StopUnit(unit string) (err error) {
conn, err := dbus.NewWithContext(context.Background())
defer conn.Close()

_, err = conn.StopUnitContext(context.Background(), unit, "replace", nil)

return err
}

0 comments on commit 8606029

Please sign in to comment.