Docker action persistence not working as expected

I have a docker action that is copying data into $HOME

# Install to github .m2
mkdir -p $HOME/.m2/repository
echo "Copying from /root/.m2/repository to $HOME/.m2/repository"
cp -a /root/.m2/repository/. $HOME/.m2/repository

However when I add

- run: ls -lah $HOME/.m2

to my workflow, the repository directory is not found. Why is this not being persisted, and what are the workarounds?

@derongan ,

I tested and tried the commands mkdir , ls and cp on my repository like as below:

    name: Test
    runs-on: ubuntu-latest
      - name: Checkout
        uses: actions/checkout@v2

      - name: Create directory
        run: |
          echo "run mkdir -p $HOME/.m2/repository"
          mkdir -p $HOME/.m2/repository
          echo " ********************************ls in #HOME********************************"
          echo $HOME
          ls -lah $HOME
          echo " ******************************ls in $HOME/.m2******************************"
          ls -lah $HOME/.m2
      - name: Copy files
        run: |
          echo "run cp -a TestClock/. $HOME/.m2/repository"
          cp -a TestClock/. $HOME/.m2/repository
          echo " ******************************ls in $HOME/.m2******************************"
          ls -lah $HOME/.m2
          echo " *************************ls in $HOME/.m2/repository*************************"
          ls -lah $HOME/.m2/repository

and this is the result:

You can see I run the ls command after using mkdir command to create the directory and after using cp command to copy files. Looks like all the commands can work fine on my side, and did not occur the problem as you reported.

Maybe you also can try the steps like as that in my example, to check whether the directory  $HOME/.m2/repository is really created successfully after execute the mkdir command. And also after copying the files.

And if possible, please also share your repository with us, so that we can check the complete configurations of your workflow and the detailed debug logs of the workflow run to analyze the root cause.

1 Like

@derongan ,

How are things going? Is my suggestions in the previous reply helpful to your?

Let me add some more points here:

  1. If you execute these commands on a Docker container (or a Docker container action), when building and running the container, it will automatically mount volumes on the container to share files between the runner machine. From the logs of the workflow run, you can see the command line like as below example:

    /usr/bin/docker run … -v “/home/runner/work/_temp/_github_home”:"/github/home" -v “/home/runner/work/_temp/_github_workflow”:"/github/workflow" -v “/home/runner/work/TestClock/TestClock”:"/github/workspace" …

This means files updated will be synced between the mounted volumes. For example update files in the directory " /github/home" on the container will be synced to the directory " /home/runner/work/_temp/_github_home" on the runner machine.

  1. On the container , the $HOME is the directory " /github/home", if run the mkdir command on the container ( mkdir -p $HOME/.m2/repository ), it will generate the directory " /github/home/.m2/repository",and also sync to the runner machine to generate the directory " /home/runner/work/_temp/_github_home/.m2/repository". However, on the runner machine , the $HOME is the directory " /home/runner".

According to the above points, if you execute the command " mkdir -p $HOME/.m2/repository" in your Docker container action, and then execute the command " ls -lah $HOME/.m2" in another step which runs on the runner machine, not on the container, you will definitely get the “directory not found"error. You should view the file list in the directory " /home/runner/work/_temp/_github_home” on runner machine, instead of in $HOME.

Hope this reply can help you.



I have not had a chance to play around yet with your solution. I am still playing around with a number of things with actions, but will get to this once I figure those out. Thanks!

@derongan ,

All right, if you have any progress, feel free to tell me.

However, as I mentioned in my second reply, I think the reason causes the problem you are facing is that you created directory with the $HOME on the container but when viewing file list you used the $ HOME on the runner machine. Because the environment variable  $HOME  on the container and on the runner machine points to different directories.

1 Like

This is great information for test reports. Thank you for this!!!