Skip to content

Commit d9220a5

Browse files
authored
Merge pull request #656 from dzcode-io/chore/deploy-prod-to-zcluster
2 parents a874312 + 6d839b2 commit d9220a5

15 files changed

+174
-217
lines changed

.github/workflows/cd.deploy.yml

Lines changed: 97 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ jobs:
1818
env:
1919
CI: true
2020
STAGE: production
21-
SSH_ADDRESS_PRD: ${{ secrets.SSH_ADDRESS_PRD }}
2221
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) }}
2322

2423
steps:
@@ -34,29 +33,103 @@ jobs:
3433
uses: actions/download-artifact@v4
3534
with:
3635
name: build output (ubuntu-latest, 20)
37-
- name: "SSH"
38-
uses: shimataro/ssh-key-action@v2
36+
37+
- name: "Generate Bundle info"
38+
run: npm run generate:bundle-info $DEPLOY_VERSION production
39+
40+
- name: "Sentry Release"
41+
# todo-zm: remove sentry entirely
42+
run: cd ./api && npm run generate:sentry-release $DEPLOY_VERSION production ${{ secrets.SENTRY_AUTH_TOKEN }}
43+
44+
- name: "Write ./api deps into Dockerfile..."
45+
run: |
46+
cd ./api
47+
npm run prepare-dockerfile
48+
49+
- name: Build docker image
50+
run: |
51+
docker buildx build -f api.Dockerfile . -t ghcr.io/dzcode-io/api-dot-production-dot-dzcode-dot-io-server:latest
52+
env:
53+
DOCKER_BUILDKIT: 1
54+
55+
- name: Push docker image
56+
run: |
57+
echo $CR_PAT | docker login ghcr.io -u dzcode-io --password-stdin
58+
docker push ghcr.io/dzcode-io/api-dot-production-dot-dzcode-dot-io-server:latest
59+
env:
60+
CR_PAT: ${{ secrets.CR_PAT }}
61+
62+
docker-build-push-web-server:
63+
needs: build
64+
runs-on: ubuntu-latest
65+
env:
66+
CI: true
67+
STAGE: production
68+
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) }}
69+
70+
steps:
71+
- name: "Git"
72+
uses: actions/checkout@v4
73+
- name: "Nodejs"
74+
uses: actions/setup-node@v4
75+
with:
76+
node-version: "20"
77+
cache: "npm"
78+
- run: npm ci
79+
- name: Download artifact
80+
uses: actions/download-artifact@v4
3981
with:
40-
key: ${{ secrets.SSH_KEY }}
41-
known_hosts: ${{ secrets.SSH_KNOWN_HOSTS }}
42-
- name: "Bundle info"
82+
name: build output (ubuntu-latest, 20)
83+
84+
- name: "Generate Bundle info"
4385
run: npm run generate:bundle-info $DEPLOY_VERSION production
44-
- name: "Bundle ./web"
45-
run: npx lerna run bundle:alone --scope @dzcode.io/web
86+
4687
- name: "Sentry Release"
47-
run: npm run generate:sentry-release $DEPLOY_VERSION production ${{ secrets.SENTRY_AUTH_TOKEN }}
48-
- name: "Pre-deploy"
49-
run: npm run pre-deploy
50-
- name: "Deploy"
51-
run: npm run deploy
52-
53-
lighthouse:
54-
needs: bundle-deploy
55-
uses: ./.github/workflows/ci.reusable.lighthouse.yml
56-
with:
57-
serverBaseUrl: "https://lh.dzcode.io"
58-
testBaseUrl: "https://www.dzcode.io"
59-
stage: "production"
60-
secrets:
61-
LH_SERVER_TOKEN_STG: ${{ secrets.LH_SERVER_TOKEN_STG }}
62-
LH_SERVER_TOKEN_PRD: ${{ secrets.LH_SERVER_TOKEN_PRD }}
88+
# todo-zm: remove sentry entirely
89+
run: cd ./web && npm run generate:sentry-release $DEPLOY_VERSION production ${{ secrets.SENTRY_AUTH_TOKEN }}
90+
91+
- name: "Bundle ./web for deployment"
92+
run: |
93+
cd ./web
94+
npm run bundle:alone
95+
npm run pre-deploy
96+
97+
- name: "Write ./web-server deps into Dockerfile..."
98+
run: |
99+
cd ./web-server
100+
npm run prepare-dockerfile
101+
102+
- name: Build docker image
103+
run: |
104+
docker buildx build -f web-server.Dockerfile . -t ghcr.io/dzcode-io/production-dot-dzcode-dot-io-server:latest
105+
env:
106+
DOCKER_BUILDKIT: 1
107+
108+
- name: Push docker image
109+
run: |
110+
echo $CR_PAT | docker login ghcr.io -u dzcode-io --password-stdin
111+
docker push ghcr.io/dzcode-io/production-dot-dzcode-dot-io-server:latest
112+
env:
113+
CR_PAT: ${{ secrets.CR_PAT }}
114+
115+
deploy-to-zcluster:
116+
needs: [docker-build-push-api, docker-build-push-web-server]
117+
runs-on: ubuntu-latest
118+
env:
119+
CI: true
120+
121+
steps:
122+
- name: "Git"
123+
uses: actions/checkout@v4
124+
125+
- name: install zcluster
126+
run: |
127+
curl -fsSL https://infra.zak-man.com/install.sh | sh
128+
echo "/home/runner/.zcluster/bin" >> $GITHUB_PATH
129+
130+
- name: Deploy to zcluster
131+
run: zcluster deploy -p production-dzcode ./docker-compose.production.yml
132+
env:
133+
ADMIN_AUTH_TOKEN: ${{ secrets.ADMIN_AUTH_TOKEN }}
134+
OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
135+
GITHUB_TOKEN: ${{ secrets.API_GITHUB_TOKEN }}

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ coverage
1616
.bundle-info.json
1717

1818
# api
19-
api/oracle-cloud/build
2019
api/fetch_cache
2120
api/postgres_db
2221
api/meilisearch_db

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ The code for [dzcode.io](https://dzcode.io), a website for the Algerian open-sou
77
**Apps:**
88

99
- [`./web`](./web) ([dzcode.io](https://dzcode.io) or [stage.dzcode.io](https://stage.dzcode.io))
10-
- [`./api`](./api) ([api.dzcode.io](https://api.dzcode.io) or [api-stage.dzcode.io](https://api-stage.dzcode.io))
10+
- [`./api`](./api) ([api.dzcode.io](https://api.dzcode.io) or [api.stage.dzcode.io](https://api.stage.dzcode.io))
1111

1212
**Packages:**
1313

api.Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ FROM --platform=linux/amd64 node:22
33
WORKDIR /usr/src/repo
44

55
COPY ./package.json ./package.json
6+
COPY ./package-lock.json ./package-lock.json
67

78
# AUTO_GEN
89
COPY ./api/dist ./api/dist
@@ -18,7 +19,7 @@ COPY ./packages/utils/dist ./packages/utils/dist
1819
COPY ./packages/utils/package.json ./packages/utils/package.json
1920
# AUTO_GEN_END
2021

21-
RUN npm install --omit=dev [email protected]/api
22+
RUN npm install --omit=dev [email protected]/api --frozen-lockfile
2223

2324
ENV PORT=80
2425
WORKDIR /usr/src/repo/api

api/oracle-cloud/Dockerfile

Lines changed: 0 additions & 20 deletions
This file was deleted.

api/oracle-cloud/deploy.ts

Lines changed: 0 additions & 95 deletions
This file was deleted.

api/oracle-cloud/docker-compose.yml

Lines changed: 0 additions & 43 deletions
This file was deleted.

api/oracle-cloud/nginx.conf

Lines changed: 0 additions & 22 deletions
This file was deleted.

api/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,9 @@
6363
"build:alone:watch": "tspc --watch --preserveWatchOutput",
6464
"build:watch": "lerna run build:alone:watch [email protected]/api --include-dependencies --parallel",
6565
"clean": "lerna run clean:alone [email protected]/api --include-dependencies --stream",
66-
"clean:alone": "del dist coverage fetch_cache oracle-cloud/build",
66+
"clean:alone": "del dist coverage fetch_cache",
6767
"db:generate-migration": "drizzle-kit generate",
6868
"db:server": "docker compose down && docker compose up",
69-
"deploy": "del ./oracle-cloud/build && tsx oracle-cloud/deploy.ts production",
70-
"deploy:stg": "del ./oracle-cloud/build && tsx oracle-cloud/deploy.ts staging",
7169
"generate:bundle-info": "tsx ../packages/tooling/bundle-info.ts",
7270
"generate:sentry-release": "tsx ../packages/tooling/sentry-release.ts api dist",
7371
"lint": "npm run build && npm run lint:alone",
@@ -78,9 +76,9 @@
7876
"lint:prettier": "prettier --config ../packages/tooling/.prettierrc --ignore-path ../packages/tooling/.prettierignore --log-level warn",
7977
"lint:ts-prune": "tsx ../packages/tooling/setup-ts-prune.ts && ts-prune --error",
8078
"lint:tsc": "tspc --noEmit",
79+
"prepare-dockerfile": "tsx ../packages/tooling/write-dockerfile.ts @dzcode.io/api",
8180
"start": "node dist/app/index.js",
8281
"start:dev": "tsx ../packages/tooling/nodemon.ts \"@dzcode.io/api\" && npm-run-all --parallel start:nodemon db:server",
83-
"prepare-dockerfile": "tsx ../packages/tooling/write-dockerfile.ts @dzcode.io/api",
8482
"start:nodemon": "wait-port localhost:5432 && delay 2 && nodemon dist/app/index.js",
8583
"test": "npm run build && npm run test:alone",
8684
"test:alone": "jest --config ../packages/tooling/jest.config.ts --rootDir .",

0 commit comments

Comments
 (0)