From bef44169c5d5da73bde5c1fa32f60dce67d3515f Mon Sep 17 00:00:00 2001 From: JP Bochi Date: Fri, 3 Feb 2017 14:47:16 +0100 Subject: [PATCH 1/5] replaces netcat with curl for simplicity and consistency (some netcat version have no -U option) --- drun | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drun b/drun index 71af7d8..d341156 100755 --- a/drun +++ b/drun @@ -108,7 +108,7 @@ fi DSOCK=/var/run/docker.sock if [ "${MOUNTDOCKERSOCK:-}" != 'n' -a -r "$DSOCK" -a -w "$DSOCK" -a -S "$DSOCK" ]; then - if printf 'GET /_ping HTTP/1.1\nHost: daemon\n\n' | nc -U /var/run/docker.sock | head -n 1 | grep -q '200 OK'; then + if curl -sS --unix-socket /var/run/docker.sock http://docker/_ping | grep -q OK; then EXTRA_OPTS="${EXTRA_OPTS:-} -v ${DSOCK}:${DSOCK}" fi fi From 58632dd12b32a2f5aaa428a57bea344a7a3f4074 Mon Sep 17 00:00:00 2001 From: JP Bochi Date: Fri, 3 Feb 2017 15:27:35 +0100 Subject: [PATCH 2/5] tries either curl or nc, verifying which can connect to unix sockets --- drun | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drun b/drun index d341156..f5a01bd 100755 --- a/drun +++ b/drun @@ -108,7 +108,9 @@ fi DSOCK=/var/run/docker.sock if [ "${MOUNTDOCKERSOCK:-}" != 'n' -a -r "$DSOCK" -a -w "$DSOCK" -a -S "$DSOCK" ]; then - if curl -sS --unix-socket /var/run/docker.sock http://docker/_ping | grep -q OK; then + if curl --help | grep -q unix-socket && curl -sS --unix-socket "$DSOCK" http://docker/_ping | grep -q OK; then + EXTRA_OPTS="${EXTRA_OPTS:-} -v ${DSOCK}:${DSOCK}" + elif nc -h 2>&1 | grep -qe '-X\b' && printf 'GET /_ping HTTP/1.1\nHost: daemon\n\n' | nc -U "$DSOCK" | head -n 1 | grep -q '200 OK'; then EXTRA_OPTS="${EXTRA_OPTS:-} -v ${DSOCK}:${DSOCK}" fi fi From c3b45dc48c592972ef0ec6b4c001665dd7d6b016 Mon Sep 17 00:00:00 2001 From: JP Bochi Date: Fri, 3 Feb 2017 15:30:59 +0100 Subject: [PATCH 3/5] checkbashisms on build --- circle.yml | 2 ++ drun | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index e4d7f7f..7d57e8e 100644 --- a/circle.yml +++ b/circle.yml @@ -1,11 +1,13 @@ machine: pre: - curl -sSL https://s3.amazonaws.com/circle-downloads/install-circleci-docker.sh | bash -s -- 1.10.0 + - sudo apt-get install devscripts services: - docker test: override: + - checkbashisms -f ./drun - ./drun -x docker:1.10.0 docker version - ./drun ubuntu:16.04 cat /etc/issue | grep 'Ubuntu 16.04' - ./drun mhart/alpine-node:5.12.0 node --version | grep 'v5.12.0' diff --git a/drun b/drun index f5a01bd..c1e1ba9 100755 --- a/drun +++ b/drun @@ -25,7 +25,7 @@ usage() { node_version() { if [ ! -f package.json ]; then echo 'latest' - elif hash jq 2> /dev/null; then + elif jq --version | grep -q jq; then echo $(jq -r -e '.engines.node // "latest"' package.json) else echo $(python -c "import json;print json.load(open('package.json'))['engines']['node']" 2> /dev/null || echo latest) From 3c727377c3f521bf006e17f62bc9aec2ab69137c Mon Sep 17 00:00:00 2001 From: JP Bochi Date: Fri, 3 Feb 2017 15:41:53 +0100 Subject: [PATCH 4/5] updated all tests with comments --- circle.yml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/circle.yml b/circle.yml index 7d57e8e..baf0812 100644 --- a/circle.yml +++ b/circle.yml @@ -8,8 +8,11 @@ machine: test: override: - checkbashisms -f ./drun - - ./drun -x docker:1.10.0 docker version - - ./drun ubuntu:16.04 cat /etc/issue | grep 'Ubuntu 16.04' - - ./drun mhart/alpine-node:5.12.0 node --version | grep 'v5.12.0' - - echo '{"test":"passing"}' | ./drun -x stedolan/jq '.test' | grep '"passing"' - - echo '{"test":"passing"}' > test.json && ./drun -x stedolan/jq '.test' test.json | grep '"passing"' + - ./drun -x ubuntu:16.04 cat /etc/issue | grep 'Ubuntu 16.04' # should execute command inside container + - ./drun -x docker:1.10.0 docker version # should bind docker.sock + - ./drun -x docker:1.10.0 sh -c './drun -x docker:1.10.0 true' # should do inception in 2 levels + - ./drun -x docker:1.10.0 sh -c './drun -x docker:1.10.0 sh -c "./drun -x docker:1.10.0 true"' # should do inception in 3 levels + - ./drun -x mhart/alpine-node:5.12.0 node --version | grep 'v5.12.0' # should get version of node + - ./drun -xNA node --version | grep 'v5.12.0' # should read version from package.json + - echo '{"test":"passing"}' | ./drun -x stedolan/jq '.test' | grep '"passing"' # should pipe into command inside container + - echo '{"test":"passing"}' > test.json && ./drun -x stedolan/jq '.test' test.json | grep '"passing"' # should mount current directory From 7d15474c511b7a7ecc00a75154f605e90af6b1df Mon Sep 17 00:00:00 2001 From: JP Bochi Date: Fri, 3 Feb 2017 17:08:33 +0100 Subject: [PATCH 5/5] improves parsing options for node version from package.json --- circle.yml | 2 ++ drun | 16 +++++++++++++--- package.json | 5 +++++ 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 package.json diff --git a/circle.yml b/circle.yml index baf0812..0d2d778 100644 --- a/circle.yml +++ b/circle.yml @@ -4,6 +4,8 @@ machine: - sudo apt-get install devscripts services: - docker + environment: + RM_OPT: "" # tells drun not to --rm since CircleCI doesn't like it test: override: diff --git a/drun b/drun index c1e1ba9..872f5a4 100755 --- a/drun +++ b/drun @@ -22,13 +22,23 @@ usage() { exit 1 } +node_version_jq() { + jq -r -e '.engines.node // "latest"' package.json +} +node_version_python() { + python -c "import json;print json.load(open('package.json')).get('engines',{}).get('node','latestpython')" +} +node_version_ruby() { + cat package.json | ruby -e 'require "json"; puts JSON[STDIN.read].fetch("engine",{}).fetch("node","lastestruby")' +} node_version() { if [ ! -f package.json ]; then echo 'latest' - elif jq --version | grep -q jq; then - echo $(jq -r -e '.engines.node // "latest"' package.json) else - echo $(python -c "import json;print json.load(open('package.json'))['engines']['node']" 2> /dev/null || echo latest) + node_version_jq 2> /dev/null || \ + node_version_python 2> /dev/null || \ + node_version_ruby 2> /dev/null || \ + (echo >&2 'drun ERR! Failed to resolve node version. Defaulting to "latest"' && echo 'latest') fi } diff --git a/package.json b/package.json new file mode 100644 index 0000000..47eb760 --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "engines": { + "node": "5.12.0" + } +}