diff --git a/internal/command/container.go b/internal/command/container.go index 6d300cf..0eb0578 100644 --- a/internal/command/container.go +++ b/internal/command/container.go @@ -24,7 +24,8 @@ type baseEngine struct { env map[string]string // Env is the list of custom env variable to set. Specified as "KEY=VALUE" tags []string // Tags defines the tags to use - vol volume.Volume + vol volume.Volume + extraMount string } type containerImage interface { diff --git a/internal/command/context.go b/internal/command/context.go index 484e3b8..61001c0 100644 --- a/internal/command/context.go +++ b/internal/command/context.go @@ -62,7 +62,7 @@ type Context struct { NoProjectUpload bool // NoProjectUpload if true, the build will be done with the artifact already stored on S3 NoResultDownload bool // NoResultDownload if true, the result of the build will be left on S3 and not downloaded locally NoNetwork bool // NoNetwork if true, the build will be done without network access - + ExtraMount string //ExtraMount if is set, mount this directories Ex: FROM|TO,FROM2|TO2 //Build context BuildMode string // The -buildmode argument to pass to go build @@ -149,6 +149,7 @@ func makeDefaultContext(flags *CommonFlags, args []string) (Context, error) { Volume: vol, Pull: flags.Pull, Release: flags.Release, + ExtraMount: flags.ExtraMount, } if flags.AppBuild <= 0 { diff --git a/internal/command/docker.go b/internal/command/docker.go index 8fb6865..0df5d10 100644 --- a/internal/command/docker.go +++ b/internal/command/docker.go @@ -33,9 +33,10 @@ type localContainerEngine struct { func newLocalContainerEngine(context Context) (containerEngine, error) { return &localContainerEngine{ baseEngine: baseEngine{ - env: context.Env, - tags: context.Tags, - vol: context.Volume, + env: context.Env, + tags: context.Tags, + vol: context.Volume, + extraMount: context.ExtraMount, }, engine: &context.Engine, pull: context.Pull, @@ -113,6 +114,16 @@ func (i *localContainerImage) cmd(vol volume.Volume, opts options, cmdArgs []str args = append(args, "-v", fmt.Sprintf(mountFormat, mountPoint.localHost, mountPoint.inContainer)) } + //Apply extra mount if is set. + if i.runner.baseEngine.extraMount != "" { + paths := strings.Split(i.runner.baseEngine.extraMount, ",") + + for _, m := range paths { + parts := strings.Split(m, ":") + args = append(args, "-v", fmt.Sprintf(mountFormat, parts[0], parts[1])) + } + } + arch := "amd64" if runtime.GOARCH == "arm64" && (runtime.GOOS != "darwin" || i.os != "android") { // If we are running on arm64, we should have arm64 image to avoid using emulation diff --git a/internal/command/flag.go b/internal/command/flag.go index 41aa8dc..646d619 100644 --- a/internal/command/flag.go +++ b/internal/command/flag.go @@ -71,6 +71,8 @@ type CommonFlags struct { Pull bool // DockerRegistry changes the pull/push docker registry (defualt docker.io) DockerRegistry string + //Extra mount + ExtraMount string } // newCommonFlags defines all the flags for the shared options @@ -136,6 +138,7 @@ func newCommonFlags() (*CommonFlags, error) { flagSet.BoolVar(&flags.Pull, "pull", false, "Attempt to pull a newer version of the docker image") flagSet.StringVar(&flags.DockerRegistry, "docker-registry", "docker.io", "The docker registry to be used instead of dockerhub (only used with defualt docker images)") flagSet.BoolVar(&flags.NoNetwork, "no-network", false, "If set, the build will be done without network access") + flagSet.StringVar(&flags.ExtraMount, "extra-mount", "", "If set, mount extra volumes on docker") return flags, nil }