Skip to content
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

build tarball without version in name #100

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ dist: resources check perfspect
cp NOTICE dist/perfspect/
cp targets.yaml dist/perfspect/
cp perfspect dist/perfspect/
cd dist && tar -czf perfspect_$(VERSION_NUMBER).tgz perfspect
cd dist && md5sum perfspect_$(VERSION_NUMBER).tgz > perfspect_$(VERSION_NUMBER).tgz.md5.txt
cd dist && tar -czf perfspect.tgz perfspect
cd dist && md5sum perfspect.tgz > perfspect.tgz.md5.txt
rm -rf dist/perfspect
echo '{"version": "$(VERSION_NUMBER)", "date": "$(COMMIT_DATE)", "time": "$(COMMIT_TIME)", "commit": "$(COMMIT_ID)" }' | jq '.' > dist/manifest.json
ifneq ("$(wildcard /prebuilt)","") # /prebuilt is a directory in the container
Expand Down
42 changes: 29 additions & 13 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ import (
)

var gLogFile *os.File
var gVersion = "9.9.9" // overwritten by ldflags in Makefile, set to high number here to avoid update prompt while debugging
var gVersion = "9.9.9" // overwritten by ldflags in Makefile

const (
// LongAppName is the name of the application
LongAppName = "PerfSpect"
LongAppName = "PerfSpect"
artifactoryUrl = "https://af01p-fm.devtools.intel.com/artifactory/perfspectnext-fm-local/releases/latest/"
)

var examples = []string{
Expand Down Expand Up @@ -326,10 +327,24 @@ func updateApp(latestManifest manifest, localTempDir string) error {
runningAppFile := filepath.Base(runningAppPath)

// download the latest release
slog.Debug("Downloading latest release")
fileName := "perfspect" + "_" + latestManifest.Version + ".tgz"
url := "https://af01p-fm.devtools.intel.com/artifactory/perfspectnext-fm-local/releases/latest/" + fileName
resp, err := http.Get(url)
// try both versioned and unversioned filenames, until we settle on a naming convention
versionedFileName := "perfspect" + "_" + latestManifest.Version + ".tgz"
unVersionedfileName := "perfspect.tgz"
fileNames := []string{unVersionedfileName, versionedFileName}
var err error
var resp *http.Response
for _, fileName := range fileNames {
url := artifactoryUrl + fileName
resp, err = http.Get(url)
if err == nil && resp.StatusCode == http.StatusOK {
slog.Info("Downloaded latest release", slog.String("url", url))
break
} else if err != nil {
slog.Warn("Failed to download latest release", slog.String("url", url), slog.String("error", err.Error()))
} else {
slog.Warn("Failed to download latest release", slog.String("url", url), slog.String("status", resp.Status))
}
}
if err != nil {
return err
}
Expand All @@ -346,24 +361,25 @@ func updateApp(latestManifest manifest, localTempDir string) error {
return err
}
tarballFile.Close()
// rename the running app to ".sav"
slog.Debug("Renaming running app")
oldAppPath := filepath.Join(runningAppDir, runningAppFile+".sav")
// rename the running app to "_<version>"
oldAppFile := runningAppFile + "_" + gVersion
oldAppPath := filepath.Join(runningAppDir, oldAppFile)
slog.Info("Renaming running app", slog.String("from", runningAppFile), slog.String("to", oldAppFile))
err = os.Rename(runningAppPath, oldAppPath)
if err != nil {
return err
}
// rename the targets.yaml file to ".sav" if it exists
targetsFile := filepath.Join(runningAppDir, "targets.yaml")
if util.Exists(targetsFile) {
slog.Debug("Renaming targets file")
slog.Info("Renaming targets file", slog.String("from", "targets.yaml"), slog.String("to", "targets.yaml.sav"))
err = os.Rename(targetsFile, targetsFile+".sav")
if err != nil {
return err
}
}
// extract the tarball over the running app's directory
slog.Debug("Extracting tarball")
slog.Info("Extracting latest release", slog.String("from", tarballFile.Name()), slog.String("to", runningAppDir))
err = util.ExtractTGZ(tarballFile.Name(), runningAppDir, true)
if err != nil {
slog.Error("Error extracting downloaded tarball", slog.String("error", err.Error()))
Expand Down Expand Up @@ -393,7 +409,7 @@ func updateApp(latestManifest manifest, localTempDir string) error {
}
// replace the new targets.yaml with the saved one
if util.Exists(targetsFile + ".sav") {
slog.Debug("Restoring targets file")
slog.Info("Restoring targets file", slog.String("from", "targets.yaml.sav"), slog.String("to", "targets.yaml"))
err = os.Rename(targetsFile+".sav", targetsFile)
if err != nil {
return err
Expand All @@ -412,7 +428,7 @@ type manifest struct {

func getLatestManifest() (manifest, error) {
// download manifest file from server
url := "https://af01p-fm.devtools.intel.com/artifactory/perfspectnext-fm-local/releases/latest/manifest.json"
url := artifactoryUrl + "manifest.json"
resp, err := http.Get(url)
if err != nil {
return manifest{}, err
Expand Down