Skip to content

Commit

Permalink
Merge pull request #46 from Optum/dockerfile-patch
Browse files Browse the repository at this point in the history
update dockerfile logic
  • Loading branch information
mkrouse committed Nov 18, 2021
2 parents df477ac + 89fd907 commit aeee2d3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
21 changes: 12 additions & 9 deletions cmd/cli/cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,7 @@ var deployCmd = &cobra.Command{
buildKit := "DOCKER_BUILDKIT=1"
containerTag := viper.GetString("project")

if Dockerfile != "" {
//Dockerfile = Dockerfile
} else if viper.GetString("dockerfile") != "" {
Dockerfile = viper.GetString("dockerfile")
} else {
Dockerfile = DockerfileTemplate
}

cmdd := exec.Command("docker", "build", "-t", containerTag, "-f", Dockerfile)
cmdd := exec.Command("docker", "build", "-t", containerTag, "-f", getDockerfileForBuild())

cmdd.Args = append(cmdd.Args, getBuildArguments()...)

Expand Down Expand Up @@ -236,6 +228,17 @@ func checkInitialized() bool {
return InitAction()
}

func getDockerfileForBuild() string {
if Dockerfile != "" {
//Dockerfile = Dockerfile
} else if viper.GetString("dockerfile") != "" {
return viper.GetString("dockerfile")
} else {
return DefaultDockerfile
}
return Dockerfile
}

func getBuildArguments() (args []string) {
// check viper configuration if not set
if Container == "" && viper.GetString("container") != "" {
Expand Down
13 changes: 12 additions & 1 deletion cmd/cli/cmd/deploy_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package cmd

import (
"github.com/stretchr/testify/require"
"testing"

"github.com/spf13/viper"
"github.com/stretchr/testify/require"
)

func TestSanitizeMachinename(t *testing.T) {
Expand Down Expand Up @@ -37,3 +39,12 @@ func TestGetBuildArguments_ShouldSetBuildArgContainerOnlyWhenValueExists(t *test
require.Equal(t, expected, result)
}
}

func TestGetDockerfileForBuild(t *testing.T) {
result := getDockerfileForBuild()
require.Equal(t, ".runiac/Dockerfile", result)
viper.Set("dockerfile", "mock")
result2 := getDockerfileForBuild()
require.Equal(t, "mock", result2)
viper.Set("dockerfile", "")
}

0 comments on commit aeee2d3

Please sign in to comment.