Ver Fonte

Merge pull request #1810 from infosiftr/docker-1.10

Explicitly note that Docker 1.10+ is required for the new Bashbrew
yosifkit há 9 anos atrás
pai
commit
913735abfd

+ 5 - 4
Dockerfile

@@ -1,12 +1,13 @@
-FROM docker:1.9-git
+FROM docker:1.10-git
 
 # add "edge" since Alpine 3.3 only has Go 1.5 and we need 1.6+
 RUN sed -ri -e 'p; s!^!@edge !; s!v[0-9.]+!edge!' /etc/apk/repositories
 
-RUN apk add --update \
+RUN apk add --no-cache \
+# bash for running scripts
 		bash \
-		go@edge \
-	&& rm -rf /var/cache/apk/*
+# go for compiling bashbrew
+		go@edge
 
 ENV GOPATH /go
 ENV PATH $GOPATH/bin:$PATH

+ 4 - 0
bashbrew/README.md

@@ -34,12 +34,16 @@ GLOBAL OPTIONS:
 
 ## Building
 
+Go version 1.6 or above is required for compilation of Bashbrew.
+
 Bashbrew itself is built using `gb` ([github.com/constabulary/gb](https://github.com/constabulary/gb)).
 
 Once in the `go` subdirectory, `gb build` should produce `go/bin/bashbrew`, ready for use.
 
 ## Usage
 
+Docker version 1.10 or above is required for use of Bashbrew.
+
 In general, `bashbrew build some-repo` or `bashbrew build ./some-file` should be sufficient for using the tool at a surface level, especially for testing. For more complex usage, please see the built-in help (`bashbrew --help`, `bashbrew build --help`, etc).
 
 ## Configuration

+ 3 - 3
bashbrew/go/src/bashbrew/docker.go

@@ -141,7 +141,7 @@ func dockerBuild(tag string, context io.Reader) error {
 		cmd.Stderr = buf
 		err := cmd.Run()
 		if err != nil {
-			err = cli.NewMultiError(err, fmt.Errorf(`docker build %q output:%s`, args, "\n"+buf.String()))
+			err = cli.NewMultiError(err, fmt.Errorf(`docker %q output:%s`, args, "\n"+buf.String()))
 		}
 		return err
 	}
@@ -151,10 +151,10 @@ func dockerTag(tag1 string, tag2 string) error {
 	if debugFlag {
 		fmt.Printf("$ docker tag %q %q\n", tag1, tag2)
 	}
-	_, err := exec.Command("docker", "tag", "-f", tag1, tag2).Output()
+	_, err := exec.Command("docker", "tag", tag1, tag2).Output()
 	if err != nil {
 		if ee, ok := err.(*exec.ExitError); ok {
-			return fmt.Errorf("%v\ncommand: docker tag -f %q %q\n%s", ee, tag1, tag2, string(ee.Stderr))
+			return fmt.Errorf("%v\ncommand: docker tag %q %q\n%s", ee, tag1, tag2, string(ee.Stderr))
 		}
 	}
 	return err

+ 3 - 0
bashbrew/go/src/bashbrew/main.go

@@ -11,6 +11,9 @@ import (
 	"pault.ag/go/topsort"
 )
 
+// TODO somewhere, ensure that the Docker engine we're talking to is API version 1.22+ (Docker 1.10+)
+//   docker version --format '{{.Server.APIVersion}}'
+
 var (
 	configPath  string
 	flagsConfig *FlagsConfig

+ 69 - 27
test-pr.sh

@@ -21,23 +21,51 @@ shift || { usage >&2 && exit 1; }
 if [ -z "$BASHBREW_SECOND_STAGE" ]; then
 	docker build --pull -t bashbrew "$dir" > /dev/null
 
+	args=(
+		-it --rm
+	)
+
 	if [ "$pull" = '0' ]; then
-		name="bashbrew-test-local-$RANDOM"
+		args+=( --name "bashbrew-test-local-$RANDOM" )
 	else
-		name="bashbrew-test-pr-$pull"
+		args+=( --name "bashbrew-test-pr-$pull" )
+	fi
+
+	args+=(
+		-v /var/run/docker.sock:/var/run/docker.sock
+		--group-add 0
+	)
+	if getent group docker &> /dev/null; then
+		args+=( --group-add "$(getent group docker | cut -d: -f3)" )
+	fi
+
+	# if we don't have DOCKER_HOST set, let's bind-mount cache for speed!
+	if [ -z "$DOCKER_HOST" ]; then
+		export BASHBREW_CACHE="${BASHBREW_CACHE:-${XDG_CACHE_HOME:-$HOME/.cache}/bashbrew}" # resolve path to current "host-side" cache directory
+		mkdir -p "$BASHBREW_CACHE" # ensure it's created by our user, not root
+		export BASHBREW_CACHE="$(cd "$BASHBREW_CACHE" && pwd -P)" # readlink -f
+		args+=(
+			-v "$BASHBREW_CACHE":/bashbrew-cache
+			-e BASHBREW_CACHE=/bashbrew-cache
+			# make sure our user in the container can read it
+			--group-add "$(stat -c '%g' "$BASHBREW_CACHE")"
+		)
 	fi
 
-	exec docker run \
-		-it --rm \
-		--name "$name" \
-		-e BASHBREW_SECOND_STAGE=1 \
-		-v /var/run/docker.sock:/var/run/docker.sock \
-		-e BASHBREW_DEBUG \
-		-w /usr/src/pr \
-		bashbrew /usr/src/official-images/test-pr.sh "$pull" "$@"
-
-	# TODO somehow reconcile remote hosts so we can re-use our cache from invocation to invocation :(
-	# -v "${BASHBREW_CACHE:-${XDG_CACHE_HOME:-$HOME/.cache}/bashbrew}":/bashbrew-cache
+	args+=(
+		--user "$(id -u)":"$(id -g)"
+		$(id -G | xargs -n1 echo --group-add)
+		-v /etc/passwd:/etc/passwd:ro
+		-v /etc/group:/etc/group:ro
+
+		-e BASHBREW_DEBUG
+		-e BASHBREW_SECOND_STAGE=1
+		-w /usr/src/pr
+	)
+
+	cmd=( /usr/src/official-images/test-pr.sh "$pull" "$@" )
+
+	exec docker run "${args[@]}" bashbrew "${cmd[@]}"
 fi
 
 if [ -d .git ]; then
@@ -86,27 +114,41 @@ join() {
 	[ $# -gt 0 ] && printf "${sep}%s" "$@"
 }
 
-#IFS=$'\n'
-#files=( $(bashbrew list --build-order "${files[@]}") )
-#unset IFS
+IFS=$'\n'
+files=( $(bashbrew list --repos --uniq --build-order "${files[@]}") )
+unset IFS
 
 echo 'Build test of' '#'"$pull"';' "$commit" '(`'"$(join '`, `' "${files[@]}")"'`):'
-failed=
+failedBuild=()
+failedTests=()
 for img in "${files[@]}"; do
+	IFS=$'\n'
+	uniqImgs=( $(bashbrew list --uniq "$img") )
+	unset IFS
+
 	echo
 	echo '```console'
-	echo '$ bashbrew build "'"$img"'"'
-	if bashbrew build --pull-missing "$img"; then
-		echo '$ bashbrew list --uniq "$url" | xargs test/run.sh'
-		if ! bashbrew list --uniq "$img" | xargs ./test/run.sh; then
-			failed=1
+	for uniqImg in "${uniqImgs[@]}"; do
+		echo
+		echo '$ bashbrew build' "$uniqImg"
+		if bashbrew build --pull-missing "$uniqImg"; then
+			echo
+			echo '$ test/run.sh' "$uniqImg"
+			if ! ./test/run.sh "$uniqImg"; then
+				failedTests+=( "$uniqImg" )
+			fi
+		else
+			failedBuild+=( "$uniqImg" )
 		fi
-	else
-		failed=1
-	fi
+		echo
+	done
 	echo '```'
 done
-if [ "$failed" ]; then
+if [ "${#failedBuild[@]}" -gt 0 ]; then
+	echo
+	echo 'The following images failed to build:' "${failedBuild[@]}"
+fi
+if [ "${#failedTests[@]}" -gt 0 ]; then
 	echo
-	echo 'There is at least one failure in the above build log.'
+	echo 'The following images failed at least one test:' "${failedTests[@]}"
 fi

+ 1 - 1
test/tests/docker-build.sh

@@ -34,6 +34,6 @@ if [ "$onbuilds" -gt 0 ]; then
 	mv "$tmp/Dockerfile.new" "$tmp/Dockerfile"
 fi
 
-cp -aL "$dir" "$tmp/dir"
+cp -RL "$dir" "$tmp/dir"
 
 docker build -t "$imageTag" "$tmp" > /dev/null