Add command line flag to override docker image. (#233)

This commit is contained in:
John Burkhardt 2022-09-13 09:04:12 -04:00 committed by GitHub
parent a89ba5a40a
commit 83eeb847ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 2 deletions

View File

@ -41,6 +41,7 @@ func init() {
rootCmd.PersistentFlags().BoolVar(&flags.CI, "ci", false, "CI mode disabled interactive mode and colors and enables verbosity") rootCmd.PersistentFlags().BoolVar(&flags.CI, "ci", false, "CI mode disabled interactive mode and colors and enables verbosity")
rootCmd.PersistentFlags().BoolVarP(&flags.VERBOSE, "verbose", "v", false, "verbose mode") rootCmd.PersistentFlags().BoolVarP(&flags.VERBOSE, "verbose", "v", false, "verbose mode")
rootCmd.PersistentFlags().StringVar(&flags.RESTIC_BIN, "restic-bin", "restic", "specify custom restic binary") rootCmd.PersistentFlags().StringVar(&flags.RESTIC_BIN, "restic-bin", "restic", "specify custom restic binary")
rootCmd.PersistentFlags().StringVar(&flags.DOCKER_IMAGE, "docker-image", "cupcakearmy/autorestic:"+internal.VERSION, "specify a custom docker image")
cobra.OnInitialize(initConfig) cobra.OnInitialize(initConfig)
} }

View File

@ -9,6 +9,7 @@ import (
"strings" "strings"
"github.com/cupcakearmy/autorestic/internal/colors" "github.com/cupcakearmy/autorestic/internal/colors"
"github.com/cupcakearmy/autorestic/internal/flags"
) )
type BackendRest struct { type BackendRest struct {
@ -160,7 +161,6 @@ func (b Backend) ExecDocker(l Location, args []string) (int, string, error) {
args = append([]string{"restic"}, args...) args = append([]string{"restic"}, args...)
docker := []string{ docker := []string{
"run", "--rm", "run", "--rm",
"--pull", "always",
"--entrypoint", "ash", "--entrypoint", "ash",
"--workdir", dir, "--workdir", dir,
"--volume", volume + ":" + dir, "--volume", volume + ":" + dir,
@ -194,6 +194,7 @@ 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, flags.DOCKER_IMAGE, "-c", strings.Join(args, " "))
return ExecuteCommand(options, docker...) return ExecuteCommand(options, docker...)
} }

View File

@ -5,4 +5,5 @@ var (
VERBOSE bool = false VERBOSE bool = false
CRON_LEAN bool = false CRON_LEAN bool = false
RESTIC_BIN string RESTIC_BIN string
DOCKER_IMAGE string
) )