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

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
927db93
added script and config files to deploy to zcluster
ZibanPirate Apr 26, 2025
59ae348
initiated ./web-server
ZibanPirate Apr 26, 2025
727c349
feat: initialize web server with express and TypeScript
ZibanPirate Apr 26, 2025
bee4195
added dynamic routes and fallback to static content
ZibanPirate Apr 26, 2025
a9c5a45
refactor: update Dockerfile for Node.js setup and remove Nginx config…
ZibanPirate Apr 26, 2025
6a25150
included fullstack config
ZibanPirate Apr 26, 2025
ba81541
generate project sitemap in ./web-server
ZibanPirate Apr 27, 2025
7e67739
auto gen web-server deps into dockerfile copy steps
ZibanPirate Apr 27, 2025
f61b9d5
generate the rest of sitemaps in ./web-server
ZibanPirate Apr 27, 2025
73b6e81
refactor: improve XML escaping in sitemap generation
ZibanPirate Apr 27, 2025
644b109
render project page
ZibanPirate Apr 27, 2025
734fd27
feat: add contribution and contributor page rendering logic
ZibanPirate Apr 27, 2025
55c7f93
removed cloudflare
ZibanPirate Apr 27, 2025
7e95413
removed redundant rsbuild config file
ZibanPirate Apr 27, 2025
8cb7473
modify deploy action to only deploy api using the old way
ZibanPirate Apr 27, 2025
a7a01a7
setup ./web-server CD
ZibanPirate Apr 27, 2025
e9f2994
fix: specify Dockerfile path in build command for consistency
ZibanPirate Apr 27, 2025
a40fb14
fix: update Docker build command to use buildx and correct file path
ZibanPirate Apr 27, 2025
6fabbb9
feat: add zcluster installation and deployment steps to workflow
ZibanPirate Apr 27, 2025
1f619a1
fix: streamline zcluster installation steps in deployment workflow
ZibanPirate Apr 27, 2025
61537ce
fix: update zcluster deployment command to use correct docker-compose…
ZibanPirate Apr 27, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 67 additions & 20 deletions .github/workflows/cd.deploy.stg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ jobs:
node-version: "20"
os: "ubuntu-latest"

