From 61583984acabd533a44420869fbdc18b5943e9bc Mon Sep 17 00:00:00 2001 From: Andrej Petras Date: Sun, 24 Jan 2021 20:03:55 +0100 Subject: [PATCH] Fix current dir configuration. Add docker-build-push flag --- cmd/docker.go | 3 +++ cmd/root.go | 4 +++- docker/docker.go | 9 +++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cmd/docker.go b/cmd/docker.go index e025062..7887474 100644 --- a/cmd/docker.go +++ b/cmd/docker.go @@ -16,6 +16,7 @@ type dockerFlags struct { DockerContext string `mapstructure:"docker-context"` DockerSkipPull bool `mapstructure:"docker-pull-skip"` DockerSkipPush bool `mapstructure:"docker-push-skip"` + DockerBuildpPush bool `mapstructure:"docker-build-push"` DockerReleaseRegistry string `mapstructure:"docker-release-registry"` DockerReleaseRepoPrefix string `mapstructure:"docker-release-group"` DockerReleaseRepository string `mapstructure:"docker-release-repository"` @@ -45,6 +46,7 @@ var ( DockerfileProfile: op.DockerfileProfile, Context: op.DockerContext, SkipPull: op.DockerSkipPull, + SkipPush: !op.DockerBuildpPush, Versions: createVersions(p, op.Project), } docker.Build() @@ -110,6 +112,7 @@ func initDocker() { addFlag(dockerBuildCmd, "docker-file-profile", "p", "", "profile of the Dockerfile.") addFlag(dockerBuildCmd, "docker-context", "", ".", "the docker build context") addBoolFlag(dockerBuildCmd, "docker-pull-skip", "", false, "skip docker pull for the build") + addBoolFlag(dockerBuildCmd, "docker-build-push", "", false, "push docker images after build") addChildCmd(dockerCmd, dockerPushCmd) addBoolFlag(dockerPushCmd, "docker-push-skip", "", false, "skip docker push of release image to registry") diff --git a/cmd/root.go b/cmd/root.go index 6f32443..5244df1 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -87,7 +87,9 @@ func initConfig() { log.Fatal(err) } - // Search config in home directory with name ".cobra" (without extension). + // Search confing in current directory + viper.AddConfigPath(".") + // Search config in home directory with name ".samo" (without extension). viper.AddConfigPath(home) viper.SetConfigName(".samo") } diff --git a/docker/docker.go b/docker/docker.go index eebfee2..1f4260b 100644 --- a/docker/docker.go +++ b/docker/docker.go @@ -130,6 +130,15 @@ func (request DockerRequest) Build() { "image": dockerImage, "tags": tags, }).Info("Docker build done!") + + if !request.SkipPush { + request.Push() + } else { + log.WithFields(log.Fields{ + "image": dockerImage, + "tags": tags, + }).Debug("Skip push docker images after build.") + } } // DockerPush push docker image of the project