Dockerfile COPY files to /drone not working

Hi, I have a .drone.yml looking something like this:

pipeline:
  test:
    image: felixmulder/dotty:0.1
    pull: true
    commands:
      - ls -la /drone
      - cp /drone/scala-scala .
      - ./scripts/jobs/validate/junit

The image felixmulder/dotty:0.1 has the following Dockerfile:

FROM 1science/sbt:0.13.8-oracle-jre-8

# Add git to image
RUN apk add --update git

WORKDIR /drone

# Clone the modified standard library for testing, then copy it via the .drone.yml file
RUN git clone -b dotty-library https://github.com/DarkDimius/scala.git scala-scala

# Add ivy2 cache
COPY ivy2/ ivy2

When running and attaching to the dotty image on my machine I can see the directories ivy2 and scala-scala in /drone. But the commands in the .drone.yml file fail because there is nothing (except src) in /drone when the CI is running.

I’m sure I’m missing something obvious as I’m fairly new to both docker and drone.

Cheers,
Felix

The problem is that /drone is a reserved path, by default, for every build. It is the path at which your build workspace (where your code is cloned) is mounted as a volume.

Let’s say we have the following Yaml file:

pipeine:
  build:
    image: golang
    commands:
      - go build
      - go test

The build container is started with a shared volume mounted at /drone. You can think of it like drone running the following docker commands:

docker volume add drone-volume-for-build
docker run --volume=drone-volume-for-buid:/drone golang:latest

The volume mounted at /drone is therefore mounted on top of the /drone directory you created in your dockerfile, which is why it isn’t visible during the build. This can be resolved by using a different cache path in your Dockerfile:

-WORKDIR /drone
-COPY ivy2/ ivy2
+WORKDIR /var/cache/drone
+COPY ivy2/ ivy2

OR this can be resolved by changing the default Drone workspace path for your build. The below example overrides the default workspace to use /code instead of /drone as the base volume.

+workspace:
+ base: /code

pipeine:
  build:
    image: golang
    commands:
      - go build
      - go test

You can read more about the workspace in the 0.5 documentation at http://readme.drone.io/0.5

1 Like

Thanks! Now everything works :smile:

I’m sorry, but I do not understand something here. Are you sharing the file/folder between the docker pipelines ? Is that what you’re achieving ?

the volume is shared between all steps in the same pipeline (it is not shared across pipelines). For a more detailed explanation see https://docs.drone.io/pipeline/docker/syntax/workspace/.