From 6a94287fce5f267bf1037fc7406dbc8b8336e781 Mon Sep 17 00:00:00 2001 From: Cyrill Troxler Date: Wed, 17 Jul 2024 16:53:35 +0200 Subject: [PATCH] feat: add dockerfile flags This adds all relevant flags for the app create/update command to enable and configure dockerfile build support. --- create/application.go | 17 +++++++++++++++++ update/application.go | 14 ++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/create/application.go b/create/application.go index d78513e..971ba01 100644 --- a/create/application.go +++ b/create/application.go @@ -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 { @@ -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) @@ -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, + }, }, }, } @@ -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 } diff --git a/update/application.go b/update/application.go index 9d499e8..c34beb9 100644 --- a/update/application.go +++ b/update/application.go @@ -38,6 +38,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 { @@ -79,6 +80,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{ @@ -223,6 +229,14 @@ 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 + } + + if cmd.DockerfileBuild.BuildContext != nil { + app.Spec.ForProvider.DockerfileBuild.BuildContext = *cmd.DockerfileBuild.BuildContext + } } func (job deployJob) applyUpdates(cfg *apps.Config) {