diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..94aed82 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,68 @@ +version: 2 +stages: + build: + working_directory: /home/circleci/drun + machine: true + docker: + - image: docker:17.03.0 + environment: + RM_OPT: "" # tells drun not to --rm since CircleCI doesn't like it + steps: + - type: shell + pwd: / + shell: /bin/sh + command: apk --update add git openssh checkbashisms + - type: checkout + - type: shell + shell: /bin/sh + command: checkbashisms -f ./drun + - type: setup-docker-engine + - type: shell + shell: /bin/sh + command: env + - type: shell + shell: /bin/sh + command: | + docker version + docker --help + docker info + docker --log-level debug ps + find /tmp/docker-* + mkdir -p /home/circleci/drun/.docker/ + cp ${DOCKER_CERT_PATH}/*.pem /home/circleci/drun/.docker/ + ls -lha /home/circleci/drun/.docker/ + ./drun -x alpine:3.5 ls -lha /home/circleci/drun/ + ./drun -x alpine:3.5 ls -lha /home/circleci/drun/.docker/ + - type: shell + shell: /bin/sh + command: ./drun -x alpine:3.5 date + - type: shell + shell: /bin/sh + command: ./drun -x alpine:3.5 cat /etc/issue | grep 'Alpine Linux 3.5' # should execute command inside container + - type: shell + shell: /bin/sh + command: ./drun -x docker:17.03.0 docker version # should bind docker.sock + - type: shell + shell: /bin/sh + command: ./drun -x docker:1.10.0 sh -c './drun -x docker:1.10.0 true' # should do inception in 2 levels + - type: shell + shell: /bin/sh + command: ./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 + - type: shell + shell: /bin/sh + command: ./drun -x mhart/alpine-node:5.12.0 node --version | grep 'v5.12.0' # should get version of node + - type: shell + shell: /bin/sh + command: ./drun -xNA node --version | grep 'v7.7.1' # should read version from package.json with mhart/alpine-node-auto image + - type: shell + shell: /bin/sh + command: ./drun -xNM slim node --version | grep 'v7.7.1' # should read version from package.json node:7.7.1-slim image + - type: shell + shell: /bin/sh + command: echo '{"test":"passing"}' | ./drun -x stedolan/jq '.test' | grep '"passing"' # should pipe into command inside container + - type: shell + shell: /bin/sh + command: echo '{"test":"passing"}' > test.json && ./drun -x stedolan/jq '.test' test.json | grep '"passing"' # should mount current directory + - type: shell + shell: /bin/sh + command: ./drun -? diff --git a/circle.yml b/circle.yml deleted file mode 100644 index 0ec9f1c..0000000 --- a/circle.yml +++ /dev/null @@ -1,22 +0,0 @@ -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 - environment: - RM_OPT: "" # tells drun not to --rm since CircleCI doesn't like it - -test: - override: - - checkbashisms -f ./drun - - ./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 'v7.7.1' # should read version from package.json with mhart/alpine-node-auto image - - ./drun -xNM slim node --version | grep 'v7.7.1' # should read version from package.json node:7.7.1-slim image - - 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 - - ./drun -? diff --git a/drun b/drun index 6731f8b..2c5b4e7 100755 --- a/drun +++ b/drun @@ -111,16 +111,17 @@ if [ -n "${ENV_REGEX:-}" ]; then ENV_FILE_OPT="--env-file=$ENV_FILE" fi -MAP_CURRENT_DIR_OPT="-v $CURRENT_DIR:$CONTAINER_HOME" +MAP_CURRENT_DIR_OPT="-v $CURRENT_DIR/:$CONTAINER_HOME/" # Inception detection if [ -f '/proc/1/cgroup' ]; then + cat /proc/1/cgroup CURRENT_CONTAINER=$(grep '/docker/' -- /proc/1/cgroup | head -n1 | cut -d '/' -f 3) - if [ -n "${CURRENT_CONTAINER}" ]; then + if [ -n "${CURRENT_CONTAINER}" ] && docker inspect --format='ok' "${CURRENT_CONTAINER}" 2>&1 > /dev/null; then # Maps volumes from current container EXTRA_OPTS="${EXTRA_OPTS:-} --volumes-from $CURRENT_CONTAINER" # If current directory is inside any of the mounts of the current container - MOUNTS=$(docker inspect --format='{{range .Mounts}} -e '{{.Destination}}'{{end}}' ${CURRENT_CONTAINER}) + MOUNTS=$(docker inspect --format='{{range .Mounts}} -e '{{.Destination}}'{{end}}' "${CURRENT_CONTAINER}") if [ "0" != $(echo "${CURRENT_DIR}" | grep ${MOUNTS}) ]; then MAP_CURRENT_DIR_OPT='' fi @@ -128,12 +129,20 @@ if [ -f '/proc/1/cgroup' ]; then fi DSOCK=/var/run/docker.sock -if [ "${MOUNTDOCKERSOCK:-}" != 'n' -a -r "$DSOCK" -a -w "$DSOCK" -a -S "$DSOCK" ]; then +if [ "${MOUNTDOCKERSOCK:-}" != 'n' -a -r "$DSOCK" -a -w "$DSOCK" -a -S "$DSOCK" ]; 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 +elif [ -n "${DOCKER_HOST}" ]; then + # ARRRGH=$(echo $DOCKER_HOST | sed 's/tcp:/https:/') + # echo curl -ik "$ARRRGH"/_ping + # curl -ik "$ARRRGH"/_ping + # echo '--------' + EXTRA_OPTS="${EXTRA_OPTS:-} -e DOCKER_HOST=${DOCKER_HOST}" + EXTRA_OPTS="${EXTRA_OPTS:-} -e DOCKER_TLS_VERIFY=1" + # EXTRA_OPTS="${EXTRA_OPTS:-} -e DOCKER_CERT_PATH=${DOCKER_CERT_PATH} -v ${DOCKER_CERT_PATH}/:${DOCKER_CERT_PATH}/:ro" fi RM_OPT=${RM_OPT=--rm}