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

[proposal] Add node and yarn installation logic to dockerfile, bump ruby to 3.3.6, bump rails to 8.0.0 #23

Merged
merged 2 commits into from
Jan 16, 2025

Conversation

onshi
Copy link
Contributor

@onshi onshi commented Aug 6, 2024

This PR addresses issue #22

Currently our Dockerfile image doesn't have node and yarn binaries which results in errors when using --js or --css switches.

This PR adds logic for downloading node 22.7.0 binary and installing yarn 1.22.22 to our dockerfiles. It also bumps default ruby to 3.3.5 and default rails to 7.2.1

How this was tested?

> cargo build
> ./target/debug/rails-new main --js esbuild --css tailwind

>  docker run -it --rm -v $(pwd)/main:/rails -w /rails -p 3000:3000 -e BINDING=0.0.0.0 rails-new-3.3.5-7.2.1 /bin/bash -c "bundle install && ./bin/dev"

> visited http://localhost:3000 and confirmed that page is live

> docker run -it --rm rails-new-3.3.5-7.2.1 bash

root@ac7b091459cb:/# ruby --version
ruby 3.3.5 (2024-09-03 revision ef084cc8f4) [x86_64-linux]
root@ac7b091459cb:/# rails --version
Rails 7.2.1
root@ac7b091459cb:/#  node --version
v22.7.0
root@ac7b091459cb:/#  yarn --version
1.22.22

@rafaelfranca, @excid3 let me know what do you think, I'm open to rewritting this PR to your prefered approach

Fixes #22
Fixes #31

@rafaelfranca
Copy link
Member

Do we need to care about different node and yarn versions given we are just creating the application with those Dockerfiles? I think we should just hardcoded a single version of it.

@onshi
Copy link
Contributor Author

onshi commented Aug 14, 2024

Sure, this also makes sense. I'll redo it later today

@onshi onshi force-pushed the issues_22 branch 2 times, most recently from a0b3d19 to 97474ac Compare August 15, 2024 17:39
@onshi
Copy link
Contributor Author

onshi commented Aug 15, 2024

Next round of changes ready for review

@onshi onshi changed the title [proposal] Introduce mise as dev tools manager to dockerfile + add node and yarn to dockerfile [proposal] Add node and yarn installation logic to dockerfile Aug 15, 2024
@nkruk
Copy link

nkruk commented Aug 25, 2024

Hey @onshi, I'm getting the following on macOS Sonoma 14.6.1.

± ./target/debug/rails-new main --js esbuild --css tailwind
[+] Building 0.7s (6/7) docker:desktop-linux
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 727B 0.0s
=> [internal] load metadata for docker.io/library/ruby:3.3.4 0.5s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [1/4] FROM docker.io/library/ruby:3.3.4@sha256:d4233f4242ea25346f157709bb8417c615e7478468e2699c8 0.0s
=> CACHED [2/4] RUN curl -fsSL https://nodejs.org/dist/v22.6.0/node-v22.6.0-linux-x64.tar.gz 0.0s
=> ERROR [3/4] RUN npm install -g [email protected] 0.1s

    [3/4] RUN npm install -g [email protected]:
    0.107 rosetta error: failed to open elf at /lib64/ld-linux-x86-64.so.2
    0.107 Trace/breakpoint trap

Dockerfile:14

Could this be an issue just on my machine?

@onshi
Copy link
Contributor Author

onshi commented Aug 26, 2024

Hey @nkruk,

oh boy I think rosetta error would indicate that you're using arm processor? I currently have only Intel x86 based computers so I didn't test my changes on this architecture ;/

Can you let me know if running

softwareupdate --install-rosetta

changes anything for you?

If it doesn't I can try to rewrite our Dockerfiles to install node using different approach.

Cheers!

@nkruk
Copy link

nkruk commented Aug 26, 2024

Yes @onshi, I'm running an M2 Pro and had already ran softwareupdate --install-rosetta before. I get:

Install of Rosetta 2 finished successfully

But same output.

@onshi
Copy link
Contributor Author

onshi commented Aug 26, 2024

Hey @nkruk,

I see. I rewrote node installation logic in our Dockerfiles to use apt-get instead of downloading prebuilt binaries, do you mind taking another shot at this and letting me know if it works now for you?

Cheers!

@nkruk
Copy link

nkruk commented Aug 26, 2024

Hey @onshi: worked like a charm! Hope it gets merged soon. Thanks!

@betogrun
Copy link

@onshi it worked fine for me as well. Thanks!

@onshi onshi force-pushed the issues_22 branch 2 times, most recently from 5687eed to 87b86de Compare September 4, 2024 23:54
@NielsKSchjoedt
Copy link

Any holdback on release of this? ❤️

@NielsKSchjoedt
Copy link

@onshi would you mind giving a tip on how I can run your fork?

