Skip to content

Commit

Permalink
Adds frontend server configuration (#28)
Browse files Browse the repository at this point in the history
* Adds frontend server confiuration

- These new order groups will allow users that have nodejs apps that
build to a static side to serve those builds on either NGINX or HTTPD

* Apply suggestions from code review

Co-authored-by: Tim Hitchener <[email protected]>

Co-authored-by: Tim Hitchener <[email protected]>
  • Loading branch information
ForestEckhardt and thitch97 authored Mar 24, 2022
1 parent fd1f3d8 commit 5e76a65
Show file tree
Hide file tree
Showing 83 changed files with 42,723 additions and 1 deletion.
80 changes: 80 additions & 0 deletions buildpack.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,86 @@ api = "0.6"
[metadata]
include-files = ["buildpack.toml"]

[[order]]

[[order.group]]
id = "paketo-buildpacks/node-engine"
version = "0.12.1"

[[order.group]]
id = "paketo-buildpacks/yarn"
version = "0.6.0"

[[order.group]]
id = "paketo-buildpacks/yarn-install"
version = "0.8.0"

[[order.group]]
id = "paketo-buildpacks/node-run-script"
version = "0.3.2"

[[order.group]]
id = "paketo-buildpacks/nginx"
version = "0.5.3"

[[order]]

[[order.group]]
id = "paketo-buildpacks/node-engine"
version = "0.12.1"

[[order.group]]
id = "paketo-buildpacks/npm-install"
version = "0.8.0"

[[order.group]]
id = "paketo-buildpacks/node-run-script"
version = "0.3.2"

[[order.group]]
id = "paketo-buildpacks/nginx"
version = "0.5.3"

[[order]]

[[order.group]]
id = "paketo-buildpacks/node-engine"
version = "0.12.1"

[[order.group]]
id = "paketo-buildpacks/yarn"
version = "0.6.0"

[[order.group]]
id = "paketo-buildpacks/yarn-install"
version = "0.8.0"

[[order.group]]
id = "paketo-buildpacks/node-run-script"
version = "0.3.2"

[[order.group]]
id = "paketo-buildpacks/httpd"
version = "0.3.0"

[[order]]

[[order.group]]
id = "paketo-buildpacks/node-engine"
version = "0.12.1"

[[order.group]]
id = "paketo-buildpacks/npm-install"
version = "0.8.0"

[[order.group]]
id = "paketo-buildpacks/node-run-script"
version = "0.3.2"

[[order.group]]
id = "paketo-buildpacks/httpd"
version = "0.3.0"

[[order]]

[[order.group]]
Expand Down
2 changes: 2 additions & 0 deletions integration/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@ func TestIntegration(t *testing.T) {
suite := spec.New("Integration", spec.Parallel(), spec.Report(report.Terminal{}))
suite("HTTPD", testHttpd)
suite("NGINX", testNginx)
suite("NPM Frontend", testNPMFrontend)
suite("Yarn Frontend", testYarnFrontend)
suite.Run(t)
}
132 changes: 132 additions & 0 deletions integration/npm_frontend_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package integration_test

import (
"fmt"
"os"
"path/filepath"
"testing"

"github.com/paketo-buildpacks/occam"
"github.com/sclevine/spec"

. "github.com/onsi/gomega"
. "github.com/paketo-buildpacks/occam/matchers"
)

func testNPMFrontend(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect
Eventually = NewWithT(t).Eventually

pack occam.Pack
docker occam.Docker
)

it.Before(func() {
pack = occam.NewPack()
docker = occam.NewDocker()
})

context("when building a NPM frontend app using NGINX as the webserver", func() {
var (
image occam.Image
container occam.Container

name string
source string
)

it.Before(func() {
var err error
name, err = occam.RandomName()
Expect(err).NotTo(HaveOccurred())

source, err = occam.Source(filepath.Join("testdata", "npm-nginx-javascript-frontend"))
Expect(err).NotTo(HaveOccurred())
})

it.After(func() {
Expect(docker.Container.Remove.Execute(container.ID)).To(Succeed())
Expect(docker.Image.Remove.Execute(image.ID)).To(Succeed())
Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed())
Expect(os.RemoveAll(source)).To(Succeed())
})

it("creates a working OCI image", func() {
var err error
var logs fmt.Stringer
image, logs, err = pack.WithNoColor().Build.
WithBuildpacks(webServersBuildpack).
WithPullPolicy("never").
WithEnv(map[string]string{"BP_NODE_RUN_SCRIPTS": "build"}).
Execute(name, source)
Expect(err).NotTo(HaveOccurred(), logs.String())

Expect(logs).To(ContainLines(ContainSubstring("Node Engine Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("NPM Install Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("Node Run Script Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("Nginx Server Buildpack")))
Expect(logs).NotTo(ContainLines(ContainSubstring("HTTP Server Buildpack")))
Expect(logs).NotTo(ContainLines(ContainSubstring("Procfile Buildpack")))

container, err = docker.Container.Run.
WithEnv(map[string]string{"PORT": "8080"}).
WithPublish("8080").
Execute(image.ID)
Expect(err).NotTo(HaveOccurred())
Eventually(container).Should(Serve(ContainSubstring("<title>React App</title>")).OnPort(8080).WithEndpoint("/index.html"))
})
})

context("when building a NPM frontend app using HTTPD as the webserver", func() {
var (
image occam.Image
container occam.Container

name string
source string
)

it.Before(func() {
var err error
name, err = occam.RandomName()
Expect(err).NotTo(HaveOccurred())

source, err = occam.Source(filepath.Join("testdata", "npm-httpd-javascript-frontend"))
Expect(err).NotTo(HaveOccurred())
})

it.After(func() {
Expect(docker.Container.Remove.Execute(container.ID)).To(Succeed())
Expect(docker.Image.Remove.Execute(image.ID)).To(Succeed())
Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed())
Expect(os.RemoveAll(source)).To(Succeed())
})

it("creates a working OCI image", func() {
var err error
var logs fmt.Stringer
image, logs, err = pack.WithNoColor().Build.
WithBuildpacks(webServersBuildpack).
WithPullPolicy("never").
WithEnv(map[string]string{"BP_NODE_RUN_SCRIPTS": "build"}).
Execute(name, source)
Expect(err).NotTo(HaveOccurred(), logs.String())

Expect(logs).To(ContainLines(ContainSubstring("Node Engine Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("NPM Install Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("Node Run Script Buildpack")))
Expect(logs).NotTo(ContainLines(ContainSubstring("Nginx Server Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("HTTP Server Buildpack")))
Expect(logs).NotTo(ContainLines(ContainSubstring("Procfile Buildpack")))

container, err = docker.Container.Run.
WithEnv(map[string]string{"PORT": "8080"}).
WithPublish("8080").
Execute(image.ID)
Expect(err).NotTo(HaveOccurred())
Eventually(container).Should(Serve(ContainSubstring("<title>React App</title>")).OnPort(8080).WithEndpoint("/index.html"))
})

})
}
23 changes: 23 additions & 0 deletions integration/testdata/npm-httpd-javascript-frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
70 changes: 70 additions & 0 deletions integration/testdata/npm-httpd-javascript-frontend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Getting Started with Create React App

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.

The page will reload when you make changes.\
You may also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can't go back!**

If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.

You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)

### Analyzing the Bundle Size

This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)

### Making a Progressive Web App

This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)

### Advanced Configuration

This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)

### Deployment

This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)

### `npm run build` fails to minify

This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
Loading

0 comments on commit 5e76a65

Please sign in to comment.