Skip to content

Commit

Permalink
Merge pull request #2302 from lizardruss/v5
Browse files Browse the repository at this point in the history
fix: update asset download urls
  • Loading branch information
FabianKramm authored Sep 12, 2022
2 parents 025444a + 294d413 commit 04e45e7
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 72 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ name: Documentation
on:
push:
branches:
- master
- v5
paths:
- "docs/**"
- ".github/workflows/docs.yaml"
pull_request:
branches:
- master
- v5
paths:
- "docs/**"
- ".github/workflows/docs.yaml"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
types: [created]
pull_request:
branches:
- master
- v5
paths:
- "Dockerfile"
- "**.go"
Expand Down
12 changes: 7 additions & 5 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
types: [created]
pull_request:
branches:
- master
- v5
paths:
- "**.go"
- ".github/workflows/lint.yaml"
Expand All @@ -16,11 +16,13 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
- uses: actions/setup-go@v3
with:
go-version: 1.18
- uses: actions/checkout@v3
- name: Run golangci-lint
uses: golangci/[email protected]
with:
version: v1.29
args:
-v
--config=.golangci.yml
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/npm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Test NPM Installer
on:
pull_request:
branches:
- master
- v5
paths:
- "dist/npm/**"
- ".github/workflows/npm.yaml"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ on:
types: [created]
push:
branches:
- master
- v5
paths:
- "Dockerfile"
- "**.go"
- "hack/coverage.bash"
- ".github/workflows/release.yaml"
pull_request:
branches:
- master
- v5
paths:
- "Dockerfile"
- "**.go"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Test UI
on:
pull_request:
branches:
- master
- v5
paths:
- "ui/**"
- "hack/build-ui.bash"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
types: [created]
pull_request:
branches:
- master
- v5
paths:
- "**.go"
- "!e2e/**" # exclude files from e2e tests
Expand Down
4 changes: 2 additions & 2 deletions dist/npm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const inquirer = require('inquirer');
const findProcess = require('find-process');

const downloadPathTemplate =
"https://github.com/loft-sh/devspace/releases/download/{{version}}/devspace-{{platform}}-{{arch}}";
"https://github.com/loft-sh/devspace/releases/download/v{{version}}/devspace-{{platform}}-{{arch}}";
const ARCH_MAPPING = {
ia32: "386",
x64: "amd64",
Expand Down Expand Up @@ -460,4 +460,4 @@ if (process.ppid > 1) {
})
} else {
continueProcess(true);
}
}
36 changes: 10 additions & 26 deletions pkg/devspace/server/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,27 @@ import (
"compress/gzip"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"regexp"
"strings"
"time"

"github.com/loft-sh/devspace/assets"

"github.com/loft-sh/devspace/pkg/devspace/config/constants"
"github.com/loft-sh/devspace/pkg/devspace/upgrade"
"github.com/loft-sh/devspace/pkg/util/git"

homedir "github.com/mitchellh/go-homedir"
"github.com/pkg/errors"
)

// UIDownloadBaseURL is the base url where to look for the ui
const UIDownloadBaseURL = "https://github.com/loft-sh/devspace/releases"
// UIRepository is the repository containing the devspace UI
const UIRepository = "https://github.com/loft-sh/devspace"

// UIDownloadRegEx is the regexp that finds the correct download link for the ui
var UIDownloadRegEx = regexp.MustCompile(`href="(\/loft-sh\/devspace\/releases\/download\/[^\/]*\/ui.tar.gz)"`)
// UIDownloadBaseURL is the base url where to look for the ui
const UIDownloadBaseURL = UIRepository + "/releases/download"

// UITempFolder is the temp folder to cache the ui in
const UITempFolder = "ui"
Expand Down Expand Up @@ -77,30 +76,15 @@ func downloadFile(version string, folder string) error {
}

// Create download url
url := ""
if version == "latest" {
url = fmt.Sprintf("%s/%s", UIDownloadBaseURL, version)
} else {
url = fmt.Sprintf("%s/tag/%s", UIDownloadBaseURL, version)
version, err = git.GetLatestVersion(UIRepository)
if err != nil {
return errors.Wrap(err, "get latest version")
}
}

// Download html
url := fmt.Sprintf("%s/%s/%s", UIDownloadBaseURL, version, "ui.tar.gz")
resp, err := http.Get(url)
if err != nil {
return errors.Wrap(err, "get url")
}

body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return errors.Wrap(err, "read body")
}

matches := UIDownloadRegEx.FindStringSubmatch(string(body))
if len(matches) != 2 {
return errors.Errorf("Couldn't find ui in github release %s at url %s", version, url)
}