@NielsKSchjoedt
Copy link

@rafaelfranca you the only maintainer here or?

@onshi
Copy link
Contributor Author

onshi commented Oct 25, 2024

@onshi would you mind giving a tip on how I can run your fork?

@NielsKSchjoedt sure, I'm assuming you've rust and cargo installed. This way you can just point cargo to install from my fork

cargo install --verbose --git https://github.com/onshi/rails-new --branch issues_22

binary will be installed in your $HOME/.cargo/bin directory. Let me know if you would need any more help with this

cheers!

@onshi
Copy link
Contributor Author

onshi commented Nov 11, 2024

update:

last commit bumped default ruby to 3.3.6 and default rails to 8.0.0

tested with

./target/debug/rails-new main --js esbuild --css tailwind
 docker run -it --rm -v $(pwd)/main:/rails -w /rails -p 3000:3000 -e BINDING=0.0.0.0 rails-new-3.3.6-8.0.0 /bin/bash -c "bundle install && ./bin/dev"
docker run -it --rm -v $(pwd)/main:/rails -w /rails -p 3000:3000 -e BINDING=0.0.0.0 rails-new-3.3.6-8.0.0 /bin/bash

root@b9f3d4a1f2d4:/rails# ruby --version
ruby 3.3.6 (2024-11-05 revision 75015d4c1f) [x86_64-linux]
root@b9f3d4a1f2d4:/rails# rails --version
Rails 8.0.0
root@b9f3d4a1f2d4:/rails# node --version
v22.11.0
root@b9f3d4a1f2d4:/rails# yarn --version
1.22.22
open http://localhost:3000

obraz

@onshi onshi changed the title [proposal] Add node and yarn installation logic to dockerfile [proposal] Add node and yarn installation logic to dockerfile, bump ruby to 3.3.6, bump rails to 8.0.0 Nov 11, 2024
@onshi onshi mentioned this pull request Dec 6, 2024
@JohnSmall
Copy link

This appears to have been merged, even though this ticket is still open. When I run rails-new to create a Rails app in a devcontainer and open the devcontainer then I see

vscode ➜ /workspaces/dummy2_project (main) $ npx -v
10.9.2
vscode ➜ /workspaces/dummy2_project (main) $ yarn -v
1.22.22
vscode ➜ /workspaces/dummy2_project (main) $ node -v
v22.13.0

So the npx, yarn and node part of things appears to be working.

But that then leads to the next problem which is that yarn build:css does not work, and hence bin\dev will fail. I'll investigate a bit more to identify the problem and raise a separate ticket

@onshi
Copy link
Contributor Author

onshi commented Jan 14, 2025

This appears to have been merged, even though this ticket is still open. When I run rails-new to create a Rails app in a devcontainer and open the devcontainer then I see

vscode ➜ /workspaces/dummy2_project (main) $ npx -v 10.9.2 vscode ➜ /workspaces/dummy2_project (main) $ yarn -v 1.22.22 vscode ➜ /workspaces/dummy2_project (main) $ node -v v22.13.0

So the npx, yarn and node part of things appears to be working.

But that then leads to the next problem which is that yarn build:css does not work, and hence bin\dev will fail. I'll investigate a bit more to identify the problem and raise a separate ticket

hey @JohnSmall,

do you mind posting steps to reproduce your problem?

From what I understood you're talking about devcontainer images/containers, which are different thing from what we're using here. Dockerfiles created here are only used to generate new rails project, we dont use them to run actual dev environment.

Here is how I tried to simulate your flow, but I can be wrong here:

from plain - "non devcontainer" terminal I ran

./target/debug/rails-new main --js esbuild --css tailwind --devcontainer

to generate fresh project

Then in vscode I created devcontainer environment using config from main/.devcontainer directory

Then I spun devcontainer terminal in vscode and ran your commands

vscode ➜ /workspaces/main (main) $ npx -v
10.9.2
vscode ➜ /workspaces/main (main) $  yarn -v
1.22.22
vscode ➜ /workspaces/main (main) $ node -v
v22.13.0
vscode ➜ /workspaces/main (main) $ yarn build:css
yarn run v1.22.22
$ tailwindcss -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css --minify

Rebuilding...

Done in 267ms.
Done in 2.08s.
vscode ➜ /workspaces/main (main) $ ruby --version
ruby 3.3.6 (2024-11-05 revision 75015d4c1f) [x86_64-linux]

after running bin/dev in terminal session from above I got working app connected to localhost:3000

Cheers, and let me know if I can help you further

@rafaelfranca rafaelfranca merged commit 7ba18e0 into rails:main Jan 16, 2025
3 checks passed
@onshi onshi deleted the issues_22 branch January 16, 2025 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rails new --css boostrap failed npx missing when using --js esbuild
6 participants