How to build a repository inside Docker container and copy executable back to host?

I’m working on a Haskell project and I want to build it inside the following Docker container:

This Docker container prepares nice environment for building statically linked Haskell binaries. I want to make use of this container, so I can attach such binaries to GitHub releases of my project. I already know how to build my project with GitHub actions, create binary files, create releases and attach my binaries to releases. But what I want now is to build my Haskell project not on the host machine provided by GitHub Actions, but inside that Docker container.

I’m okay with writing a separate Docker-based action for that (or reuse some existing one if it already exists). What I ultimately want to be able to do in my workflow:

  1. Copy repo inside the ghc-musl Docker container.
  2. Run my custom command inside that container.
  3. Copy executable back to GitHub actions host so I can put it into release.

Is it possible to do so? And if yes, how can I achieve this goal?

I’d say the easiest way would be to mount the repository into the container as a volume, and then run your build command. If the build can be done with just one command (or a simple script) that might work with just one docker run command. That should be pretty easy to do as a Docker-based action if you like, in that case Actions already sets up the mount for you.

Another option would be to use jobs.<job_id>.container to run your whole job inside the ghc-musl container.

1 Like