Skip to content

Commit

Permalink
Merge pull request #2 from dinkelk/dockerfile
Browse files Browse the repository at this point in the history
adding docker environment for running and building redo
  • Loading branch information
dinkelk authored Jan 24, 2024
2 parents 0bb68d8 + 7efe714 commit cf5e9aa
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 48 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -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 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/), then 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 the image can be recreated from scratch by running:

```
$ ./build_image.sh
```

Enjoy.
7 changes: 7 additions & 0 deletions docker/build_image.sh
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions docker/create_container.sh
Original file line number Diff line number Diff line change
@@ -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."
12 changes: 12 additions & 0 deletions docker/docker_config.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"
}
5 changes: 5 additions & 0 deletions docker/login_container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

. ./docker_config.sh

execute "docker exec -it -u root $DOCKER_CONTAINER_NAME //bin//bash"
4 changes: 4 additions & 0 deletions docker/push_image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

. ./docker_config.sh
execute "docker push $DOCKER_IMAGE_NAME"
5 changes: 5 additions & 0 deletions docker/remove_container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

. ./docker_config.sh
execute "docker rm $DOCKER_CONTAINER_NAME"
execute "docker ps -a"
5 changes: 5 additions & 0 deletions docker/start_container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

. ./docker_config.sh
execute "docker start $DOCKER_CONTAINER_NAME"
execute "docker ps -a"
5 changes: 5 additions & 0 deletions docker/stop_container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

. ./docker_config.sh
execute "docker stop $DOCKER_CONTAINER_NAME"
execute "docker ps -a"

0 comments on commit cf5e9aa

Please sign in to comment.