From c8af2844c82282aee3c0ed2dfcb458f4beb85842 Mon Sep 17 00:00:00 2001 From: "R. Tyler Croy" Date: Tue, 19 Dec 2017 22:15:35 -0800 Subject: [PATCH] Tweak plugin builds as to not require superuser permissions anywhere This will keep all the build work done by the user who invokes the commands, which allows for a little more development environment sanity. But only a little bit more. --- .dockerignore | 4 ++++ Makefile | 2 +- scripts/build-plugin | 15 ++++++++++++--- scripts/build-plugins | 10 ++++++---- scripts/ruby | 6 ++++-- 5 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..805fd1e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +build/repos +webapp/ +proxy/ +assets/ diff --git a/Makefile b/Makefile index 51b20e0..4dbc6f3 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ builder: Dockerfile.builder master: Dockerfile build/git-refs.txt agent-templates docker build -t ${IMAGE_PREFIX}-$@ . -plugins: ./scripts/build-plugins plugins.txt builder +plugins: ./scripts/build-plugins plugins.yml builder ./scripts/build-plugins build/git-refs.txt: plugins diff --git a/scripts/build-plugin b/scripts/build-plugin index 018bbfa..cf1859a 100755 --- a/scripts/build-plugin +++ b/scripts/build-plugin @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env bash BUILDER_CONTAINER="rtyler/codevalet-builder" @@ -17,13 +17,22 @@ if [ $? -eq 0 ]; then TTY="-ti" fi; +# Ensure ~/.m2 exists to avoid letting the Docker daemon create the directory +# owned by the root user +mkdir -p $HOME/.m2 $HOME/.npm $HOME/.cache + pushd $1 if [ -f pom.xml ]; then echo ">> Building ${1}" exec docker run --rm ${TTY} \ - -v $HOME/.m2:/root/.m2 \ + -u $(id -u):$(id -g) \ + -e MAVEN_CONFIG=/var/maven/.m2 \ + -v $HOME/.npm:/.npm \ + -v $HOME/.cache:/.cache \ + -v $HOME/.m2:/var/maven/.m2 \ -v $PWD:/data \ -w /data \ - ${BUILDER_CONTAINER} mvn install -e -B -DskipTests + ${BUILDER_CONTAINER} \ + mvn -Duser.home=/var/maven -e -B -U -DskipTests install fi; popd diff --git a/scripts/build-plugins b/scripts/build-plugins index f892e5a..b2ac0e0 100755 --- a/scripts/build-plugins +++ b/scripts/build-plugins @@ -5,6 +5,7 @@ REPOS_DIR=$BUILD_DIR/repos SCRIPTS_DIR=$(realpath $(dirname $0)) PLUGINS_OUTPUT_DIR=$BUILD_DIR/plugins BUILDER_CONTAINER="rtyler/codevalet-builder" +PATH=${SCRIPTS_DIR}:$PATH mkdir -p $REPOS_DIR mkdir -p $PLUGINS_OUTPUT_DIR @@ -52,9 +53,10 @@ pushd $REPOS_DIR # https://issues.jenkins-ci.org/browse/JENKINS-45668 (cd js-libs-plugin && find . -maxdepth 1 -type d -exec mkdir -p {}/src/main/webapp/jsmodules \;) - - for plugin in $(${SCRIPTS_DIR}/plugins-from-yaml $SCRIPTS_DIR/../plugins.yml); do - cloneWithDependencies $plugin + # Pipeling /dev/null into stdin for Docker to avoid stupidity with the tty, see: + # https://github.com/moby/moby/issues/8513 + for plugin in $(${SCRIPTS_DIR}/plugins-from-yaml $SCRIPTS_DIR/../plugins.yml < /dev/null); do + cloneWithDependencies "${plugin}" done; # This was merged into the blueocean-plugin repository but still exists as a tombstone @@ -63,7 +65,7 @@ pushd $REPOS_DIR set -e for d in *-plugin; do - ./scripts/build-plugin $d + ${SCRIPTS_DIR}/build-plugin $d done; set +e diff --git a/scripts/ruby b/scripts/ruby index 21efa27..a880533 100755 --- a/scripts/ruby +++ b/scripts/ruby @@ -1,5 +1,7 @@ #!/bin/sh +ROOTDIR=$(realpath $(dirname $0)/../) + tty --quiet if [ $? -eq 0 ]; then @@ -7,6 +9,6 @@ if [ $? -eq 0 ]; then fi; exec docker run --rm ${TTY} \ - -v ${PWD}:${PWD} \ - -w ${PWD} \ + -v ${ROOTDIR}:${ROOTDIR} \ + -w ${ROOTDIR} \ ruby:2-alpine $@