Installer API: Add buildTime and tectonicVersion#2915
Conversation
|
Can one of the admins verify this patch? |
installer/api/api.go
Outdated
|
|
||
| //handlers_latest_release.go | ||
| mux.Handle("/releases/latest", logRequests(httpHandler("GET", ctx, latestReleaseHandler))) | ||
| mux.Handle("/releases/build", logRequests(httpHandler("GET", ctx, currentReleaseHandler))) |
There was a problem hiding this comment.
need to use the name build? because the other is using latest and this new endpoint is to get the current. then maybe use current instead of build
There was a problem hiding this comment.
I was deliberating between the two (I actually created the endpoint with "current" to start with). I thought that "current" sounded weird. can be changed, if you think it's better.
|
changed endpoint from |
alexsomesan
left a comment
There was a problem hiding this comment.
Very cool solution, Karen! 👍
squat
left a comment
There was a problem hiding this comment.
Overall looks like a fine approach. Needs a little bit of clean up
installer/stamp/stamp.go
Outdated
| @@ -0,0 +1,7 @@ | |||
| package stamp | |||
There was a problem hiding this comment.
What does stamp mean? Is it timestamp? It is convention to call this package version, see for example https://github.com/coreos/matchbox/blob/master/matchbox/version/version.go or https://github.com/coreos-inc/bridge/blob/master/version/version.go. Please rename for legibility and consistency
There was a problem hiding this comment.
The name was taken from a bazel example of using x_defs to add variables to compiled binaries, and they named it "stamped bin". But your suggestion is actually clearer.
| package stamp | ||
|
|
||
| // TectonicVersion - defaults to 'dev-build' if TECTONIC_VERSION was not set | ||
| var TectonicVersion = "dev-build" |
There was a problem hiding this comment.
For simplicity can we just call this Version?
| func currentReleaseHandler(w http.ResponseWriter, req *http.Request, _ *Context) error { | ||
|
|
||
| verMap := map[string]string{ | ||
| "TectonicVersion": stamp.TectonicVersion, |
There was a problem hiding this comment.
This returns a json object with title-cased keys, which is a little odd. By convention, json keys are normally camel-cased, or sometimes snake-cased. Can you fix the casing?
| // Fetch tectonic's Build version and return in JSON format | ||
| func currentReleaseHandler(w http.ResponseWriter, req *http.Request, _ *Context) error { | ||
|
|
||
| verMap := map[string]string{ |
There was a problem hiding this comment.
For cases such as this where all the fields are known, we typically use an anonymous struct rather than a map. This should also be more memory-efficient
| // Fetch tectonic's Build version and return in JSON format | ||
| func currentReleaseHandler(w http.ResponseWriter, req *http.Request, _ *Context) error { | ||
|
|
||
| verMap := map[string]string{ |
There was a problem hiding this comment.
There is no need to specify the type of this variable in the name. Please rename to just “version”
| "TectonicVersion": stamp.TectonicVersion, | ||
| "BuildTime": stamp.BuildTime, | ||
| } | ||
| return writeJSONResponse(w, req, http.StatusOK, verMap) |
There was a problem hiding this comment.
Where is this API endpoint consumed in the front end? Without it, this pull request does not fully solve our issue of the reported build version being wrong
There was a problem hiding this comment.
I'm planning to add that change in a separate commit
There was a problem hiding this comment.
Sounds good. Separate commit in this same PR or a different PR?
| #!/bin/bash | ||
|
|
||
| # Vars exported to the build info | ||
| echo TECTONIC_VERSION ${TECTONIC_VERSION} |
There was a problem hiding this comment.
Who sets this environment variable? Please add this detail to the build documentation. For consistency, with the rest of the build process, I think that this variable should be simply VERSION
There was a problem hiding this comment.
I'd actually prefer to keep these environment inputs namespaced like this, with TECTONIC_*
Two reasons for this:
- VERSION is much too common and the probability of it affecting other tools or just being used for something else in the system seems rather high.
- The prefixing helps to visualize the current state of the environment much easier by piping
envtosort.
There was a problem hiding this comment.
that's fine; the main issues here are twofold:
- Who sets this variable? We need this documented somewhere.
- We need to make this consistent with the rest of the build process; if we want to go the namespaced route, then that means changing the variables used by the tarball bazel build rule so that we do not need to set two different variables.
There was a problem hiding this comment.
I agree with @alexsomesan in that using just VERSION would be too generic. We could use this api endpoint in the future, to output any kind of build information that would help us debug issues, such as go / bazel versions, etc, etc. So I'd opt for modifying the documentation and existing vars.
There was a problem hiding this comment.
Sounds good. Please make those changes in this PR then
There was a problem hiding this comment.
@squat Both are valid questions.
I think for 1) it's whatever RA ends up running in - most likely their Jenkins pipeline.
For 2), if there're no hard blockers, I'd prefer we align everything that's an input to the build process under TECTONIC_ or TECTONIC_BUILD_. We have to keep in mind that the CLI will also support env var overrides. We might want to make a distinction between the runtime and the buildtime inputs (namespaces). But that's mostly off-topic for this change.
buildvars.sh
Outdated
| @@ -0,0 +1,5 @@ | |||
| #!/bin/bash | |||
|
@kalmog Looks like the commit comment needs updating with the new API endpoint and JSON keys. Let me know if you need any help with the frontend changes. |
|
|
||
| // Fetch tectonic's Build version and return in JSON format | ||
| func currentReleaseHandler(w http.ResponseWriter, req *http.Request, _ *Context) error { | ||
|
|
There was a problem hiding this comment.
nit: can you eliminate this extra newline?
squat
left a comment
There was a problem hiding this comment.
I have one small nit, otherwise looks good!
|
ok to retest |
|
retest this please |
a10e771 to
a01ab31
Compare
this will add a new endpoint "/releases/current" to the API which will fetch TECTONIC_VERSION from the build environment and displays the build time in a JSON format.

this will add a new endpoint
/releases/currentto the APIwhich will fetch TECTONIC_VERSION from the build environment
and displays the build time in a JSON format.