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.
- drone-yaml: https://github.com/suzuki-shunsuke/drone-yaml/tree/add-CreateCopyHostWorkspace
- drone-runtime: https://github.com/suzuki-shunsuke/drone-runtime/tree/add-copyHostToContainer
- drone-cli: https://github.com/suzuki-shunsuke/drone-cli/tree/add-copy-flag
At dockerEngine.Setup
,
- create the container and mount the empty volume to container’s working directory
- create a tar file from host’s working directory and copy it to container’s working directory
- 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
- Clone https://github.com/suzuki-shunsuke/drone-cli to $GOPATH/src/github.com/drone/drone-ci
- Checkout the branch
add-copy-flag
- 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"
- Run
dep ensure
- Build the binary
go build -o ~/bin/drone drone