bundle-deploy:
deploy-api:
needs: build
runs-on: ubuntu-latest
env:
CI: true
STAGE: staging
SSH_ADDRESS_STG: ${{ secrets.SSH_ADDRESS_STG }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
DEPLOY_VERSION: ${{ github.ref_type == 'tag' && github.ref_name || format('stg-0.0.0-{0}-{1}-{2}', github.ref_name, github.run_number, github.run_attempt) }}

steps:
Expand All @@ -42,24 +40,73 @@ jobs:
with:
key: ${{ secrets.SSH_KEY }}
known_hosts: ${{ secrets.SSH_KNOWN_HOSTS }}
- name: "Bundle info"
- name: "Generate Bundle info"
run: npm run generate:bundle-info $DEPLOY_VERSION stage
- name: "Bundle ./web"
run: npx lerna run bundle:alone --scope @dzcode.io/web
- name: "Sentry Release"
run: npm run generate:sentry-release $DEPLOY_VERSION stage ${{ secrets.SENTRY_AUTH_TOKEN }}
- name: "Pre-deploy"
run: npm run pre-deploy
# todo-zm: remove sentry entirely
run: cd ./api && npm run generate:sentry-release $DEPLOY_VERSION stage ${{ secrets.SENTRY_AUTH_TOKEN }}
- name: "Deploy"
run: npm run deploy:stg
run: cd ./api && npm run deploy:stg

lighthouse:
needs: bundle-deploy
uses: ./.github/workflows/ci.reusable.lighthouse.yml
with:
serverBaseUrl: "https://lh-stage.dzcode.io"
testBaseUrl: "https://stage.dzcode.io"
stage: "staging"
secrets:
LH_SERVER_TOKEN_STG: ${{ secrets.LH_SERVER_TOKEN_STG }}
LH_SERVER_TOKEN_PRD: ${{ secrets.LH_SERVER_TOKEN_PRD }}
deploy-web-server:
needs: build
runs-on: ubuntu-latest
env:
CI: true
STAGE: staging
DEPLOY_VERSION: ${{ github.ref_type == 'tag' && github.ref_name || format('stg-0.0.0-{0}-{1}-{2}', github.ref_name, github.run_number, github.run_attempt) }}

steps:
- name: "Git"
uses: actions/checkout@v4
- name: "Nodejs"
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
- run: npm ci
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: build output (ubuntu-latest, 20)

- name: "Generate Bundle info"
run: npm run generate:bundle-info $DEPLOY_VERSION stage

- name: "Sentry Release"
# todo-zm: remove sentry entirely
run: cd ./web && npm run generate:sentry-release $DEPLOY_VERSION stage ${{ secrets.SENTRY_AUTH_TOKEN }}

- name: "Bundle ./web for deployment"
run: |
cd ./web
npm run bundle
npm run pre-deploy

- name: "Write ./web-server deps into Dockerfile..."
run: |
cd ./web-server
npm run prepare-dockerfile

- name: Build docker image
run: |
docker buildx build -f web-server.Dockerfile . -t ghcr.io/dzcode-io/stage-dot-dzcode-dot-io-server:latest
env:
DOCKER_BUILDKIT: 1

- name: Push docker image
run: |
echo $CR_PAT | docker login ghcr.io -u dzcode-io --password-stdin
docker push ghcr.io/dzcode-io/stage-dot-dzcode-dot-io-server:latest
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?

run: |
curl -fsSL https://infra.zak-man.com/install.sh | sh
echo "/home/runner/.zcluster/bin" >> $GITHUB_PATH

- name: Deploy to zcluster
run: zcluster deploy -p stage-dzcode ./docker-compose.stage.yml
env:
ADMIN_AUTH_TOKEN: ${{ secrets.ADMIN_AUTH_TOKEN }}
2 changes: 0 additions & 2 deletions .github/workflows/cd.deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ jobs:
CI: true
STAGE: production
SSH_ADDRESS_PRD: ${{ secrets.SSH_ADDRESS_PRD }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
DEPLOY_VERSION: ${{ github.ref_type == 'tag' && github.ref_name || format('0.0.0-{0}-{1}-{2}', github.ref_name, github.run_number, github.run_attempt) }}

steps:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/ci.reusable.misc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ jobs:
- run: npx lerna run bundle:alone --scope "@dzcode.io/web"
- run: npx lerna run generate:sitemap --scope "@dzcode.io/web"
- run: npx lerna run generate:htmls --scope "@dzcode.io/web"
- run: npm run --prefix web/cloudflare ts:check
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ build
src/_e2e-test/downloads
src/_e2e-test/videos
src/_e2e-test/screenshots
cloudflare/public/*
**/cloudflare/public/*
**.lighthouseci
.wrangler
**/cloudflare/wrangler.toml

# web server
web-server/nodemon.json

# data
data/nodemon.json
18 changes: 10 additions & 8 deletions api/src/digest/cron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { AIResponseTranslateNameDto, AIResponseTranslateTitleDto } from "./dto";
import { DataProjectEntity } from "src/data/types";
import { RepositoryEntity } from "@dzcode.io/models/dist/repository";
import { BitbucketService } from "src/bitbucket/service";
import { ConfigService } from "src/config/service";

type RepoInfo = Pick<RepositoryEntity, "id" | "name" | "owner" | "provider" | "stars">;
interface RepoContributor {
Expand Down Expand Up @@ -56,6 +57,7 @@ export class DigestCron {
private readonly tagRepository: TagRepository,
private readonly aiService: AIService,
private readonly bitbucketService: BitbucketService,
private readonly configService: ConfigService,
) {
const SentryCronJob = cron.instrumentCron(CronJob, "DigestCron");
new SentryCronJob(
Expand Down Expand Up @@ -98,14 +100,14 @@ export class DigestCron {
const runId = Math.random().toString(36).slice(2);
this.logger.info({ message: `Digest cron started, runId: ${runId}` });

const projectsFromDataFolder = await this.dataService.listProjects();
// todo-ZM: make this configurable
// uncomment during development
// const projectsFromDataFolder = (await this.dataService.listProjects()).filter((p) =>
// ["Open-listings", "dzcode.io website", "Mishkal", "System Monitor"].includes(p.name),
// );
// or uncomment to skip the cron
// if (Math.random()) return;
let projectsFromDataFolder = await this.dataService.listProjects();

if (this.configService.env().NODE_ENV === "development") {
this.logger.info({ message: `Running in development mode, filtering projects` });
projectsFromDataFolder = projectsFromDataFolder.filter((p) =>
["Open-listings", "dzcode.io website", "Mishkal", "System Monitor"].includes(p.name),
);
}

const projectTitleSystemPrompt = `user will give you an open-source project name, and you will translate it to Arabic.
it may contain non-translatable parts like acronyms, keep them as is.`;
Expand Down
4 changes: 2 additions & 2 deletions data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"description": "data.dzcode.io code",
"version": "6.1.0",
"author": {
"email": "contact@zakiii.com",
"email": "zakman.dev@gmail.com",
"name": "Zakaria Mansouri",
"url": "https://www.zakiii.com"
"url": "https://zak-man.com"
},
"dependencies": {
"fs-extra": "^11.2.0",
Expand Down
15 changes: 15 additions & 0 deletions docker-compose.stage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
services:
web:
image: ghcr.io/dzcode-io/stage-dot-dzcode-dot-io-server:latest
pull_policy: always
restart: unless-stopped
environment:
- VIRTUAL_HOST=stage.dzcode.io
- LETSENCRYPT_HOST=stage.dzcode.io
- STAGE=staging
networks:
- main-infra-network

networks:
main-infra-network:
external: true
Loading
Loading