Skip to content
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

feat(lib): Serverless output for static websites and Next.js #135

Merged
merged 6 commits into from
Sep 15, 2023

Conversation

yuaanlin
Copy link
Member

@yuaanlin yuaanlin commented Sep 14, 2023

This Pull Request is introducing some features about serverless deployment for static files and serverless function, starts with Next.js.

Static Websites

For static websites, we no longer need Nginx and we just copy files to .zeabur/output/static folder.

zbpack .

2023/09/15 01:06:17
╔══════════════════════════ Build Plan ═════════════════════════╗
║ provider         │ nodejs                                     ║
║───────────────────────────────────────────────────────────────║
║ packageManager   │ pnpm                                       ║
║───────────────────────────────────────────────────────────────║
║ framework        │ vite                                       ║
║───────────────────────────────────────────────────────────────║
║ nodeVersion      │ 18                                         ║
║───────────────────────────────────────────────────────────────║
║ installCmd       │ pnpm install                               ║
║───────────────────────────────────────────────────────────────║
║ buildCmd         │ pnpm run build                             ║
║───────────────────────────────────────────────────────────────║
║ outputDir        │ dist                                       ║
╚═══════════════════════════════════════════════════════════════╝

[+] Building 11.3s (12/12) FINISHED                                                 docker:orbstack
 => [internal] load build definition from Dockerfile                                           0.0s
 => => transferring dockerfile: 242B                                                           0.0s
 => [internal] load .dockerignore                                                              0.0s
 => => transferring context: 2B                                                                0.0s
 => [internal] load metadata for docker.io/library/node:18                                     2.1s
 => [auth] library/node:pull token for registry-1.docker.io                                    0.0s
 => [1/6] FROM docker.io/library/node:18@sha256:933bcfad91e9052a02bc29eb5aa29033e542afac4174f  0.0s
 => [internal] load build context                                                              0.7s
 => => transferring context: 1.10MB                                                            0.7s
 => CACHED [2/6] WORKDIR /src                                                                  0.0s
 => CACHED [3/6] RUN corepack enable && corepack prepare --all                                 0.0s
 => [4/6] COPY . .                                                                             0.7s
 => [5/6] RUN pnpm install                                                                     5.3s
 => [6/6] RUN pnpm run build                                                                   1.5s
 => exporting to image                                                                         1.0s
 => => exporting layers                                                                        1.0s
 => => writing image sha256:8a23982a48109c9b7ffcb69062da56f5738783f024db3cb91c664de739cef440   0.0s
 => => naming to docker.io/library/vite-template                                               0.0s
Transforming build output to serverless format ...

Build successful

To run the image, use the following command:
npx serve .zeabur/output/static
tree .zeabur -L 5

.zeabur
└── output
    ├── config.json
    └── static
        ├── assets
        │   ├── index-d526a0c5.css
        │   ├── index-e92ae01e.js
        │   └── react-35ef61ed.svg
        ├── index.html
        └── vite.svg

3 directories, 6 files
cat .zeabur/output/config.json

{"routes":[{"src":".*","dest":"/index.html"}],"containerized":false}⏎ 

Next.js

EXPERIMENTAL_SERVERLESS=1 zbpack .

2023/09/15 01:08:31
╔══════════════════════════ Build Plan ═════════════════════════╗
║ provider         │ nodejs                                     ║
║───────────────────────────────────────────────────────────────║
║ installCmd       │ npm install                                ║
║───────────────────────────────────────────────────────────────║
║ buildCmd         │ npm run build                              ║
║───────────────────────────────────────────────────────────────║
║ startCmd         │ npm run start                              ║
║───────────────────────────────────────────────────────────────║
║ serverless       │ true                                       ║
║───────────────────────────────────────────────────────────────║
║ packageManager   │ npm                                        ║
║───────────────────────────────────────────────────────────────║
║ framework        │ next.js                                    ║
║───────────────────────────────────────────────────────────────║
║ nodeVersion      │ 18                                         ║
╚═══════════════════════════════════════════════════════════════╝

[+] Building 2.0s (11/11) FINISHED                                                  docker:orbstack
 => [internal] load build definition from Dockerfile                                           0.0s
 => => transferring dockerfile: 253B                                                           0.0s
 => [internal] load .dockerignore                                                              0.0s
 => => transferring context: 2B                                                                0.0s
 => [internal] load metadata for docker.io/library/node:18                                     1.3s
 => [1/6] FROM docker.io/library/node:18@sha256:933bcfad91e9052a02bc29eb5aa29033e542afac4174f  0.0s
 => [internal] load build context                                                              0.7s
 => => transferring context: 36.87MB                                                           0.6s
 => CACHED [2/6] WORKDIR /src                                                                  0.0s
 => CACHED [3/6] RUN corepack enable && corepack prepare --all                                 0.0s
 => CACHED [4/6] COPY . .                                                                      0.0s
 => CACHED [5/6] RUN npm install                                                               0.0s
 => CACHED [6/6] RUN npm run build                                                             0.0s
 => exporting to image                                                                         0.0s
 => => exporting layers                                                                        0.0s
 => => writing image sha256:1086775ccdc30e0e88cc1d4c4f0fcfe1752c55ebb26f3d02babb39d896b427f1   0.0s
 => => naming to docker.io/library/next-page                                                   0.0s
Transforming build output to serverless format ...

Build successful

To run the image, use the following command:
docker run -p 8080:8080 -it next-page
tree .zeabur -L 4
.zeabur
└── output
    ├── config.json
    ├── functions
    │   ├── about.func
    │   │   ├── index.js
    │   │   ├── node_modules
    │   │   └── package.json
    │   └── api
    │       ├── bye.func -> .zeabur/output/functions/about.func
    │       └── hello.func -> .zeabur/output/functions/about.func
    └── static
        ├── 404.html
        ├── 500.html
        ├── _next
        │   └── static
        ├── contact.html
        ├── favicon.ico
        ├── index.html
        ├── next.svg
        └── vercel.svg
cat .zeabur/output/config.json

{"routes":[],"containerized":false}

@yuaanlin yuaanlin added the enhancement New feature or request label Sep 14, 2023
@yuaanlin yuaanlin self-assigned this Sep 14, 2023
Copy link
Member

@pan93412 pan93412 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically LGTM!

pkg/zeaburpack/main.go Outdated Show resolved Hide resolved
@yuaanlin yuaanlin merged commit a60ce8a into main Sep 15, 2023
7 checks passed
@yuaanlin yuaanlin deleted the yuanlin/zea-1828-zbpack-implementation branch September 15, 2023 04:30
hackerchai pushed a commit to hackerchai/zbpack that referenced this pull request Oct 29, 2023
…lementation

feat(lib): Serverless output for static websites and Next.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants