Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -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 -?
22 changes: 0 additions & 22 deletions circle.yml

This file was deleted.

17 changes: 13 additions & 4 deletions drun
Original file line number Diff line number Diff line change
Expand Up @@ -111,29 +111,38 @@ 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
fi
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}
Expand Down