Skip to content

Commit 49f3a52

Browse files
committed
Merge branch 'main' of https://github.com/loft-sh/devspace
2 parents a8efc1d + f56dc02 commit 49f3a52

13 files changed

Lines changed: 88 additions & 78 deletions

File tree

cmd/init.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import (
55
"context"
66
"fmt"
77
"io/ioutil"
8-
"mvdan.cc/sh/v3/expand"
98
"os"
109
"path/filepath"
1110
"regexp"
1211
"strconv"
1312
"strings"
1413

14+
"mvdan.cc/sh/v3/expand"
15+
1516
"github.com/loft-sh/devspace/pkg/devspace/compose"
1617
"github.com/loft-sh/devspace/pkg/devspace/config/localcache"
1718
"github.com/sirupsen/logrus"
@@ -787,11 +788,15 @@ func (cmd *InitCmd) render(f factory.Factory, config *latest.Config) (string, er
787788
return "", errors.Wrap(err, "temp render.yaml")
788789
}
789790

791+
silent := true
792+
if cmd.Debug {
793+
silent = false
794+
}
790795
// Use the render command to render it.
791796
writer := &bytes.Buffer{}
792797
renderCmd := &RunPipelineCmd{
793798
GlobalFlags: &flags.GlobalFlags{
794-
Silent: true,
799+
Silent: silent,
795800
ConfigPath: renderPath,
796801
},
797802
Pipeline: "deploy",

docs/pages/configuration/_partials/v2beta1/deployments/updateImageTags.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<details className="config-field" data-expandable="false" open>
33
<summary>
44

5-
### `updateImageTags` <span className="config-field-required" data-required="false">required</span> <span className="config-field-type">boolean</span> <span className="config-field-default">false</span> <span className="config-field-enum"></span> {#deployments-updateImageTags}
5+
### `updateImageTags` <span className="config-field-required" data-required="false">required</span> <span className="config-field-type">boolean</span> <span className="config-field-default">true</span> <span className="config-field-enum"></span> {#deployments-updateImageTags}
66

77
UpdateImageTags lets you define if DevSpace should update the tags of the images defined in the
88
images section with their most recent built tag.

docs/pages/configuration/deployments/helm/values.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ DevSpace allows you to specify `values` (for inline values) and `valuesFiles` (f
6565

6666

6767
## Update Image Tags
68-
If the `updateImageTags` is set to `true`, DevSpace searches through the Helm values for this deployment (specified via `values` or `valuesFiles`) and tries to find any images in the Helm values that are also defined in the `images` section of the `devspace.yaml`. If DevSpace finds an image, it updates the image tag in the Helm values dynamically, so the tag in the Helm values matches the tag that DevSpace created during the most recent image building process for this image. Image tag updates make sure that your application will always be started with the most up-to-date image that DevSpace has built for you.
68+
If the `updateImageTags` (defaults to true) is set to `true`, DevSpace searches through the Helm values for this deployment (specified via `values` or `valuesFiles`) and tries to find any images in the Helm values that are also defined in the `images` section of the `devspace.yaml`. If DevSpace finds an image, it updates the image tag in the Helm values dynamically, so the tag in the Helm values matches the tag that DevSpace created during the most recent image building process for this image. Image tag updates make sure that your application will always be started with the most up-to-date image that DevSpace has built for you.
6969

7070
#### Example: Enable Tag Updates
7171
```yaml {3}

docs/pages/configuration/dev/connections/restart-helper.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import ConfigPartial from '../../_partials/v2beta1/dev/restartHelper.mdx'
77

88
DevSpace provides a small shell script that can used as container entrypoint (PID 1 process) to start the container instead of your actual container start command.
99

10-
For example, if your entrypoint would be `pyhton main.py`, DevSpace would rewrite the container start command to:
10+
For example, if your entrypoint would be `python main.py`, DevSpace would rewrite the container start command to:
1111
```bash
1212
/.devspace/devspace-restart-helper python main.py
1313
```

docs/pages/configuration/variables.mdx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,21 @@ While there is no need to explicitly define a config variable, it allows you to
1414

1515
## Built-In Variables
1616
DevSpace provides a set of built-in variables:
17-
- `${DEVSPACE_NAMESPACE}` contains the current namespace
17+
1818
- `${DEVSPACE_CONTEXT}` contains the name of the current kube-context (e.g. `minikube`)
19-
- `${DEVSPACE_NAME}` contains the value of the `name` field of the current `devspace.yaml` file
19+
- `${DEVSPACE_EXECUTABLE}` contains the path to the devspace binary used
2020
- `${DEVSPACE_GIT_BRANCH}` contains the name of the local git branch that the user is currently on
2121
- `${DEVSPACE_GIT_COMMIT}` contains the hash of the latest git commit in the current repository
22+
- `${DEVSPACE_KUBECTL_EXECUTABLE}` contains the path to the kubectl binary
23+
- `${DEVSPACE_NAME}` contains the value of the `name` field of the current `devspace.yaml` file
24+
- `${DEVSPACE_NAMESPACE}` contains the current namespace
25+
- `${DEVSPACE_PROFILE}` contains the profile that is currently active in DevSpace (e.g. the string provided via `-p / --profile` in a command such as `devspace dev -p my-profile`)
26+
- `${DEVSPACE_RANDOM}` contains a random 6 character long string
2227
- `${DEVSPACE_TIMESTAMP}` contains the current UNIX timestamp
23-
- `${DEVSPACE_USER_HOME}` contains the path to the current user's home directory
2428
- `${DEVSPACE_TMPDIR}` contains a path to a temporary folder that DevSpace cleans up after the `devspace` command terminates
25-
- `${DEVSPACE_PROFILE}` contains the profile that is currently active in DevSpace (e.g. the string provided via `-p / --profile` in a command such as `devspace dev -p my-profile`)
29+
- `${DEVSPACE_USER_HOME}` contains the path to the current user's home directory
2630
- `${DEVSPACE_VERSION}` contains the version of DevSpace that is currently running
2731

28-
2932
## Custom Variables
3033
DevSpace lets you define custom varables inside `devspace.yaml` within the `vars` section.
3134

pkg/devspace/docker/auth.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ func (c *client) Login(ctx context.Context, registryURL, user, password string,
3939
}
4040

4141
authConfig, err := getDefaultAuthConfig(checkCredentialsStore, serverAddress, isDefaultRegistry)
42-
authConfig.IdentityToken = ""
4342
if err != nil || authConfig.Username == "" || authConfig.Password == "" || relogin {
4443
authConfig.Username = strings.TrimSpace(user)
4544
authConfig.Password = strings.TrimSpace(password)

pkg/devspace/pullsecrets/init.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package pullsecrets
22

33
import (
4+
"time"
5+
46
devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
57
"github.com/loft-sh/devspace/pkg/devspace/docker"
68
"github.com/loft-sh/devspace/pkg/util/stringutil"
7-
"time"
89

910
"github.com/loft-sh/devspace/pkg/devspace/config/versions/latest"
1011
"github.com/loft-sh/devspace/pkg/devspace/hook"
@@ -166,6 +167,10 @@ func (r *client) createPullSecret(ctx devspacecontext.Context, dockerClient dock
166167
if authConfig != nil {
167168
username = authConfig.Username
168169
password = authConfig.Password
170+
171+
if password == "" && authConfig.IdentityToken != "" {
172+
password = authConfig.IdentityToken
173+
}
169174
}
170175
}
171176

pkg/devspace/server/download.go

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,27 @@ import (
66
"compress/gzip"
77
"fmt"
88
"io"
9-
"io/ioutil"
109
"net/http"
1110
"os"
1211
"path/filepath"
13-
"regexp"
1412
"strings"
1513
"time"
1614

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

1917
"github.com/loft-sh/devspace/pkg/devspace/config/constants"
2018
"github.com/loft-sh/devspace/pkg/devspace/upgrade"
19+
"github.com/loft-sh/devspace/pkg/util/git"
2120

2221
homedir "github.com/mitchellh/go-homedir"
2322
"github.com/pkg/errors"
2423
)
2524

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

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

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

7978
// Create download url
80-
url := ""
8179
if version == "latest" {
82-
url = fmt.Sprintf("%s/%s", UIDownloadBaseURL, version)
83-
} else {
84-
url = fmt.Sprintf("%s/tag/%s", UIDownloadBaseURL, version)
80+
version, err = git.GetLatestVersion(UIRepository)
81+
if err != nil {
82+
return errors.Wrap(err, "get latest version")
83+
}
8584
}
8685

87-
// Download html
86+
url := fmt.Sprintf("%s/%s/%s", UIDownloadBaseURL, version, "ui.tar.gz")
8887
resp, err := http.Get(url)
89-
if err != nil {
90-
return errors.Wrap(err, "get url")
91-
}
92-
93-
body, err := ioutil.ReadAll(resp.Body)
94-
if err != nil {
95-
return errors.Wrap(err, "read body")
96-
}
97-
98-
matches := UIDownloadRegEx.FindStringSubmatch(string(body))
99-
if len(matches) != 2 {
100-
return errors.Errorf("Couldn't find ui in github release %s at url %s", version, url)
101-
}
102-
103-
resp, err = http.Get("https://github.com" + matches[1])
10488
if err != nil {
10589
return errors.Wrap(err, "download ui archive")
10690
}

pkg/devspace/services/inject/inject.go

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,41 @@ import (
66
"compress/gzip"
77
"context"
88
"fmt"
9-
"github.com/loft-sh/devspace/assets"
10-
"github.com/loft-sh/devspace/pkg/devspace/env"
119
"io"
1210
"io/fs"
1311
"io/ioutil"
14-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1512
"net/http"
1613
"os"
1714
"path/filepath"
18-
"regexp"
1915
"strings"
2016
"sync"
2117
"time"
2218

19+
"github.com/loft-sh/devspace/assets"
20+
"github.com/loft-sh/devspace/pkg/devspace/env"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
2323
"github.com/loft-sh/devspace/pkg/devspace/config/constants"
2424
"github.com/loft-sh/devspace/pkg/devspace/config/versions/latest"
2525
"github.com/loft-sh/devspace/pkg/devspace/kubectl"
2626
"github.com/loft-sh/devspace/pkg/devspace/upgrade"
27+
"github.com/loft-sh/devspace/pkg/util/git"
2728
"github.com/loft-sh/devspace/pkg/util/hash"
2829
logpkg "github.com/loft-sh/devspace/pkg/util/log"
2930
"github.com/mitchellh/go-homedir"
3031
"github.com/pkg/errors"
3132
v1 "k8s.io/api/core/v1"
3233
)
3334

35+
// DevSpaceHelperRepository is the repository containing the devspace helper
36+
const DevSpaceHelperRepository = "https://github.com/loft-sh/devspace"
37+
3438
// DevSpaceHelperBaseURL is the base url where to look for the sync helper
35-
const DevSpaceHelperBaseURL = "https://github.com/loft-sh/devspace/releases"
39+
const DevSpaceHelperBaseURL = DevSpaceHelperRepository + "/releases/download"
3640

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

40-
// helperBinaryRegEx is the regexp that finds the correct download link for the sync helper binary
41-
var helperBinaryRegEx = `href="(\/loft-sh\/devspace\/releases\/download\/[^\/]*\/%s)"`
42-
4344
// DevSpaceHelperContainerPath is the path of the devspace helper in the container
4445
const DevSpaceHelperContainerPath = "/tmp/devspacehelper"
4546

@@ -153,34 +154,15 @@ func installDevSpaceHelperInContainer(ctx context.Context, client kubectl.Client
153154

154155
// getDownloadURL
155156
func devSpaceHelperDownloadURL(version, filename string) (string, error) {
156-
url := ""
157157
if version == "latest" {
158-
url = fmt.Sprintf("%s/%s", DevSpaceHelperBaseURL, version)
159-
} else {
160-
url = fmt.Sprintf("%s/tag/%s", DevSpaceHelperBaseURL, version)
161-
}
162-
163-
// Download html
164-
resp, err := http.Get(url)
165-
if err != nil {
166-
return "", errors.Wrap(err, "get url")
167-
}
168-
169-
body, err := ioutil.ReadAll(resp.Body)
170-
if err != nil {
171-
return "", errors.Wrap(err, "read body")
172-
}
173-
174-
regEx, err := regexp.Compile(fmt.Sprintf(helperBinaryRegEx, filename))
175-
if err != nil {
176-
return "", err
158+
var err error
159+
version, err = git.GetLatestVersion(DevSpaceHelperRepository)
160+
if err != nil {
161+
return "", errors.Wrap(err, "get latest version")
162+
}
177163
}
178164

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

186168
func downloadSyncHelper(ctx context.Context, helperName, syncBinaryFolder, version string, log logpkg.Logger) error {

pkg/util/git/helper.go

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@ package git
22

33
import (
44
"context"
5-
"github.com/loft-sh/devspace/pkg/util/command"
6-
"mvdan.cc/sh/v3/expand"
5+
"fmt"
6+
"net/http"
77
"os"
8+
"regexp"
89
"strings"
910

11+
"github.com/loft-sh/devspace/pkg/util/command"
12+
"mvdan.cc/sh/v3/expand"
13+
1014
"github.com/pkg/errors"
1115
"gopkg.in/src-d/go-git.v4"
1216
)
1317

18+
var LatestTagRegEx = regexp.MustCompile(`\/tag\/(.*)$`)
19+
1420
// GetBranch retrieves the current HEADs name
1521
func GetBranch(localPath string) (string, error) {
1622
repo, err := git.PlainOpen(localPath)
@@ -79,3 +85,28 @@ func GetRemote(localPath string) (string, error) {
7985

8086
return urls[0], nil
8187
}
88+
89+
func GetLatestVersion(repository string) (string, error) {
90+
client := &http.Client{
91+
CheckRedirect: func(req *http.Request, via []*http.Request) error {
92+
return http.ErrUseLastResponse
93+
},
94+
}
95+
96+
resp, err := client.Get(repository + "/releases/latest")
97+
if err != nil {
98+
return "", err
99+
}
100+
101+
redirect := resp.Header.Get("location")
102+
if redirect == "" {
103+
return "", fmt.Errorf("redirect URL not found")
104+
}
105+
106+
matches := LatestTagRegEx.FindStringSubmatch(redirect)
107+
if len(matches) != 2 {
108+
return "", errors.Errorf("Couldn't find latest release version")
109+
}
110+
111+
return matches[1], nil
112+
}

0 commit comments

Comments
 (0)