Removed docker.sh and added new docker related files into docker folder (#535)

* Removed docker.sh and added new docker related files into docker folder
This commit is contained in:
ps 2018-06-25 11:43:59 +02:00 committed by xarkes
parent 400a2c184d
commit 4c3320838f
7 changed files with 156 additions and 115 deletions

1
.gitignore vendored
View File

@ -30,7 +30,6 @@ moc_*.cpp
qrc_*.cpp qrc_*.cpp
moc_*.h moc_*.h
ui_*.h ui_*.h
Makefile*
build* build*
cmake-build-* cmake-build-*

View File

@ -68,6 +68,10 @@ If any of those do not work, check the more detailed version [here](https://gith
Check this [page](https://github.com/radareorg/cutter/blob/master/docs/Common-errors.md) for common issues. Check this [page](https://github.com/radareorg/cutter/blob/master/docs/Common-errors.md) for common issues.
### Docker
To deploy *cutter* using a pre-built `Dockerfile`, it's possible to use the [provided configuration](docker). The corresponding `README.md` file also contains instructions on how to get started using the docker image with minimal effort.
## Keyboard shortcuts ## Keyboard shortcuts
| Shortcut | Function | | Shortcut | Function |

112
docker.sh
View File

@ -1,112 +0,0 @@
#!/bin/sh
docker build \
--build-arg uid=$(id -u) --build-arg gid=$(id -g) \
-t r2cutter \
- <<\#\#\ DOCKERFILE\ END\ \#\# \
|| exit 1
######################
## DOCKERFILE START ##
######################
# A lighter debian distribution should be used
FROM ubuntu:xenial
# www.github.com/danielhenrymantilla
MAINTAINER daniel.henry.mantilla@gmail.com
# Dependencies
RUN apt-get update
RUN apt-get install -y build-essential
RUN apt-get install -y git nano wget
RUN apt-get install -y libdbus-1-3 libx11-xcb1
RUN apt-get install -y libdrm-common libdrm-dev libgl1-mesa-dev pkg-config libsm6
RUN apt-get install -y libfontconfig1-dev libfreetype6-dev libx11-dev libxext-dev libxfixes-dev libxi-dev libxrender-dev libxcb1-dev libx11-xcb-dev libxcb-glx0-dev libxcb-keysyms1-dev libxcb-image0-dev libxcb-shm0-dev libxcb-icccm4-dev libxcb-sync0-dev libxcb-xfixes0-dev libxcb-shape0-dev libxcb-randr0-dev libxcb-render-util0-dev
RUN rm -rf /var/cache/apt/
ENV QT_XKB_CONFIG_ROOT=/usr/share/X11/xkb
# Using benlau's qtci tool to headless-ly install QT 5.9.1
RUN git clone https://github.com/benlau/qtci /tmp/qtci
ENV PATH="/tmp/qtci/bin:/tmp/qtci/recipes:$PATH"
# Download the QT 5.9.1 installer (1G) and check its md5sum
WORKDIR /tmp/qtci/recipes/
RUN echo "Downloading Qt..." && wget https://download.qt.io/archive/qt/5.9/5.9.1/qt-opensource-linux-x64-5.9.1.run && echo "Downloaded. Checking md5sum..." && ([ "b8dd904894ac6b09076b5f61d8b9d71a" = "$(md5sum qt-opensource-linux-x64-5.9.1.run | cut -d\ -f1)" ] || (echo "Error: MD5 checksum mismatch"; false)) && echo "QT installer downloaded successfully"
# Install QT 5.9.1
ENV QT_CI_PACKAGES=qt.591.gcc_64
RUN sync && extract-qt-installer "qt-opensource-linux-x64-5.9.1.run" /opt/Qt
RUN rm "qt-opensource-linux-x64-5.9.1.run"
RUN find /opt/Qt/5.9.1/gcc_64/bin -type f -executable -exec ln -s {} /usr/bin \;
# Download r2 and cutter
RUN git clone --recurse-submodules https://github.com/radareorg/cutter /tmp/cutter
WORKDIR /tmp/cutter
# Compilation & Installation
RUN sed -i -e 's/#QMAKE_CONF/QMAKE_CONF/' build.sh
RUN printf "\n" | ./build.sh
RUN make -C build clean
RUN ln -s /tmp/cutter/build/Cutter /usr/bin/r2cutter
#### Creating guest's user ####
# Use '--build-arg uid=$(id -u)' and '--build-arg gid=$(id -g)' at build time
# to match the guest's uid and gid with the host's
ARG uid=1000
ARG gid=1000
RUN echo "Got uid = ${uid} and gid = ${gid}"
RUN mkdir -p /home/reverser && \
mkdir -p /etc/sudoers.d && \
echo "reverser:x:${uid}:${gid}:Reverser,,,:/home/reverser:/bin/bash" >> /etc/passwd && \
echo "reverser:x:${uid}:" >> /etc/group && \
echo "reverser ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/reverser && \
chmod 0440 /etc/sudoers.d/reverser && \
chown ${uid}:${gid} -R /home/reverser
USER reverser
ENV HOME="/home/reverser"
# Entrypoint
WORKDIR /home/reverser
CMD r2cutter 2>/dev/null
####################
## DOCKERFILE END ##
####################
############
## X auth ##
XSOCK=/tmp/.X11-unix
XAUTH=$(mktemp /tmp/r2cutter_tmp.XXX.xauth)
touch $XAUTH
xauth nlist $DISPLAY | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge -
############
####################
## RUN DOCKER CMD ##
if [ -z "$1" ]; then
docker run -ti --rm \
-e DISPLAY \
-u reverser \
-v $XSOCK:$XSOCK:rw \
-v $XAUTH:/home/reverser/.Xauthority:rw \
-v ~/.r2cutter_docker_config:/home/reverser/.config \
r2cutter
else # Arg $1 may be mounted (read-only) to the docker
BINARY="$(echo "$1" | sed -e "s/^\.\//$(pwd | sed -e 's/\//\\\//g')\//")"
R2BINARY="$(basename "$1")"
docker run -ti --rm \
-e DISPLAY \
-u reverser \
-v $XSOCK:$XSOCK:rw \
-v $XAUTH:/home/reverser/.Xauthority:rw \
-v ~/.r2cutter_docker_config:/home/reverser/.config \
"-v${BINARY}:/home/reverser/${R2BINARY}:ro" \
r2cutter \
sh -c "r2cutter \"${R2BINARY}\" 2>/dev/null"
fi
####################
##############
## Cleanup ###
rm -f $XAUTH #
##############

8
docker/.travis.yml Normal file
View File

@ -0,0 +1,8 @@
sudo: required
services:
- docker
script:
- docker build -t radare/cutter .
- docker images

65
docker/Dockerfile Normal file
View File

@ -0,0 +1,65 @@
FROM ubuntu:rolling
LABEL maintainer "pschmied <ps1337@mailbox.org>"
# Dependencies
RUN apt-get update && \
apt-get -y install \
curl \
libqt5svg5-dev \
make \
qtbase5-dev \
qtwebengine5-dev \
unzip \
wget \
cmake \
g++ \
gcc \
git-core \
python3 \
python3-dev \
pkg-config
# Get latest cutter release
WORKDIR /opt
RUN curl https://api.github.com/repos/radareorg/cutter/releases/latest | \
grep "zipball_url" | \
tr -d ",\" " | \
cut -d ":" -f 2,3 | \
wget -O cutter.zip -i - && \
unzip cutter.zip && \
rm cutter.zip && \
mv radareorg-cutter* cutter
# Get latest radare2 release and build it
WORKDIR /opt/cutter
RUN rm -rf radare2 && \
curl https://api.github.com/repos/radare/radare2/releases/latest | \
grep "zipball_url" | \
tr -d ",\" " | \
cut -d ":" -f 2,3 | \
wget -O radare2.zip -i - && \
unzip radare2.zip && \
rm radare2.zip && \
mv radare-radare2* radare2
RUN cd radare2 && ./sys/install.sh
# Build cutter
RUN mkdir build
WORKDIR /opt/cutter/build
RUN cmake ../src
RUN make
# Add r2 user
RUN useradd r2
WORKDIR /home/r2
RUN mkdir /var/sharedFolder
RUN mkdir -p /home/r2/.config/radare2
RUN touch /home/r2/.radare2rc
RUN chown -R r2:r2 /var/sharedFolder
RUN chown -R r2:r2 /home/r2/
USER r2
ENTRYPOINT ["/bin/bash", "-c", "/opt/cutter/build/cutter"]

53
docker/Makefile Normal file
View File

@ -0,0 +1,53 @@
SHELL := /bin/bash
# The directory of this file
DIR := $(shell echo $(shell cd "$(shell dirname "${BASH_SOURCE[0]}" )" && pwd ))
VERSION ?= latest
IMAGE_NAME ?= radare/cutter
CONTAINER_NAME ?= cutter
# This will output the help for each task
# thanks to https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
.PHONY: help
help: ## This help
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
.DEFAULT_GOAL := help
# DOCKER TASKS
# Build the container
build: ## Build the container
sudo docker build --rm -t $(IMAGE_NAME) .
build-nc: ## Build the container without caching
sudo docker build --rm --no-cache -t $(IMAGE_NAME) .
run: ## Run container
touch $(DIR)/radare2rc && \
mkdir -p $(DIR)/r2-config && \
mkdir -p $(DIR)/sharedFolder && \
xhost +local:root && \
sudo docker run \
-it \
--name $(CONTAINER_NAME) \
--cap-drop=ALL \
--cap-add=SYS_PTRACE \
-e DISPLAY=$$DISPLAY \
-v /tmp/.X11-unix:/tmp/.X11-unix:ro \
-v $(DIR)/sharedFolder:/var/sharedFolder \
-v $(DIR)/radare2rc:/home/r2/.radare2rc \
-v $(DIR)/r2-config:/home/r2/.config/radare2 \
$(IMAGE_NAME):$(VERSION)
stop: ## Stop a running container
sudo docker stop $(CONTAINER_NAME)
remove: ## Remove a (running) container
sudo docker rm -f $(CONTAINER_NAME)
remove-image-force: ## Remove the latest image (forced)
sudo docker rmi -f $(IMAGE_NAME):$(VERSION)

24
docker/README.md Normal file
View File

@ -0,0 +1,24 @@
# Docker Configuration for Cutter
These files provide an easy way to deploy *cutter* in a docker container.
You can use the pre-built image like:
```
touch $PWD/radare2rc && \
mkdir -p $PWD/r2-config && \
mkdir -p $PWD/sharedFolder && \
xhost +local:root && \
sudo docker run \
-it \
--name cutter \
--cap-drop=ALL \
--cap-add=SYS_PTRACE \
-e DISPLAY=$DISPLAY \
-v /tmp/.X11-unix:/tmp/.X11-unix:ro \
-v $PWD/sharedFolder:/var/sharedFolder \
-v $PWD/radare2rc:/home/r2/.radare2rc \
-v $PWD/r2-config:/home/r2/.config/radare2 \
radare/cutter:latest
```
or by using the `Makefile` (after additional configuration to make it fit your needs) by executing `make build` and `make run`.