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 support for extra mount #271

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion internal/command/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion internal/command/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand Down
17 changes: 14 additions & 3 deletions internal/command/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions internal/command/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
Loading