Use restic version of host system in Docker container

pull/230/head
Christoph Loy 2 years ago
parent 6990bf6adc
commit b11e4a2875

@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"net/url" "net/url"
"os" "os"
"os/exec"
"strings" "strings"
"github.com/cupcakearmy/autorestic/internal/colors" "github.com/cupcakearmy/autorestic/internal/colors"
@ -169,6 +170,11 @@ func (b Backend) ExecDocker(l Location, args []string) (int, string, error) {
if hostname, err := os.Hostname(); err == nil { if hostname, err := os.Hostname(); err == nil {
docker = append(docker, "--hostname", hostname) docker = append(docker, "--hostname", hostname)
} }
resticPath, err := GetResticPath()
if err != nil {
return -1, "", err
}
docker = append(docker, "--volume", resticPath+":/usr/bin/restic:ro")
switch b.Type { switch b.Type {
case "local": case "local":
actual := env["RESTIC_REPOSITORY"] actual := env["RESTIC_REPOSITORY"]
@ -180,6 +186,9 @@ func (b Backend) ExecDocker(l Location, args []string) (int, string, error) {
case "gs": case "gs":
// No additional setup needed // No additional setup needed
case "rclone": case "rclone":
if rclonePath, err := exec.LookPath("rclone"); err == nil {
docker = append(docker, "--volume", rclonePath+":/usr/bin/rclone:ro")
}
// Read host rclone config and mount it into the container // Read host rclone config and mount it into the container
code, configFile, err := ExecuteCommand(ExecuteOptions{Command: "rclone"}, "config", "file") code, configFile, err := ExecuteCommand(ExecuteOptions{Command: "rclone"}, "config", "file")
if err != nil { if err != nil {
@ -194,6 +203,6 @@ func (b Backend) ExecDocker(l Location, args []string) (int, string, error) {
for key, value := range env { for key, value := range env {
docker = append(docker, "--env", key+"="+value) docker = append(docker, "--env", key+"="+value)
} }
docker = append(docker, "cupcakearmy/autorestic:"+VERSION, "-c", strings.Join(args, " ")) docker = append(docker, "alpine:3", "-c", strings.Join(args, " "))
return ExecuteCommand(options, docker...) return ExecuteCommand(options, docker...)
} }

@ -21,6 +21,10 @@ func CheckIfResticIsCallable() bool {
return CheckIfCommandIsCallable(flags.RESTIC_BIN) return CheckIfCommandIsCallable(flags.RESTIC_BIN)
} }
func GetResticPath() (result string, err error) {
return exec.LookPath(flags.RESTIC_BIN)
}
type ExecuteOptions struct { type ExecuteOptions struct {
Command string Command string
Envs map[string]string Envs map[string]string

Loading…
Cancel
Save