Skip to content

chore: P1 - stage.dzcode.io to new more powerful VPS #654

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

Merged
merged 21 commits into from
Apr 30, 2025

Conversation

ZibanPirate
Copy link
Member

@ZibanPirate ZibanPirate commented Apr 26, 2025

this is part one of the migration:

  • removed ./web/cloudflare workspace
  • created a new workspace ./web-server: express server with Open-Graph functionalities
  • update CD workflows to deploy frontend (./web and ./web-server) to cluster (example run)
  • Removed lighthouse job from CD

Next steps:

End goal

before:

  • two cheap vps to deploy ./api, one for each environement
  • two page apps in cloudflare to deploy ./web
  • two cloudflare workers to handle SEO URLs
  • SSL done through Cloudflare proxy (limited to one subdomain level, so can't do SSL for api.stage.dzcode.io, we had to rename it to api-stage.dzcode.io)

after:
we only ever need one VPS (zcluster; basically a VPS with a Rust server that handles infra stuff, you connect to via zcluster cli app)
Inside it we can define as many containers as we want, so:

  • docker container for ./api (including postgress and meilisearch containers)
  • docker container for ./web (also handles SEO)

a nice bonus, is we already have grafana monitoring setup for this server, so we can even replace/remove the analytics tools we have:

  • sentry on ./api
  • sentry on ./web
  • Google Analytics on ./web
  • lighthouse-ci on ./web

change:

  • Bug fix
  • New feature
  • Other

@github-actions github-actions bot added data Data related changes ( data folder ) web Web related changes ( web folder ) api API related changes ( api folder ) models models package utils utils package tooling tooling package labels Apr 26, 2025
@github-actions github-actions bot added the repo label Apr 27, 2025
@ZibanPirate ZibanPirate changed the title chore: deploy to new more powerful VPS chore: P1 - deploy frontend stage to new more powerful VPS Apr 27, 2025
@ZibanPirate ZibanPirate changed the title chore: P1 - deploy frontend stage to new more powerful VPS chore: P1 - stage.dzcode.io to new more powerful VPS Apr 27, 2025
@ZibanPirate ZibanPirate marked this pull request as ready for review April 27, 2025 12:17
@ZibanPirate ZibanPirate requested a review from a team April 27, 2025 12:18
env:
CR_PAT: ${{ secrets.CR_PAT }}

- name: install zcluster
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you share what is this tool and why it's needed here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • as shown in line 110, it takes a docker-compose file
  • replaces any {{string}} with env variables
  • then send it to this endpoint: https://infra.zak-man.com/project/stage-dzcode/deploy
  • on the infra backend (cx32 VPS from hetzner), an axum server will take that docker compose file
  • save it on a directory as shown in the logs
  • then runs docker compose up as shown here as well

and since in that VPS we have nginx-proxy and acme-companion running, they will auto handle both redirecting traffic from stage.dzcode.io to this docker compose file, as well as handling SSL automatically, all using these two variables

Copy link
Member

@omdxp omdxp Apr 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can still write the Dockerfil this way (or just copy package.json and package-lock.json and install on the server) here but we can add a security step (audit fix) to ensure that these packages are safe to use

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice cargo script ❤️

Copy link
Member

@omdxp omdxp Apr 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a bot commit to CI if this file change (maybe because of adding or deleting local packages)?

It's not necessary for deployment but at least it will be readable to the readers

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i thought about it, i don't see a clean way of doing this:

  • postinstall script would run the script file
  • pre-commit hook
  • CI check for dirty git status

still, this will be an extra check, the actual correctness of dockerfile is guaranteed because we run this script before each deployment, so we may be trying to solve no actual problems here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no problem to solve here except for readability

const port = process.env.PORT || 6060;

app.get("/w/contributions-sitemap.xml", async (req, res) => {
const xml = await generateContributionsSitemap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we cache these generations between cron jobs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, we can have that as improevemnt later, thoe it is not an issue now (don't tell k6s about it 👀)

@github-project-automation github-project-automation bot moved this to Approved in DzCode i/o Apr 30, 2025
@ZibanPirate ZibanPirate merged commit d98f224 into main Apr 30, 2025
55 checks passed
@ZibanPirate ZibanPirate deleted the chore/deploy-to-zcluster branch April 30, 2025 19:25
@github-project-automation github-project-automation bot moved this from Approved to Merged in DzCode i/o Apr 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api API related changes ( api folder ) data Data related changes ( data folder ) models models package repo tooling tooling package utils utils package web Web related changes ( web folder )
Projects
Status: Merged
Development

Successfully merging this pull request may close these issues.

2 participants