Skip to content

Commit

Permalink
Added interpolation to docker option in manifest.yaml (#1100)
Browse files Browse the repository at this point in the history
* Added interpolation to docker option in manifest.yaml

* Migrate to using Go Module. Upgraded Go version to 1.14 alongside with other packages. Modified unit tests to accomodate changes.

* Upgraded Travis Go version to 1.14

* Added End-of-Line to a test data file

* Fixed test manifest.yml for integration test. Applied golint and sanitized code

* Added example for docker interpolation in manifest.yaml

Co-authored-by: Huy Doan <huy@ibm.com>
  • Loading branch information
huydoan2 and Huy Doan authored Aug 21, 2020
1 parent 507665d commit 1979827
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 24 deletions.
3 changes: 3 additions & 0 deletions docs/wskdeploy_interpolation.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ project:
function: ${OPENWHISK_FUNCTION_PYTHON}.py
hello4:
function: https://${OPENWHISK_FUNCTION_GITHUB_DIR}.js function: github.com/apache/openwhisk-test/packages/helloworlds
hello5:
function: $OPENWHISK_FUNCTION_FILE
docker: $DOCKER_HUB_IMAGE
```
#### Trigger Feed
Expand Down
5 changes: 3 additions & 2 deletions parsers/manifest_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (

"gopkg.in/yaml.v2"

"net/url"

"github.com/apache/openwhisk-client-go/whisk"
"github.com/apache/openwhisk-wskdeploy/conductor"
"github.com/apache/openwhisk-wskdeploy/dependencies"
Expand All @@ -40,7 +42,6 @@ import (
"github.com/apache/openwhisk-wskdeploy/wski18n"
"github.com/apache/openwhisk-wskdeploy/wskprint"
yamlHelper "github.com/ghodss/yaml"
"net/url"
)

const (
Expand Down Expand Up @@ -796,7 +797,7 @@ func (dm *YAMLParser) composeActionExec(manifestFilePath string, manifestFileNam
if action.Native {
exec.Image = NATIVE_DOCKER_IMAGE
} else {
exec.Image = action.Docker
exec.Image = wskenv.InterpolateStringWithEnvVar(action.Docker).(string)
}
}

Expand Down
9 changes: 8 additions & 1 deletion parsers/manifest_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ func TestComposeActionsForFunctionWithRemoteDir(t *testing.T) {

// validate manifest_parser.ComposeActions() method
func TestComposeActionsForDocker(t *testing.T) {

os.Setenv("image_name", "environmental_variable/image")
file := "../tests/dat/manifest_data_compose_actions_for_docker.yaml"
actionFile := "../tests/src/integration/docker/actions/exec.zip"

Expand Down Expand Up @@ -960,8 +960,15 @@ func TestComposeActionsForDocker(t *testing.T) {
assert.NotNil(t, action.Action.Exec.Code, TEST_MSG_ACTION_CODE_MISSING)
assert.Equal(t, runtimes.BLACKBOX, action.Action.Exec.Kind, fmt.Sprintf(TEST_MSG_ACTION_DOCKER_KIND_MISMATCH, action.Action.Exec.Kind))
assert.Equal(t, "mydockerhub/myimage", action.Action.Exec.Image, TEST_MSG_ACTION_DOCKER_IMAGE_MISMATCH)
case "CustomDockerAction6":
println(action.Action.Exec.Image)
assert.NotNil(t, action.Action.Exec.Code, TEST_MSG_ACTION_CODE_MISSING)
assert.Equal(t, runtimes.BLACKBOX, action.Action.Exec.Kind, fmt.Sprintf(TEST_MSG_ACTION_DOCKER_KIND_MISMATCH, action.Action.Exec.Kind))
assert.Equal(t, os.Getenv("image_name"), action.Action.Exec.Image, TEST_MSG_ACTION_DOCKER_IMAGE_MISMATCH)
}
}

os.Unsetenv("image_name")
}

func TestComposeActionsForEnvVariableInFunction(t *testing.T) {
Expand Down
44 changes: 23 additions & 21 deletions tests/dat/manifest_data_compose_actions_for_docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,26 @@

packages:
IntegrationTestDocker:
actions:
OpenWhiskSkeleton:
docker: openwhisk/skeleton
OpenWhiskSkeletonWithNative:
native: true
CustomDockerAction1:
function: ../src/integration/docker/actions/exec.zip
docker: openwhisk/skeleton
CustomDockerAction2:
function: ../src/integration/docker/actions/exec.zip
native: true
CustomDockerAction3:
function: ../src/integration/docker/actions/bash
native: true
CustomDockerAction4:
function: ../src/integration/docker/actions/go
native: true
CustomDockerAction5:
function: ../src/integration/docker/actions/go
docker: mydockerhub/myimage

actions:
OpenWhiskSkeleton:
docker: openwhisk/skeleton
OpenWhiskSkeletonWithNative:
native: true
CustomDockerAction1:
function: ../src/integration/docker/actions/exec.zip
docker: openwhisk/skeleton
CustomDockerAction2:
function: ../src/integration/docker/actions/exec.zip
native: true
CustomDockerAction3:
function: ../src/integration/docker/actions/bash
native: true
CustomDockerAction4:
function: ../src/integration/docker/actions/go
native: true
CustomDockerAction5:
function: ../src/integration/docker/actions/go
docker: mydockerhub/myimage
CustomDockerAction6:
function: ../src/integration/docker/actions/go
docker: ${image_name}

0 comments on commit 1979827

Please sign in to comment.