Tailwind infinite build loop
TL;DR
I recently migrated my personal website from the tailwind CDN to tailwind proper. In my go code for starting my server, I'm using
exec.Run()
to run tailwind's build process on server startup. All of this is working excellently on my local machine, but when I deploy it to Railway it appears to be launching the server in a loop about every five seconds.
What changed
- I added node as a dependency to my deploy so that npx
could be used for the tailwind cli
- I wrote the following function in order to do the automatic build:
- I'm not actually using the error return from that function, so even if the build fails it shouldn't be causing the server restart (and didn't when I initially deployed it without the node dependency)
- I'm aware that it's silly to ignore that error and I'm going to fix that. But it doesn't explain the problem so I'm leaving it as-is for now
that's really it. I'm not super sure where to start looking for what the problem might be. For now the deployment has been canceled because it's just my personal site and I would rather have it down than run up my compute bill on a bug I don't know how to fix lol. Any suggestions would be greatly appreciated.35 Replies
Project ID:
271ed33d-be6b-40ce-96ba-504a94362dac
project id: 271ed33d-be6b-40ce-96ba-504a94362dac
you are likely trying to use more than 500MB of memory, if you still have issues after upgrading to the hobby plan we can then debug this further
oh, okay. I wasn't aware of the memory constraint, let me take a look at that and try upgrading
yeah 500MB on trial
ok looks like upgrading worked but now it's... not building properly? or not saving the output? Let me set it up to panic if the tailwind build fails and that'll probably give me some more info
why not run that tailwind build command as a regular build command? is there any specific reason you are doing it in such a convoluted way?
if i can be so real
i thought this way would be easier
that is the main reason
now i want it to work but if it doesn't i'll probably just cave and do it as a build command
but i thought it would be cool to have the server handle the tailwind build itself
oh it's saying that npx isn't in the path
id go with a multi stage Dockerfile where the first stage is a node image and it builds the css, then the second stage is a golang image and then you copy over the built files into the final image
i see
gotta go learn docker then. brb
you dont though
its just a text file
oh i see
in all my years of writing Dockerfiles, i have never once ran docker on my own computer
so this should be one dockerfile with two sections, one running a node image and the second running a go image?
you got your terminology wrong, but you have the idea more or less, if you want to share your repo i can try to write one for you
I think I have one that should work, but if you want to give it a sanity check that would be great
I just went off of docker's tutorial for building an image for go lol
you are on the right track, but your golang layer does not have a work dir, and you have no copied the built css into the golang layer either
ohhhh okay i can take care of that lol thank you
if I wanna just copy the whole dist dir onto a dist dir in the image, it would just be
COPY dist/ ./dist
right? or do I have to make a directory on the image first?COPY will make paths as needed, but you need to copy the dist dir from the node layer
okay, and that will stay when you enter the go layer. gotcha. I was wondering about that
it wont stay unless you copy it with --from
like this?
you where copying the wrong way
oh okay
and doing
COPY . ./
instead of COPY *.go ./
will add my other packages as well I assume?
do I need to worry about node modules from the node step with that or do they go away when the stage changes to the go oneeverything goes away unless you specifically copy it over
okay cool
and I assume I can just add
COPY --from=assets /app/static ./static
to keep the static dir as well? It's got my fonts and my resume lolupdated
gotcha
don't need to copy from assets because assets didn't change it
that makes sense
oh wait
if that's the case then
COPY . ./
will already take care of that, right?good catch, you are right, updated
you catch on fast
lol I try
let's see if this works then
oh oh oh my bad
did not copy the views folder into the assets phase so that tailwind could read from it
also the go build failed because I didn't organize my imports lol. hodl
OKAYYYYYY 🎉 IT WORKED
are you keeping the dist folder out of github?
I would post a screenshot of the successful build screen if I knew how to take a screenshot on this computer. I guess I should figure out how to do that. But it works!
yep
only because I'm only putting the style.css in it for not
now
I had a lot of internal turmoil about whether or not a font is distributable but I decided to just keep them in static so i could just put dist/ in my .gitignore
always, always make sure to keep the dist or build folders out of github, as whatever would end up in them should be done by the build
if its static like fonts then static is what you want and that goes to github
yeah that's what I was thinking putting fonts in static
glad that was the right call
now I have to rebuild the fonts from source because firefox doesn't like unhinted ttfs
but first im gonna go make some coffee lol
thanks so much for your help!
happy to help!