Skip to content

Commit

Permalink
Environment variables should be replaced in URLs in ADD commands.
Browse files Browse the repository at this point in the history
We were previously explicitly skipping this for some reason, but Docker
seems to expand these in URLs so we should too.
  • Loading branch information
dlorenc committed Feb 22, 2019
1 parent 4b7e2b3 commit 420b980
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 6 deletions.
7 changes: 5 additions & 2 deletions integration/dockerfiles/Dockerfile_test_add
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@ ARG file
COPY $file /arg

# Finally, test adding a remote URL, concurrently with a normal file
ADD https://github.com/GoogleCloudPlatform/docker-credential-gcr/releases/download/v1.4.3/docker-credential-gcr_linux_386-1.4.3.tar.gz context/foo /test/all/
ADD https://github.com/GoogleCloudPlatform/docker-credential-gcr/releases/download/v1.4.3-static/docker-credential-gcr_linux_amd64-1.4.3.tar.gz /destination
ADD https://github.com/GoogleCloudPlatform/docker-credential-gcr/releases/download/1.4.3/docker-credential-gcr_linux_386-1.4.3.tar.gz context/foo /test/all/

# Test environment replacement in the URL
ENV VERSION=1.4.3
ADD https://github.com/GoogleCloudPlatform/docker-credential-gcr/releases/download/${VERSION}-static/docker-credential-gcr_linux_amd64-1.4.3.tar.gz /destination
4 changes: 0 additions & 4 deletions pkg/util/command_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ import (
func ResolveEnvironmentReplacementList(values, envs []string, isFilepath bool) ([]string, error) {
var resolvedValues []string
for _, value := range values {
if IsSrcRemoteFileURL(value) {
resolvedValues = append(resolvedValues, value)
continue
}
resolved, err := ResolveEnvironmentReplacement(value, envs, isFilepath)
logrus.Debugf("Resolved %s to %s", value, resolved)
if err != nil {
Expand Down
55 changes: 55 additions & 0 deletions pkg/util/command_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package util

import (
"reflect"
"sort"
"testing"

Expand Down Expand Up @@ -448,3 +449,57 @@ func Test_RemoteUrls(t *testing.T) {
}

}

func TestResolveEnvironmentReplacementList(t *testing.T) {
type args struct {
values []string
envs []string
isFilepath bool
}
tests := []struct {
name string
args args
want []string
wantErr bool
}{
{
name: "url",
args: args{
values: []string{
"https://google.com/$foo", "$bar",
},
envs: []string{
"foo=baz",
"bar=bat",
},
},
want: []string{"https://google.com/baz", "bat"},
},
{
name: "mixed",
args: args{
values: []string{
"$foo", "$bar$baz", "baz",
},
envs: []string{
"foo=FOO",
"bar=BAR",
"baz=BAZ",
},
},
want: []string{"FOO", "BARBAZ", "baz"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := ResolveEnvironmentReplacementList(tt.args.values, tt.args.envs, tt.args.isFilepath)
if (err != nil) != tt.wantErr {
t.Errorf("ResolveEnvironmentReplacementList() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("ResolveEnvironmentReplacementList() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 420b980

Please sign in to comment.