From d61b602e899cf1981fd0039502d50c3150b42cb3 Mon Sep 17 00:00:00 2001 From: Kevin Dinkel <1225857+dinkelk@users.noreply.github.com> Date: Wed, 24 Jan 2024 08:02:12 -0700 Subject: [PATCH 1/2] adding docker environment for running and building redo --- README.md | 2 ++ docker/Dockerfile | 48 ++++++++++++++++++++++++++++++++++++++ docker/README.md | 32 +++++++++++++++++++++++++ docker/build_image.sh | 7 ++++++ docker/create_container.sh | 17 ++++++++++++++ docker/docker_config.sh | 12 ++++++++++ docker/login_container.sh | 5 ++++ docker/push_image.sh | 4 ++++ docker/remove_container.sh | 5 ++++ docker/start_container.sh | 5 ++++ docker/stop_container.sh | 5 ++++ 11 files changed, 142 insertions(+) create mode 100644 docker/Dockerfile create mode 100644 docker/README.md create mode 100755 docker/build_image.sh create mode 100755 docker/create_container.sh create mode 100755 docker/docker_config.sh create mode 100755 docker/login_container.sh create mode 100755 docker/push_image.sh create mode 100755 docker/remove_container.sh create mode 100755 docker/start_container.sh create mode 100755 docker/stop_container.sh diff --git a/README.md b/README.md index a090027..893e689 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,8 @@ Next, clone this repository and run: in the top level directory. A `bin/` directory will be created with the `redo`, `redo-ifchange`, `redo-ifcreate`, and `redo-always` binaries. Add this `bin/` directory to your path, or copy its contents to a directory on your path, and enjoy! +If you want to try `redo` without compiling, there is a [Dockerfile](docker/) available with `redo` preinstalled. This container also contains the Haskell Stack if you want to make modifications and recompile. + ## Documentation I try to keep this implementation compatible with [Avery Pennarun](https://github.com/apenwarr/redo)'s Python implementation, plus some bug fixes, and extra features documented in `redo -h`. Thus, the best documentation on `redo` that exists is Avery's [documentation](https://redo.readthedocs.io/en/latest/) via readthedocs.org diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..c6a3482 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,48 @@ +# +# This Dockerfile needs to be run from within the project/ directory (AKA ../../ from here) +# so that docker has access to all the files it needs. ie. +# +# $ docker build -t $DOCKER_IMAGE_NAME -f redo/docker/Dockerfile . +# +# For best results use the ./build_image.sh and ./create_container.sh scripts +# provided in this directory. +# +FROM ubuntu:22.04 AS base +LABEL org.opencontainers.image.source=https://github.com/dinkelk/redo +LABEL org.opencontainers.image.description="Development environment for redo" +LABEL org.opencontainers.image.licenses=MIT + +ENV DEBIAN_FRONTEND=noninteractive + +# install common dependencies +RUN DEBIAN_FRONTEND=noninteractive apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -yq install \ + software-properties-common \ + apt-utils \ + locales \ + curl \ + lsb-release \ + sudo \ + python3 \ + git \ + build-essential \ + cmake \ + hlint \ + && DEBIAN_FRONTEND=noninteractive apt-get -yq clean + +# ensure we have the en_US.UTF-8 locale available +RUN locale-gen en_US.UTF-8 +RUN rm /etc/apt/apt.conf.d/docker-clean + +# Install redo: +ENV STACK_ROOT=/root/.stack +RUN DEBIAN_FRONTEND=noninteractive sudo apt-get install -yq wget \ + && wget -qO- https://get.haskellstack.org/ | sh \ + && git config --global core.autocrlf false \ + && git clone https://github.com/dinkelk/redo.git /root/redo \ + && /root/redo/do /root/redo/all + +# Add redo to the root user's path +RUN echo 'export PATH="/root/redo/bin:$PATH"' >> /root/.bashrc + +# Make sure user is root at end. +USER root diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 0000000..21011aa --- /dev/null +++ b/docker/README.md @@ -0,0 +1,32 @@ +# docker + +The Dockerfile in this directory contains an environment with `redo` already installed, if you want to quickly try it out. The container also includes the Haskell Stack, so you can make modifications and recompile `redo` easily. + +To create the container, first install [Docker Desktop](https://www.docker.com/products/docker-desktop/) and run: + + ``` + $ ./create_container.sh + ``` + +Once the container is built, you can log into the container by running. + + ``` + $ ./login_container.sh + ``` + +`redo` will already be included in the build path. + +The container can be started or stopped via: + + ``` + $ ./start_container.sh + $ ./stop_container.sh + ``` + +and recreated from scratch by running: + + ``` + $ ./build_image.sh + ``` + +Enjoy. diff --git a/docker/build_image.sh b/docker/build_image.sh new file mode 100755 index 0000000..fc376d9 --- /dev/null +++ b/docker/build_image.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +. ./docker_config.sh +# Execute the docker machine from the project/ directory so that we have access +cd ../.. +execute "docker build --no-cache --progress=plain -t $DOCKER_IMAGE_NAME -f redo/docker/Dockerfile ." +cd - >/dev/null diff --git a/docker/create_container.sh b/docker/create_container.sh new file mode 100755 index 0000000..a26e4d6 --- /dev/null +++ b/docker/create_container.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +# Create the docker container with a bind mount: +echo "Creating container..." +. ./docker_config.sh + +execute "docker run -d \ + --name $DOCKER_CONTAINER_NAME \ + --mount type=bind,source=\"$(pwd)\"/../..,target=/share \ + $DOCKER_IMAGE_NAME \ + sleep infinity" + +echo "Finished creating container \"$DOCKER_CONTAINER_NAME\"." +execute "docker ps -a" + +echo "" +echo "Run ./login_container.sh to log in." diff --git a/docker/docker_config.sh b/docker/docker_config.sh new file mode 100755 index 0000000..9cd01ce --- /dev/null +++ b/docker/docker_config.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +DOCKER_CONTAINER_NAME="redo_container" +DOCKER_IMAGE_NAME="ghcr.io/dinkelk/redo:latest" +export DOCKER_CONTAINER_NAME +export DOCKER_IMAGE_NAME + +# Helper function to print out command as executed: +execute () { + echo "$ $@" + eval "$@" +} diff --git a/docker/login_container.sh b/docker/login_container.sh new file mode 100755 index 0000000..6fdffcb --- /dev/null +++ b/docker/login_container.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +. ./docker_config.sh + +execute "docker exec -it -u root $DOCKER_CONTAINER_NAME //bin//bash" diff --git a/docker/push_image.sh b/docker/push_image.sh new file mode 100755 index 0000000..057e379 --- /dev/null +++ b/docker/push_image.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +. ./docker_config.sh +execute "docker push $DOCKER_IMAGE_NAME" diff --git a/docker/remove_container.sh b/docker/remove_container.sh new file mode 100755 index 0000000..1fef816 --- /dev/null +++ b/docker/remove_container.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +. ./docker_config.sh +execute "docker rm $DOCKER_CONTAINER_NAME" +execute "docker ps -a" diff --git a/docker/start_container.sh b/docker/start_container.sh new file mode 100755 index 0000000..534dd65 --- /dev/null +++ b/docker/start_container.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +. ./docker_config.sh +execute "docker start $DOCKER_CONTAINER_NAME" +execute "docker ps -a" diff --git a/docker/stop_container.sh b/docker/stop_container.sh new file mode 100755 index 0000000..c72a575 --- /dev/null +++ b/docker/stop_container.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +. ./docker_config.sh +execute "docker stop $DOCKER_CONTAINER_NAME" +execute "docker ps -a" From 7efe714fca6a66c08efeabf8536bb206173cb814 Mon Sep 17 00:00:00 2001 From: Kevin Dinkel <1225857+dinkelk@users.noreply.github.com> Date: Wed, 24 Jan 2024 08:07:36 -0700 Subject: [PATCH 2/2] updating docker readme --- docker/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker/README.md b/docker/README.md index 21011aa..f73766f 100644 --- a/docker/README.md +++ b/docker/README.md @@ -1,8 +1,8 @@ # docker -The Dockerfile in this directory contains an environment with `redo` already installed, if you want to quickly try it out. The container also includes the Haskell Stack, so you can make modifications and recompile `redo` easily. +The Dockerfile in this directory contains an environment with `redo` already installed, if you want to quickly try it out. The container also includes the [Haskell Tool Stack](https://docs.haskellstack.org/en/stable/install_and_upgrade/), so you can make modifications and recompile `redo` easily. -To create the container, first install [Docker Desktop](https://www.docker.com/products/docker-desktop/) and run: +To create the container, first install [Docker Desktop](https://www.docker.com/products/docker-desktop/), then run: ``` $ ./create_container.sh @@ -23,7 +23,7 @@ The container can be started or stopped via: $ ./stop_container.sh ``` -and recreated from scratch by running: +and the image can be recreated from scratch by running: ``` $ ./build_image.sh