github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/swarmkit/containerized.mk (about)

     1  IMAGE_NAME=docker/swarmkit
     2  GOPATH=/go
     3  DOCKER_IMAGE_DIR=${GOPATH}/src/${PROJECT_ROOT}
     4  
     5  DOCKER_SWARMKIT_DELVE_PORT ?= 2345
     6  
     7  # don't bother writing every single make target. just pass the call through to
     8  # docker and make
     9  # we prefer `%:` to `.DEFAULT` as the latter doesn't run phony deps
    10  # (see https://www.gnu.org/software/make/manual/html_node/Special-Targets.html)
    11  %::
    12  	@ echo "Running target $@ inside a container"
    13  	@ DOCKER_SWARMKIT_DOCKER_RUN_CMD="make $*" $(MAKE) run
    14  
    15  shell:
    16  	@ DOCKER_SWARMKIT_DOCKER_RUN_CMD='bash' DOCKER_SWARMKIT_DOCKER_RUN_FLAGS='-i' $(MAKE) run
    17  
    18  .PHONY: image
    19  image:
    20  	docker build -t ${IMAGE_NAME} .
    21  
    22  # internal target, only builds the image if it doesn't exist
    23  .PHONY: ensure_image_exists
    24  ensure_image_exists:
    25  	@ if [ ! $$(docker images -q ${IMAGE_NAME}) ]; then $(MAKE) image; fi
    26  
    27  # internal target, starts the sync if needed
    28  # uses https://github.com/EugenMayer/docker-sync/blob/47363ee31b71810a60b05822b9c4bd2176951ce8/tasks/sync/sync.thor#L193-L196
    29  # which is not great, but that's all they expose so far to do this...
    30  # checks if the daemon pid in the .docker-sync directory maps to a running
    31  # process owned by the current user, and otherwise assumes the sync is not
    32  # running, and starts it
    33  .PHONY: ensure_sync_started
    34  ensure_sync_started:
    35  	@ kill -0 $$(cat .docker-sync/daemon.pid) 2&> /dev/null || docker-sync start
    36  
    37  # internal target, actually runs a command inside a container
    38  # we don't use the `-i` flag for `docker run` by default as that makes it a pain
    39  # to kill running containers (can't kill with ctrl-c)
    40  .PHONY: run
    41  run: ensure_image_exists
    42  	@ [ "$$DOCKER_SWARMKIT_DOCKER_RUN_CMD" ] || exit 1
    43  	@ DOCKER_RUN_COMMAND="docker run -t -v swarmkit-cache:${GOPATH}" \
    44  		&& if [ "$$DOCKER_SWARMKIT_USE_DOCKER_SYNC" ]; then \
    45  			$(MAKE) ensure_sync_started && DOCKER_RUN_COMMAND+=" -v swarmkit-sync:${DOCKER_IMAGE_DIR}"; \
    46  		else \
    47  			DOCKER_RUN_COMMAND+=" -v ${ROOTDIR}:${DOCKER_IMAGE_DIR}"; \
    48  		fi \
    49  		&& if [ "$$DOCKER_SWARMKIT_USE_DELVE" ]; then \
    50  			DOCKER_RUN_COMMAND="DOCKER_SWARMKIT_DELVE_PORT=${DOCKER_SWARMKIT_DELVE_PORT} $$DOCKER_RUN_COMMAND" ; \
    51  			DOCKER_RUN_COMMAND+=" -p ${DOCKER_SWARMKIT_DELVE_PORT}:${DOCKER_SWARMKIT_DELVE_PORT} -e DOCKER_SWARMKIT_DELVE_PORT"; \
    52  			`# see https://github.com/derekparker/delve/issues/515#issuecomment-214911481'` ; \
    53  			DOCKER_RUN_COMMAND+=" --security-opt=seccomp:unconfined"; \
    54  		fi \
    55  		&& DOCKER_RUN_COMMAND+=" $$DOCKER_SWARMKIT_DOCKER_RUN_FLAGS $$DOCKER_SWARMKIT_EXTRA_RUN_FLAGS ${IMAGE_NAME} $$DOCKER_SWARMKIT_DOCKER_RUN_CMD" \
    56  		&& echo $$DOCKER_RUN_COMMAND \
    57  		&& eval $$DOCKER_RUN_COMMAND