#How to publish a Go app and make it self-updatable?

32 messages · Page 1 of 1 (latest)

high willow
#

I’m working on a Go CLI app: https://github.com/Zimzozaur/don and I want it to be self-updatable from within the app itself.

Specifically, I want the update command in my main.go (line 32: https://github.com/Zimzozaur/don/blob/024e35a6011844b0cca348dbf1d6160acd7f6104/main.go#L32) to:

  1. Easily download the latest version of the app
  2. Replace the existing binary so I can run the newest version immediately

I’m also a bit confused about publishing Go apps in general. How do people usually make a CLI available for anyone to install and update easily?

What’s the simplest way to do this in Go? Ideally I’d like to avoid creating tags or releases if possible.

finite zealot
#

What’s the simplest way to do this in Go?
simplest for you or for users?

#

the simplest method for you would be simply pushing to the repo and expecting users to run go install again after somehow getting the news of an update to them, but as you can imagine that might not be ideal on the user’s end

#

integrating into well-known package managers is probably the best experience from the user’s perspective, but it takes some leg work on your end

#

Go’s tooling doesn’t provide any sort of “hey, we noticed this module has an update” like something like npm does; it’s always driven manually (either per-package or with a go get -u for all dependencies in a module, but even that doesn’t do things like notify about new major versions, since they’re separate modules)

high willow
finite zealot
#

that will update the binary when run

#

oh, i see you’re referring to the code rather than the repo in general

#

notice your README uses main while your code uses latest

#

the former will get the newest commit on main; the latter will get the newest tag

#

when you said you’d like the avoid creating tags i assumed you weren’t trying already 😁

high willow
#

I run few times on mac and linux to double check don update and it is not update. Changed version on git also to see it working

high willow
#

When you run go install github.com/Zimzozaur/don@main it install verion 0.0.4 and not 0.0.5... What is wrong with it?

#

What is the right way to install literally last commit without knowing version or hash of last commit?

finite zealot
#

that is @main, you’ve got it

high willow
finite zealot
#

are you sure that you’re not still running the old version of the binary’s update command?

#

i’m not sure off the top of my head whether the proxy factors into commit-based pulls in addition to tag-based ones, but that could be what’s happening

#

if you set GOPROXY=direct in the environment and you get the new version, that's probably what happened

#

in any case, i think the caching won't last for more than fifteen minutes or so

high willow
#

It still downloads the older version

finite zealot
#

try GOPROXY=direct go install github.com/Zimzozaur/don@main

finite zealot
high willow
finite zealot
#

this should only be relevant for a few minutes after you publish the commit

#

the proxy will eventually time out the old cached copy

high willow
finite zealot
#

yes, if you want to get it absolutely immediately then you may need to