From 19798274025c54b11329df940c13f2726af5694b Mon Sep 17 00:00:00 2001 From: huydoan2 Date: Fri, 21 Aug 2020 12:51:31 -0500 Subject: [PATCH] Added interpolation to docker option in manifest.yaml (#1100) * 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 --- docs/wskdeploy_interpolation.md | 3 ++ parsers/manifest_parser.go | 5 ++- parsers/manifest_parser_test.go | 9 +++- ...ifest_data_compose_actions_for_docker.yaml | 44 ++++++++++--------- 4 files changed, 37 insertions(+), 24 deletions(-) diff --git a/docs/wskdeploy_interpolation.md b/docs/wskdeploy_interpolation.md index 57f5d1960..b067c6ae8 100644 --- a/docs/wskdeploy_interpolation.md +++ b/docs/wskdeploy_interpolation.md @@ -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 diff --git a/parsers/manifest_parser.go b/parsers/manifest_parser.go index beff9cce1..bf5ad9fb3 100644 --- a/parsers/manifest_parser.go +++ b/parsers/manifest_parser.go @@ -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" @@ -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 ( @@ -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) } } diff --git a/parsers/manifest_parser_test.go b/parsers/manifest_parser_test.go index 3782360b8..5068a4517 100644 --- a/parsers/manifest_parser_test.go +++ b/parsers/manifest_parser_test.go @@ -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" @@ -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) { diff --git a/tests/dat/manifest_data_compose_actions_for_docker.yaml b/tests/dat/manifest_data_compose_actions_for_docker.yaml index 8bb10c1e5..0f439ddf2 100644 --- a/tests/dat/manifest_data_compose_actions_for_docker.yaml +++ b/tests/dat/manifest_data_compose_actions_for_docker.yaml @@ -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}