-
Notifications
You must be signed in to change notification settings - Fork 512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add simple "go-wrapper" script for building and running, especially to accommodate ".godir" support #10
Conversation
de04e23
to
9643ee8
Compare
LGTM. cc @proppy |
For those watching "from the couch" (so to speak), this is based on @proppy's short |
fi | ||
|
||
case "$cmd" in | ||
get|build) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about install?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
build
technically is install
, since it really just does go get
(where go-wrapper get
is really go get -d
, ie, download only)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about naming it go-wrapper download
, because I kinda expected go-wrapper get
to be go get
:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's definitely fair, and makes sense 👍
Should we also rename build
to be install
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, actually build
is install
as currently implemented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oups, install
is really get
.
Sorry for the missunderstanding.
What about going for go-wrapper get
and just passing the arg verbatim.
That way people using the wrapper wouldn't have to rely on the usage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My problem with that is that it was never clear to me (as a layman "go
tool" user) that a raw "go get" is really "download + build + install", and
so I hate perpetuating that verbiage choice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, then I think we need different name not to confuse user.
go download
is great- what about
go compile
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we switch it to actually be "go install", and keep the install
name? (and thus assume you did a "download" beforehand)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 ❤️
@tianon Thanks for building up on my "naive" implementation :) |
|
||
ONBUILD COPY . /go/src/app | ||
ONBUILD RUN go get -d -v ./... | ||
ONBUILD RUN go build -v ./... | ||
ONBUILD RUN go-wrapper get |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if separate script would make this friendlier, when calling it from the non-onbuild image:
go-run
go-get
go-build
``
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably friendlier to users yes, but does blow up the number of scripts we copy around our repo, which is what I was trying to avoid. Maybe we just have the script itself support being symlinked to go-<cmd>
names that imply the command bit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yay git!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually technically a Docker limitation, but that's a digression. 😄
So, my problem with that is that it makes them seem more official than they really are, ie, go-install
will now be confusingly similar to go install
but ever so slightly different, which is what I was trying to avoid by keeping everything in the go-wrapper
script directly (so it's clearly separated).
So, here's the "usage" text with my latest force push: # go-wrapper
usage: /usr/local/bin/go-wrapper command [args]
ie:
/usr/local/bin/go-wrapper download
(equivalent to "go get -d <package>")
/usr/local/bin/go-wrapper download -u
(equivalent to "go get -d -u <package>")
/usr/local/bin/go-wrapper install
(equivalent to "go get <package>")
(in other words, "go get -d && go build && go install")
/usr/local/bin/go-wrapper run
(assumes "install" has run)
/usr/local/bin/go-wrapper run -app -specific -arguments |
echo | ||
echo " $0 install" | ||
echo ' (equivalent to "go get <package>")' | ||
echo ' (in other words, "go get -d && go build && go install")' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rm go get
b943e81
to
5535527
Compare
Ok, updated usage: $ ./go-wrapper
usage: ./go-wrapper command [args]
Available Commands:
./go-wrapper download
./go-wrapper download -u
(equivalent to "go get -d [args] [godir]")
./go-wrapper install
./go-wrapper install -race
(equivalent to "go install [args] [godir]")
./go-wrapper run
./go-wrapper run -app -specific -arguments |
if [ -f .godir ]; then | ||
goDir="$(cat .godir)" | ||
goBin="$(basename "$goDir")" | ||
goPath="${GOPATH%%:*}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add a comment that is used to get the first entry of the GOPATH
Add a line note
Ok, comment about $ ./go-wrapper
usage: go-wrapper command [args]
This script assumes that is is run from the root of your Go package (for
example, "/go/src/app" if your GOPATH is set to "/go").
The main feature of this wrapper over the native "go" tool is that it supports
the addition of a ".godir" file in your package directory which is a plain text
file that is the import path your application expects (ie, it would be something
like "github.com/jsmith/my-cool-app"). If this file is found, the current
package is then symlinked to /go/src/<.gopath> and the commands then use that
full import path to act on it. This allows for applications to be universally
cloned into a path like "/go/src/app" and then automatically built properly so
that inter-package imports use the existing source instead of downloading it a
second time. This also makes the final binary have the correct name (ie,
instead of being "/go/bin/app", it can be "/go/bin/my-cool-app"), which is why
the "run" command exists here.
Available Commands:
go-wrapper download
go-wrapper download -u
(equivalent to "go get -d [args] [godir]")
go-wrapper install
go-wrapper install -race
(equivalent to "go install [args] [godir]")
go-wrapper run
go-wrapper run -app -specific -arguments
(assumes "GOPATH/bin" is in "PATH")
$ ./go-wrapper some-unknown-command
error: unknown command: some-unknown-command
usage: go-wrapper command [args]
This script assumes that is is run from the root of your Go package (for
example, "/go/src/app" if your GOPATH is set to "/go").
The main feature of this wrapper over the native "go" tool is that it supports
the addition of a ".godir" file in your package directory which is a plain text
file that is the import path your application expects (ie, it would be something
like "github.com/jsmith/my-cool-app"). If this file is found, the current
package is then symlinked to /go/src/<.gopath> and the commands then use that
full import path to act on it. This allows for applications to be universally
cloned into a path like "/go/src/app" and then automatically built properly so
that inter-package imports use the existing source instead of downloading it a
second time. This also makes the final binary have the correct name (ie,
instead of being "/go/bin/app", it can be "/go/bin/my-cool-app"), which is why
the "run" command exists here.
Available Commands:
go-wrapper download
go-wrapper download -u
(equivalent to "go get -d [args] [godir]")
go-wrapper install
go-wrapper install -race
(equivalent to "go install [args] [godir]")
go-wrapper run
go-wrapper run -app -specific -arguments
(assumes "GOPATH/bin" is in "PATH")
|
goPath="${GOPATH%%:*}" # this just grabs the first path listed in GOPATH, if there are multiple (which is the detection logic "go get" itself uses, too) | ||
goDirPath="$goPath/src/$goDir" | ||
mkdir -p "$(dirname "$goDirPath")" | ||
if [ ! -L "$goDirPath" ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it's worth checking that the symlink point to the same location.
LGTM, just made 2 last comments about the symlinks and default on the go tool when the command not found. But feel free to ignore those suggestions if you think they are not appropriate. |
Passing straight through to "go" makes errors in our stuff less obvious - On the symlink though, that's probably a good point, although in that case |
…o accommodate ".godir" support
Ok, updated again. ;) |
LGTM |
Add simple "go-wrapper" script for building and running, especially to accommodate ".godir" support
Fixes #4
Fixes #9
Also,
update.sh
will make sure it's properly copied into each version subfolder, like we've done with other official images.