Skip to content

Commit

Permalink
fix as keyword in FROM instruction
Browse files Browse the repository at this point in the history
Signed-off-by: Batuhan Apaydın <batuhan.apaydin@trendyol.com>
  • Loading branch information
developer-guy committed Jul 13, 2021
1 parent f41284e commit df6994a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmd/cosign/cli/verify_dockerfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func getImagesFromDockerfile(dockerfile io.Reader) ([]string, error) {
func getImageFromLine(line string) string {
line = strings.TrimPrefix(line, "FROM") // Remove "FROM" prefix
line = os.ExpandEnv(line) // Substitute templated vars
line = strings.ReplaceAll(line, "as", "AS") // replace lower "as" with "AS"
line = strings.Split(line, " AS ")[0] // Remove the "AS" portion of line
fields := strings.Fields(line)
return fields[len(fields)-1] // The image should be the last portion of the line that remains
Expand Down
4 changes: 2 additions & 2 deletions cmd/cosign/cli/verify_dockerfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func TestGetImagesFromDockerfile(t *testing.T) {
},
{
name: "tag with as",
fileContents: `FROM golang:1.16.5 as build`,
expected: []string{"gcr.io/test/image:latest"},
fileContents: `FROM gcr.io/test/image:1.16.5 as build`,
expected: []string{"gcr.io/test/image:1.16.5"},
},
{
name: "digest",
Expand Down

0 comments on commit df6994a

Please sign in to comment.