-
Notifications
You must be signed in to change notification settings - Fork 264
[nginx]Add nginx static file planner DEV-1147 #105
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
Conversation
I'm not sure if we need to support nginx in a shell. I do also have a working version with just some customization on |
@LucilleH this PR is build only. But I think I can make it work in shell |
I don't know if this is the right way to solve it. I pulled the branch and tested with Docusaurus and it doesn't serve as expected (broken pages w no proper css files, etc). I might have misconfigured it perhaps. But more importantly, do we want to use Nix services? We can generalize it to support services in general, nginx, Apache, LAMP stack, etc. See https://github.com/NixOS/nixpkgs/blob/master/nixos/tests/nginx.nix Thoughts? |
planner/languages/nginx/README.md
Outdated
with a few options. If you want to see what this wrapper does, use `cat $(which shell-nginx)` | ||
|
||
In shell everything is local so you should avoid pointing to assets or files outside | ||
the directory because the nix shell might not have access. For example your root |
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.
Which directory?
} | ||
|
||
func (p *Planner) GetPlan(srcDir string) *plansdk.Plan { | ||
fmt.Println(srcDir) |
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.
Intentional?
nginx -c /app/%[1]s -g 'daemon off;' | ||
`) | ||
|
||
const customNginxDefintion = ` |
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.
const customNginxDefintion = ` | |
const customNginxDefinition = ` |
// These definitions are only used in shell. Since nix is lazy, it won't | ||
// actually build them at all if they are not used. | ||
Definitions: []string{ | ||
customNginxDefintion, |
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.
customNginxDefintion, | |
customNginxDefinition, |
planner/plansdk/plansdk.go
Outdated
// TODO: Plan currently has a bunch of fields that it should not export. | ||
// Two reasons why we need this right now: | ||
// 1/ So that individual planners can use the fields | ||
// 2/ So that we print them out correctly in `devbox plan` | ||
// | ||
// (1) can be solved by using a WithOption pattern, (e.g. NewPlan(..., WithWelcomeMessage(...))) | ||
// (2) can be solved by using a custom JSON marshaler. | ||
type Plan struct { |
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.
Let's put an empty line between this comment and Plan so it doesn't show up in godocs.
planner/plansdk/plansdk.go
Outdated
@@ -116,6 +108,10 @@ func (p *Plan) WithError(err error) *Plan { | |||
return p | |||
} | |||
|
|||
func (p *Plan) ShellAndDevPackages() []string { | |||
return pkgslice.Unique(append(p.DevPackages, p.ShellPackages...)) |
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.
You probably want to copy to a new slice here, otherwise the returned slice and DevPackages will share the same backing array.
planner/plansdk/plansdk.go
Outdated
DevPackages []string `cue:"[...string]" json:"dev_packages"` | ||
|
||
// ShellPackages are only available in the shell environment. | ||
ShellPackages []string `cue:"[...string]" json:"shell_packages"` |
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.
Does including shell packages in the dev environment add a lot of extra stuff?
I think trying to keep a single set of packages would be more reliable. If the shell has extra packages, then it means your dev environment no longer matches what gets built.
tmpl/shell.nix.tmpl
Outdated
{{ if .ShellWelcomeMessage }} | ||
echo "{{ .ShellWelcomeMessage }}" | ||
{{- end }} |
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 know we also echo another message in this hook, but we should probably move them to the shellrc template. This hook will also run with non-interactive shells, so devbox run 'some-command'
or devbox shell < myscript.sh
will end up printing these messages.
@LucilleH @gcurtis reimplemented using same nginx for shell and build. The user needs to add some config options when running in shell. For simplicity I generate the file and tell them to include it in the welcome message. It's not a fantastic experience, but it prevents us from having two different nginx builds. We could try to automate the nginx.conf construction, but I feel like that could be really error prone. Ideally we can add the options in the command line call but I'm not sure that's possible. |
Tested locally, when running shell-nginx I got the following error:
|
} | ||
|
||
func AllFiles() []string { | ||
return []string{"."} |
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.
oh this is nice. Should've done this earlier
Doing devbox build and docker run, I got the following error:
It was working in the previous version 🤔 |
mkdir -p /var/cache/nginx/client_body && \ | ||
mkdir -p /var/log/nginx/ && \ | ||
PKG_PATH=$(readlink -f $(which nginx) | sed -r "s/\/bin\/nginx//g") && \ | ||
ln -s /app/%[1]s $PKG_PATH/conf/devbox-%[1]s && \ |
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.
wow ok. I'm still getting nginx: [emerg] open() "./mime.types" failed (2: No such file or directory) in ./nginx.conf:4
nginx fails to start when the temporary directories in shell-helper-nginx.conf don't exist yet. Specifically, the `cache` subdirectory needs to be created under the temp directory. To fix this: 1. Use os.TempDir() to ensure we use the OS-specific temporary directory (which on macOS isn't `/tmp`). 2. Don't use a `cache` subdirectory so we don't need to worry about the directory existing.
@mikeland86 I resolved the conflicts so I could test things out. Is it okay if I push them here? |
@gcurtis go for it |
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 was able to run both a shell and a built image. I think this is a good first iteration.
## Summary This is stacked on #105. Please review that one first. Adds basic pip support. * Uses requirements.txt for detection. * Uses venv for shell * Uses venv + pex for build Does not yet libraries with native extensions like `pandas` but there's a plan for that. ## How was it tested? * `devbox shell`. * `devbox build` * Unit tests Co-authored-by: Greg Curtis <greg.curtis@jetpack.io>
Summary
Implements static nginx planner for both shell and build commands. The strategy is a bit different for each:
How was it tested?
nginx-shell
docker run -p 80:80