Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
Merge pull request #90 from grammarly/f-fix-onbuild-variables-expansion
Browse files Browse the repository at this point in the history
Expand variables at the time of ONBUILD command execution
  • Loading branch information
Yuriy Bogdanov committed Apr 5, 2016
2 parents 2fb7b13 + 08b65be commit 6dab76d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/build/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,14 @@ func (c *CommandOnbuildWrap) Execute(b *Build) (State, error) {
return c.cmd.Execute(b)
}

// ReplaceEnv implements EnvReplacableCommand interface
func (c *CommandOnbuildWrap) ReplaceEnv(env []string) error {
if command, ok := c.cmd.(EnvReplacableCommand); ok {
return command.ReplaceEnv(env)
}
return nil
}

////////// Private stuff //////////

func replaceEnv(args []string, env []string) (err error) {
Expand Down
32 changes: 32 additions & 0 deletions test/env_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package tests

import (
"github.com/stretchr/testify/assert"
"testing"
)

func TestEnvExpansion(t *testing.T) {

err := runRockerBuildWithOptions(`
FROM alpine
ENV foo=bar
ENV qux=replaced-$foo
RUN touch /$qux
RUN ls -l /replaced-bar`, "--no-cache")

assert.Nil(t, err, "should expand variable in ENV command")
}

func TestEnvExpansionInOnbuild(t *testing.T) {

err := runRockerBuildWithOptions(`
FROM alpine
ENV foo=bar
ONBUILD ENV qux=replaced-onbuild-$foo
TAG bla
FROM bla
RUN touch /$qux
RUN ls -l /replaced-onbuild-bar`, "--no-cache")

assert.Nil(t, err, "should expand variable in ONBUILD command")
}

0 comments on commit 6dab76d

Please sign in to comment.