Proposal: add the flag to `drone exec` command to copy host's current directory to the docker volume instead of mounting the host's current directory

Overview

drone exec command mounts the host’s current directory to containers as the working directory,
so host files may be changed.

On the other hand, circleci local execute doesn’t change them.

For detail, please see https://github.com/suzuki-shunsuke/verification-drone-exec-and-circleci-local-execute .

Change of host’s files may be danger so I propose to add the flag to copy host’s current directory to the Docker volume instead of mounting the host’s current directory.

We shouldn’t change the default behavior because of the backward compatibility and performance.

Specification

We add the flag “copy” to the drone exec command.
Both “clone” and “copy” flags can’t be used at the same time.

When the flag is true, instead of mounting the host’s current directory to the Docker volume,
create the empty volume and copy files in the host’s current directory and bind the volume to containers.

Prototype

I have implemented a prototype and confirmed it works well on macOS High Sierra 10.13.6.

At dockerEngine.Setup,

  1. create the container and mount the empty volume to container’s working directory
  2. create a tar file from host’s working directory and copy it to container’s working directory
  3. clean up the container and tar file
$ cat .drone.yml
---
kind: pipeline
name: default
steps:
- name: create file
  image: busybox
  commands:
  - pwd
  - ls -lAh
  - echo foo > foo.txt

$ ls -A
.circleci  .drone.yml  .git  LICENSE  README.md

$ time drone exec --copy
[create file:0] + pwd
[create file:1] /drone/src
[create file:2] + ls -lAh
[create file:3] total 20K
[create file:4] drwxr-xr-x    2 502      20          4.0K Apr 28 00:47 .circleci
[create file:5] -rw-r--r--    1 502      20           132 Apr 28 08:50 .drone.yml
[create file:6] drwxr-xr-x    7 502      20          4.0K Apr 28 11:18 .git
[create file:7] -rw-r--r--    1 502      20          1.0K Apr 28 00:46 LICENSE
[create file:8] -rw-r--r--    1 502      20          2.4K Apr 28 00:50 README.md
[create file:9] + echo foo > foo.txt
../../drone/drone-cli/drone-cli exec --copy  0.03s user 0.03s system 1% cpu 5.924 total

$ ls -A
.circleci  .drone.yml  .git  LICENSE  README.md

$ time drone exec
[create file:0] + pwd
[create file:1] /drone/src
[create file:2] + ls -lAh
[create file:3] total 12K
[create file:4] drwxr-xr-x    3 root     root          96 Apr 28 00:47 .circleci
[create file:5] -rw-r--r--    1 root     root         132 Apr 28 08:50 .drone.yml
[create file:6] drwxr-xr-x   14 root     root         448 Apr 28 11:20 .git
[create file:7] -rw-r--r--    1 root     root        1.0K Apr 28 00:46 LICENSE
[create file:8] -rw-r--r--    1 root     root        2.4K Apr 28 00:50 README.md
[create file:9] + echo foo > foo.txt
../../drone/drone-cli/drone-cli exec  0.02s user 0.01s system 0% cpu 5.183 total

# foo.txt is created
$ ls -A
.circleci  .drone.yml  .git  LICENSE  README.md  foo.txt

How to build the prototype

  1. Clone https://github.com/suzuki-shunsuke/drone-cli to $GOPATH/src/github.com/drone/drone-ci
  2. Checkout the branch add-copy-flag
  3. Edit Gopkg.toml
[[constraint]]
  name = "github.com/drone/drone-runtime"
  source = "github.com/suzuki-shunsuke/drone-runtime"
  branch = "add-copyHostToContainer"

[[constraint]]
  name = "github.com/drone/drone-yaml"
  source = "github.com/suzuki-shunsuke/drone-yaml"
  branch = "add-CreateCopyHostWorkspace"
  1. Run dep ensure
  2. Build the binary go build -o ~/bin/drone drone

Oh, sorry.
The prototype doesn’t wok well.
I’ll check.

I have fixed the bug.

I have sent the following pull requests.

I have create the issue to discuss this feature.