Skip to content

Go package for auto-updating binaries and other assets via HTTP Fileserver (Students project)

License

Notifications You must be signed in to change notification settings

haevg-rz/go-updater

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

79 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-updater

Go package for auto-updating binaries and other assets via HTTP Fileserver (Students project)

Go codecov

Install

go get github.com/haevg-rz/go-updater/update

Feature set

  • Self update (of running executable or deamon/services)
  • Check for update 👀
  • Optional no major version update 💂‍♂️
  • Updating of external assets (with optional compression) 💾
  • Support of different asset version (like windows, linux) 🍎 🍋
  • Only a 🌍 CDN or 💻 FileShare is needed
  • Delegate to check if update is allowed or skipped ❓
  • Automatic updating 🕑

under development

  • every asset is signed with Ed25519 🔒

Upload Tool (to be implemented)

  • Different targets
    • FileShare
    • Azure CDN
    • more to come
  • Signing of assets

Use Case

myapp.exe -> https://example.org/myapp/1/myapp_win_amd64.zip

(.NET 5 App)
- /shippedFirstDotNetApp/mydotnetapp.exe  -> https://example.org/shippedFirstDotNetApp/beta/1/shippedFirstDotNetApp_win_amd64.zip
- /shippedFirstDotNetApp/*.dll

(Single file Publish)
- /shippedSecondDotNetApp/mydotnetapp.exe -> https://example.org/shippedSecondDotNetApp/beta/1/shippedSecondDotNetApp_win_amd64.exe

- /databases/database_customer_xyz.sqlite -> https://example.org/shippedSecondDotNetApp/beta/1/database_customer_xyz.sqlite

myapp.exe uses this package to update itself and the .NET application mydotnetapp.exe and its dependencies and the database database_customer_xyz.sqlite.

File Structure

CDN

https://example.org/{AssetName}/{Channel}/latest.txt pointing to the latest major, eg. "1"
https://example.org/{AssetName}/{Channel}/{Major}/latest.txt pointing to the latest minor or patch, eg. "1.2.3"
https://example.org/{AssetName}/{Channel}/{Major}/{AssetName}_{Version}_{Specs}_{FileExtension} the actual major´s minor or patch file

Example

TOOO

Client

package main

import (
	"runtime"
	"time"
	"updatersample/update"
)

var Version = "0.0.0" // Set in build
const AppName = "MyAppName"

func main() {
	var assetApp = &update.Asset{
		AssetVersion:  Version,
		AssetName:     AppName,
		Channel:       "Stable",
		CdnBaseURL:    "https://cdn.company.com/updates/",
		DoMajorUpdate: false,
		Specs: map[string]string{
			"Arch": runtime.GOARCH,
			"OS":   runtime.GOOS,
		},
	}

	// Do a check for an update
	_, _ = assetApp.CheckForUpdate()

	// Do a self update
	_, _ = assetApp.SelfUpdate()

	// Check if a previous update was aborted
	_ = assetApp.UpdateAborted()

	// Start a background goroutine for continuous checks
	go assetApp.Background(time.Hour, time.Minute*10, allowUpdate)

	updateDatabaseAsset()
	updateDotNetApp()
}

func allowUpdate() bool {
	return true
}

Update external assets

func updateDatabaseAsset() {
	assetDb := &update.Asset{
		AssetVersion: getVersion(),
		AssetName:    "MyDatabases",
		Channel:      "Stable",
		CdnBaseURL:   "https://cdn.company.com/updates/",
		Specs: map[string]string{
			"Name": "MyContacts",
			"Type": "SQlite",
		},
		TargetFolder: "db",
	}

	// Update asset
	_, _ = assetDb.Update()
}

func getVersion() string {
	return "0.0.1"
}

Update external dot net apps

func updateDotNetApp() {
	assetDotNet := &update.Asset{
		AssetVersion: getVersion(),
		AssetName:    "MyDotNetApp",
		Channel:      "Stable",
		CdnBaseURL:   "https://cdn.company.com/updates/",
		Specs: map[string]string{
			"Arch":         runtime.GOARCH,
			"OS":           runtime.GOOS,
			"Distribution": "RedHat",
		},
		TargetFolder: "MyDotNetApp",
	}

	// Update asset
	_, _ = assetDotNet.Update()
}

func getVersion() string {
	return "0.0.1"
}

Upload tool

About

Go package for auto-updating binaries and other assets via HTTP Fileserver (Students project)

Resources

License

Stars

Watchers

Forks

Packages

No packages published