-
Notifications
You must be signed in to change notification settings - Fork 264
Change welcome message to shell init hook #172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -29,10 +29,8 @@ func (p *Planner) IsRelevant(srcDir string) bool { | |||||||||||||||||
|
||||||||||||||||||
func (p *Planner) GetPlan(srcDir string) *plansdk.Plan { | ||||||||||||||||||
return &plansdk.Plan{ | ||||||||||||||||||
ShellWelcomeMessage: fmt.Sprintf(welcomeMessage, p.shellConfig(srcDir)), | ||||||||||||||||||
DevPackages: []string{ | ||||||||||||||||||
"nginx", | ||||||||||||||||||
"shell-nginx", | ||||||||||||||||||
}, | ||||||||||||||||||
RuntimePackages: []string{ | ||||||||||||||||||
"nginx", | ||||||||||||||||||
|
@@ -45,11 +43,12 @@ func (p *Planner) GetPlan(srcDir string) *plansdk.Plan { | |||||||||||||||||
Command: fmt.Sprintf(startCommand, p.buildConfig(srcDir)), | ||||||||||||||||||
InputFiles: plansdk.AllFiles(), | ||||||||||||||||||
}, | ||||||||||||||||||
Definitions: []string{ | ||||||||||||||||||
fmt.Sprintf(nginxShellStartScript, srcDir, p.shellConfig(srcDir)), | ||||||||||||||||||
}, | ||||||||||||||||||
GeneratedFiles: map[string]string{ | ||||||||||||||||||
"shell-helper-nginx.conf": fmt.Sprintf(shellHelperNginxConfig, os.TempDir()), | ||||||||||||||||||
"shell-nginx.sh": fmt.Sprintf(nginxShellStartScript, srcDir, p.shellConfig(srcDir)), | ||||||||||||||||||
}, | ||||||||||||||||||
ShellInitHook: []string{ | ||||||||||||||||||
fmt.Sprintf(". %s", filepath.Join(srcDir, ".devbox/gen/shell-nginx.sh")), | ||||||||||||||||||
}, | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
|
@@ -68,18 +67,6 @@ func (p *Planner) buildConfig(srcDir string) string { | |||||||||||||||||
return "shell-nginx.conf" | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
const welcomeMessage = ` | ||||||||||||||||||
##### WARNING: nginx planner is experimental ##### | ||||||||||||||||||
|
||||||||||||||||||
You may need to add | ||||||||||||||||||
|
||||||||||||||||||
\"include ./.devbox/gen/shell-helper-nginx.conf;\" | ||||||||||||||||||
|
||||||||||||||||||
to your %s file to ensure the server can start in the nix shell. | ||||||||||||||||||
|
||||||||||||||||||
Use \"shell-nginx\" to start the server | ||||||||||||||||||
` | ||||||||||||||||||
|
||||||||||||||||||
var startCommand = strings.TrimSpace(` | ||||||||||||||||||
addgroup --system --gid 101 nginx && \ | ||||||||||||||||||
adduser --system --ingroup nginx --no-create-home --home /nonexistent --gecos "nginx user" --shell /bin/false --uid 101 nginx && \ | ||||||||||||||||||
|
@@ -92,12 +79,35 @@ var startCommand = strings.TrimSpace(` | |||||||||||||||||
`) | ||||||||||||||||||
|
||||||||||||||||||
const nginxShellStartScript = ` | ||||||||||||||||||
shell-nginx = pkgs.writeShellScriptBin "shell-nginx" '' | ||||||||||||||||||
#!/bin/bash | ||||||||||||||||||
|
||||||||||||||||||
welcome() { | ||||||||||||||||||
echo "##### WARNING: nginx planner is experimental ##### | ||||||||||||||||||
|
||||||||||||||||||
echo "Starting nginx with command:" | ||||||||||||||||||
echo "nginx -p %[1]s -c %[2]s -e /tmp/error.log -g \"pid /tmp/mynginx.pid;daemon off;\"" | ||||||||||||||||||
nginx -p %[1]s -c %[2]s -e /tmp/error.log -g "pid /tmp/shell-nginx.pid;daemon off;" | ||||||||||||||||||
'';` | ||||||||||||||||||
You may need to add | ||||||||||||||||||
|
||||||||||||||||||
\"include shell-helper-nginx.conf;\" | ||||||||||||||||||
|
||||||||||||||||||
to your %[2]s file to ensure the server can start in the nix shell. | ||||||||||||||||||
|
||||||||||||||||||
Use \"shell-nginx\" to start the server" | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
pkg_path=$(readlink -f $(which nginx) | sed -r "s/\/bin\/nginx//g") | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
conf_path=$pkg_path/conf | ||||||||||||||||||
|
||||||||||||||||||
mkdir -p %[1]s/.devbox/gen/nginx | ||||||||||||||||||
ln -sf $conf_path/* %[1]s/.devbox/gen/nginx/ | ||||||||||||||||||
ln -sf $(pwd)/%[1]s/.devbox/gen/shell-helper-nginx.conf %[1]s/.devbox/gen/nginx/shell-helper-nginx.conf | ||||||||||||||||||
for file in %[1]s/*; do if [[ ! $file = .devbox ]]; then ln -sf $(pwd)/%[1]s/$file .devbox/gen/nginx/$file; fi; done | ||||||||||||||||||
Comment on lines
+99
to
+102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
shell-nginx() { | ||||||||||||||||||
echo "Starting nginx with command:" | ||||||||||||||||||
echo "nginx -p %[1]s -c %[1]s/.devbox/gen/nginx/%[2]s -e /tmp/error.log -g \"pid /tmp/mynginx.pid;daemon off;\"" | ||||||||||||||||||
nginx -p %[1]s -c %[1]s/.devbox/gen/nginx/%[2]s -e /tmp/error.log -g "pid /tmp/shell-nginx.pid;daemon off;" | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
} | ||||||||||||||||||
welcome | ||||||||||||||||||
Comment on lines
+82
to
+109
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is long enough that is could benefit from being in own |
||||||||||||||||||
` | ||||||||||||||||||
|
||||||||||||||||||
const shellHelperNginxConfig = `access_log %[1]s/access.log; | ||||||||||||||||||
client_body_temp_path %[1]s/client_body; | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,7 +52,7 @@ func (p *Planner) GetPlan(srcDir string) *plansdk.Plan { | |
fmt.Sprintf("php%s", v.MajorMinorConcatenated()), | ||
fmt.Sprintf("php%sPackages.composer", v.MajorMinorConcatenated()), | ||
}, | ||
Definitions: p.definitions(srcDir, v), | ||
PackageExtensions: p.pkgExtensions(srcDir, v), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we call these NixLocalVariables instead? extending packages is just one use case. You could argue that we should avoid adding stuff here because it makes it harder to do nix free version, but would probably prefer a name that more closely resembles what it represents in the nix file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
if !plansdk.FileExists(filepath.Join(srcDir, "public/index.php")) { | ||
return plan.WithError(usererr.New("Can't build. No public/index.php found.")) | ||
|
@@ -119,7 +119,7 @@ func (p *Planner) version(srcDir string) *plansdk.Version { | |
return latestVersion | ||
} | ||
|
||
func (p *Planner) definitions(srcDir string, v *plansdk.Version) []string { | ||
func (p *Planner) pkgExtensions(srcDir string, v *plansdk.Version) []string { | ||
extensions, err := p.extensions(srcDir) | ||
if len(extensions) == 0 || err != nil { | ||
return []string{} | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -26,18 +26,17 @@ type PlanError struct { | |||||||||||||||
|
||||||||||||||||
// Plan tells devbox how to start shells and build projects. | ||||||||||||||||
type Plan struct { | ||||||||||||||||
ShellWelcomeMessage string `json:"shell_welcome_message,omitempty"` | ||||||||||||||||
|
||||||||||||||||
NixOverlays []string `cur:"[...string]" json:"nix_overlays,omitempty"` | ||||||||||||||||
|
||||||||||||||||
// DevPackages is the slice of Nix packages that devbox makes available in | ||||||||||||||||
// its development environment. They are also available in shell. | ||||||||||||||||
DevPackages []string `cue:"[...string]" json:"dev_packages"` | ||||||||||||||||
|
||||||||||||||||
// RuntimePackages is the slice of Nix packages that devbox makes available in | ||||||||||||||||
// in both the development environment and the final container that runs the | ||||||||||||||||
// application. | ||||||||||||||||
RuntimePackages []string `cue:"[...string]" json:"runtime_packages"` | ||||||||||||||||
// packageExtensions is the slice of Nix packages that devbox wants to extend | ||||||||||||||||
// to include extra packages that needs global installation. | ||||||||||||||||
PackageExtensions []string `cue:"[...string]" json:"package_extensions,omitempty"` | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mikeland86 for php, I wonder if we can use the same mechanism I did for nginx, in that we can create a folder There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you may be misunderstanding what these do in php. They are not installing packages, they are recompiling PHP with the appropriate extensions. Some extensions are included by default but need to be "enabled". Other extensions are not included at all and require php to be built from source. There's no way to just add an extension into a folder. The actual source of PHP needs to change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we still need to recompile PHP if the store is mutable? |
||||||||||||||||
// InstallStage defines the actions that should be taken when | ||||||||||||||||
// installing language-specific libraries. | ||||||||||||||||
// Ex: pip install, yarn install, go get | ||||||||||||||||
|
@@ -50,15 +49,15 @@ type Plan struct { | |||||||||||||||
// starting (running) the application. | ||||||||||||||||
// Ex: python main.py | ||||||||||||||||
StartStage *Stage `json:"start_stage,omitempty"` | ||||||||||||||||
|
||||||||||||||||
Definitions []string `cue:"[...string]" json:"definitions"` | ||||||||||||||||
// Errors from plan generation. This usually means | ||||||||||||||||
// the user application may not be buildable. | ||||||||||||||||
Errors []PlanError `json:"errors,omitempty"` | ||||||||||||||||
|
||||||||||||||||
// GeneratedFiles is a map of name => content for files that should be generated | ||||||||||||||||
// in the .devbox/gen directory. (Use string to make it marshalled version nicer.) | ||||||||||||||||
GeneratedFiles map[string]string `json:"generated_files,omitempty"` | ||||||||||||||||
// This is an array of shell init hook that gets appended in front of | ||||||||||||||||
// the shell { initHook } defined by users. | ||||||||||||||||
ShellInitHook []string `cue:"[...string]" json:"shell_init_hook"` | ||||||||||||||||
Comment on lines
+58
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
type Planner interface { | ||||||||||||||||
|
@@ -118,10 +117,11 @@ func MergePlans(plans ...*Plan) (*Plan, error) { | |||||||||||||||
err := mergo.Merge( | ||||||||||||||||
mergedPlan, | ||||||||||||||||
&Plan{ | ||||||||||||||||
NixOverlays: p.NixOverlays, | ||||||||||||||||
DevPackages: p.DevPackages, | ||||||||||||||||
RuntimePackages: p.RuntimePackages, | ||||||||||||||||
Definitions: p.Definitions, | ||||||||||||||||
NixOverlays: p.NixOverlays, | ||||||||||||||||
DevPackages: p.DevPackages, | ||||||||||||||||
RuntimePackages: p.RuntimePackages, | ||||||||||||||||
PackageExtensions: p.PackageExtensions, | ||||||||||||||||
ShellInitHook: p.ShellInitHook, | ||||||||||||||||
}, | ||||||||||||||||
// Only WithAppendSlice overlays, definitions, dev, and runtime packages fields. | ||||||||||||||||
mergo.WithAppendSlice, | ||||||||||||||||
|
@@ -135,7 +135,7 @@ func MergePlans(plans ...*Plan) (*Plan, error) { | |||||||||||||||
plan.NixOverlays = pkgslice.Unique(mergedPlan.NixOverlays) | ||||||||||||||||
plan.DevPackages = pkgslice.Unique(mergedPlan.DevPackages) | ||||||||||||||||
plan.RuntimePackages = pkgslice.Unique(mergedPlan.RuntimePackages) | ||||||||||||||||
plan.Definitions = mergedPlan.Definitions | ||||||||||||||||
plan.ShellInitHook = mergedPlan.ShellInitHook | ||||||||||||||||
|
||||||||||||||||
return plan, nil | ||||||||||||||||
} | ||||||||||||||||
|
@@ -144,7 +144,9 @@ func findBuildablePlan(plans ...*Plan) *Plan { | |||||||||||||||
for _, p := range plans { | ||||||||||||||||
// For now, pick the first buildable plan. | ||||||||||||||||
if p.Buildable() { | ||||||||||||||||
return p | ||||||||||||||||
// Make a copy so that the original plan is not modified. | ||||||||||||||||
newP := *p | ||||||||||||||||
return &newP | ||||||||||||||||
Comment on lines
+147
to
+149
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know if this matters for this change, but |
||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
return &Plan{} | ||||||||||||||||
|
@@ -164,13 +166,15 @@ func MergeUserPlan(userPlan *Plan, automatedPlan *Plan) (*Plan, error) { | |||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
// Merging devPackages and runtimePackages fields. | ||||||||||||||||
packagesPlan, err := MergePlans(userPlan, automatedPlan) | ||||||||||||||||
// Order here matters because user defined shell hook should be executed last | ||||||||||||||||
mergedWithSlicePlan, err := MergePlans(automatedPlan, userPlan) | ||||||||||||||||
if err != nil { | ||||||||||||||||
return nil, errors.WithStack(err) | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
plan.DevPackages = packagesPlan.DevPackages | ||||||||||||||||
plan.RuntimePackages = packagesPlan.RuntimePackages | ||||||||||||||||
plan.DevPackages = mergedWithSlicePlan.DevPackages | ||||||||||||||||
plan.RuntimePackages = mergedWithSlicePlan.RuntimePackages | ||||||||||||||||
plan.ShellInitHook = mergedWithSlicePlan.ShellInitHook | ||||||||||||||||
|
||||||||||||||||
return plan, nil | ||||||||||||||||
} | ||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit unsure about splitting this out in this way. It feels a bit fragile. I almost want an option that does both (create a script and either calls it or sources it in the init hook)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, this should probably not be called
shell-nginx.sh
it it's an init script. Maybe justinit.sh
?