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

mounted file "is a directory" #111

Closed
Globegitter opened this issue Mar 15, 2019 · 8 comments
Closed

mounted file "is a directory" #111

Globegitter opened this issue Mar 15, 2019 · 8 comments

Comments

@Globegitter
Copy link

I am just testing out buildkite running it in google kubernetes engine, following the docs and I am running into issues when wanting to mount in secrets as a file via kubernetes. This is my yaml:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
 name: buildkite-agent
 namespace: ci
spec:
 replicas: 1
 template:
   metadata:
     labels:
       app: buildkite-agent
   spec:
     containers:
       - name: buildkite-agent
         image: buildkite/agent:3
         imagePullPolicy: Always
         securityContext:
           privileged: true
         env:
           - name: BUILDKITE_AGENT_TOKEN
             valueFrom: {secretKeyRef: {name: buildkite-agent, key: token}}
           - name: BUILDKITE_BUILD_PATH
             value: "/home/kubernetes/flexvolume/buildkite/builds"
         volumeMounts:
           - name: docker-binary
             mountPath: /usr/bin/docker
           - name: docker-socket
             mountPath: /var/run/docker.sock
           - name: ssh-keys
             mountPath: /root/.ssh/id_rsa
             subPath: id_rsa
           - name: ssh-keys
             mountPath: /root/.ssh/id_rsa.pub
             subPath: id_rsa.pub
           - name: secrets
             mountPath: /home/kubernetes/flexvolume/secrets
           - name: buildkite-path
             mountPath: /home/kubernetes/flexvolume/buildkite/builds
     volumes:
       - name: docker-binary
         hostPath: {path: /usr/bin/docker}
       - name: docker-socket
         hostPath: {path: /var/run/docker.sock}
       - name: buildkite-path
         hostPath: {path: /home/kubernetes/flexvolume/buildkite/builds}
       - name: ssh-keys
         secret:
           secretName: buildkite-agent-ssh
           defaultMode: 0400
       - name: secrets
         secret:
           secretName: buildkite-agent-secrets
           defaultMode: 0400

Then my pipeline.yml:

steps:
  - label: Build
    command: ls -lah /home/kubernetes/flexvolume/secrets && cat /home/kubernetes/flexvolume/secrets/secrets.libsonnet
    plugins:
      - docker#v3.0.1:
          image: "ecosiadev/bazel-circleci:latest"
          mount-buildkite-agent: false
          propagate-environment: true
          additional-groups: ['root']
          user: 'root'
          volumes:
            - "/home/kubernetes/flexvolume/secrets:/home/kubernetes/flexvolume/secrets"

I can see that the secrets file exists in the first ls but for the cat command I am getting the error cat: /home/kubernetes/flexvolume/secrets/secrets.libsonnet: Is a directory. I can see that the kubernetes pod has the secrets file and I can read it but I have no idea why it is turned into a directory through this volume mount. Could it be in any way related to #61?

@Globegitter
Copy link
Author

I might not need this functionality to work in the long run as we can also provides secrets differently but I still would like to know what is going on and would like to be able to fix this.

@toolmantim
Copy link
Contributor

Sorry you had problems getting this going, and the belated reply. Did you have any luck? It sounds like the best way to diagnose it would be to use a vanilla bash script to run the plain Docker commands via the agent, and see the results.

@Globegitter
Copy link
Author

I worked around the issue for now by passing it in as a base64 encoded environment variable and then decoding and storing it into a file in the command. Not nice but it works for now. Otherwise I had to pause progress one our buildkite ci setup for now, but hope to resume soon again.

@ritvick
Copy link

ritvick commented Feb 24, 2021

This is still and issue
when I try to mount something with
volumes:

  • "/sourcePath/fileName:/destinationPath/fileName"

And later if I use /destinationPath/fileName it says its a directory. It is not recognizing it as a file.

@pzeballos
Copy link
Contributor

Sorry @ritvick for the delay. I did a quick look but couldn't reproduce it, are you still having issues? did you have the issue on kubernetes? Thanks!

@pzeballos
Copy link
Contributor

Hey folks! We did some tests but couldn't reproduce the issue, so I'm closing this. Feel free to re-open this if not. Thanks!

@axsuul
Copy link

axsuul commented May 14, 2024

Hi I am still experiencing this issue. I have a file on Docker container of build agent and attempt to mount it as volume as so:

steps:
  - label: "Test"
    command: "cat /root/.ssh/id_rsa"
    plugins:
      - docker#v5.9.0:
        image: "busybox"
        network: "host"
        volumes:
          - "/root/.ssh/id_rsa:/root/.ssh/id_rsa"

Then will output an error that /root/.ssh/id_rsa is a directory

@toote
Copy link
Contributor

toote commented Aug 14, 2024

I think I was finally able to reproduce this issue: it happens when the source of the volume does not exist. You can even reproduce it without the plugin by running the following:

$ docker run --rm -t -v $HOME/.ssh/doesnotexist:/root/.ssh/id_rsa busybox cat /root/.ssh/id_rsa
cat: read error: Is a directory

Apparently, if the folder for the source exists but not the file, docker will create it as a folder (I could see $HOME/.ssh/doesnotexist existing afterwards in the host machine) and share it as if nothing was wrong 🤦

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants