Use Make to build binaries#88
Conversation
|
Hmmm... adding a Makefile to a Go project? This doesn't seem very portable or Go-like. |
|
I am definitely also confused, and that build.sh script is used by the Dockerfile build method, so it can't be removed. ;) |
|
Also, why not just do something like: default:
./build.sh
all: darwin linux windows
%:
GOOS=$@ ./build.sh |
|
Oops… I wrote the Makefile to simplify releasing binaries. For each release we need to build three binaries according to a specific naming convention (see https://github.com/boot2docker/boot2docker-cli/releases). I'll fix the problems you mentioned now. |
Need the shell script for Docker build
|
Easy, just add |
|
@tianon I also need the version number for naming… :| |
|
Indeed, still simple (but more importantly, still extremely DRY): diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..433db0d
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,11 @@
+default:
+ ./build.sh
+
+all: darwin linux windows
+ @true # stop "all" from matching "%" later
+
+GOARCH := amd64
+VERSION = $(shell cat VERSION)
+
+%:
+ GOOS=$@ GOARCH=$(GOARCH) ./build.sh -o boot2docker-cli-$(VERSION)-$@-$(GOARCH)$(if $(filter windows, $@),.exe)
diff --git a/build.sh b/build.sh
index 10ab07b..6b05be2 100755
--- a/build.sh
+++ b/build.sh
@@ -5,4 +5,4 @@ version="$(cat VERSION)"
gitSha="$(git rev-parse --short HEAD)"
set -x
-exec go build -ldflags "-X main.Version $version -X main.GitSHA $gitSha"
+exec go build -ldflags "-X main.Version $version -X main.GitSHA $gitSha" "$@"# make all
GOOS=darwin GOARCH=amd64 ./build.sh -o boot2docker-cli-v0.8.0-darwin-amd64
+ exec go build -ldflags -X main.Version v0.8.0 -X main.GitSHA 408532a -o boot2docker-cli-v0.8.0-darwin-amd64
GOOS=linux GOARCH=amd64 ./build.sh -o boot2docker-cli-v0.8.0-linux-amd64
+ exec go build -ldflags -X main.Version v0.8.0 -X main.GitSHA 408532a -o boot2docker-cli-v0.8.0-linux-amd64
GOOS=windows GOARCH=amd64 ./build.sh -o boot2docker-cli-v0.8.0-windows-amd64.exe
+ exec go build -ldflags -X main.Version v0.8.0 -X main.GitSHA 408532a -o boot2docker-cli-v0.8.0-windows-amd64.exe |
|
BLACK MAGIC! @tianon you're the best! Never know you could do conditionals in Makefile like that… Lesson learned! :D |
|
:) |
|
I'm gonna go back and re-learn Make! |
|
@tianon I noticed quite a few Docker builds tend to prefer shell script over Makefiles, but I'm wondering why? |
|
I would guess that it's because Bash is so much easier to wrap your head around than GNU Make (since Bash is an actual programming/scripting language, where GNU Make is a lot of strange incantations). Personally, I'm a fan of both, but I love using them together especially for cool stuff like this. :) Needing a Makefile is also sometimes a sign that your build/project is getting too complicated, so there's some natural aversion there. :) |
|
Oh, and of course, since the crux of this is basically exactly what I created, LGTM now, but I think it ought to have at least two of @SvenDowideit @gmlewis and/or @steeve review it also, since I'm "too close to the fire" now, so to speak. :) |
|
Thanks for the explanation! That confirmed my doubt. I actually wrote a Bash script that handles an entire Docker build (by pumping commands to Docker via stdin instead of storing them in a Dockerfile, just to have some flexibility :). Makefile still feels a bit foreign IMHO… Maybe I should extend |
|
@tianon @riobard I'm confused. I use the a Docker container to build: I'm assuming this does not currently work for OSX, but I would be much more comfortable with the Linux and Windows builds being done in a Container - so we have consistent builds for everyone. (so no, I do not like.) |
|
@SvenDowideit of course - note my example output, which occurred in a container ;) This makes it easy to "make all" in just one container instead of running three separate containers to perform that same task. |
|
@SvenDowideit Yep, basically it's to make the job easier and to enforce the naming convention for the binary releases. Otherwise you'll have to repeat the Docker build for different OS and also remember to rename the binaries copied out of the container correctly each time. |
|
LGTM |
|
LGTM fosho'! (From the airport)— On Wed, Apr 9, 2014 at 4:58 AM, Sven Dowideit notifications@github.com
|
|
So there's a build process change - can you please update the README.md to match? |
|
@SvenDowideit I didn't intend to replace the existing Docker build with the Make approach here. This is strictly a convenience tool for us to release binaries, i.e. mostly likely it'll be used just by you and me, until we figure out how to do CI later. Or do you want others to use it too? In the case, I can definitely update the README. We'll have to mention the caveat of building for OS X from Docker anyway due to the TLS issue. Please let me know which you'd prefer. |
|
@riobard for repeat ability, it would be better if we all only build one way (tho the OSX case is a problem until we fix it). I don't like developing with a build system that is not identical to the release one - it introduces unknowns that we just don't need. |
|
You're still confused. All the Makefile does is equivalent to
There is no different builds. |
|
excellent. me being confused is good. so - can we please update the README.md to use the makefile? that way only experts will do the typing that might lead to errors :) |
The Makefile will handle native build, cross compiling, and Docker build as well. Also updated the README to reflect the changes.
|
Well, now the build process is completely streamlined and simplified. @SvenDowideit For a Docker build you can now just run @tianon You might want to take a second look at the Makefile and please let me know if you have any suggestions for improvement! :) |
|
README is also updated to reflect the changes. |
|
If you are unclear about the new build process, please read the new README https://github.com/riobard/boot2docker-cli/tree/Makefile |
|
much awesome. thankyou :) I'll test tomorrow when I stop getting kicked by heartblead related leftovers of a past life |
|
No problem! :) I tested it on OS X and it works fine. I don't think the build process works on Windows though (no shell/make). This Heartbleed thing is so f*cked up… |
|
LGTM |
|
Sorry guys I'm locked out of my gh account for tech reasons (in the us with a different sim, thus 2 factor is out). But that lgtm On Mon, Apr 14, 2014 at 9:44 AM, Tianon Gravi notifications@github.com
|
|
@SvenDowideit Have you run into any issues with this PR so far? |
|
@riobard just tried - its missing something: yup - I expect to be able to |
|
|
|
We could fix that with a |
|
@tianon I think the major problem is we have to put the source into the right place in |
|
Of course another possibility is we manage per-project |
|
seriously, if go idiom is different from well established idioms, then its only going to slow down casual contribution and should be ignored. this is a github project - so its expected that one will get the code using git and then make. I'm somewhat sure that typing |
|
Well, every language has its idioms and well-established best practices. A Node project on GitHub expects different procedures from a Rails project. There're no standard "GitHub projects" and although we take At this point, putting everything correctly under As for the best way to handle forks and PRs on GitHub, @tianon once told me his setup and I found it really nice. I've been using his approach for all my GitHub projects ever since. I wrote a short comment explaining how here #70 (comment) You can give a try and see if you like it. BTW, it's not the Makefile's fault that you have this problem. The problem exists for the old |
|
PS: |
|
Maybe the dockerbuild should be our default? It'll be the most consistent, for sure. |
|
Docker build is gonna take REALLY long time initially. I'm not sure it's a For deployment we should use docker build for sure (except for OS X). On Thursday, April 17, 2014, Tianon Gravi notifications@github.com wrote:
|
|
we want the default builds to always use the container - only rare and odd people would realise they can build outside - and once we fix the bugs in cross building, then building outside the container creates an unsupported Docker is about doing things in containers for consistency. GitHub is to simplify contribution. The other options are there for experts - so don't need to be defaults. |
|
If initial container build is a problem, we can just make it a trusted build and |
|
now that its done - yes, swap it round so go-zi-ens can still do their personal, re-invention of make by typing |
|
Now |
|
Seems to work OK here; LGTM. |
Prevent ssh warnings

Run
maketo build for your current system, and runmake allto build for Darwin, Linux, and Windows. You can alsomake darwin,make windowsandmake linuxindividually.