Skip to content

Commit eda6a19

Browse files
authored
build tarball without version in name (#100)
1 parent b35e20e commit eda6a19

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ dist: resources check perfspect
4545
cp NOTICE dist/perfspect/
4646
cp targets.yaml dist/perfspect/
4747
cp perfspect dist/perfspect/
48-
cd dist && tar -czf perfspect_$(VERSION_NUMBER).tgz perfspect
49-
cd dist && md5sum perfspect_$(VERSION_NUMBER).tgz > perfspect_$(VERSION_NUMBER).tgz.md5.txt
48+
cd dist && tar -czf perfspect.tgz perfspect
49+
cd dist && md5sum perfspect.tgz > perfspect.tgz.md5.txt
5050
rm -rf dist/perfspect
5151
echo '{"version": "$(VERSION_NUMBER)", "date": "$(COMMIT_DATE)", "time": "$(COMMIT_TIME)", "commit": "$(COMMIT_ID)" }' | jq '.' > dist/manifest.json
5252
ifneq ("$(wildcard /prebuilt)","") # /prebuilt is a directory in the container

cmd/root.go

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ import (
3232
)
3333

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

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

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

328329
// download the latest release
329-
slog.Debug("Downloading latest release")
330-
fileName := "perfspect" + "_" + latestManifest.Version + ".tgz"
331-
url := "https://af01p-fm.devtools.intel.com/artifactory/perfspectnext-fm-local/releases/latest/" + fileName
332-
resp, err := http.Get(url)
330+
// try both versioned and unversioned filenames, until we settle on a naming convention
331+
versionedFileName := "perfspect" + "_" + latestManifest.Version + ".tgz"
332+
unVersionedfileName := "perfspect.tgz"
333+
fileNames := []string{unVersionedfileName, versionedFileName}
334+
var err error
335+
var resp *http.Response
336+
for _, fileName := range fileNames {
337+
url := artifactoryUrl + fileName
338+
resp, err = http.Get(url)
339+
if err == nil && resp.StatusCode == http.StatusOK {
340+
slog.Info("Downloaded latest release", slog.String("url", url))
341+
break
342+
} else if err != nil {
343+
slog.Warn("Failed to download latest release", slog.String("url", url), slog.String("error", err.Error()))
344+
} else {
345+
slog.Warn("Failed to download latest release", slog.String("url", url), slog.String("status", resp.Status))
346+
}
347+
}
333348
if err != nil {
334349
return err
335350
}
@@ -346,24 +361,25 @@ func updateApp(latestManifest manifest, localTempDir string) error {
346361
return err
347362
}
348363
tarballFile.Close()
349-
// rename the running app to ".sav"
350-
slog.Debug("Renaming running app")
351-
oldAppPath := filepath.Join(runningAppDir, runningAppFile+".sav")
364+
// rename the running app to "_<version>"
365+
oldAppFile := runningAppFile + "_" + gVersion
366+
oldAppPath := filepath.Join(runningAppDir, oldAppFile)
367+
slog.Info("Renaming running app", slog.String("from", runningAppFile), slog.String("to", oldAppFile))
352368
err = os.Rename(runningAppPath, oldAppPath)
353369
if err != nil {
354370
return err
355371
}
356372
// rename the targets.yaml file to ".sav" if it exists
357373
targetsFile := filepath.Join(runningAppDir, "targets.yaml")
358374
if util.Exists(targetsFile) {
359-
slog.Debug("Renaming targets file")
375+
slog.Info("Renaming targets file", slog.String("from", "targets.yaml"), slog.String("to", "targets.yaml.sav"))
360376
err = os.Rename(targetsFile, targetsFile+".sav")
361377
if err != nil {
362378
return err
363379
}
364380
}
365381
// extract the tarball over the running app's directory
366-
slog.Debug("Extracting tarball")
382+
slog.Info("Extracting latest release", slog.String("from", tarballFile.Name()), slog.String("to", runningAppDir))
367383
err = util.ExtractTGZ(tarballFile.Name(), runningAppDir, true)
368384
if err != nil {
369385
slog.Error("Error extracting downloaded tarball", slog.String("error", err.Error()))
@@ -393,7 +409,7 @@ func updateApp(latestManifest manifest, localTempDir string) error {
393409
}
394410
// replace the new targets.yaml with the saved one
395411
if util.Exists(targetsFile + ".sav") {
396-
slog.Debug("Restoring targets file")
412+
slog.Info("Restoring targets file", slog.String("from", "targets.yaml.sav"), slog.String("to", "targets.yaml"))
397413
err = os.Rename(targetsFile+".sav", targetsFile)
398414
if err != nil {
399415
return err
@@ -412,7 +428,7 @@ type manifest struct {
412428

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

0 commit comments

Comments
 (0)