Skip to content

Commit d98f224

Browse files
authored
Merge pull request #654 from dzcode-io/chore/deploy-to-zcluster
chore: P1 - `stage.dzcode.io` to new more powerful VPS
2 parents f26ff65 + 61537ce commit d98f224

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1244
-1611
lines changed

.github/workflows/cd.deploy.stg.yml

Lines changed: 67 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@ jobs:
1313
node-version: "20"
1414
os: "ubuntu-latest"
1515

16-
bundle-deploy:
16+
deploy-api:
1717
needs: build
1818
runs-on: ubuntu-latest
1919
env:
2020
CI: true
2121
STAGE: staging
2222
SSH_ADDRESS_STG: ${{ secrets.SSH_ADDRESS_STG }}
23-
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
24-
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
2523
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) }}
2624

2725
steps:
@@ -42,24 +40,73 @@ jobs:
4240
with:
4341
key: ${{ secrets.SSH_KEY }}
4442
known_hosts: ${{ secrets.SSH_KNOWN_HOSTS }}
45-
- name: "Bundle info"
43+
- name: "Generate Bundle info"
4644
run: npm run generate:bundle-info $DEPLOY_VERSION stage
47-
- name: "Bundle ./web"
48-
run: npx lerna run bundle:alone --scope @dzcode.io/web
4945
- name: "Sentry Release"
50-
run: npm run generate:sentry-release $DEPLOY_VERSION stage ${{ secrets.SENTRY_AUTH_TOKEN }}
51-
- name: "Pre-deploy"
52-
run: npm run pre-deploy
46+
# todo-zm: remove sentry entirely
47+
run: cd ./api && npm run generate:sentry-release $DEPLOY_VERSION stage ${{ secrets.SENTRY_AUTH_TOKEN }}
5348
- name: "Deploy"
54-
run: npm run deploy:stg
49+
run: cd ./api && npm run deploy:stg
5550

56-
lighthouse:
57-
needs: bundle-deploy
58-
uses: ./.github/workflows/ci.reusable.lighthouse.yml
59-
with:
60-
serverBaseUrl: "https://lh-stage.dzcode.io"
61-
testBaseUrl: "https://stage.dzcode.io"
62-
stage: "staging"
63-
secrets:
64-
LH_SERVER_TOKEN_STG: ${{ secrets.LH_SERVER_TOKEN_STG }}
65-
LH_SERVER_TOKEN_PRD: ${{ secrets.LH_SERVER_TOKEN_PRD }}
51+
deploy-web-server:
52+
needs: build
53+
runs-on: ubuntu-latest
54+
env:
55+
CI: true
56+
STAGE: staging
57+
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) }}
58+
59+
steps:
60+
- name: "Git"
61+
uses: actions/checkout@v4
62+
- name: "Nodejs"
63+
uses: actions/setup-node@v4
64+
with:
65+
node-version: "20"
66+
cache: "npm"
67+
- run: npm ci
68+
- name: Download artifact
69+
uses: actions/download-artifact@v4
70+
with:
71+
name: build output (ubuntu-latest, 20)
72+
73+
- name: "Generate Bundle info"
74+
run: npm run generate:bundle-info $DEPLOY_VERSION stage
75+
76+
- name: "Sentry Release"
77+
# todo-zm: remove sentry entirely
78+
run: cd ./web && npm run generate:sentry-release $DEPLOY_VERSION stage ${{ secrets.SENTRY_AUTH_TOKEN }}
79+
80+
- name: "Bundle ./web for deployment"
81+
run: |
82+
cd ./web
83+
npm run bundle
84+
npm run pre-deploy
85+
86+
- name: "Write ./web-server deps into Dockerfile..."
87+
run: |
88+
cd ./web-server
89+
npm run prepare-dockerfile
90+
91+
- name: Build docker image
92+
run: |
93+
docker buildx build -f web-server.Dockerfile . -t ghcr.io/dzcode-io/stage-dot-dzcode-dot-io-server:latest
94+
env:
95+
DOCKER_BUILDKIT: 1
96+
97+
- name: Push docker image
98+
run: |
99+
echo $CR_PAT | docker login ghcr.io -u dzcode-io --password-stdin
100+
docker push ghcr.io/dzcode-io/stage-dot-dzcode-dot-io-server:latest
101+
env:
102+
CR_PAT: ${{ secrets.CR_PAT }}
103+
104+
- name: install zcluster
105+
run: |
106+
curl -fsSL https://infra.zak-man.com/install.sh | sh
107+
echo "/home/runner/.zcluster/bin" >> $GITHUB_PATH
108+
109+
- name: Deploy to zcluster
110+
run: zcluster deploy -p stage-dzcode ./docker-compose.stage.yml
111+
env:
112+
ADMIN_AUTH_TOKEN: ${{ secrets.ADMIN_AUTH_TOKEN }}

.github/workflows/cd.deploy.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ jobs:
1919
CI: true
2020
STAGE: production
2121
SSH_ADDRESS_PRD: ${{ secrets.SSH_ADDRESS_PRD }}
22-
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
23-
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
2422
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) }}
2523

2624
steps:

.github/workflows/ci.reusable.misc.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,3 @@ jobs:
2727
- run: npx lerna run bundle:alone --scope "@dzcode.io/web"
2828
- run: npx lerna run generate:sitemap --scope "@dzcode.io/web"
2929
- run: npx lerna run generate:htmls --scope "@dzcode.io/web"
30-
- run: npm run --prefix web/cloudflare ts:check

.gitignore

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@ build
2828
src/_e2e-test/downloads
2929
src/_e2e-test/videos
3030
src/_e2e-test/screenshots
31-
cloudflare/public/*
32-
**/cloudflare/public/*
3331
**.lighthouseci
34-
.wrangler
35-
**/cloudflare/wrangler.toml
32+
33+
# web server
34+
web-server/nodemon.json
3635

3736
# data
3837
data/nodemon.json

api/src/digest/cron.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { AIResponseTranslateNameDto, AIResponseTranslateTitleDto } from "./dto";
1919
import { DataProjectEntity } from "src/data/types";
2020
import { RepositoryEntity } from "@dzcode.io/models/dist/repository";
2121
import { BitbucketService } from "src/bitbucket/service";
22+
import { ConfigService } from "src/config/service";
2223

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

101-
const projectsFromDataFolder = await this.dataService.listProjects();
102-
// todo-ZM: make this configurable
103-
// uncomment during development
104-
// const projectsFromDataFolder = (await this.dataService.listProjects()).filter((p) =>
105-
// ["Open-listings", "dzcode.io website", "Mishkal", "System Monitor"].includes(p.name),
106-
// );
107-
// or uncomment to skip the cron
108-
// if (Math.random()) return;
103+
let projectsFromDataFolder = await this.dataService.listProjects();
104+
105+
if (this.configService.env().NODE_ENV === "development") {
106+
this.logger.info({ message: `Running in development mode, filtering projects` });
107+
projectsFromDataFolder = projectsFromDataFolder.filter((p) =>
108+
["Open-listings", "dzcode.io website", "Mishkal", "System Monitor"].includes(p.name),
109+
);
110+
}
109111

110112
const projectTitleSystemPrompt = `user will give you an open-source project name, and you will translate it to Arabic.
111113
it may contain non-translatable parts like acronyms, keep them as is.`;

data/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"description": "data.dzcode.io code",
44
"version": "6.1.0",
55
"author": {
6-
"email": "contact@zakiii.com",
6+
"email": "zakman.dev@gmail.com",
77
"name": "Zakaria Mansouri",
8-
"url": "https://www.zakiii.com"
8+
"url": "https://zak-man.com"
99
},
1010
"dependencies": {
1111
"fs-extra": "^11.2.0",

docker-compose.stage.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
services:
2+
web:
3+
image: ghcr.io/dzcode-io/stage-dot-dzcode-dot-io-server:latest
4+
pull_policy: always
5+
restart: unless-stopped
6+
environment:
7+
- VIRTUAL_HOST=stage.dzcode.io
8+
- LETSENCRYPT_HOST=stage.dzcode.io
9+
- STAGE=staging
10+
networks:
11+
- main-infra-network
12+
13+
networks:
14+
main-infra-network:
15+
external: true

0 commit comments

Comments
 (0)