How to create a Docker container GitHub Action to provide executable for the main workflow?

Hi GitHub Actions community :wave:

I want to implement my own Docker GitHub Action that should provide an executable called my-tool which I can use in my workflows. Ideally, I want to be able to write the following config in my workflow:

- name: Setup My Tool
  uses: actions/my-tool@v1
- name: Run My Tool
  run: my-tool --option1 --option2 arg1 arg2

My custom action that provides my-tool is responsible for creating the my-tool executable (either by downloading it or building from sources). And I want my action to make this executable available within the rest of my workflow. However, I can’t find any way to copy my executable from the docker container back to the host that runs my action.

Alternatively, I can transfer some files to the image instead of copying my executable back to the host. But I also can’t find a way to do that. The upload-artifact action doesn’t provide a link to an asset which I can use via curl from inside the container. More details here:

So I’m curious, what is the simplest (or even possible) way to transfer data between the main workflow and the Docker container action?

Hi @chshersh,

Glad to see you in Github Community Forum!

To transfer files from repository to image, you can use COPY command in action Dockerfile.

COPY file.ext /file.ext     # Copy file.ext from repository to container image.

Regarding the artifacts link, you can get it via rest api, parse the url from the result.

Please be aware that you cannot get the artifacts info before the workflow complete. You have to send out the runnerid(for example:in payload of actions peter-evans/repository-dispatch@v1) and get it from another workflow, then you can use the rest api to get the artifacts url.


1 Like

The workspace directory gets mounted into the action container, so you could just drop the executable there. A bit inconvenient because it won’t be in the PATH that way, but it’d be available.

Other than that you might want to look at the existing setup actions (e.g. setup-python) for examples, but those are Javascript actions, not Docker actions, presumably specifically because Docker actions can’t modify the host installation.

1 Like

Thanks @weide-zhou! Unfortunately, the COPY command doesn’t work in my case. I want to copy files which are created as a result of other commands running during the workflow. But according to the action log, the Dockerfile is built before all steps, not in the place where I actually call this action. That’s why I’m thinking of some dynamic way to transfer files to Docker image.

Regarding copying files back from Docker image, I could use the docker cp command to copy files from container back to host, but for this I need to the Docker image name. I can’t find a way to know the image name…

Hi @chshersh,

Thanks for your reply!

Is it possible to use container id instead of name? Which i find in this ticket, use below code to get the id in docker file.

basename $(cat /proc/1/cpuset)

and same value can be got from /proc/self/cgroup.

Checked in my workflow here.