oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.13k stars 2.76k forks source link

When I tried to deploy a bun app to fly.io, a docker error occered. #6110

Closed kumastry closed 1 year ago

kumastry commented 1 year ago

What version of Bun is running?

1.0.0+822a00c4d508b54f650933a73ca5f4a3af9a7983

What platform is your computer?

Linux 5.15.90.1-microsoft-standard-WSL2 x86_64 x86_64

What steps can reproduce the bug?

I was trying to deploy a bun app to fly.io following this tutorial. https://github.com/fly-apps/bun/

But a docker error occured like below.

> fly deploy
==> Verifying app config
Validating /home/kumastry/prgm/js/bun/fly.toml
Platform: machines
✓ Configuration is valid
--> Verified app config
==> Building image
Remote builder fly-builder-black-bird-705 ready
==> Building image with Docker
--> docker host: 20.10.12 linux x86_64
[+] Building 4.0s (12/15)
 => [internal] load build definition from Dockerfile                                                               0.1s
 => => transferring dockerfile: 828B                                                                               0.1s
 => [internal] load .dockerignore                                                                                  0.1s
 => => transferring context: 35B                                                                                   0.1s
 => resolve image config for docker.io/docker/dockerfile:1                                                         1.1s
 => CACHED docker-image://docker.io/docker/dockerfile:1@sha256:ac85f380a63b13dfcefa89046420e1781752bab202122f8f50  0.0s
 => [internal] load build definition from Dockerfile                                                               0.0s
 => [internal] load metadata for docker.io/oven/bun:1.0.0                                                          2.3s
 => [internal] load .dockerignore                                                                                  0.0s
 => CANCELED [base 1/2] FROM docker.io/oven/bun:1.0.0@sha256:65d57939cbfadac8aec3c5d0df1579c1d7c033dfb536cc7d794d  0.1s
 => => resolve docker.io/oven/bun:1.0.0@sha256:65d57939cbfadac8aec3c5d0df1579c1d7c033dfb536cc7d794d80fe8b5ac6ed    0.0s
 => => sha256:b2fd58d2286c8e0802dca8a9f80f45041d3662336fe05551a44f1cd6b6dd6278 0B / 294B                           0.3s
 => => sha256:91767ef6925a11e8be40af64ffcfa8dd6107f4a887e6f9384655ffcebd00e022 0B / 36.98MB                        0.3s
 => => sha256:a2f6cbefcca93f7a411f572cc0e7e4137325f187c9d64e1488da4893f213a975 0B / 36.98MB                        0.3s
 => => sha256:0a66add3d7bcb433f66a209b2704d00eab62dde9b5772a15bf00e97d90021bab 0B / 141B                           0.3s
 => => sha256:65d57939cbfadac8aec3c5d0df1579c1d7c033dfb536cc7d794d80fe8b5ac6ed 685B / 685B                         0.0s
 => => sha256:9a62eb27553cd1d44f3a3235fe355e6f87ef78056a4d631f793973b809827957 2.74kB / 2.74kB                     0.0s
 => => sha256:7d97e254a0461b0a30b3f443f1daa0d620a3cc6ff4e2714cc1cfd96ace5b7a7e 0B / 31.42MB                        0.3s
 => => sha256:367411b96ee37e7e9485b3259d5111d62305fb6ce776c43a304aea19c8ce4bae 0B / 4.07kB                         0.3s
 => => sha256:a5893e848f2fefd25e5452fc289202c6b0caa9f0e7dd1c1b8a457fb1eda2c707 1.49kB / 1.49kB                     0.0s
 => [internal] load build context                                                                                  0.1s
 => => transferring context: 1.70kB                                                                                0.1s
 => CACHED [base 2/2] WORKDIR /app                                                                                 0.0s
 => CACHED [build 1/4] RUN apt-get update -qq &&     apt-get install -y build-essential pkg-config python-is-pyth  0.0s
 => ERROR [build 2/4] COPY --link bun.lockb package.json ./                                                        0.0s
------
 > [build 2/4] COPY --link bun.lockb package.json ./:
------
Error: failed to fetch an image or build from source: error building: failed to solve: failed to compute cache key: "/bun.lockb" not found: not found

And a dockerfile generated by fly launch is like below.

# syntax = docker/dockerfile:1

# Adjust BUN_VERSION as desired
ARG BUN_VERSION=1.0.0
FROM oven/bun:${BUN_VERSION} as base

LABEL fly_launch_runtime="Bun"

# Bun app lives here
WORKDIR /app

# Set production environment
ENV NODE_ENV="production"

# Throw-away build stage to reduce size of final image
FROM base as build

# Install packages needed to build node modules
RUN apt-get update -qq && \
    apt-get install -y build-essential pkg-config python-is-python3

# Install node modules
COPY --link bun.lockb package.json ./
RUN bun install --ci

# Copy application code
COPY --link . .

# Final stage for app image
FROM base

# Copy built application
COPY --from=build /app /app

# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
CMD [ "bun", "http.ts" ]

Is this a Bun's bug?

What is the expected behavior?

deploying sccessfully to fly.io

What do you see instead?

No response

Additional information

flyctl's version is v0.1.103.

> fly version
flyctl v0.1.103 linux/amd64 Commit: e091df05ab9d089443f3812b593a1c3350f9b3fb BuildDate: 2023-09-26T22:21:08Z
itsnamangoyal commented 1 year ago

.dockerignore file generated by fly launch has bun.lockb file mentioned which is the cause of this problem. simply remove bun.lockb and it should work.

irvile commented 1 year ago

yes, @itsnamangoyal is right. If help in anything, I have a repository that can be deployed on fly.io. bun + elysia. https://github.com/codiplace/bun-elysia

kumastry commented 1 year ago

@itsnamangoyal @irvile Thank you for teaching! It works!

Kitanga commented 1 year ago

If you are having issues with "sh: 1: bun: not found", flyio isn't generating the correct Dockerfile for some reason. Follow @irvile 's link: https://github.com/codiplace/bun-elysia

Use that instead, or copy the Dockerfile, it will launch correctly

fly io bun issue