Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --dry-run for install #16

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 5 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,35 +53,14 @@ $ pq inspect nextcloud
Inspect quadlet "nextcloud"
# Source: https://github.com/rgolangh/podman-quadlets nextcloud/nextcloud-aio-master.container
[Unit]
Description=Nextcloud AIO Master Container
Documentation=https://github.com/nextcloud/all-in-one/blob/main/docker-rootless.md
After=local-fs.target
Requires=podman.socket

[Service]
TimeoutStartSec=900

[Container]
ContainerName=nextcloud-aio-mastercontainer
Image=docker.io/nextcloud/all-in-one:latest
AutoUpdate=registry
PublishPort=127.0.0.1:11001:8080
Volume=nextcloud_aio_mastercontainer:/mnt/docker-aio-config
Volume=/run/user/%U/podman/podman.sock:/var/run/docker.sock:ro
Network=bridge
SecurityLabelDisable=true

Environment=APACHE_PORT=11000
Environment=APACHE_IP_BINDING=127.0.0.1
Environment=WATCHTOWER_DOCKER_SOCKET_PATH=/run/user/%U/podman/podman.sock

[Install]
WantedBy=multi-user.target default.target

...
# Source: https://github.com/rgolangh/podman-quadlets nextcloud/nextcloud-aio-master.volume
[Volume]
VolumeName=nextcloud_aio_mastercontainer
...

$ pq install --dry-run redpanda
---redpanda-network-network.service---
...
```


23 changes: 22 additions & 1 deletion cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
"strings"

Expand All @@ -32,6 +33,7 @@ import (
var (
repoURL string
installed bool
dryRun bool
noSystemdDaemonReload bool
installDir string
)
Expand Down Expand Up @@ -90,14 +92,20 @@ func init() {
"r",
"https://github.com/rgolangh/podman-quadlets",
"The repo url (currently only git support), where the quadlets are stored")
installCmd.Flags().BoolVarP(
&dryRun,
"dry-run",
"",
false,
"Don't install, just output the generated quadlet for dubugging",
)
installCmd.Flags().BoolVarP(
&noSystemdDaemonReload,
"no-systemd-daemon-reload",
"",
false,
"No systemd daemon reloading after installing. Useful for controlling when to reload the deamon",
)

configDir, err := os.UserConfigDir()
if err != nil {
panic(err)
Expand All @@ -117,6 +125,19 @@ func downloadDirectory(repoURL, quadletName, downloadPath string) error {
return fmt.Errorf("failed to clone repository: %v", err)
}

if dryRun {
noSystemdDaemonReload = true
log.Debug("Install Dry Run")
cmd := exec.Command("/usr/lib/systemd/system-generators/podman-system-generator", "--user", "--dryrun")
cmd.Env = append(cmd.Env, "QUADLET_UNIT_DIRS="+filepath.Join(downloadPath, quadletName))
out, err := cmd.Output()
if err != nil {
log.Error(err)
return err
}
fmt.Fprint(os.Stdout, string(out))
return nil
}
err = copyDir(filepath.Join(downloadPath, quadletName), filepath.Join(installDir, quadletName))
if err != nil {
log.Errorf("Error copying the directory %v\n", err)
Expand Down