Skip to content
This repository has been archived by the owner on Jul 13, 2022. It is now read-only.

Commit

Permalink
Add support for custom root directory
Browse files Browse the repository at this point in the history
Co-authored-by: Arjun Sreedharan <[email protected]>
  • Loading branch information
joshzarrabi and arjun024 committed Nov 30, 2020
1 parent 9f3ac20 commit b136a9f
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ This builds the buildpack's Go source using `GOOS=linux` by default. You can sup
```yaml
staticfile:
nginx:
root:
root: # default value: "public"
host_dot_files:
location_include:
directory:
Expand Down
4 changes: 4 additions & 0 deletions buildpack_yml_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ func parse(path string) (Config, error) {
return Config{}, fmt.Errorf("unable to parse buildpack.yml: %q", err)
}

if buildpack.Staticfile.Nginx != nil && buildpack.Staticfile.Nginx.RootDir == "" {
buildpack.Staticfile.Nginx.RootDir = "public"
}

return buildpack.Staticfile, err

}
16 changes: 16 additions & 0 deletions buildpack_yml_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@ staticfile:
"some-staus": "some-code",
}))
})

when("the root dir is not specified", func() {
it.Before(func() {
err := ioutil.WriteFile(path, []byte(`---
staticfile:
nginx: {}
`), os.ModePerm)
Expect(err).NotTo(HaveOccurred())
})
it("sets RootDir to 'public'", func() {
configData, err := buildpackYMLParser.Parse(path)
Expect(err).NotTo(HaveOccurred())

Expect(configData.Nginx.RootDir).To(Equal("public"))
})
})
})

})
Expand Down
31 changes: 31 additions & 0 deletions integration/nginx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,36 @@ func testNginx(t *testing.T, context spec.G, it spec.S) {

Expect(string(content)).To(ContainSubstring("helloworld"))
})

context("app with custom root", func() {
it("builds and runs successfully", func() {
var err error
source, err = occam.Source(filepath.Join("testdata", "custom_root_app"))
Expect(err).NotTo(HaveOccurred())

var logs fmt.Stringer
image, logs, err = pack.WithNoColor().Build.
WithPullPolicy("never").
WithBuildpacks(nginxBuildpack, buildpack).
Execute(name, source)
Expect(err).NotTo(HaveOccurred(), logs.String)

container, err = docker.Container.Run.Execute(image.ID)
Expect(err).NotTo(HaveOccurred())

Eventually(container).Should(BeAvailable())

response, err := http.Get(fmt.Sprintf("http://localhost:%s", container.HostPort()))
Expect(err).NotTo(HaveOccurred())
defer response.Body.Close()

Expect(response.StatusCode).To(Equal(http.StatusOK))

content, err := ioutil.ReadAll(response.Body)
Expect(err).NotTo(HaveOccurred())

Expect(string(content)).To(ContainSubstring("helloworld"))
})
})
})
}
4 changes: 4 additions & 0 deletions integration/testdata/custom_root_app/buildpack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
staticfile:
nginx:
root: "dir1/dir2"
10 changes: 10 additions & 0 deletions integration/testdata/custom_root_app/dir1/dir2/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html>
<head>
<title>hello World</title>
</head>
<body>
<p>
helloworld
</p>
</body>
</html>
2 changes: 1 addition & 1 deletion server_configs/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ http {
listen {{port}};
server_name localhost;

root {{ env "APP_ROOT" }}/public;
root {{ env "APP_ROOT" }}/$(( .RootDir ));

$(( if .ForceHTTPS ))
set $updated_host $host;
Expand Down

0 comments on commit b136a9f

Please sign in to comment.