From ec75e3d081efe863cdd75262cac8fae1f4e0cce6 Mon Sep 17 00:00:00 2001 From: Michael Rodler Date: Fri, 20 Apr 2018 15:21:06 +0200 Subject: [PATCH] Updated Dockerfiles, added script to quickly run manage-tools in a container for testing * Dockerfile updates * Ubuntus now use apt-get-install wrapper to not leave package lists in the container * Copy uncommited manage-tools, etc. scripts into container, which is good for manual testing. * Remove dependency on virtualenvwrapper for Ubuntus and Fedora * `ctf-tools-test-action` to quickly test something for another distribution in a docker container, e.g. `ctf-tools-test-action -d fedora -s -v reinstall qemu` --- .docker/apt-get-install | 13 +++++++++++++ .dockerignore | 2 ++ Dockerfile | 33 +++++++++++++++++++++---------- Dockerfile.archlinux | 10 ++++++++++ Dockerfile.artful | 38 ++++++++++++++++++++++++++++++++++++ Dockerfile.fedora | 12 +++++++++++- Dockerfile.xenial | 31 ++++++++++++++++++++--------- bin/ctf-tools-test-action | 41 +++++++++++++++++++++++++++++++++++++++ 8 files changed, 160 insertions(+), 20 deletions(-) create mode 100755 .docker/apt-get-install create mode 100644 Dockerfile.artful create mode 100755 bin/ctf-tools-test-action diff --git a/.docker/apt-get-install b/.docker/apt-get-install new file mode 100755 index 0000000..1059d5f --- /dev/null +++ b/.docker/apt-get-install @@ -0,0 +1,13 @@ +#!/bin/sh -e +export DEBIAN_FRONTEND="noninteractive" +# update the package lists etc. +apt-get -q update +# this is actually against docker recommendations... But we'll do it anyway in +# case our base image was not yet updated. +apt-get dist-upgrade -y --no-install-recommends --auto-remove +# finally install the package +apt-get install -y --no-install-recommends --auto-remove "$@" +# remove the package lists and apt-get metadata, such that the docker image +# layer stays small +apt-get -q clean +rm -rf /var/lib/apt/lists/* diff --git a/.dockerignore b/.dockerignore index ab507cc..cf77dd3 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,4 @@ * !.git +!.docker +!bin/ diff --git a/Dockerfile b/Dockerfile index ee2cfb5..5f3d19f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,38 @@ -from ubuntu:trusty -maintainer yans@yancomm.net +FROM ubuntu:trusty -RUN apt-get update && apt-get install -y build-essential libtool g++ gcc \ +# wrapper script for apt-get +COPY .docker/apt-get-install /usr/local/bin/apt-get-install +RUN chmod +x /usr/local/bin/apt-get-install + +RUN apt-get-install build-essential libtool g++ gcc \ texinfo curl wget automake autoconf python python-dev git subversion \ - unzip virtualenvwrapper sudo + unzip virtualenvwrapper sudo git virtualenvwrapper RUN useradd -m ctf +RUN echo "ctf ALL=NOPASSWD: ALL" > /etc/sudoers.d/ctf + COPY .git /home/ctf/tools/.git RUN chown -R ctf.ctf /home/ctf/tools -RUN echo "ctf ALL=NOPASSWD: ALL" > /etc/sudoers.d/ctf -RUN apt-get update -RUN apt-get -y install git virtualenvwrapper - +# git checkout of the files USER ctf - WORKDIR /home/ctf/tools RUN git checkout . + +# add non-commited scripts +USER root +COPY bin/manage-tools /home/ctf/tools/bin/ +COPY bin/ctf-tools-pip /home/ctf/tools/bin/ +COPY bin/ctf-tools-venv-activate /home/ctf/tools/bin/ +COPY bin/ctf-tools-venv-activate3 /home/ctf/tools/bin/ +RUN chown -R ctf.ctf /home/ctf/tools + +# finally run ctf-tools setup +USER ctf RUN bin/manage-tools -s setup RUN bin/ctf-tools-pip install appdirs -RUN echo "workon ctftools" >> /home/ctf/.bashrc +#RUN echo "workon ctftools" >> /home/ctf/.bashrc +RUN echo 'source $(which ctf-tools-venv-activate)' >> /home/ctf/.bashrc WORKDIR /home/ctf CMD bash -i diff --git a/Dockerfile.archlinux b/Dockerfile.archlinux index 7665e74..4f93b0f 100644 --- a/Dockerfile.archlinux +++ b/Dockerfile.archlinux @@ -38,6 +38,16 @@ USER ctf WORKDIR /home/ctf/tools RUN git checkout . + +# add non-commited scripts +USER root +COPY bin/manage-tools /home/ctf/tools/bin/ +COPY bin/ctf-tools-pip /home/ctf/tools/bin/ +COPY bin/ctf-tools-venv-activate /home/ctf/tools/bin/ +COPY bin/ctf-tools-venv-activate3 /home/ctf/tools/bin/ +RUN chown -R ctf.ctf /home/ctf/tools + +USER ctf RUN bin/manage-tools -s setup RUN echo 'source $(which virtualenvwrapper.sh)' >> ~/.zshrc RUN echo 'workon ctftools' >> ~/.zshrc diff --git a/Dockerfile.artful b/Dockerfile.artful new file mode 100644 index 0000000..84294b0 --- /dev/null +++ b/Dockerfile.artful @@ -0,0 +1,38 @@ +FROM ubuntu:artful + +# wrapper script for apt-get +COPY .docker/apt-get-install /usr/local/bin/apt-get-install +RUN chmod +x /usr/local/bin/apt-get-install + +RUN apt-get-install build-essential libtool g++ gcc \ + texinfo curl wget automake autoconf python python-dev git subversion \ + unzip virtualenvwrapper sudo git virtualenvwrapper + +RUN useradd -m ctf +RUN echo "ctf ALL=NOPASSWD: ALL" > /etc/sudoers.d/ctf + +COPY .git /home/ctf/tools/.git +RUN chown -R ctf.ctf /home/ctf/tools + +# git checkout of the files +USER ctf +WORKDIR /home/ctf/tools +RUN git checkout . + +# add non-commited scripts +USER root +COPY bin/manage-tools /home/ctf/tools/bin/ +COPY bin/ctf-tools-pip /home/ctf/tools/bin/ +COPY bin/ctf-tools-venv-activate /home/ctf/tools/bin/ +COPY bin/ctf-tools-venv-activate3 /home/ctf/tools/bin/ +RUN chown -R ctf.ctf /home/ctf/tools + +# finally run ctf-tools setup +USER ctf +RUN bin/manage-tools -s setup +RUN bin/ctf-tools-pip install appdirs +#RUN echo "workon ctftools" >> /home/ctf/.bashrc +RUN echo 'source $(which ctf-tools-venv-activate)' >> /home/ctf/.bashrc + +WORKDIR /home/ctf +#CMD bash -i diff --git a/Dockerfile.fedora b/Dockerfile.fedora index 24c059f..fb16b49 100644 --- a/Dockerfile.fedora +++ b/Dockerfile.fedora @@ -11,9 +11,19 @@ USER ctf WORKDIR /home/ctf/tools RUN git checkout . + +# add non-commited scripts +USER root +COPY bin/manage-tools /home/ctf/tools/bin/ +COPY bin/ctf-tools-pip /home/ctf/tools/bin/ +COPY bin/ctf-tools-venv-activate /home/ctf/tools/bin/ +COPY bin/ctf-tools-venv-activate3 /home/ctf/tools/bin/ +RUN chown -R ctf.ctf /home/ctf/tools + +USER ctf RUN bin/manage-tools -s setup RUN bin/ctf-tools-pip install appdirs -RUN echo "workon ctftools" >> /home/ctf/.bashrc +RUN echo 'source $(which ctf-tools-venv-activate)' >> /home/ctf/.bashrc WORKDIR /home/ctf CMD bash -i diff --git a/Dockerfile.xenial b/Dockerfile.xenial index 70f2e20..4a265fd 100644 --- a/Dockerfile.xenial +++ b/Dockerfile.xenial @@ -1,25 +1,38 @@ from ubuntu:xenial -maintainer yans@yancomm.net -RUN apt-get update && apt-get install -y build-essential libtool g++ gcc \ +# wrapper script for apt-get +COPY .docker/apt-get-install /usr/local/bin/apt-get-install +RUN chmod +x /usr/local/bin/apt-get-install + +RUN apt-get-install build-essential libtool g++ gcc \ texinfo curl wget automake autoconf python python-dev git subversion \ - unzip virtualenvwrapper sudo + unzip virtualenvwrapper sudo git virtualenvwrapper RUN useradd -m ctf +RUN echo "ctf ALL=NOPASSWD: ALL" > /etc/sudoers.d/ctf + COPY .git /home/ctf/tools/.git RUN chown -R ctf.ctf /home/ctf/tools -RUN echo "ctf ALL=NOPASSWD: ALL" > /etc/sudoers.d/ctf -RUN apt-get update -RUN apt-get -y install git virtualenvwrapper - +# git checkout of the files USER ctf - WORKDIR /home/ctf/tools RUN git checkout . + +# add non-commited scripts +USER root +COPY bin/manage-tools /home/ctf/tools/bin/ +COPY bin/ctf-tools-pip /home/ctf/tools/bin/ +COPY bin/ctf-tools-venv-activate /home/ctf/tools/bin/ +COPY bin/ctf-tools-venv-activate3 /home/ctf/tools/bin/ +RUN chown -R ctf.ctf /home/ctf/tools + +# finally run ctf-tools setup +USER ctf RUN bin/manage-tools -s setup RUN bin/ctf-tools-pip install appdirs -RUN echo "workon ctftools" >> /home/ctf/.bashrc +#RUN echo "workon ctftools" >> /home/ctf/.bashrc +RUN echo 'source $(which ctf-tools-venv-activate)' >> /home/ctf/.bashrc WORKDIR /home/ctf CMD bash -i diff --git a/bin/ctf-tools-test-action b/bin/ctf-tools-test-action new file mode 100755 index 0000000..3e4779e --- /dev/null +++ b/bin/ctf-tools-test-action @@ -0,0 +1,41 @@ +#!/bin/bash -e + +function usage() +{ + cat < + +Run a manage-tools actions inside of a docker container, with the current +ctf-tools repository mounted into the container. This is primarily useful for +testing uncommited changes to a tool. + +END +} + + +CTFTOOLS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/../" + +DOCKER_DIST="" +DOCKER_CONTAINER="ctftools${DOCKER_DIST}" + +if [[ "$1" == "-h" || "$1" == "--help" ]]; then + usage + exit 0 +fi + +if [[ "$1" == "-d" ]]; then + DOCKER_DIST=".$2" + shift 2 +fi + +pushd $CTFTOOLS_DIR >/dev/null +set -x +sudo docker build \ + -t "$DOCKER_CONTAINER" \ + -f "Dockerfile${DOCKER_DIST}" \ + . + +sudo docker run --rm -it \ + -v $CTFTOOLS_DIR:/home/ctf/tools:z \ + "$DOCKER_CONTAINER" bash -c "/home/ctf/tools/bin/manage-tools $*" +exit $?