From f83e459ae0a050536e5c64c48d3cfaff08c8f8cc Mon Sep 17 00:00:00 2001 From: lucklove Date: Wed, 5 Aug 2020 20:03:56 +0800 Subject: [PATCH 1/3] Fix tiup update --self with offline package Fix https://github.com/pingcap/tiup/issues/658 Signed-off-by: lucklove --- pkg/environment/env.go | 12 +++++++++++- pkg/repository/clone_mirror.go | 21 --------------------- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/pkg/environment/env.go b/pkg/environment/env.go index 3932881480..8cfb95de09 100644 --- a/pkg/environment/env.go +++ b/pkg/environment/env.go @@ -215,7 +215,17 @@ func (env *Environment) PlatformString() string { // SelfUpdate updates TiUp. func (env *Environment) SelfUpdate() error { if env.v1Repo != nil { - return env.v1Repo.DownloadTiup(env.LocalPath("bin")) + if err := env.v1Repo.DownloadTiup(env.LocalPath("bin")); err != nil { + return err + } + + // Cover the root.json from tiup.bar.gz + profile := localdata.InitProfile() + if err := profile.ResetMirror(Mirror(), ""); err != nil { + return err + } + + return nil } return env.repo.DownloadTiup(env.LocalPath("bin")) diff --git a/pkg/repository/clone_mirror.go b/pkg/repository/clone_mirror.go index bf9eb0bb08..2d51e7c6e8 100644 --- a/pkg/repository/clone_mirror.go +++ b/pkg/repository/clone_mirror.go @@ -306,27 +306,6 @@ func cloneComponents(repo *V1Repository, compManifests[name] = newManifest } - // Download TiUP binary - for _, goos := range options.OSs { - for _, goarch := range options.Archs { - url := fmt.Sprintf("/tiup-%s-%s.tar.gz", goos, goarch) - dstFile := filepath.Join(targetDir, url) - tmpFile := filepath.Join(tmpDir, url) - - if err := repo.Mirror().Download(url, tmpDir); err != nil { - if errors.Cause(err) == ErrNotFound { - fmt.Printf("TiUP donesn't have %s/%s, skipped\n", goos, goarch) - continue - } - return nil, err - } - // Move file to target directory if hashes pass verify. - if err := os.Rename(tmpFile, dstFile); err != nil { - return nil, err - } - } - } - return compManifests, nil } From b58a10c6757459a315848da42fcde8c38707f50d Mon Sep 17 00:00:00 2001 From: lucklove Date: Fri, 7 Aug 2020 14:54:17 +0800 Subject: [PATCH 2/3] Revert download tiup binary Signed-off-by: lucklove --- pkg/repository/clone_mirror.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pkg/repository/clone_mirror.go b/pkg/repository/clone_mirror.go index 2d51e7c6e8..bf9eb0bb08 100644 --- a/pkg/repository/clone_mirror.go +++ b/pkg/repository/clone_mirror.go @@ -306,6 +306,27 @@ func cloneComponents(repo *V1Repository, compManifests[name] = newManifest } + // Download TiUP binary + for _, goos := range options.OSs { + for _, goarch := range options.Archs { + url := fmt.Sprintf("/tiup-%s-%s.tar.gz", goos, goarch) + dstFile := filepath.Join(targetDir, url) + tmpFile := filepath.Join(tmpDir, url) + + if err := repo.Mirror().Download(url, tmpDir); err != nil { + if errors.Cause(err) == ErrNotFound { + fmt.Printf("TiUP donesn't have %s/%s, skipped\n", goos, goarch) + continue + } + return nil, err + } + // Move file to target directory if hashes pass verify. + if err := os.Rename(tmpFile, dstFile); err != nil { + return nil, err + } + } + } + return compManifests, nil } From 2b59ce3ed6f1037d5be4f84fdf6efd297537d28d Mon Sep 17 00:00:00 2001 From: lucklove Date: Fri, 7 Aug 2020 15:31:36 +0800 Subject: [PATCH 3/3] Address comment Signed-off-by: lucklove --- .github/workflows/install.yaml | 4 +++- pkg/environment/env.go | 7 +------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/install.yaml b/.github/workflows/install.yaml index 4bef306bd2..e8770e90d5 100644 --- a/.github/workflows/install.yaml +++ b/.github/workflows/install.yaml @@ -24,6 +24,7 @@ jobs: sh install.sh source ~/.profile which tiup || (echo "no tiup found" && exit 1) + ! tiup update --self | grep -i "WARN: adding root certificate" local_install: name: Local Install runs-on: ubuntu-latest @@ -50,4 +51,5 @@ jobs: run: | sh local_install.sh source ~/.profile - which tiup || (echo "no tiup found" && exit 1) \ No newline at end of file + which tiup || (echo "no tiup found" && exit 1) + ! tiup update --self | grep -i "WARN: adding root certificate" \ No newline at end of file diff --git a/pkg/environment/env.go b/pkg/environment/env.go index 8cfb95de09..1f822534f6 100644 --- a/pkg/environment/env.go +++ b/pkg/environment/env.go @@ -220,12 +220,7 @@ func (env *Environment) SelfUpdate() error { } // Cover the root.json from tiup.bar.gz - profile := localdata.InitProfile() - if err := profile.ResetMirror(Mirror(), ""); err != nil { - return err - } - - return nil + return localdata.InitProfile().ResetMirror(Mirror(), "") } return env.repo.DownloadTiup(env.LocalPath("bin"))