resp, err = http.Get("https://github.com" + matches[1])
if err != nil {
return errors.Wrap(err, "download ui archive")
}
Expand Down
43 changes: 12 additions & 31 deletions pkg/devspace/services/inject/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,38 @@ import (
"bytes"
"compress/gzip"
"fmt"
"github.com/loft-sh/devspace/assets"
"io"
"io/fs"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"regexp"
"strings"
"sync"
"time"

"github.com/loft-sh/devspace/assets"
"github.com/loft-sh/devspace/pkg/devspace/config/constants"
"github.com/loft-sh/devspace/pkg/devspace/config/versions/latest"
"github.com/loft-sh/devspace/pkg/devspace/kubectl"
"github.com/loft-sh/devspace/pkg/devspace/upgrade"
"github.com/loft-sh/devspace/pkg/util/git"
"github.com/loft-sh/devspace/pkg/util/hash"
logpkg "github.com/loft-sh/devspace/pkg/util/log"
"github.com/mitchellh/go-homedir"
"github.com/pkg/errors"
v1 "k8s.io/api/core/v1"
)

// DevSpaceHelperRepository is the repository containing the devspace helper
const DevSpaceHelperRepository = "https://github.com/loft-sh/devspace"

// DevSpaceHelperBaseURL is the base url where to look for the sync helper
const DevSpaceHelperBaseURL = "https://github.com/loft-sh/devspace/releases"
const DevSpaceHelperBaseURL = DevSpaceHelperRepository + "/releases/download"

// DevSpaceHelperTempFolder is the local folder where we store the sync helper
const DevSpaceHelperTempFolder = "devspacehelper"

// helperBinaryRegEx is the regexp that finds the correct download link for the sync helper binary
var helperBinaryRegEx = `href="(\/loft-sh\/devspace\/releases\/download\/[^\/]*\/%s)"`

// DevSpaceHelperContainerPath is the path of the devspace helper in the container
const DevSpaceHelperContainerPath = "/tmp/devspacehelper"

Expand Down Expand Up @@ -143,34 +143,15 @@ func installDevSpaceHelperInContainer(client kubectl.Client, pod *v1.Pod, contai

// getDownloadURL
func devSpaceHelperDownloadURL(version, filename string) (string, error) {
url := ""
if version == "latest" {
url = fmt.Sprintf("%s/%s", DevSpaceHelperBaseURL, version)
} else {
url = fmt.Sprintf("%s/tag/%s", DevSpaceHelperBaseURL, version)
}

// Download html
resp, err := http.Get(url)
if err != nil {
return "", errors.Wrap(err, "get url")
}

body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", errors.Wrap(err, "read body")
}

regEx, err := regexp.Compile(fmt.Sprintf(helperBinaryRegEx, filename))
if err != nil {
return "", err
var err error
version, err = git.GetLatestVersion(DevSpaceHelperRepository)
if err != nil {
return "", errors.Wrap(err, "get latest version")
}
}

matches := regEx.FindStringSubmatch(string(body))
if len(matches) != 2 {
return "", errors.Errorf("couldn't find %s in github release %s at url %s", filename, version, url)
}
return "https://github.com" + matches[1], nil
return fmt.Sprintf("%s/%s/%s", DevSpaceHelperBaseURL, version, filename), nil
}

func downloadSyncHelper(helperName, syncBinaryFolder, version string, log logpkg.Logger) error {
Expand Down
30 changes: 30 additions & 0 deletions pkg/util/git/helper.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package git

import (
"fmt"
"net/http"
"os"
"os/exec"
"regexp"
"strings"

"github.com/pkg/errors"
"gopkg.in/src-d/go-git.v4"
)

var LatestTagRegEx = regexp.MustCompile(`\/tag\/(.*)$`)

// GetBranch retrieves the current HEADs name
func GetBranch(localPath string) (string, error) {
repo, err := git.PlainOpen(localPath)
Expand Down Expand Up @@ -77,3 +82,28 @@ func GetRemote(localPath string) (string, error) {

return urls[0], nil
}

func GetLatestVersion(repository string) (string, error) {
client := &http.Client{
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
}

resp, err := client.Get(repository + "/releases/latest")
if err != nil {
return "", err
}

redirect := resp.Header.Get("location")
if redirect == "" {
return "", fmt.Errorf("redirect URL not found")
}

matches := LatestTagRegEx.FindStringSubmatch(redirect)
if len(matches) != 2 {
return "", errors.Errorf("Couldn't find latest release version")
}

return matches[1], nil
}

0 comments on commit 04e45e7

Please sign in to comment.