Skip to content

Instantly share code, notes, and snippets.

@agustinmista
Created June 30, 2022 17:50
Show Gist options
  • Select an option

  • Save agustinmista/26c09b128c69c298f98477255c26e64c to your computer and use it in GitHub Desktop.

Select an option

Save agustinmista/26c09b128c69c298f98477255c26e64c to your computer and use it in GitHub Desktop.
Self-installing binaries using Docker
#!/bin/bash
BIN_NAME=alex
USER_NAME=`id -un`
USER_UID=`id -g`
USER_GID=`id -g`
if [[ "$(docker images -q $BIN_NAME 2> /dev/null)" == "" ]]; then
docker build -t $BIN_NAME -f . - <<EOF
FROM haskell:9.0
RUN groupadd --gid $USER_GID $USER_NAME
RUN useradd -m --uid $USER_UID --gid $USER_GID $USER_NAME
USER $USER_NAME
RUN cabal update && \
cabal install $BIN_NAME
ENV PATH /home/$USER_NAME/.cabal/bin:$PATH
WORKDIR "workdir"
ENTRYPOINT ["$BIN_NAME"]
EOF
fi
docker run -it --rm \
-v "$PWD:/home/$USER_NAME/workdir" \
-u $USER_GID \
$BIN_NAME "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment