Giter VIP home page Giter VIP logo

Comments (17)

rubys avatar rubys commented on September 26, 2024 1

That's fixed in github, but unreleased. I've also fixed other things, including some cosmetic changes like naming the stage bun not node. If you want to try it, replace the entry in your gemfile with:

gem "dockerfile-rails", "~> 1.5", :group => :development, :git => "https://github.com/fly-apps/dockerfile-rails.git"

from dockerfile-rails.

rubys avatar rubys commented on September 26, 2024 1

Released: https://github.com/fly-apps/dockerfile-rails/releases/tag/v1.5.9

from dockerfile-rails.

rubys avatar rubys commented on September 26, 2024

Where bun was added rails/jsbundling-rails#167

from dockerfile-rails.

rubys avatar rubys commented on September 26, 2024

Initial support installs bun instead of yarn. Node in still installed, for now. I should be able to remove Node. Neither node nor bun will be in the deployed image unless execjs is used.

from dockerfile-rails.

rubys avatar rubys commented on September 26, 2024

reopening as testing without node at all is going surprisingly well...

from dockerfile-rails.

luizkowalski avatar luizkowalski commented on September 26, 2024

hey Sam!
first of all, thank you so much for the quick reply and implementation!

I'm still getting mentions of yarn.lock on my Dockerfile

This is my configuration:

# generated by dockerfile-rails

---
options:
  bin-cd: true
  cache: true
  fullstaq: true
  jemalloc: true
  parallel: true
  postgresql: true
  redis: true
  root: true
  yjit: true
  envs:
    base:
      BUNDLE_WITHOUT: development:test:linting:profiler
      GIT_REV: "${GIT_REV}"
      BUILD_DATE: "${BUILD_DATE}"
  args:
    base:
      GIT_REV: "${GIT_REV}"
      BUILD_DATE: "${BUILD_DATE}"

and this is what is being generated (relevant part)

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

# Install packages needed to build gems and node modules
RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt \
    --mount=type=cache,id=dev-apt-lib,sharing=locked,target=/var/lib/apt \
    apt-get update -qq && \
    apt-get install --no-install-recommends -y build-essential curl libpq-dev node-gyp pkg-config python-is-python3


FROM prebuild as node

# Install Node.js
ARG NODE_VERSION=20.6.1
ARG BUN_VERSION=1.0.0
ENV PATH=/usr/local/node/bin:$PATH
RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
    /tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
    npm install -g bun@$BUN_VERSION && \
    rm -rf /tmp/node-build-master

# Install node modules
COPY --link package.json yarn.lock ./
RUN --mount=type=cache,id=bld-yarn-cache,target=/root/.yarn \
    YARN_CACHE_FOLDER=/root/.yarn bun install --frozen-lockfile

from dockerfile-rails.

rubys avatar rubys commented on September 26, 2024

You are getting mentions of a yarn.lock because.... drum roll you have a yarn.lock. If you remove your yarn.lock file and regenerate your dockerfile this should go away.

More troublesome is that bun.lockb is not listed on the COPY line. That's either because you don't have that file, or this is a path that I've not yet tested.

from dockerfile-rails.

rubys avatar rubys commented on September 26, 2024

Bun's addition to Rails: rails/rails@274bc97

from dockerfile-rails.

luizkowalski avatar luizkowalski commented on September 26, 2024

I'm getting an error because I do not have a yarn.lock file on my root folder but I do have a bun.lockb. I manually change yarn.lock to bun.lockb and it worked but any new dockerfile generation overrides it, obviously

from dockerfile-rails.

luizkowalski avatar luizkowalski commented on September 26, 2024

@rubys thanks! I will give it a try tonight and let you know!

from dockerfile-rails.

luizkowalski avatar luizkowalski commented on September 26, 2024

couple of things:

  1. now it is installing bun instead of node but it is trying to run npm install instead of bun install:
FROM prebuild as bun

# Install Bun
ARG BUN_VERSION=1.0.1
ENV BUN_INSTALL=/usr/local/bun
ENV PATH=/usr/local/node/bin:$PATH
RUN curl -fsSL https://bun.sh/install | bash -s -- "${BUN_VERSION}"

# Install node modules
COPY --link package.json bun.lockb ./
RUN --mount=type=cache,id=bld-npm-cache,target=/root/.npm \
    npm install

I don't have a yarn.lock, not sure why it is trying to use npm

  1. bun install step is failing:
 => CANCELED [stage-4 1/3] RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt     --mount=type=cache,id=dev-apt-lib,sh  20.0s
 => ERROR [bun 1/3] RUN curl -fsSL https://bun.sh/install | bash -s -- "1.0.1"                                                                     0.6s
 => [build 1/7] COPY --link Gemfile Gemfile.lock ./                                                                                                0.0s
 => CANCELED [build 2/7] RUN --mount=type=cache,id=bld-gem-cache,sharing=locked,target=/srv/vendor     bundle config set app_config .bundle &&     0.6s
------
 > [bun 1/3] RUN curl -fsSL https://bun.sh/install | bash -s -- "1.0.1":
#0 0.619 error: unzip is required to install bun (see: https://github.com/oven-sh/bun#unzip-is-required)

it might have to do with my image maybe? (fullstaq-ruby:${RUBY_VERSION}-jemalloc-slim).

I guess fullstaq-ruby slim does not include unzip while the ruby docker image does?

edit: I manually added unzip and got this error instead

 => CANCELED [stage-4 1/3] RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt     --mount=type=cache,id=dev-apt-lib,sh  18.8s
 => ERROR [bun 1/3] RUN curl -fsSL https://bun.sh/install | bash -s -- "1.0.1"                                                                     1.0s
 => [build 1/7] COPY --link Gemfile Gemfile.lock ./                                                                                                0.0s
 => CANCELED [build 2/7] RUN --mount=type=cache,id=bld-gem-cache,sharing=locked,target=/srv/vendor     bundle config set app_config .bundle &&     1.0s
------
 > [bun 1/3] RUN curl -fsSL https://bun.sh/install | bash -s -- "1.0.1":
curl: (22) The requested URL returned error: 404
#0 0.989
#0 0.991 error: Failed to download bun from "https://github.com/oven-sh/bun/releases/download/1.0.1/bun-linux-x64.zip"

but that seems to be a mistake on bun's install script

from dockerfile-rails.

rubys avatar rubys commented on September 26, 2024

I don't have a yarn.lock, not sure why it is trying to use npm

That should now be fixed.

but that seems to be a mistake on bun's install script

OK, switched back to installing bun via npm.

from dockerfile-rails.

luizkowalski avatar luizkowalski commented on September 26, 2024
 => ERROR [build 4/7] COPY --from=bun /usr/local/bun /usr/local/bun                                                                                0.0s
------
 > [build 4/7] COPY --from=bun /usr/local/bun /usr/local/bun:
------
Error: failed to fetch an image or build from source: error building: failed to solve: failed to compute cache key: "/usr/local/bun" not found: not found

I thought that COPY --from=bun /usr/local/bun /usr/local/bun is not necessary when using npm so I removed but then I got a different error

 => ERROR [build 6/6] RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile                                                                      2.1s
------
 > [build 6/6] RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile:
#0 2.108 rails aborted!
#0 2.108 cssbundling-rails: Command install failed, ensure bun is installed

I guess it is needed but the path is incorrect. I couldn't figure out the path exactly

from dockerfile-rails.

luizkowalski avatar luizkowalski commented on September 26, 2024

ok, so I got bun installed with my Dockerfile configuration. This is what I've done

FROM prebuild as bun

# Install Bun
ARG BUN_VERSION=bun-v1.0.2
ENV BUN_INSTALL=/usr/local/bun
ENV PATH=/usr/local/bun/bin:$PATH
RUN curl -fsSL https://bun.sh/install | bash -s -- "${BUN_VERSION}"

noticed that the BUN_VERSION arg should be bun-v{version} not just the version

after that, you need to copy the installer and set the path on the next step

FROM prebuild as build
# Install application gems
...

# Copy bun modules
COPY --from=bun /rails/node_modules /rails/node_modules
COPY --from=bun /usr/local/bun /usr/local/bun
ENV PATH=/usr/local/bun/bin:$PATH

I noticed you got to set the PATH for bun twice tho

from dockerfile-rails.

rubys avatar rubys commented on September 26, 2024

Thanks! I pushed a change with basically those fixes applied, with some minor cosmetic differences (example: I put "bun-v" on the curl line). Can you give it a try?

from dockerfile-rails.

luizkowalski avatar luizkowalski commented on September 26, 2024

Works perfectly!
The only thing I noticed was that it kept the PATH addition for node:

ENV PATH=/usr/local/bun/bin:$PATH
ENV PATH=/usr/local/node/bin:$PATH

it's not going to break anything ofc but it can be removed I believe

apart from that, it is compiling now 🎉

from dockerfile-rails.

rubys avatar rubys commented on September 26, 2024

Fixed: 56d0373

from dockerfile-rails.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.