forked from moby/swarmkit
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a Dockerfile and making it easy to use it for dev
Credit goes to dperny (moby#2687) **- What I did** Adds a Dockerfile for the swarmkit project, to easily get off the ground. Modifies the Makefile to make intelligent use of Docker. Also made small clean up changes to the Makefile. **- How I did it** Modifies the Makefile to have two paths: containerized.mk, which builds the docker image and forwards any make targets to a container, and direct.mk, which encompasses the old Makefile's workflow. By default, nothing will run inside a container. Set the environment variable `DOCKER_SWARMKIT_USE_CONTAINER` to use dockerized making. Also leverages docker-sync for synchronizing code to the container if the `DOCKER_SWARMKIT_USE_DOCKER_SYNC` env variable is set; comes in handy on Macs, for example. **- How to test it** Set `DOCKER_SWARMKIT_USE_CONTAINER` and verify that your favorite make targets all work! Signed-off-by: Jean Rouge <[email protected]> (cherry picked from commit f8c048c) Signed-off-by: Sebastiaan van Stijn <[email protected]>
- Loading branch information
Showing
7 changed files
with
271 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,3 +31,6 @@ bin/swarmkitstate | |
|
||
# ignore code coverage output | ||
*coverage.txt | ||
|
||
# dev sync, if used | ||
/.docker-sync/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# NOTE(dperny): for some reason, alpine was giving me trouble | ||
FROM golang:1.10.3-stretch | ||
|
||
RUN apt-get update && apt-get install -y make git unzip | ||
|
||
# should stay consistent with the version we use in Circle builds | ||
ARG PROTOC_VERSION=3.5.0 | ||
# make a directory to do these operations in | ||
RUN export PROTOC_TMP_DIR=protoc && mkdir -p $PROTOC_TMP_DIR && cd $PROTOC_TMP_DIR \ | ||
# download the pre-built protoc binary | ||
&& curl --silent --show-error --location --output protoc.zip \ | ||
https://github.com/google/protobuf/releases/download/v$PROTOC_VERSION/protoc-$PROTOC_VERSION-linux-x86_64.zip \ | ||
# move the binary to /bin. move the well-known types ot /usr/local/include | ||
&& unzip protoc.zip && mv bin/protoc /bin/protoc && mv include/* /usr/local/include \ | ||
# remove all of the installation files | ||
&& cd .. && rm -rf $PROTOC_TMP_DIR | ||
|
||
WORKDIR /go/src/github.com/docker/swarmkit/ | ||
|
||
# install the dependencies from `make setup` | ||
# we only copy `direct.mk` to avoid busting the cache too easily | ||
COPY direct.mk . | ||
RUN make --file=direct.mk setup | ||
|
||
# now we can copy the rest | ||
COPY . . | ||
|
||
# default to just `make`. If you want to change the default command, change the | ||
# default make command, not this command. | ||
CMD ["make"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
IMAGE_NAME=docker/swarmkit | ||
GOPATH=/go | ||
DOCKER_IMAGE_DIR=${GOPATH}/src/${PROJECT_ROOT} | ||
|
||
# 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 | ||
# (see https://www.gnu.org/software/make/manual/html_node/Special-Targets.html) | ||
%:: | ||
@ echo "Running target $@ inside a container" | ||
@ DOCKER_SWARMKIT_DOCKER_RUN_CMD="make $*" $(MAKE) run | ||
|
||
shell: | ||
@ DOCKER_SWARMKIT_DOCKER_RUN_CMD='bash' DOCKER_SWARMKIT_DOCKER_RUN_FLAGS='-i' $(MAKE) run | ||
|
||
.PHONY: image | ||
image: | ||
docker build -t ${IMAGE_NAME} . | ||
|
||
# internal target, only builds the image if it doesn't exist | ||
.PHONY: ensure_image_exists | ||
ensure_image_exists: | ||
@ if [ ! $$(docker images -q ${IMAGE_NAME}) ]; then $(MAKE) image; fi | ||
|
||
# internal target, starts the sync if needed | ||
# uses https://github.com/EugenMayer/docker-sync/blob/47363ee31b71810a60b05822b9c4bd2176951ce8/tasks/sync/sync.thor#L193-L196 | ||
# which is not great, but that's all they expose so far to do this... | ||
# checks if the daemon pid in the .docker-sync directory maps to a running | ||
# process owned by the current user, and otherwise assumes the sync is not | ||
# running, and starts it | ||
.PHONY: ensure_sync_started | ||
ensure_sync_started: | ||
@ kill -0 $$(cat .docker-sync/daemon.pid) 2&> /dev/null || docker-sync start | ||
|
||
# internal target, actually runs a command inside a container | ||
# we don't use the `-i` flag for `docker run` by default as that makes it a pain | ||
# to kill running containers (can't kill with ctrl-c) | ||
.PHONY: run | ||
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}"; \ | ||
else \ | ||
DOCKER_RUN_COMMAND="$$DOCKER_RUN_COMMAND -v ${ROOTDIR}:${DOCKER_IMAGE_DIR}"; \ | ||
fi \ | ||
&& DOCKER_RUN_COMMAND="$$DOCKER_RUN_COMMAND $$DOCKER_SWARMKIT_DOCKER_RUN_FLAGS ${IMAGE_NAME} $$DOCKER_SWARMKIT_DOCKER_RUN_CMD" \ | ||
&& echo $$DOCKER_RUN_COMMAND \ | ||
&& $$DOCKER_RUN_COMMAND |
Oops, something went wrong.