diff --git a/pkg/container/container.go b/pkg/container/container.go index b85e0587..eb62a394 100644 --- a/pkg/container/container.go +++ b/pkg/container/container.go @@ -10,6 +10,7 @@ import ( "strings" "syscall" + "github.com/google/uuid" "github.com/lxc/go-lxc" "github.com/pkg/errors" embed_exec "stackerbuild.io/stacker/pkg/embed-exec" @@ -36,7 +37,8 @@ func New(sc types.StackerConfig, name string) (*Container, error) { return nil, errors.WithStack(err) } - lxcC, err := lxc.NewContainer(name, sc.RootFSDir) + uniqname := fmt.Sprintf("%s-%s", name, uuid.NewString()) + lxcC, err := lxc.NewContainer(uniqname, sc.RootFSDir) if err != nil { return nil, err } diff --git a/test/concurrent.bats b/test/concurrent.bats new file mode 100644 index 00000000..58e2d5d4 --- /dev/null +++ b/test/concurrent.bats @@ -0,0 +1,37 @@ +load helpers + +function setup() { + stacker_setup +} + +function teardown() { + cleanup +} + +@test "concurrent w aliased rootdir" { + cat > stacker.yaml <<"EOF" +robertos: + from: + type: oci + url: ${{BUSYBOX_OCI}} + run: | + sleep ${{SNOOZ}} # make sure they have time to conflict +EOF + + mkdir -p 1/roots 1/stacker 2/roots 2/stacker aliased-rootsdir + chmod -R 777 1 2 + + # simulate shared CI infra where name of sandbox dir is same despite backing store being different + + mount --bind 1/roots aliased-rootsdir + ${ROOT_DIR}/stacker --debug --roots-dir=aliased-rootsdir --stacker-dir=1/stacker --oci-dir=1/oci --log-file=1.log build --substitute BUSYBOX_OCI=${BUSYBOX_OCI} --substitute SNOOZ=15 & + + sleep 5 + + unshare -m bash <