Skip to content
Merged
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
21 changes: 0 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,29 +1,8 @@
# Root directory of the project (absolute path).
ROOTDIR=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))

# Base path used to install.
DESTDIR=/usr/local

# Used to populate version variable in main package.
VERSION=$(shell git describe --match 'v[0-9]*' --dirty='.m' --always)

PROJECT_ROOT=github.com/docker/swarmkit

# Race detector is only supported on amd64.
RACE := $(shell test $$(go env GOARCH) != "amd64" || (echo "-race"))

# Project packages.
PACKAGES=$(shell go list ./... | grep -v /vendor/)
INTEGRATION_PACKAGE=${PROJECT_ROOT}/integration

# Project binaries.
COMMANDS=swarmd swarmctl swarm-bench swarm-rafttool protoc-gen-gogoswarm
BINARIES=$(addprefix bin/,$(COMMANDS))

VNDR=$(shell which vndr || echo '')

GO_LDFLAGS=-ldflags "-X `go list ./version`.Version=$(VERSION)"

SHELL := /bin/bash

# stop here. do we want to run everything inside of a container, or do we want
Expand Down
16 changes: 12 additions & 4 deletions containerized.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ IMAGE_NAME=docker/swarmkit
GOPATH=/go
DOCKER_IMAGE_DIR=${GOPATH}/src/${PROJECT_ROOT}

DOCKER_SWARMKIT_DELVE_PORT ?= 2345

# don't bother writing every single make target. just pass the call through to
# docker and make
# we prefer `%:` to `.DEFAULT` as the latter doesn't run phony deps
Expand Down Expand Up @@ -40,10 +42,16 @@ run: ensure_image_exists
@ [ "$$DOCKER_SWARMKIT_DOCKER_RUN_CMD" ] || exit 1
@ DOCKER_RUN_COMMAND="docker run -t -v swarmkit-cache:${GOPATH}" \
&& if [ "$$DOCKER_SWARMKIT_USE_DOCKER_SYNC" ]; then \
$(MAKE) ensure_sync_started && DOCKER_RUN_COMMAND="$$DOCKER_RUN_COMMAND -v swarmkit-sync:${DOCKER_IMAGE_DIR}"; \
$(MAKE) ensure_sync_started && DOCKER_RUN_COMMAND+=" -v swarmkit-sync:${DOCKER_IMAGE_DIR}"; \
else \
DOCKER_RUN_COMMAND="$$DOCKER_RUN_COMMAND -v ${ROOTDIR}:${DOCKER_IMAGE_DIR}"; \
DOCKER_RUN_COMMAND+=" -v ${ROOTDIR}:${DOCKER_IMAGE_DIR}"; \
fi \
&& if [ "$$DOCKER_SWARMKIT_USE_DELVE" ]; then \
DOCKER_RUN_COMMAND="DOCKER_SWARMKIT_DELVE_PORT=${DOCKER_SWARMKIT_DELVE_PORT} $$DOCKER_RUN_COMMAND" ; \
DOCKER_RUN_COMMAND+=" -p ${DOCKER_SWARMKIT_DELVE_PORT}:${DOCKER_SWARMKIT_DELVE_PORT} -e DOCKER_SWARMKIT_DELVE_PORT"; \
`# see https://github.com/derekparker/delve/issues/515#issuecomment-214911481'` ; \
DOCKER_RUN_COMMAND+=" --security-opt=seccomp:unconfined"; \
fi \
&& DOCKER_RUN_COMMAND="$$DOCKER_RUN_COMMAND $$DOCKER_SWARMKIT_DOCKER_RUN_FLAGS ${IMAGE_NAME} $$DOCKER_SWARMKIT_DOCKER_RUN_CMD" \
&& DOCKER_RUN_COMMAND+=" $$DOCKER_SWARMKIT_DOCKER_RUN_FLAGS ${IMAGE_NAME} $$DOCKER_SWARMKIT_DOCKER_RUN_CMD" \
&& echo $$DOCKER_RUN_COMMAND \
&& $$DOCKER_RUN_COMMAND
&& eval $$DOCKER_RUN_COMMAND
22 changes: 22 additions & 0 deletions direct.mk
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
# Base path used to install.
DESTDIR=/usr/local

# Used to populate version variable in main package.
VERSION=$(shell git describe --match 'v[0-9]*' --dirty='.m' --always)

# Race detector is only supported on amd64.
RACE := $(shell test $$(go env GOARCH) != "amd64" || (echo "-race"))

# Project packages.
PACKAGES=$(shell go list ./... | grep -v /vendor/)
INTEGRATION_PACKAGE=${PROJECT_ROOT}/integration

# Project binaries.
COMMANDS=swarmd swarmctl swarm-bench swarm-rafttool protoc-gen-gogoswarm
BINARIES=$(addprefix bin/,$(COMMANDS))

VNDR=$(shell which vndr || echo '')

GO_LDFLAGS=-ldflags "-X `go list ./version`.Version=$(VERSION)"


.DEFAULT_GOAL = all
.PHONY: all
all: check binaries test integration-tests ## run check, build the binaries and run the tests
Expand Down
71 changes: 71 additions & 0 deletions hack/debug
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/bin/bash

## Installs delve, then runs it as a headless server
## Keeps running until killed
## Also adds some goodies: delve servers ignore interrupts, which is annoying...
## and also once a debugging session is done, the server just hangs there, which
## is equally annoying.
## This script takes care of both these things

SUBSHELL_PID=
DLV_PID_FILE=
RUNNING=true

main() {
[ "$1" ] || usage

ensure_delve_installed || exit $?

local PORT="$DOCKER_SWARMKIT_DELVE_PORT"
[ "$PORT" ] || PORT=2345

local DLV_CMD="dlv test --accept-multiclient --headless --listen=:$PORT --api-version=2 --log $@"
echo $DLV_CMD

trap handle_interrupt INT

DLV_PID_FILE=$(mktemp /tmp/dlv.XXXXXX.pid)
local DLV_OUTPUT_FILE=$(mktemp /tmp/dlv.XXXXXX.out)

# the weird regex is because we keep the output colored
local HALTING_REGEX='^\e\[37mDEBU\e\[0m\[[0-9]+\] halting\s+\e\[37mlayer\e\[0m=debugger'
while $RUNNING; do
# using `script` to keep colored output, and `exec` to get the PID from the
# subshell
script --flush --quiet "$DLV_OUTPUT_FILE" --command 'printf $$ > '"$DLV_PID_FILE && exec $DLV_CMD" &
SUBSHELL_PID=$!

# wait for either the subshell to die, or for the "halting" line to appear
# in the output
tail --follow --pid="$SUBSHELL_PID" --sleep-interval=0.1 "$DLV_OUTPUT_FILE" 2> /dev/null | grep --perl-regex --line-buffered "$HALTING_REGEX" | ( read && kill_delve )

wait "$SUBSHELL_PID"
done

rm -f "$DLV_PID_FILE" "$DLV_OUTPUT_FILE"
}

handle_interrupt() {
RUNNING=false
kill_delve
}

kill_delve() {
if [ -r "$DLV_PID_FILE" ]; then
local DLV_PID=$(cat "$DLV_PID_FILE")
[ "$DLV_PID" ] && kill "$DLV_PID" &> /dev/null
fi

[ "$SUBSHELL_PID" ] && kill $SUBSHELL_PID &> /dev/null
}

ensure_delve_installed() {
which dlv &> /dev/null || go get -u github.com/derekparker/delve/cmd/dlv
}

usage() {
echo "Usage: $0 name/of/go/package [additional dlv test options]"
exit 1
}

main "$@"