primocms / primo

Primo is a visual CMS with a built-in code editor, Svelte blocks, and static site generator.
https://primocms.org
MIT License
1.92k stars 474 forks source link

Deploy to Github serverside #329

Closed mateomorris closed 10 months ago

mateomorris commented 11 months ago

The static site generation and deployment to Github happens entirely in the browser, which means the Personal Access Token gets sent to the client. This is probably fine for a personal server, but presents security risks when you have other people on your server, and would expose the token if the server got compromised.

If the files were only generated client-side and then sent to the server to be deployed to Github from there, the PAT wouldn't have to be sent to the browser. There'll just be a small tradeoff in a [probably imperceptibly] longer deployment time since the files have to go up to the server before being deployed to Github, but that should be even less noticable when Primo only generates changed pages.

Relevant: https://github.com/primocms/primo/discussions/307

rallisf1 commented 10 months ago

Seems broken to me

deploy-error

sadly it doesn't show up in vercel logs at all

mateomorris commented 10 months ago

@rallisf1 413 makes me think it's because the site is too big to be uploaded to the vercel function, but the size limit is 4.5 MB so idk. Are even your smaller sites failing to deploy?

mateomorris commented 10 months ago

Actually it does seem to be a size issue, considering the deployed size of a theme without edits is 1.5MB. A huge majority of this is JS, which gets duplicated across every page a Symbol is used, so it should be straightforward to cut the size of the bundle down significantly by building one module file per Symbol [that includes JS] and importing that file into every HTML page that uses it. That would still present a size limit for larger sites but it the size limit would be probably 10x larger. Looking into this now.

rallisf1 commented 10 months ago

@rallisf1 413 makes me think it's because the site is too big to be uploaded to the vercel function, but the size limit is 4.5 MB so idk. Are even your smaller sites failing to deploy?

You're right, It is a size issue. Small sites deploy fine. Damn!

mateomorris commented 10 months ago

@rallisf1 okay go ahead and try the latest version - I refactored so the JS for symbols only gets built once to the /_symbols/ directory and imported individually onto pages containing hydratable instances of them. Looks like it cut down my bundle size by half. But I'm working on a chunking method for larger sites to avoid the problem altogether.

mateomorris commented 10 months ago

Okay shouldn't have issues deploying now, lemme know if you do

rallisf1 commented 10 months ago

I strongly suggest you revert back to client-side deployment and work on this on a separate branch.

Pages that include large external packages (e.g. tiny-slider) fail to build and the symbol files only include undefined

Reach out on discord for more info.

P.S. I've reverted back to #319 . Please stop pushing breaking changes on the master branch. I'm using this on production!

mateomorris commented 10 months ago

@rallisf1 the undefined symbol module is caused by corrupted data in that particular symbol. You can fix it by opening the symbol's content from the sidebar, editing whatever field it's showing as undefined, and saving it. I've added a console.error whenever a symbol has a deployment error as well.