Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e16101865d | |||
| b5b4167c7c | |||
| 5b31a2bfb8 | |||
| 9383696026 | |||
| 5dbdeebe6e | |||
| 0d451b8e03 | |||
| 27c1d0d919 | |||
| d9bbe5bfb8 | |||
| e6d0969a0e | |||
| 020d219d3d | |||
| 7f42afe42b | |||
| ae02099dbd | |||
| 4476f03955 | |||
| abda86256c |
@@ -27,6 +27,11 @@ jobs:
|
||||
REGISTRY_USERNAME="${{ vars.REGISTRY_USERNAME }}"
|
||||
REGISTRY_PASSWORD="${{ vars.REGISTRY_PASSWORD }}"
|
||||
|
||||
if ! command -v docker >/dev/null 2>&1; then
|
||||
apt-get update
|
||||
apt-get install -y docker.io
|
||||
fi
|
||||
|
||||
mkdir -p ~/.ssh
|
||||
echo "${SSH_PRIVATE_KEY}" > ~/.ssh/id_rsa
|
||||
chmod 600 ~/.ssh/id_rsa
|
||||
@@ -47,11 +52,13 @@ jobs:
|
||||
docker build -f deploy/docker/Dockerfile -t "${IMAGE_REPO}:${IMAGE_TAG}" .
|
||||
docker push "${IMAGE_REPO}:${IMAGE_TAG}"
|
||||
|
||||
ssh -p "${DEPLOY_PORT:-22}" "${DEPLOY_USER}@${DEPLOY_HOST}" <<EOF
|
||||
ssh -p "${DEPLOY_PORT:-22}" "${DEPLOY_USER}@${DEPLOY_HOST}" "mkdir -p \"${DEPLOY_PATH}/deploy/docker\""
|
||||
scp -P "${DEPLOY_PORT:-22}" deploy/docker/docker-compose.yml "${DEPLOY_USER}@${DEPLOY_HOST}:${DEPLOY_PATH}/deploy/docker/docker-compose.yml"
|
||||
|
||||
ssh -p "${DEPLOY_PORT:-22}" "${DEPLOY_USER}@${DEPLOY_HOST}" "DEPLOY_PATH='${DEPLOY_PATH}' IMAGE_REPO='${IMAGE_REPO}' IMAGE_TAG='${IMAGE_TAG}' REGISTRY='${REGISTRY}' REGISTRY_USERNAME='${REGISTRY_USERNAME}' REGISTRY_PASSWORD='${REGISTRY_PASSWORD}' bash -se" <<'EOF'
|
||||
set -euo pipefail
|
||||
cd "${DEPLOY_PATH}"
|
||||
|
||||
mkdir -p deploy/docker
|
||||
cat > deploy/docker/.env <<EOT
|
||||
${{ secrets.DEPLOY_DOCKER_ENV }}
|
||||
IMAGE_REPO=${IMAGE_REPO}
|
||||
@@ -62,5 +69,17 @@ jobs:
|
||||
docker compose -f deploy/docker/docker-compose.yml --env-file deploy/docker/.env pull app
|
||||
docker compose -f deploy/docker/docker-compose.yml --env-file deploy/docker/.env up -d app
|
||||
docker compose -f deploy/docker/docker-compose.yml ps
|
||||
curl -fsS "http://127.0.0.1:\${HOST_BIND_PORT:-3000}/api/docs" >/dev/null
|
||||
HEALTH_OK=0
|
||||
for i in $(seq 1 30); do
|
||||
if curl -fsS "http://127.0.0.1:${HOST_BIND_PORT:-3000}/docs" >/dev/null; then
|
||||
HEALTH_OK=1
|
||||
break
|
||||
fi
|
||||
sleep 2
|
||||
done
|
||||
if [ "${HEALTH_OK}" -ne 1 ]; then
|
||||
docker compose -f deploy/docker/docker-compose.yml --env-file deploy/docker/.env logs --tail=200 app || true
|
||||
echo "Health check failed: http://127.0.0.1:${HOST_BIND_PORT:-3000}/docs"
|
||||
exit 1
|
||||
fi
|
||||
EOF
|
||||
|
||||
@@ -5,6 +5,12 @@ RUN npm i -g pm2
|
||||
|
||||
FROM base AS deps
|
||||
COPY package.json yarn.lock ./
|
||||
COPY prisma.config.ts ./
|
||||
COPY prisma ./prisma
|
||||
ENV DATABASE_URL="postgresql://postgres:postgres@127.0.0.1:5432/postgres?schema=public"
|
||||
RUN yarn config set registry https://registry.npmmirror.com \
|
||||
&& npm config set registry https://registry.npmmirror.com \
|
||||
&& yarn config set network-timeout 600000 -g
|
||||
RUN yarn install --frozen-lockfile
|
||||
|
||||
FROM deps AS build
|
||||
@@ -21,6 +27,7 @@ COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY --from=build /app/dist ./dist
|
||||
COPY --from=build /app/prisma ./prisma
|
||||
COPY package.json yarn.lock ./
|
||||
COPY prisma.config.ts ./
|
||||
COPY deploy/docker/app.entrypoint.sh ./app.entrypoint.sh
|
||||
COPY deploy/docker/ecosystem.config.cjs ./ecosystem.config.cjs
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ module.exports = {
|
||||
{
|
||||
name: process.env.APP_NAME,
|
||||
script: 'dist/main.js',
|
||||
node_args: '-r module-alias/register',
|
||||
cwd: '/app',
|
||||
instances: 1,
|
||||
exec_mode: 'fork',
|
||||
|
||||
@@ -3,6 +3,7 @@ module.exports = {
|
||||
{
|
||||
name: 'chat-one-service',
|
||||
script: 'dist/main.js',
|
||||
node_args: '-r module-alias/register',
|
||||
cwd: '/srv/chat-one-service/current',
|
||||
instances: 1,
|
||||
exec_mode: 'fork',
|
||||
|
||||
12
package.json
12
package.json
@@ -9,9 +9,9 @@
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build": "tsc -p tsconfig.json",
|
||||
"start": "node dist/main.js",
|
||||
"start": "node -r module-alias/register dist/main.js",
|
||||
"start:dev": "tsx watch src/main.ts",
|
||||
"start:debug": "node --inspect=0.0.0.0:9229 dist/main.js",
|
||||
"start:debug": "node --inspect=0.0.0.0:9229 -r module-alias/register dist/main.js",
|
||||
"lint": "eslint \"src/**/*.ts\"",
|
||||
"postinstall": "prisma generate"
|
||||
},
|
||||
@@ -34,6 +34,7 @@
|
||||
"dotenv": "^17.4.2",
|
||||
"helmet": "^8.1.0",
|
||||
"ioredis": "^5.10.1",
|
||||
"module-alias": "^2.3.4",
|
||||
"nestjs-pino": "^4.6.1",
|
||||
"passport": "^0.7.0",
|
||||
"passport-jwt": "^4.0.1",
|
||||
@@ -55,5 +56,12 @@
|
||||
"tsx": "^4.21.0",
|
||||
"typescript": "^6.0.2",
|
||||
"typescript-eslint": "^8.59.0"
|
||||
},
|
||||
"_moduleAliases": {
|
||||
"@common": "dist/common",
|
||||
"@config": "dist/config",
|
||||
"@apps": "dist/apps",
|
||||
"@shared": "dist/apps/shared-domain",
|
||||
"@db": "dist/prisma"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import { JwtService } from '@nestjs/jwt';
|
||||
import { randomUUID } from 'crypto';
|
||||
import { SmsService } from '@shared/sms/sms.service';
|
||||
import { RedisService } from '@shared/cache/redis.service';
|
||||
import { PrismaService } from '@prisma/prisma.service';
|
||||
import { PrismaService } from '@db/prisma.service';
|
||||
|
||||
interface AccessPayload {
|
||||
sub: string;
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
import { PrismaService } from '@prisma/prisma.service';
|
||||
import { PrismaService } from '@db/prisma.service';
|
||||
import {
|
||||
ChatMessage,
|
||||
ProviderUsage,
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
"@config/*": ["./src/config/*"],
|
||||
"@apps/*": ["./src/apps/*"],
|
||||
"@shared/*": ["./src/apps/shared-domain/*"],
|
||||
"@prisma/*": ["./src/prisma/*"]
|
||||
"@db/*": ["./src/prisma/*"]
|
||||
},
|
||||
},
|
||||
"include": ["src/**/*", "prisma/**/*"],
|
||||
|
||||
@@ -1861,6 +1861,11 @@ minipass@^7.1.2, minipass@^7.1.3:
|
||||
resolved "https://registry.npmmirror.com/minipass/-/minipass-7.1.3.tgz#79389b4eb1bb2d003a9bba87d492f2bd37bdc65b"
|
||||
integrity sha512-tEBHqDnIoM/1rXME1zgka9g6Q2lcoCkxHLuc7ODJ5BxbP5d4c2Z5cGgtXAku59200Cx7diuHTOYfSBD8n6mm8A==
|
||||
|
||||
module-alias@^2.3.4:
|
||||
version "2.3.4"
|
||||
resolved "https://registry.npmmirror.com/module-alias/-/module-alias-2.3.4.tgz#7c2b0442ba1114744e97288963db637859db4094"
|
||||
integrity sha512-bOclZt8hkpuGgSSoG07PKmvzTizROilUTvLNyrMqvlC9snhs7y7GzjNWAVbISIOlhCP1T14rH1PDAV9iNyBq/w==
|
||||
|
||||
ms@^2.1.1, ms@^2.1.3:
|
||||
version "2.1.3"
|
||||
resolved "https://registry.npmmirror.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2"
|
||||
|
||||
Reference in New Issue
Block a user