Skip to content

chore: P3 deploy prod to zcluster #656

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 6 commits into from
May 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
121 changes: 97 additions & 24 deletions .github/workflows/cd.deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ jobs:
env:
CI: true
STAGE: production
SSH_ADDRESS_PRD: ${{ secrets.SSH_ADDRESS_PRD }}
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 All @@ -34,29 +33,103 @@ jobs:
uses: actions/download-artifact@v4
with:
name: build output (ubuntu-latest, 20)
- name: "SSH"
uses: shimataro/ssh-key-action@v2

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

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

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

- name: Build docker image
run: |
docker buildx build -f api.Dockerfile . -t ghcr.io/dzcode-io/api-dot-production-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/api-dot-production-dot-dzcode-dot-io-server:latest
env:
CR_PAT: ${{ secrets.CR_PAT }}

docker-build-push-web-server:
needs: build
runs-on: ubuntu-latest
env:
CI: true
STAGE: production
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:
- 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:
key: ${{ secrets.SSH_KEY }}
known_hosts: ${{ secrets.SSH_KNOWN_HOSTS }}
- name: "Bundle info"
name: build output (ubuntu-latest, 20)

- name: "Generate Bundle info"
run: npm run generate:bundle-info $DEPLOY_VERSION production
- name: "Bundle ./web"
run: npx lerna run bundle:alone --scope @dzcode.io/web

- name: "Sentry Release"
run: npm run generate:sentry-release $DEPLOY_VERSION production ${{ secrets.SENTRY_AUTH_TOKEN }}
- name: "Pre-deploy"
run: npm run pre-deploy
- name: "Deploy"
run: npm run deploy

lighthouse:
needs: bundle-deploy
uses: ./.github/workflows/ci.reusable.lighthouse.yml
with:
serverBaseUrl: "https://lh.dzcode.io"
testBaseUrl: "https://www.dzcode.io"
stage: "production"
secrets:
LH_SERVER_TOKEN_STG: ${{ secrets.LH_SERVER_TOKEN_STG }}
LH_SERVER_TOKEN_PRD: ${{ secrets.LH_SERVER_TOKEN_PRD }}
# todo-zm: remove sentry entirely
run: cd ./web && npm run generate:sentry-release $DEPLOY_VERSION production ${{ secrets.SENTRY_AUTH_TOKEN }}

- name: "Bundle ./web for deployment"
run: |
cd ./web
npm run bundle:alone
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/production-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/production-dot-dzcode-dot-io-server:latest
env:
CR_PAT: ${{ secrets.CR_PAT }}

deploy-to-zcluster:
needs: [docker-build-push-api, docker-build-push-web-server]
runs-on: ubuntu-latest
env:
CI: true

steps:
- name: "Git"
uses: actions/checkout@v4

- name: install zcluster
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 production-dzcode ./docker-compose.production.yml
env:
ADMIN_AUTH_TOKEN: ${{ secrets.ADMIN_AUTH_TOKEN }}
OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
GITHUB_TOKEN: ${{ secrets.API_GITHUB_TOKEN }}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ coverage
.bundle-info.json

# api
api/oracle-cloud/build
api/fetch_cache
api/postgres_db
api/meilisearch_db
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The code for [dzcode.io](https://dzcode.io), a website for the Algerian open-sou
**Apps:**

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

**Packages:**

Expand Down
3 changes: 2 additions & 1 deletion api.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ FROM --platform=linux/amd64 node:22
WORKDIR /usr/src/repo

COPY ./package.json ./package.json
COPY ./package-lock.json ./package-lock.json

# AUTO_GEN
COPY ./api/dist ./api/dist
Expand All @@ -18,7 +19,7 @@ COPY ./packages/utils/dist ./packages/utils/dist
COPY ./packages/utils/package.json ./packages/utils/package.json
# AUTO_GEN_END

RUN npm install --omit=dev --workspace=@dzcode.io/api
RUN npm install --omit=dev --workspace=@dzcode.io/api --frozen-lockfile

ENV PORT=80
WORKDIR /usr/src/repo/api
Expand Down
20 changes: 0 additions & 20 deletions api/oracle-cloud/Dockerfile

This file was deleted.

95 changes: 0 additions & 95 deletions api/oracle-cloud/deploy.ts

This file was deleted.

43 changes: 0 additions & 43 deletions api/oracle-cloud/docker-compose.yml

This file was deleted.

22 changes: 0 additions & 22 deletions api/oracle-cloud/nginx.conf

This file was deleted.

6 changes: 2 additions & 4 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,9 @@
"build:alone:watch": "tspc --watch --preserveWatchOutput",
"build:watch": "lerna run build:alone:watch --scope=@dzcode.io/api --include-dependencies --parallel",
"clean": "lerna run clean:alone --scope=@dzcode.io/api --include-dependencies --stream",
"clean:alone": "del dist coverage fetch_cache oracle-cloud/build",
"clean:alone": "del dist coverage fetch_cache",
"db:generate-migration": "drizzle-kit generate",
"db:server": "docker compose down && docker compose up",
"deploy": "del ./oracle-cloud/build && tsx oracle-cloud/deploy.ts production",
"deploy:stg": "del ./oracle-cloud/build && tsx oracle-cloud/deploy.ts staging",
"generate:bundle-info": "tsx ../packages/tooling/bundle-info.ts",
"generate:sentry-release": "tsx ../packages/tooling/sentry-release.ts api dist",
"lint": "npm run build && npm run lint:alone",
Expand All @@ -78,9 +76,9 @@
"lint:prettier": "prettier --config ../packages/tooling/.prettierrc --ignore-path ../packages/tooling/.prettierignore --log-level warn",
"lint:ts-prune": "tsx ../packages/tooling/setup-ts-prune.ts && ts-prune --error",
"lint:tsc": "tspc --noEmit",
"prepare-dockerfile": "tsx ../packages/tooling/write-dockerfile.ts @dzcode.io/api",
"start": "node dist/app/index.js",
"start:dev": "tsx ../packages/tooling/nodemon.ts \"@dzcode.io/api\" && npm-run-all --parallel start:nodemon db:server",
"prepare-dockerfile": "tsx ../packages/tooling/write-dockerfile.ts @dzcode.io/api",
"start:nodemon": "wait-port localhost:5432 && delay 2 && nodemon dist/app/index.js",
"test": "npm run build && npm run test:alone",
"test:alone": "jest --config ../packages/tooling/jest.config.ts --rootDir .",
Expand Down
Loading
Loading