Skip to content

Commit

Permalink
feat: add dockerfile flags
Browse files Browse the repository at this point in the history
This adds all relevant flags for the app create/update command to enable
and configure dockerfile build support.
  • Loading branch information
ctrox committed Jul 18, 2024
1 parent b715b9f commit 6a94287
Show file tree
Hide file tree
Showing 2 changed files with 31 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
}
14 changes: 14 additions & 0 deletions update/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 6a94287

Please sign in to comment.