Skip to content

Commit

Permalink
Merge pull request #129 from ninech/dockerfile-build
Browse files Browse the repository at this point in the history
feat: add dockerfile flags
  • Loading branch information
ctrox authored Jul 18, 2024
2 parents b715b9f + 3b40b71 commit 1fd7644
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
17 changes: 17 additions & 0 deletions create/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type applicationCmd struct {
SkipRepoAccessCheck bool `help:"Skip the git repository access check" default:"false"`
Debug bool `help:"Enable debug messages" default:"false"`
Language string `help:"${app_language_help} Possible values: ${enum}" enum:"ruby,php,python,golang,nodejs,static,ruby-heroku," default:""`
DockerfileBuild dockerfileBuild `embed:""`
}

type gitConfig struct {
Expand All @@ -65,6 +66,12 @@ type deployJob struct {
Timeout time.Duration `default:"${app_default_deploy_job_timeout}" help:"Timeout of the job. Default is ${app_default_deploy_job_timeout}, minimum is 1 minute and maximum is 30 minutes."`
}

type dockerfileBuild struct {
Enabled bool `name:"dockerfile" help:"${app_dockerfile_enable_help}" default:"false"`
Path string `name:"dockerfile-path" help:"${app_dockerfile_path_help}" default:""`
BuildContext string `name:"dockerfile-build-context" help:"${app_dockerfile_build_context_help}" default:""`
}

func (g gitConfig) sshPrivateKey() (*string, error) {
if g.SSHPrivateKey != nil {
return util.ValidatePEM(*g.SSHPrivateKey)
Expand Down Expand Up @@ -294,6 +301,11 @@ func (app *applicationCmd) newApplication(project string) *apps.Application {
Hosts: app.Hosts,
Config: app.config(),
BuildEnv: util.EnvVarsFromMap(app.BuildEnv),
DockerfileBuild: apps.DockerfileBuild{
Enabled: app.DockerfileBuild.Enabled,
DockerfilePath: app.DockerfileBuild.Path,
BuildContext: app.DockerfileBuild.BuildContext,
},
},
},
}
Expand Down Expand Up @@ -572,5 +584,10 @@ func ApplicationKongVars() (kong.Vars, error) {
result["app_language_help"] = "Language specifies which language your app is. " +
"If left empty, deploio will detect the language automatically. " +
"Note that *-heroku languages are experimental and may be removed in future releases."
result["app_dockerfile_enable_help"] = "Enable Dockerfile build (Beta) instead of the automatic " +
"buildpack detection"
result["app_dockerfile_path_help"] = "Specifies the path to the Dockerfile. If left empty a file " +
"named Dockerfile will be searched in the application code root directory."
result["app_dockerfile_build_context_help"] = "Defines the build context. If left empty, the application code root directory will be used as build context."
return result, nil
}
4 changes: 4 additions & 0 deletions internal/format/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func PrintFailuref(icon, format string, a ...any) {
fmt.Print(FailureMessagef(icon, format, a...) + "\n")
}

func PrintWarningf(msg string, a ...any) {
fmt.Printf(color.YellowString("Warning: ")+msg, a...)
}

// Confirmf prints a confirm dialog using format and then waits until prompt
// is confirmed or denied. Only y and yes are accepted for confirmation.
func Confirmf(format string, a ...any) (bool, error) {
Expand Down
23 changes: 23 additions & 0 deletions update/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/ninech/nctl/api"
"github.com/ninech/nctl/api/util"
"github.com/ninech/nctl/api/validation"
"github.com/ninech/nctl/internal/format"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -38,6 +39,7 @@ type applicationCmd struct {
SkipRepoAccessCheck bool `help:"Skip the git repository access check" default:"false"`
Debug bool `help:"Enable debug messages" default:"false"`
Language *string `help:"${app_language_help} Possible values: ${enum}" enum:"ruby,php,python,golang,nodejs,static,ruby-heroku," default:""`
DockerfileBuild dockerfileBuild `embed:""`
}

type gitConfig struct {
Expand Down Expand Up @@ -79,6 +81,11 @@ type deployJob struct {
Timeout *time.Duration `help:"Timeout of the job." placeholder:"${app_default_deploy_job_timeout}"`
}

type dockerfileBuild struct {
Path *string `name:"dockerfile-path" help:"${app_dockerfile_path_help}" placeholder:"."`
BuildContext *string `name:"dockerfile-build-context" help:"${app_dockerfile_build_context_help}" placeholder:"."`
}

func (cmd *applicationCmd) Run(ctx context.Context, client *api.Client) error {
app := &apps.Application{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -223,6 +230,16 @@ func (cmd *applicationCmd) applyUpdates(app *apps.Application) {
buildDelEnv = *cmd.DeleteBuildEnv
}
app.Spec.ForProvider.BuildEnv = util.UpdateEnvVars(app.Spec.ForProvider.BuildEnv, buildEnv, buildDelEnv)

if cmd.DockerfileBuild.Path != nil {
app.Spec.ForProvider.DockerfileBuild.DockerfilePath = *cmd.DockerfileBuild.Path
warnIfDockerfileNotEnabled(app, "path")
}

if cmd.DockerfileBuild.BuildContext != nil {
app.Spec.ForProvider.DockerfileBuild.BuildContext = *cmd.DockerfileBuild.BuildContext
warnIfDockerfileNotEnabled(app, "build context")
}
}

func (job deployJob) applyUpdates(cfg *apps.Config) {
Expand Down Expand Up @@ -253,3 +270,9 @@ func ensureDeployJob(cfg *apps.Config) *apps.Config {
}
return cfg
}

func warnIfDockerfileNotEnabled(app *apps.Application, flag string) {
if !app.Spec.ForProvider.DockerfileBuild.Enabled {
format.PrintWarningf("updating %s has no effect as dockefile builds are not enabled on this app\n", flag)
}
}

0 comments on commit 1fd7644

Please sign in to comment.