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

Best way to install yarn and nodejs #497

Closed
Jenny13800 opened this issue Oct 27, 2023 · 4 comments
Closed

Best way to install yarn and nodejs #497

Jenny13800 opened this issue Oct 27, 2023 · 4 comments

Comments

@Jenny13800
Copy link

Hi !

Thank you for this great job! It's really great.

I want to install nodejs and yarn in docker.
What's the best way to do it ?
It would be great to have symfony/webpack-encore-bundle in Extra Services.

There is an issue on this topic but i don't know if it's the right method. The dockerfile is different.

Thank you for your help.

@zpi12lmm
Copy link

I can offer my version, how I implemented it in my project. Since we only need nodejs to minify and package assets, we don't need to create a separate service in production mode, so let's add a service for developer mode, for this, add the following service to the compose.override.yaml file:

services:
  node:
    image: node:lts-alpine
    tty: true
    working_dir: /app
    depends_on:
      - php
    volumes:
      - ./:/app
    environment:
      NODE_ENV: development

After that, run your docker compose and you will have a new node service in developer mode, and by going into the docker compose exec node sh container, you can run all the commands you need for symfony/webpack-encore-bundle.

By the way, to deploy assets in production mode, you can use the scp command to transfer already compiled files, or on the production server itself, before starting the docker compose, build as follows:

docker run --rm -v ./:/app -w /app node:lts-alpine sh -c 'yarn install; yarn build' && rm -rf './node_modules/'

@Jenny13800
Copy link
Author

Hey, thank you for your help.

I don't know if this the best pratice but I added in the dockerfile :

# Install nodejs & yarn
RUN apk update && apk add --no-cache nodejs yarn

@zpi12lmm
Copy link

This is a bad practice because each container should be responsible for only one dependency (in this case, you have php and node in the same container). If you need to customize the node service, then you need to create a separate container for this, I recommend following the official guide.
In most cases, the webpack-encore-bundle component only needs to define the node image (as I implemented in my project), because customizing the node in the Dockerfile is required for the node server or SPA/PWA.

@Jenny13800
Copy link
Author

Jenny13800 commented Oct 31, 2023

Hello,

Thanks for your quick reply.

Indeed, It wasn't the best option. On the old project I'm working on, they installed node with apt-get in the PHP image.

I followed your example.

Thanks for sharing code.

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

No branches or pull requests

2 participants