diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..3b7e111 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,29 @@ +name: Build Server and Push to Docker Hub +on: + push: + branches: + - master +jobs: + build-and-push: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + with: + version: v0.9.1 + driver-opts: | + image=moby/buildkit:v0.10.6 + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build and Push Image + uses: docker/build-push-action@v3.2.0 + with: + context: ./ + file: ./Dockerfile + push: true + tags: ${{ secrets.DOCKERHUB_USERNAME }}/thenac_paste:latest diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..12bf11b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM algoux/nodebase:16 + +WORKDIR /app/ + +RUN npm install -g pnpm@8 +COPY common /tmp/common +COPY server /tmp/server +RUN cd /tmp/server && pnpm i --frozen-lockfile && npm run build && cp -r /tmp/server/app /app && mv /tmp/server/node_modules /app/node_modules && rm -rf /tmp/{common,server} + +ENV PATH="/app/node_modules/pm2/bin:${PATH}" +CMD npm run deploy:foreground diff --git a/server/package.json b/server/package.json index 2753f39..63883d2 100644 --- a/server/package.json +++ b/server/package.json @@ -10,7 +10,7 @@ "init": "pnpm i --frozen-lockfile", "dev": "cross-env NODE_ENV=development tsnd --respawn --rs --transpile-only -P tsconfig.json --unhandled-rejections=warn --inspect=127.0.0.1:9232 src/index.ts", "dev:job:clear": "cross-env NODE_ENV=development tsnd --respawn --rs --transpile-only -P tsconfig.json --unhandled-rejections=warn --inspect=127.0.0.1:9233 src/jobs/clear.ts", - "build": "rimraf app && tsc -p tsconfig.json && copyfiles -u1 \"src/**/*.{js,lua}\" app", + "build": "rimraf app && tsc -p tsconfig.json && copyfiles -u1 \"src/**/*.{js,lua}\" app/server/src && copyfiles \"{package.json,pnpm-lock.yaml,pm2.config.js}\" app", "start": "cross-env NODE_ENV=production node --unhandled-rejections=warn app/index.js", "deploy": "cross-env NODE_ENV=production pm2 pm2.config.js", "deploy:foreground": "cross-env NODE_ENV=production pm2-runtime pm2.config.js" @@ -50,7 +50,7 @@ "@types/fs-extra": "^9.0.13", "@types/ip": "^1.1.3", "@types/koa-favicon": "^2.0.21", - "@types/lodash": "^4.17.7", + "@types/lodash": "~4.14.202", "@types/node": "^16.18.69", "@types/statuses": "^2.0.4", "copyfiles": "^2.4.1", diff --git a/server/pm2.config.js b/server/pm2.config.js index b87f6b2..330c4e1 100644 --- a/server/pm2.config.js +++ b/server/pm2.config.js @@ -1,7 +1,7 @@ const apps = [ { name: 'paste-server', - script: `./app/index.js`, + script: `./server/src/index.js`, log_date_format: 'YYYY-MM-DD HH:mm:ss', exec_mode: 'cluster', max_memory_restart: '256M', @@ -18,7 +18,7 @@ const apps = [ }, { name: 'paste-job-clear', - script: `./app/jobs/clear.js`, + script: `./server/src/jobs/clear.js`, log_date_format: 'YYYY-MM-DD HH:mm:ss', exec_mode: 'fork', max_memory_restart: '128M', diff --git a/server/pnpm-lock.yaml b/server/pnpm-lock.yaml index 8dc0cab..6ae645f 100644 --- a/server/pnpm-lock.yaml +++ b/server/pnpm-lock.yaml @@ -101,8 +101,8 @@ devDependencies: specifier: ^2.0.21 version: 2.1.3 '@types/lodash': - specifier: ^4.17.7 - version: 4.17.7 + specifier: ~4.14.202 + version: 4.14.202 '@types/node': specifier: ^16.18.69 version: 16.18.69 @@ -642,8 +642,8 @@ packages: '@types/koa-compose': 3.2.8 '@types/node': 16.18.69 - /@types/lodash@4.17.7: - resolution: {integrity: sha512-8wTvZawATi/lsmNu10/j2hk1KEP0IvjubqPE3cu1Xz7xfXXt5oCq3SNUz4fMIP4XGF9Ky+Ue2tBA3hcS7LSBlA==} + /@types/lodash@4.14.202: + resolution: {integrity: sha512-OvlIYQK9tNneDlS0VN54LLd5uiPCBOp7gS5Z0f1mjoJYBrtStzgmJBxONW3U6OZqdtNzZPmn9BS/7WI7BFFcFQ==} /@types/mime@1.3.5: resolution: {integrity: sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w==} @@ -1053,7 +1053,7 @@ packages: '@types/koa': 2.13.12 '@types/koa-bodyparser': 4.3.12 '@types/koa-router': 7.4.8 - '@types/lodash': 4.17.7 + '@types/lodash': 4.14.202 '@types/multer': 1.4.11 async-exit-hook-improved: 2.0.3 bwcx-common: 1.0.1 diff --git a/server/src/modules/piece/piece.controller.ts b/server/src/modules/piece/piece.controller.ts index ef0c7f3..5b9c086 100644 --- a/server/src/modules/piece/piece.controller.ts +++ b/server/src/modules/piece/piece.controller.ts @@ -8,7 +8,7 @@ import { AddPieceReqDTO, AddPieceRespDTO } from './piece.dto'; import MiscUtils from '@server/utils/misc.util'; import QCloudCosUtils from '@server/utils/qcloud-cos.util'; import { RateLimitIp } from '@server/middlewares/rate-limit.middleware'; -import IndexConfig from '../../../../common/configs/index.json'; +import IndexConfig from '@root/common/configs/index.json'; @ApiController() export default class PieceController {