R
Railway15mo ago
abc222

Deploying without having to do npx playwright install-deps

Hello, I'm deploying a node.js application that is using playwright, and it needs some dependencies in the container to run playwright well However, I don't know how to use an image, or a setup that already has those dependencies For now, I have this in my package.json scripts : "start": "npx playwright install-deps && vite preview --host 0.0.0.0 --port $PORT" However, it implies that the command is executed at every deployment, and it may just consume CPU power and slow down deployment, so I'm searching for a more elegant and efficient way of deploying with those playwright dependencies It would be awesome if I could get some help to solve that issue !
38 Replies
Percy
Percy15mo ago
Project ID: df1ac280-a03b-4213-9495-09597046a130
abc222
abc22215mo ago
df1ac280-a03b-4213-9495-09597046a130
Brody
Brody15mo ago
honestly, the far bigger issue is that you are running a preview server on railway but lets fix both what kind of vite app is this?
abc222
abc22215mo ago
Hello, it is a SvelteKit app, I know it's not recommended to run a preview app, but it doesn't affect performance I could do something like "start": "node ./build/index.js" or something like that, even if I don't exactly get in which folder my project is built
Brody
Brody15mo ago
oh yes it does, it also effects costs
abc222
abc22215mo ago
but I think I should do that when the first issue is fixed my app is also taking 900 MB of RAM just on deploy, without touching anything yes maybe it's because I ran in preview so you may be right on this
Brody
Brody15mo ago
i am right
abc222
abc22215mo ago
yes
Brody
Brody15mo ago
but okay install playwright in the build phase instead of at start
abc222
abc22215mo ago
how should I do that ? do i need to make a docker image ?
Brody
Brody15mo ago
add this as a nixpacks.toml file to your project
[phases.playwright]
dependsOn = ['install']
cmds = ['npx playwright install-deps']
[phases.playwright]
dependsOn = ['install']
cmds = ['npx playwright install-deps']
abc222
abc22215mo ago
okay, i have no nixpacks.toml file for now in my project can I just write only that in it ?
Brody
Brody15mo ago
and then you can remove the playwright from the start command
abc222
abc22215mo ago
Or should I init a nixpacks.toml with a specific command ?
Brody
Brody15mo ago
just make that file with that contents, nothing special
abc222
abc22215mo ago
okay thank you it's done and i removed the command from my start script
Brody
Brody15mo ago
okay, let me know how that goes
abc222
abc22215mo ago
Okay, i'll let you know if it works well and try to solve the preview running on my own, if it works i'll mark it as solved thank you
Brody
Brody15mo ago
the solution to that would require merging two nixpacks.toml files together
abc222
abc22215mo ago
Error: ╔══════════════════════════════════════════════════════╗ ║ Host system is missing dependencies to run browsers. ║ ║ Please install them with the following command: ║ ║ ║ ║ npx playwright install-deps ║ ║ ║ ║ Alternatively, use apt: ║ ║ apt-get install libnss3\ ║ ║ libnspr4\ ║ ║ libatk1.0-0\ ║ ║ libatk-bridge2.0-0\ ║ ║ libcups2\ ║ ║ libdrm2\ ║ ║ libdbus-1-3\ ║ ║ libxcb1\ ║ ║ libxkbcommon0\ ║ ║ libatspi2.0-0\ ║ ║ libx11-6\ ║ ║ libxcomposite1\ ║ ║ libxdamage1\ ║ ║ libxext6\ ║ ║ libxfixes3\ ║ ║ libxrandr2\ ║ ║ libgbm1\ ║ ║ libpango-1.0-0\ ║ ║ libcairo2\ ║ ║ libasound2 ║ ║ ║ ║ ❤️ Playwright Team ║ ╚══════════════════════════════════════════════════════╝ Failed btw i didn't saw anything related to playwright during build time is there a way to know if the nixpacks file was taken into account correctly ?
Brody
Brody15mo ago
❤️ Playwright Team
how cute show me the build table at the top of the build logs please
abc222
abc22215mo ago
yes pretty cute XD feels heartwarming to see
abc222
abc22215mo ago
No description
abc222
abc22215mo ago
I believe I missed something while creating the file
Brody
Brody15mo ago
no no thats my bad, i made a typo, i have fixed it recopy into your file
abc222
abc22215mo ago
yes it's gonna run now
No description
abc222
abc22215mo ago
awesome i see it executing the install-deps script you talked about merging two nixpacks files together to solve it what do you have in mind ? I was planning on just replacing something in the "start" script in package.json, do you have a better solution ?
Brody
Brody15mo ago
I do but I'm about to go cut grass, I'll send you the new nixpacks.toml file when I'm back
abc222
abc22215mo ago
Okay sure, take your time and thank you for your help, I wouldn't solve this building issue this quickly without you
Brody
Brody15mo ago
heres your new nixpacks.toml file https://gist.github.com/brody192/3e83905dd4af8e0810cc1a5574d424ee and then you will need to include this Caddyfile in your project too https://github.com/brody192/vue-3-template/blob/main/Caddyfile dont worry about that being a vue template, it uses vite so it should be all the same
abc222
abc22215mo ago
Thank you for helping me ! I have a question : why do I need to use caddy as my server instead of using a native standalone node server ? SvelteKit provide a way of generating that with building : https://kit.svelte.dev/docs/adapter-node Do you think using their Node Adapter way of hosting my app would have drawbacks instead of using Caddy ?
SvelteKit docs
Node servers • SvelteKit documentation
Brody
Brody15mo ago
well of course you don't need to, but caddy is gonna use sub 20mb of ram where as the node server may use around 60-70mb do you do any ssr? if so caddy wont work anyway
abc222
abc22215mo ago
Oh okay so it's just consuming less RAM I didn't know about that ! Yes I do use some SSR, Caddy is some sort of static hosting ? I think 60mb is okay if it's just that, since it's gonna be a RAM intensive app when some tasks are running with Playwright I also use SvelteKit as my "server" btw, i have routes with SvelteKit, so it may not work at all with Caddy
abc222
abc22215mo ago
Caddy Community
Help getting started with Caddyserver & Sveltekit app
Hello, could someone please help me with the final step/steps of getting started with Caddy? I want to host my sveltekit app. I have downloaded the repo. Then npm install → npm run build Then in my Caddyfile I added this: example.com root * /var/www/my-app/build file_server But when I go to the domain I just see an error message about too m...
abc222
abc22215mo ago
It's talking about the "static adapter"
Brody
Brody15mo ago
yeah wont work for you, forget about the caddy stuff lol youll want to install the node adapter and then set your start script to node build/index.js
abc222
abc22215mo ago
Okay, i'll try with that I'll notice you if it uses more RAM than expected, but that should do it
Brody
Brody15mo ago
sounds good
Want results from more Discord servers?
Add your server