使用 Paketo Buildpacks 容器化 Angular 应用程序:空回复
Containerizing Angular Application With Paketo Buildpacks: Empty Reply
我想使用 Paketo buildpack for nodejs 创建我的 Angular 12 应用程序的容器映像。我通过 Angular CLI 创建了应用程序并将其编码到现在我想部署它。
为了创建容器,我遵循了 paketo 示例存储库中的说明和 运行 这个命令:
pack build myui --buildpack gcr.io/paketo-buildpacks/nodejs --env "BP_NODE_RUN_SCRIPTS=build" --env "NODE_ENV=development"
只要删除 运行 pack
.
之前的 node_modules 目录就可以正常工作
现在我想在本地测试图像并尝试使用
启动它
docker run --tty --publish 4200:4200 myui
看来启动成功了:
✔ Browser application bundle generation complete.
Initial Chunk Files | Names | Size
main.js | main | 6.14 MB
vendor.js | vendor | 4.22 MB
styles.css | styles | 159.33 kB
polyfills.js | polyfills | 128.67 kB
runtime.js | runtime | 6.56 kB
| Initial Total | 10.65 MB
Build at: 2021-08-13T10:06:14.282Z - Hash: 5351646d56eaa8873a38 - Time: 15305ms
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
✔ Compiled successfully.
✔ Browser application bundle generation complete.
5 unchanged chunks
Build at: 2021-08-13T10:06:15.412Z - Hash: 149b56c677aa74ba2361 - Time: 577ms
✔ Compiled successfully.
现在问题来了:
➜ ~ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6a29ce4cdc86 myui "/cnb/process/web" 11 minutes ago Up 11 minutes 0.0.0.0:4200->4200/tcp, :::4200->4200/tcp confident_grothendieck
➜ ~ curl -vvv http://localhost:4200/
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 4200 (#0)
> GET / HTTP/1.1
> Host: localhost:4200
> User-Agent: curl/7.64.1
> Accept: */*
>
* Empty reply from server
* Connection #0 to host localhost left intact
curl: (52) Empty reply from server
* Closing connection 0
➜ ~
有人知道哪里出了问题吗?
编辑:目前我最好的猜测是 ng serve
监听 127.0.0.1:4200 但应该监听 0.0.0.0:4200
以便流量通过.但我不确定在哪里寻找配置。在构建包中?在angular.cli?其他地方?
编辑:根据要求,pack
命令的完整输出:
➜ ui2 git:(master) pack build myui --buildpack gcr.io/paketo-buildpacks/nodejs --env "BP_NODE_RUN_SCRIPTS=build" --env "NODE_ENV=development"
full: Pulling from paketobuildpacks/builder
Digest: sha256:b34eb3b43d6bf20623ad92523e9e1a055289e74a2fa661adee5d1d90e25afd48
Status: Image is up to date for paketobuildpacks/builder:full
full-cnb: Pulling from paketobuildpacks/run
Digest: sha256:691eb052281456ab5b5a62d1a0e5a67bf7246783565bbecd239c5c9cf1bf51ec
Status: Image is up to date for paketobuildpacks/run:full-cnb
latest: Pulling from paketo-buildpacks/nodejs
Digest: sha256:9887bb6b7d0c410ccdf6fa940658dddecfce5ded1ac5696ced608c78649594b3
Status: Image is up to date for gcr.io/paketo-buildpacks/nodejs:latest
===> DETECTING
5 of 8 buildpacks participating
paketo-buildpacks/ca-certificates 2.3.2
paketo-buildpacks/node-engine 0.6.2
paketo-buildpacks/npm-install 0.4.0
paketo-buildpacks/node-run-script 0.1.0
paketo-buildpacks/npm-start 0.3.0
===> ANALYZING
Previous image with name "myui" not found
===> RESTORING
===> BUILDING
Paketo CA Certificates Buildpack 2.3.2
https://github.com/paketo-buildpacks/ca-certificates
Launch Helper: Contributing to layer
Creating /layers/paketo-buildpacks_ca-certificates/helper/exec.d/ca-certificates-helper
Paketo Node Engine Buildpack 0.6.2
Resolving Node Engine version
Candidate version sources (in priority order):
-> ""
<unknown> -> ""
Selected Node Engine version (using ): 14.17.5
Executing build process
Installing Node Engine 14.17.5
Completed in 7.96s
Configuring build environment
NODE_ENV -> "development"
NODE_HOME -> "/layers/paketo-buildpacks_node-engine/node"
NODE_VERBOSE -> "false"
Configuring launch environment
NODE_ENV -> "production"
NODE_HOME -> "/layers/paketo-buildpacks_node-engine/node"
NODE_VERBOSE -> "false"
Writing profile.d/0_memory_available.sh
Calculates available memory based on container limits at launch time.
Made available in the MEMORY_AVAILABLE environment variable.
Paketo NPM Install Buildpack 0.4.0
Resolving installation process
Process inputs:
node_modules -> "Not found"
npm-cache -> "Not found"
package-lock.json -> "Found"
Selected NPM build process: 'npm ci'
Executing build process
Running 'npm ci --unsafe-perm --cache /layers/paketo-buildpacks_npm-install/npm-cache'
Completed in 23.58s
Configuring launch environment
NPM_CONFIG_LOGLEVEL -> "error"
Configuring environment shared by build and launch
PATH -> "$PATH:/layers/paketo-buildpacks_npm-install/modules/node_modules/.bin"
Paketo Node Run Script Buildpack 0.1.0
Executing build process
Executing scripts
Running 'npm run-script build'
> edit@0.0.0 build /workspace
> ng build
- Generating browser application bundles (phase: setup)...
Compiling @angular/core : es2015 as esm2015
Compiling @angular/cdk/keycodes : es2015 as esm2015
Compiling @angular/animations : es2015 as esm2015
Compiling @angular/animations/browser : es2015 as esm2015
Compiling @angular/cdk/observers : es2015 as esm2015
Compiling @angular/common : es2015 as esm2015
Compiling @angular/cdk/collections : es2015 as esm2015
Compiling @angular/platform-browser : es2015 as esm2015
Compiling @angular/cdk/platform : es2015 as esm2015
Compiling @angular/cdk/bidi : es2015 as esm2015
Compiling @angular/platform-browser/animations : es2015 as esm2015
Compiling @angular/cdk/a11y : es2015 as esm2015
Compiling @angular/forms : es2015 as esm2015
Compiling @angular/flex-layout/core : es2015 as esm2015
Compiling @angular/cdk/scrolling : es2015 as esm2015
Compiling @angular/cdk/portal : es2015 as esm2015
Compiling @angular/cdk/layout : es2015 as esm2015
Compiling @angular/material/core : es2015 as esm2015
Compiling @angular/common/http : es2015 as esm2015
Compiling @angular/cdk/overlay : es2015 as esm2015
Compiling @angular/flex-layout/extended : es2015 as esm2015
Compiling @angular/material/button : es2015 as esm2015
Compiling @angular/flex-layout/flex : es2015 as esm2015
Compiling @angular/flex-layout/grid : es2015 as esm2015
Compiling @angular/platform-browser-dynamic : es2015 as esm2015
Compiling @angular/router : es2015 as esm2015
Compiling @angular/material/sidenav : es2015 as esm2015
Compiling @angular/material/snack-bar : es2015 as esm2015
Compiling @angular/material/toolbar : es2015 as esm2015
Compiling @angular/material/icon : es2015 as esm2015
Compiling @angular/flex-layout : es2015 as esm2015
Compiling @angular/material/tabs : es2015 as esm2015
✔ Browser application bundle generation complete.
✔ Browser application bundle generation complete.
- Copying assets...
✔ Copying assets complete.
- Generating index html...
✔ Index html generation complete.
Initial Chunk Files | Names | Size
main.a6760a1641b4d1eaecd4.js | main | 4.50 MB
styles.8a29e51b15a5b6e5b823.css | styles | 90.06 kB
polyfills.a6c44b054b34d2bec03f.js | polyfills | 35.96 kB
runtime.543bd02f52b0afc6ba6a.js | runtime | 1015 bytes
| Initial Total | 4.63 MB
Build at: 2021-08-16T15:19:15.350Z - Hash: 0958e10b7d5232954d2e - Time: 46738ms
./src/app/footer/footer.component.scss - Warning: Module Warning (from ../layers/paketo-buildpacks_npm-install/modules/node_modules/postcss-loader/dist/cjs.js):
Warning
(7:3) postcss-preset-env: start value has mixed support, consider using flex-start instead
./src/app/home/home.component.scss - Warning: Module Warning (from ../layers/paketo-buildpacks_npm-install/modules/node_modules/postcss-loader/dist/cjs.js):
Warning
(84:3) postcss-preset-env: start value has mixed support, consider using flex-start instead
./src/app/home/home.component.scss - Warning: Module Warning (from ../layers/paketo-buildpacks_npm-install/modules/node_modules/postcss-loader/dist/cjs.js):
Warning
(85:3) postcss-preset-env: start value has mixed support, consider using flex-start instead
Warning: /workspace/src/app/resize.service.ts depends on 'element-resize-detector'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: initial exceeded maximum budget. Budget 500.00 kB was not met by 4.14 MB with a total of 4.63 MB.
Completed in 51.831s
Paketo NPM Start Buildpack 0.3.0
Assigning launch processes
web: ng serve
===> EXPORTING
Adding layer 'paketo-buildpacks/ca-certificates:helper'
Adding layer 'paketo-buildpacks/node-engine:node'
Adding layer 'paketo-buildpacks/npm-install:modules'
Adding layer 'paketo-buildpacks/npm-install:npm-cache'
Adding 1/1 app layer(s)
Adding layer 'launcher'
Adding layer 'config'
Adding layer 'process-types'
Adding label 'io.buildpacks.lifecycle.metadata'
Adding label 'io.buildpacks.build.metadata'
Adding label 'io.buildpacks.project.metadata'
Setting default process type 'web'
Saving myui...
*** Images (b9cd591df4be):
myui
Adding cache layer 'paketo-buildpacks/node-engine:node'
Adding cache layer 'paketo-buildpacks/npm-install:modules'
Adding cache layer 'paketo-buildpacks/npm-install:npm-cache'
Successfully built image myui
我会在回答前说,有多种方法可以做到这一点。以下是我建议的两种方式:
本地构建
本地构建,就像在您的机器上 运行 npm build
。
添加一个 buildpack.yml
文件:
staticfile:
nginx:
pushstate: true
这将指示静态文件 buildpack 生成支持 pushstate 的 Nginx 配置,这通常是单页 Javascript 应用程序所需要的。
运行 pack build myui -b paketo-buildpacks/nginx -b paketo-community/staticfile
-p dist/. dist/
是第 1 步构建过程输出的路径(即静态 HTML/CSS/Javascript 所在的位置)。
确保您的 dist/
路径包含您在上一步中创建的 buildpack.yml
文件。 这是静态文件构建包通过检测所必需的.如果您在尝试构建时看到 No buildpack groups passed detection
,这可能就是原因。
然后您可以执行 docker run -d -e PORT=8080 -p 8080:8080 myui
它会 运行 您的图像。生成的 nginx.conf 期望 PORT
设置为您希望它监听的某个端口。只需确保您 select 的端口与参数 -p
匹配,因此 docker 公开相同的端口。
在本地构建的优点是它很简单并且适用于大多数应用程序,因为构建的输出只是静态 HTML/CSS/JS 和其他资产文件。该 buildpack 仅添加了 Nginx,您就可以参加比赛了。
Buildpacks 构建
添加一个 buildpack.yml
文件:
staticfile:
nginx:
pushstate: true
这将指示静态文件 buildpack 生成支持 pushstate 的 Nginx 配置,这通常是单页 Javascript 应用程序所需要的。
确保您创建的 buildpack.yml
文件位于项目的根目录,即您在下一步中 运行 pack build
所在的目录。 这是静态文件构建包通过检测所必需的。如果您在尝试构建时看到 No buildpack groups passed detection
,这可能就是原因。
运行 pack build myui -b paketo-buildpacks/nodejs --env "BP_NODE_RUN_SCRIPTS=build" --env "NODE_ENV=development" --buildpack paketo-buildpacks/nginx --buildpack paketo-community/staticfile
这将确保安装了 Node 和 NPM,然后它将 运行 npm build
。这将从您的应用程序生成静态文件资源。然后 Nginx 和静态文件 buildpack 将 运行 安装和配置 Nginx 以托管您应用程序的静态文件。
它类似于本地构建,但不需要您在本地安装 Node 或 NPM。构建包将安装它们并在容器内构建。
我建议使用这两个构建过程之一的原因是,任何一个都会产生一个很小的启动容器,并且只包含您的静态文件和 Nginx。这将比使用构建工具的开发服务器安装 Node.js 更小、更高效、更适合生产。
我想使用 Paketo buildpack for nodejs 创建我的 Angular 12 应用程序的容器映像。我通过 Angular CLI 创建了应用程序并将其编码到现在我想部署它。
为了创建容器,我遵循了 paketo 示例存储库中的说明和 运行 这个命令:
pack build myui --buildpack gcr.io/paketo-buildpacks/nodejs --env "BP_NODE_RUN_SCRIPTS=build" --env "NODE_ENV=development"
只要删除 运行 pack
.
现在我想在本地测试图像并尝试使用
启动它docker run --tty --publish 4200:4200 myui
看来启动成功了:
✔ Browser application bundle generation complete.
Initial Chunk Files | Names | Size
main.js | main | 6.14 MB
vendor.js | vendor | 4.22 MB
styles.css | styles | 159.33 kB
polyfills.js | polyfills | 128.67 kB
runtime.js | runtime | 6.56 kB
| Initial Total | 10.65 MB
Build at: 2021-08-13T10:06:14.282Z - Hash: 5351646d56eaa8873a38 - Time: 15305ms
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
✔ Compiled successfully.
✔ Browser application bundle generation complete.
5 unchanged chunks
Build at: 2021-08-13T10:06:15.412Z - Hash: 149b56c677aa74ba2361 - Time: 577ms
✔ Compiled successfully.
现在问题来了:
➜ ~ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6a29ce4cdc86 myui "/cnb/process/web" 11 minutes ago Up 11 minutes 0.0.0.0:4200->4200/tcp, :::4200->4200/tcp confident_grothendieck
➜ ~ curl -vvv http://localhost:4200/
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 4200 (#0)
> GET / HTTP/1.1
> Host: localhost:4200
> User-Agent: curl/7.64.1
> Accept: */*
>
* Empty reply from server
* Connection #0 to host localhost left intact
curl: (52) Empty reply from server
* Closing connection 0
➜ ~
有人知道哪里出了问题吗?
编辑:目前我最好的猜测是 ng serve
监听 127.0.0.1:4200 但应该监听 0.0.0.0:4200
以便流量通过.但我不确定在哪里寻找配置。在构建包中?在angular.cli?其他地方?
编辑:根据要求,pack
命令的完整输出:
➜ ui2 git:(master) pack build myui --buildpack gcr.io/paketo-buildpacks/nodejs --env "BP_NODE_RUN_SCRIPTS=build" --env "NODE_ENV=development"
full: Pulling from paketobuildpacks/builder
Digest: sha256:b34eb3b43d6bf20623ad92523e9e1a055289e74a2fa661adee5d1d90e25afd48
Status: Image is up to date for paketobuildpacks/builder:full
full-cnb: Pulling from paketobuildpacks/run
Digest: sha256:691eb052281456ab5b5a62d1a0e5a67bf7246783565bbecd239c5c9cf1bf51ec
Status: Image is up to date for paketobuildpacks/run:full-cnb
latest: Pulling from paketo-buildpacks/nodejs
Digest: sha256:9887bb6b7d0c410ccdf6fa940658dddecfce5ded1ac5696ced608c78649594b3
Status: Image is up to date for gcr.io/paketo-buildpacks/nodejs:latest
===> DETECTING
5 of 8 buildpacks participating
paketo-buildpacks/ca-certificates 2.3.2
paketo-buildpacks/node-engine 0.6.2
paketo-buildpacks/npm-install 0.4.0
paketo-buildpacks/node-run-script 0.1.0
paketo-buildpacks/npm-start 0.3.0
===> ANALYZING
Previous image with name "myui" not found
===> RESTORING
===> BUILDING
Paketo CA Certificates Buildpack 2.3.2
https://github.com/paketo-buildpacks/ca-certificates
Launch Helper: Contributing to layer
Creating /layers/paketo-buildpacks_ca-certificates/helper/exec.d/ca-certificates-helper
Paketo Node Engine Buildpack 0.6.2
Resolving Node Engine version
Candidate version sources (in priority order):
-> ""
<unknown> -> ""
Selected Node Engine version (using ): 14.17.5
Executing build process
Installing Node Engine 14.17.5
Completed in 7.96s
Configuring build environment
NODE_ENV -> "development"
NODE_HOME -> "/layers/paketo-buildpacks_node-engine/node"
NODE_VERBOSE -> "false"
Configuring launch environment
NODE_ENV -> "production"
NODE_HOME -> "/layers/paketo-buildpacks_node-engine/node"
NODE_VERBOSE -> "false"
Writing profile.d/0_memory_available.sh
Calculates available memory based on container limits at launch time.
Made available in the MEMORY_AVAILABLE environment variable.
Paketo NPM Install Buildpack 0.4.0
Resolving installation process
Process inputs:
node_modules -> "Not found"
npm-cache -> "Not found"
package-lock.json -> "Found"
Selected NPM build process: 'npm ci'
Executing build process
Running 'npm ci --unsafe-perm --cache /layers/paketo-buildpacks_npm-install/npm-cache'
Completed in 23.58s
Configuring launch environment
NPM_CONFIG_LOGLEVEL -> "error"
Configuring environment shared by build and launch
PATH -> "$PATH:/layers/paketo-buildpacks_npm-install/modules/node_modules/.bin"
Paketo Node Run Script Buildpack 0.1.0
Executing build process
Executing scripts
Running 'npm run-script build'
> edit@0.0.0 build /workspace
> ng build
- Generating browser application bundles (phase: setup)...
Compiling @angular/core : es2015 as esm2015
Compiling @angular/cdk/keycodes : es2015 as esm2015
Compiling @angular/animations : es2015 as esm2015
Compiling @angular/animations/browser : es2015 as esm2015
Compiling @angular/cdk/observers : es2015 as esm2015
Compiling @angular/common : es2015 as esm2015
Compiling @angular/cdk/collections : es2015 as esm2015
Compiling @angular/platform-browser : es2015 as esm2015
Compiling @angular/cdk/platform : es2015 as esm2015
Compiling @angular/cdk/bidi : es2015 as esm2015
Compiling @angular/platform-browser/animations : es2015 as esm2015
Compiling @angular/cdk/a11y : es2015 as esm2015
Compiling @angular/forms : es2015 as esm2015
Compiling @angular/flex-layout/core : es2015 as esm2015
Compiling @angular/cdk/scrolling : es2015 as esm2015
Compiling @angular/cdk/portal : es2015 as esm2015
Compiling @angular/cdk/layout : es2015 as esm2015
Compiling @angular/material/core : es2015 as esm2015
Compiling @angular/common/http : es2015 as esm2015
Compiling @angular/cdk/overlay : es2015 as esm2015
Compiling @angular/flex-layout/extended : es2015 as esm2015
Compiling @angular/material/button : es2015 as esm2015
Compiling @angular/flex-layout/flex : es2015 as esm2015
Compiling @angular/flex-layout/grid : es2015 as esm2015
Compiling @angular/platform-browser-dynamic : es2015 as esm2015
Compiling @angular/router : es2015 as esm2015
Compiling @angular/material/sidenav : es2015 as esm2015
Compiling @angular/material/snack-bar : es2015 as esm2015
Compiling @angular/material/toolbar : es2015 as esm2015
Compiling @angular/material/icon : es2015 as esm2015
Compiling @angular/flex-layout : es2015 as esm2015
Compiling @angular/material/tabs : es2015 as esm2015
✔ Browser application bundle generation complete.
✔ Browser application bundle generation complete.
- Copying assets...
✔ Copying assets complete.
- Generating index html...
✔ Index html generation complete.
Initial Chunk Files | Names | Size
main.a6760a1641b4d1eaecd4.js | main | 4.50 MB
styles.8a29e51b15a5b6e5b823.css | styles | 90.06 kB
polyfills.a6c44b054b34d2bec03f.js | polyfills | 35.96 kB
runtime.543bd02f52b0afc6ba6a.js | runtime | 1015 bytes
| Initial Total | 4.63 MB
Build at: 2021-08-16T15:19:15.350Z - Hash: 0958e10b7d5232954d2e - Time: 46738ms
./src/app/footer/footer.component.scss - Warning: Module Warning (from ../layers/paketo-buildpacks_npm-install/modules/node_modules/postcss-loader/dist/cjs.js):
Warning
(7:3) postcss-preset-env: start value has mixed support, consider using flex-start instead
./src/app/home/home.component.scss - Warning: Module Warning (from ../layers/paketo-buildpacks_npm-install/modules/node_modules/postcss-loader/dist/cjs.js):
Warning
(84:3) postcss-preset-env: start value has mixed support, consider using flex-start instead
./src/app/home/home.component.scss - Warning: Module Warning (from ../layers/paketo-buildpacks_npm-install/modules/node_modules/postcss-loader/dist/cjs.js):
Warning
(85:3) postcss-preset-env: start value has mixed support, consider using flex-start instead
Warning: /workspace/src/app/resize.service.ts depends on 'element-resize-detector'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: initial exceeded maximum budget. Budget 500.00 kB was not met by 4.14 MB with a total of 4.63 MB.
Completed in 51.831s
Paketo NPM Start Buildpack 0.3.0
Assigning launch processes
web: ng serve
===> EXPORTING
Adding layer 'paketo-buildpacks/ca-certificates:helper'
Adding layer 'paketo-buildpacks/node-engine:node'
Adding layer 'paketo-buildpacks/npm-install:modules'
Adding layer 'paketo-buildpacks/npm-install:npm-cache'
Adding 1/1 app layer(s)
Adding layer 'launcher'
Adding layer 'config'
Adding layer 'process-types'
Adding label 'io.buildpacks.lifecycle.metadata'
Adding label 'io.buildpacks.build.metadata'
Adding label 'io.buildpacks.project.metadata'
Setting default process type 'web'
Saving myui...
*** Images (b9cd591df4be):
myui
Adding cache layer 'paketo-buildpacks/node-engine:node'
Adding cache layer 'paketo-buildpacks/npm-install:modules'
Adding cache layer 'paketo-buildpacks/npm-install:npm-cache'
Successfully built image myui
我会在回答前说,有多种方法可以做到这一点。以下是我建议的两种方式:
本地构建
本地构建,就像在您的机器上 运行
npm build
。添加一个
buildpack.yml
文件:staticfile: nginx: pushstate: true
这将指示静态文件 buildpack 生成支持 pushstate 的 Nginx 配置,这通常是单页 Javascript 应用程序所需要的。
运行
pack build myui -b paketo-buildpacks/nginx -b paketo-community/staticfile
-p dist/.dist/
是第 1 步构建过程输出的路径(即静态 HTML/CSS/Javascript 所在的位置)。确保您的
dist/
路径包含您在上一步中创建的buildpack.yml
文件。 这是静态文件构建包通过检测所必需的.如果您在尝试构建时看到No buildpack groups passed detection
,这可能就是原因。然后您可以执行
docker run -d -e PORT=8080 -p 8080:8080 myui
它会 运行 您的图像。生成的 nginx.conf 期望PORT
设置为您希望它监听的某个端口。只需确保您 select 的端口与参数-p
匹配,因此 docker 公开相同的端口。
在本地构建的优点是它很简单并且适用于大多数应用程序,因为构建的输出只是静态 HTML/CSS/JS 和其他资产文件。该 buildpack 仅添加了 Nginx,您就可以参加比赛了。
Buildpacks 构建
添加一个
buildpack.yml
文件:staticfile: nginx: pushstate: true
这将指示静态文件 buildpack 生成支持 pushstate 的 Nginx 配置,这通常是单页 Javascript 应用程序所需要的。
确保您创建的
buildpack.yml
文件位于项目的根目录,即您在下一步中 运行pack build
所在的目录。 这是静态文件构建包通过检测所必需的。如果您在尝试构建时看到No buildpack groups passed detection
,这可能就是原因。运行
pack build myui -b paketo-buildpacks/nodejs --env "BP_NODE_RUN_SCRIPTS=build" --env "NODE_ENV=development" --buildpack paketo-buildpacks/nginx --buildpack paketo-community/staticfile
这将确保安装了 Node 和 NPM,然后它将 运行 npm build
。这将从您的应用程序生成静态文件资源。然后 Nginx 和静态文件 buildpack 将 运行 安装和配置 Nginx 以托管您应用程序的静态文件。
它类似于本地构建,但不需要您在本地安装 Node 或 NPM。构建包将安装它们并在容器内构建。
我建议使用这两个构建过程之一的原因是,任何一个都会产生一个很小的启动容器,并且只包含您的静态文件和 Nginx。这将比使用构建工具的开发服务器安装 Node.js 更小、更高效、更适合生产。