Skip to content

Latest commit

 

History

History
88 lines (66 loc) · 2.83 KB

README.md

File metadata and controls

88 lines (66 loc) · 2.83 KB

docker-cabal-build

This is a base image for building Haskell's Cabal. (And pretty much the rest of the Haskell Platform.)

This image is heavily influenced by nubs/npm-build.

Purpose

This docker image builds on top of Arch Linux's base/archlinux image for the purpose of building projects using Cabal. It provides several key features:

  • A non-root user (build) for executing the image build. This is important for security purposes and to ensure that the package doesn't require root permissions to be built.
  • Access to the build location will be in the volume located at /code. This directory will be the default working directory.
  • The Cabal bin directory is automatically included in PATH using the /home/build/.cabal/bin directory.

Usage

This library is useful with simple .cabals from the command line. For example:

docker run --interactive --tty --rm --volume /tmp/my-code:/code suitupalex/cabal-build

# Using short-options:
docker run -i -t --rm -v /tmp/my-code:/code suitupalex/cabal-build

This will execute the default command (cabal install -j).

Other commands can also be executed. For example, to update dependencies:

docker run -i -t --rm -v /tmp/my-code:/code suitupalex/cabal-build cabal update

Permissions

This image uses a build user to run Cabal. This means that your file permissions must allow this user to write to certain folders inside your project directory. The easiest way to do this is to create a group and give that group write access to the necessary folders.

# To give permissions to the entire project directory, do:
groupadd --gid 11235 cabal-build
chmod -R g+w .
chgrp -R cabal-build .

You may also want to give your user access to files created by the build user.

usermod -a -G 11235 "$(whoami)"

Dockerfile build

Alternatively, you can create your own Dockerfile that builds on top of this image. This allows you to modify the environment by installing additional software needed, altering the commands to run, etc.

A simple one that just installs another package but leaves the rest of the process alone could look like this:

FROM suitupalex/cabal-build

USER root

RUN pacman --sync --noconfirm --noprogressbar --quiet somepackage

USER build

You can then build this docker image and run it against your .cabal volume like normal (this example assumes the .cabal and Dockerfile are in your current directory):

docker build --tag my-code .
docker run -i -t --rm -v "$(pwd):/code" my-code
docker run -i -t --rm -v "$(pwd):/code" my-code cabal update