WIP: feat/python-rewrite #4762

Draft
delliott wants to merge 66 commits from delliott/fsfe-website:feat/python-rewrite into master
Member

Rewrite the whole build process in python, for superior speed and maintenance

Rewrite the whole build process in python, for superior speed and maintenance
delliott force-pushed feat/python-rewrite from f8b17154a1 to 5d00068988 2025-01-20 23:29:41 +00:00 Compare
delliott force-pushed feat/python-rewrite from b05a51078e to af81f98f68 2025-01-26 16:15:32 +00:00 Compare
Author
Member

So, as of now this is, as far as I can tell, a fully functional website build replacement that correctly builds all pages, menus, etc. There may be some small issues somewhere.

The phase1 is significantly faster than before (7s worst case vs 120s worst case).

I have not benchmarked phase 2 yet. I believe there are some optimisations I can make to phase 2, mainly regarding that at the moment the same xhtml|xml files are parsed multiple times with lxml. I should be able to reduce this, but passing lxml objects between funcs can be tricky.

Additionally, I have enhanced the Dockerfile, Docker compose, and introduced entrypoint.sh such that the docker build process no longer interferes with the users repo. It also means that the docker builds properly use caching, so I believe it will be viable to use drone to deploy the website, as we use drone for all other deployments.

Unresolved issues as of now:

How to get files from docker volume to the several serves they need to be on? I think it would be unwise/impossible to allow the container access to the host sshkeys for rsync? easiest thing is probably a cron job on build-server that rsyncs the result from the volume to the targets. I will try and discuss with other syshackers.

While there are some features I want to add I think its best to first move to this enhanced but very similar in behavior to original builder, then add features/ enhancements. This is a significant change, so probably wisest to deploy on the test branch, then on master.

So, as of now this is, as far as I can tell, a fully functional website build replacement that correctly builds all pages, menus, etc. There may be some small issues somewhere. The phase1 is significantly faster than before (7s worst case vs 120s worst case). I have not benchmarked phase 2 yet. I believe there are some optimisations I can make to phase 2, mainly regarding that at the moment the same xhtml|xml files are parsed multiple times with lxml. I should be able to reduce this, but passing lxml objects between funcs can be tricky. Additionally, I have enhanced the Dockerfile, Docker compose, and introduced entrypoint.sh such that the docker build process no longer interferes with the users repo. It also means that the docker builds properly use caching, so I believe it will be viable to use drone to deploy the website, as we use drone for all other deployments. Unresolved issues as of now: How to get files from docker volume to the several serves they need to be on? I think it would be unwise/impossible to allow the container access to the host sshkeys for rsync? easiest thing is probably a cron job on build-server that rsyncs the result from the volume to the targets. I will try and discuss with other syshackers. While there are some features I want to add I think its best to first move to this enhanced but very similar in behavior to original builder, then add features/ enhancements. This is a significant change, so probably wisest to deploy on the test branch, then on master.
delliott force-pushed feat/python-rewrite from d507cff1a2 to d140dafa39 2025-01-26 22:09:46 +00:00 Compare
sofiaritz reviewed 2025-01-27 08:03:15 +00:00
Dockerfile Outdated
@ -1,23 +1,22 @@
FROM debian:bookworm-slim
RUN apt update
FROM fedora:latest
Member

Great work! I've never seen Fedora used in a Dockerfile :)
Why Fedora and not something like Alpine?

Great work! I've never seen Fedora used in a Dockerfile :) Why Fedora and not something like [Alpine](https://hub.docker.com/_/alpine)?
Author
Member

Under alpine the compilation of tdewolff-minify fails with error __vfprintf_chk: symbol not found. It would seem that this can be solved by building the go binary with different compile flags, E.G here, but I did not feel I knew enough about go to investigate it.

And the go version in the latest debian is too old to compile tdewolff-minify.

I get that it seems the problem here is tdewolff-minify, but it does seem to be the best minifier around for speed and supporting multiple filetypes.

At the moment it is only used for the css generated from less. But in the future, probably in a followup PR, I would like to use it to minify all css, js and html files.

Under alpine the compilation of `tdewolff-minify` fails with error `__vfprintf_chk: symbol not found`. It would seem that this can be solved by building the go binary with different compile flags, E.G [here](https://github.com/influxdata/influxdb/issues/5554), but I did not feel I knew enough about go to investigate it. And the go version in the latest debian is too old to compile `tdewolff-minify`. I get that it seems the problem here is `tdewolff-minify`, but it does seem to be the best minifier around for speed and supporting multiple filetypes. At the moment it is only used for the css generated from less. But in the future, probably in a followup PR, I would like to use it to minify all `css`, `js` and `html` files.
Author
Member

Some issues came up with fedora (broken node) and I managed to port it do debian successfully.

Some issues came up with fedora (broken node) and I managed to port it do debian successfully.
delliott marked this conversation as resolved
Author
Member

Things this branch does not do that the original script does

  • I need to fix the staging bit. At the moment it will not actually copy the result from the stage dir to the target dir.

  • It does not do the generated manifest and then the removal of files from the target. So only a full rebuild using --stage will actually remove unused files from the target. I would kinda prefer to avoid implementing this removal logic, as I don't really want to treat the generated website dir as something that is carefully managed, I would prefer that if there are any questions we just full rebuild. But the manifest and removal may be necessary.

Things this branch does not do that the original script does - I need to fix the staging bit. At the moment it will not actually copy the result from the stage dir to the target dir. - It does not do the generated manifest and then the removal of files from the target. So only a full rebuild using `--stage` will actually remove unused files from the target. I would kinda prefer to avoid implementing this removal logic, as I don't really want to treat the generated website dir as something that is carefully managed, I would prefer that if there are any questions we just full rebuild. But the manifest and removal may be necessary.
Author
Member

Some code style to work on:

There are a bunch of pretty common pathlib operation I do, like chaining `with_suffix("") and some stuff that should probably become lib functions.

Some code style to work on: There are a bunch of pretty common pathlib operation I do, like chaining `with_suffix("") and some stuff that should probably become lib functions.
delliott force-pushed feat/python-rewrite from d140dafa39 to 96e24da3d5 2025-01-27 09:34:23 +00:00 Compare
Author
Member

Unresolved issues as of now:

How to get files from docker volume to the several serves they need to be on? I think it would be unwise/impossible to allow the container access to the host sshkeys for rsync? easiest thing is probably a cron job on build-server that rsyncs the result from the volume to the targets. I will try and discuss with other syshackers.

Oh, of course. We can use drone secrets to pass things to the container. So we can pass the secrets keys as env vars, add them to files, load them and deploy.

Or the solution described in this comment seems quite elegant, if less neatly encapsulated in drone. https://stackoverflow.com/a/36648428

> Unresolved issues as of now: > > How to get files from docker volume to the several serves they need to be on? I think it would be unwise/impossible to allow the container access to the host sshkeys for rsync? easiest thing is probably a cron job on build-server that rsyncs the result from the volume to the targets. I will try and discuss with other syshackers. > Oh, of course. We can use drone secrets to pass things to the container. So we can pass the secrets keys as env vars, add them to files, load them and deploy. Or the solution described in this comment seems quite elegant, if less neatly encapsulated in drone. https://stackoverflow.com/a/36648428
Author
Member

Things this branch does not do that the original script does

  • I need to fix the staging bit. At the moment it will not actually copy the result from the stage dir to the target dir.

Fixed in latest commit, it now stages correctly.

> Things this branch does not do that the original script does > > - I need to fix the staging bit. At the moment it will not actually copy the result from the stage dir to the target dir. > Fixed in latest commit, it now stages correctly.
Author
Member

Oh, and another issue: the fsfe status cgi script is no longer works meangingfully.

I can patch the build process and the scig script to show the new logs, but if we are using drone that is kinda just unnecessary? Probably better to remove it.

I also plan to add a buildtime flag from generating the translation status pages, so we should get to replace that stuff.

Oh, and another issue: the fsfe status cgi script is no longer works meangingfully. I can patch the build process and the scig script to show the new logs, but if we are using drone that is kinda just unnecessary? Probably better to remove it. I also plan to add a buildtime flag from generating the translation status pages, so we should get to replace that stuff.
Author
Member

Did some basic benchmarking on my laptop, should not be taken as solid proof of anything, but shows general trends. Both for full rebuilds with no caching. Current bash build script was ran first, so as not to make improvements seem better than real.

Old bash build: 24 mins

New build: 8 mins

Did some basic benchmarking on my laptop, should not be taken as solid proof of anything, but shows general trends. Both for full rebuilds with no caching. Current bash build script was ran first, so as not to make improvements seem better than real. Old bash build: 24 mins New build: 8 mins
Author
Member

Some code style to work on:

There are a bunch of pretty common pathlib operation I do, like chaining `with_suffix("") and some stuff that should probably become lib functions.

The worst offenders for this have now been functionised.

> Some code style to work on: > > There are a bunch of pretty common pathlib operation I do, like chaining `with_suffix("") and some stuff that should probably become lib functions. The worst offenders for this have now been functionised.
delliott force-pushed feat/python-rewrite from 5105374e10 to 89623e5407 2025-01-30 16:39:54 +00:00 Compare
delliott changed title from WIP: feat/python-rewrite to feat/python-rewrite 2025-02-06 13:27:42 +00:00
delliott changed title from feat/python-rewrite to WIP: feat/python-rewrite 2025-02-06 13:28:57 +00:00
delliott force-pushed feat/python-rewrite from 89623e5407 to 4ea6d88597 2025-02-06 13:29:44 +00:00 Compare
delliott force-pushed feat/python-rewrite from 4ea6d88597 to 6e978b576d 2025-02-08 19:41:54 +00:00 Compare
Author
Member

Have now rewritten the translation-status script ad added it to the build process.

New one takes ~30s for all languages, old took ~33 mins for all languages.

So thats a nice improvement.

Have now rewritten the translation-status script ad added it to the build process. New one takes ~30s for all languages, old took ~33 mins for all languages. So thats a nice improvement.
Author
Member

As far as I can tell at this point, the build process works properly using the script locally, using docker and using drone exec to run the pipeline locally.

The next step is to disable the pull based ci for the test branch. I have a pr to do this fsfe-system-hackers/build-server#15. After its merged someone with access will have to redeploy the webserver.

Then merge this pr to the test branch. Alter the config so it aims at the right dirs on the webservers.

This will need sshkeys to access the webservers to deploy the test branch builds too. Load them into ssh as per https://stackoverflow.com/a/72654766

And to sign the drone file, rerun it, etc I need more drone permissions for this repo. I have commit access for the repo, but for some reason Tobias and I cant figure that does not give me drone access.

This branch is stuck waiting on the above requirements.

Pinging @tobiasd as maintainer.

As far as I can tell at this point, the build process works properly using the script locally, using docker and using drone exec to run the pipeline locally. The next step is to disable the pull based ci for the test branch. I have a pr to do this https://git.fsfe.org/fsfe-system-hackers/build-server/pulls/15. After its merged someone with access will have to redeploy the webserver. Then merge this pr to the test branch. Alter the config so it aims at the right dirs on the webservers. This will need sshkeys to access the webservers to deploy the test branch builds too. Load them into ssh as per https://stackoverflow.com/a/72654766 And to sign the drone file, rerun it, etc I need more drone permissions for this repo. I have commit access for the repo, but for some reason Tobias and I cant figure that does not give me drone access. This branch is stuck waiting on the above requirements. Pinging @tobiasd as maintainer.
delliott force-pushed feat/python-rewrite from 24391c7ef5 to 8769c12efb 2025-02-10 10:34:36 +00:00 Compare
delliott force-pushed feat/python-rewrite from 797de26bfd to e6bd3ada8f 2025-02-12 14:19:39 +00:00 Compare
delliott force-pushed feat/python-rewrite from 4115fedf9d to 30d5eaa8b4 2025-02-13 13:20:44 +00:00 Compare
delliott force-pushed feat/python-rewrite from 30d5eaa8b4 to 329e09084d 2025-02-13 13:34:34 +00:00 Compare
delliott force-pushed feat/python-rewrite from 3b6745aa93 to 17bfcf6476 2025-02-14 14:15:12 +00:00 Compare
delliott force-pushed feat/python-rewrite from c1bcf03375 to aa8d373e67 2025-02-15 13:53:48 +00:00 Compare
Author
Member

So, I appreciate that it seems like this is still under heavy development, but frankly I am just grabbing some small optimizations and code style improvements.

So, I appreciate that it seems like this is still under heavy development, but frankly I am just grabbing some small optimizations and code style improvements.
delliott force-pushed feat/python-rewrite from 2d9514e976 to aac039d57d 2025-03-02 19:40:26 +00:00 Compare
delliott force-pushed feat/python-rewrite from aac039d57d to c22c26453c 2025-03-04 16:19:37 +00:00 Compare
delliott added 1 commit 2025-03-05 10:34:41 +00:00
feat: change to only one required key
Some checks reported errors
continuous-integration/drone/pr Build encountered an error
8102298602
delliott added 1 commit 2025-03-05 11:03:27 +00:00
feat: use sshkey with password
All checks were successful
continuous-integration/drone/push Build is passing
c1a3eedb10
delliott added 1 commit 2025-03-05 12:18:48 +00:00
delliott added 1 commit 2025-03-05 16:25:34 +00:00
delliott force-pushed feat/python-rewrite from a593c6daf9 to ccb4d0e5d9 2025-03-07 16:24:55 +00:00 Compare
Author
Member

This is now deployed on the test branch.

This is now deployed on the test branch.
delliott added 5 commits 2025-03-10 12:40:54 +00:00
fix: ssh key loading
Some checks reported errors
continuous-integration/drone/push Build was killed
f2afa05c4e
feat: simplify drone
Some checks failed
continuous-integration/drone/push Build is failing
63321e0263
fix: load sshkey properly
Some checks reported errors
continuous-integration/drone/push Build was killed
86bfaac9de
feat: sign drone
Some checks reported errors
continuous-integration/drone/push Build was killed
f5738ed6f4
delliott force-pushed feat/python-rewrite from 8d75825b82 to 1d3edd02f6 2025-03-10 18:47:06 +00:00 Compare
Author
Member

So, progress report:
Loading of secrets works (I think), and the docker compose file enables ipv6 properly. Ran it locally, so a build from this branch is currently live on test.fsfe.org
But it does not work when ran in drone, I think because the parent docker container, the official docker image, does not enable ipv6.

So we can enable ipv6 by default for all images, in docker daemon conf, but thats not ideal.

So, progress report: Loading of secrets works (I think), and the docker compose file enables ipv6 properly. Ran it locally, so a build from this branch is currently live on test.fsfe.org But it does not work when ran in drone, I think because the parent docker container, the official docker image, does not enable ipv6. So we can enable ipv6 by default for all images, in docker daemon conf, but thats not ideal.
Author
Member

Other problem we have is that the ephemeral docker image used by drone means that layers dont get cached between runs, massively increasing the build time.

I think we maybe use a drone exec pipeline to run with one less layer of docker, I think would fix our ipv6+caching issues.

But less secure, and different to how most of our services work.

Other problem we have is that the ephemeral docker image used by drone means that layers dont get cached between runs, massively increasing the build time. I think we maybe use a drone exec pipeline to run with one less layer of docker, I think would fix our ipv6+caching issues. But less secure, and different to how most of our services work.
delliott force-pushed feat/python-rewrite from 1d3edd02f6 to 88721f94b9 2025-03-12 11:58:08 +00:00 Compare
Author
Member

Ipv6 now not needed, as using ipv4 proxies to the ipv6 servers.

Caching still an issue, final blocker I am aware of.

Ipv6 now not needed, as using ipv4 proxies to the ipv6 servers. Caching still an issue, final blocker I am aware of.
delliott force-pushed feat/python-rewrite from 88721f94b9 to edc241c185 2025-03-12 14:19:40 +00:00 Compare
Author
Member

Caching is now fixed.

The docker in docker container is pruned nightly, so the first build every day will do the whole dep reinstall. But I have optimized that a little, so it's not too slow.

And after that cached docker layers will be used till the next day.

And fixed the build incremental caching, so now it works. There are a few bits that dont seem to cache properly, but I think that hunting them down is a future problem.

Caching is now fixed. The docker in docker container is pruned nightly, so the first build every day will do the whole dep reinstall. But I have optimized that a little, so it's not too slow. And after that cached docker layers will be used till the next day. And fixed the build incremental caching, so now it works. There are a few bits that dont seem to cache properly, but I think that hunting them down is a future problem.
delliott added 1 commit 2025-03-12 14:28:45 +00:00
fix: localmenu urls
All checks were successful
continuous-integration/drone/push Build is passing
5f8f12bf26
delliott added 1 commit 2025-03-12 14:49:41 +00:00
feat: use norris cont2 instead of cont1
All checks were successful
continuous-integration/drone/push Build is passing
35e5515feb
delliott force-pushed feat/python-rewrite from 35e5515feb to 99a93470b0 2025-03-13 15:16:49 +00:00 Compare
Author
Member

So.

This now largely works, and is deployed on test.fsfe.org. There are a few things to iron out.

I will be very busy the next while, so there will likely be no further development for a bit.

So. This now largely works, and is deployed on `test.fsfe.org`. There are a few things to iron out. I will be very busy the next while, so there will likely be no further development for a bit.
Some checks are pending
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr
Required
This pull request is marked as a work in progress.
This branch is out-of-date with the base branch

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u feat/python-rewrite:delliott-feat/python-rewrite
git checkout delliott-feat/python-rewrite
Sign in to join this conversation.
No description provided.