Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pakizheng committed Jan 11, 2024
1 parent 39b7a6d commit 19a5d4c
Show file tree
Hide file tree
Showing 119 changed files with 17,291 additions and 637 deletions.
12 changes: 12 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ module.exports = {
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'airbnb-base',
'airbnb-typescript/base',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
Expand All @@ -17,9 +19,19 @@ module.exports = {
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'max-classes-per-file': 'off',
'class-methods-use-this': 'off',
'import/prefer-default-export': 'off',
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/naming-convention': [
'warn',
{
selector: 'default',
format: ['camelCase', 'snake_case', 'UPPER_CASE', 'PascalCase'],
},
],
},
};
53 changes: 53 additions & 0 deletions .github/workflows/docker_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Build and Deploy Docker Image

on:
push:
branches:
- master # 根据需要调整分支名称

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: zhengpq/im-web:latest
build-args: |
SECRET_ID=${{ secrets.SECRET_ID }}
SECRET_KEY=${{ secrets.SECRET_KEY }}
DB_NAME=${{ secrets.DB_NAME }}
DB_USER_NAME=${{ secrets.DB_USER_NAME }}
DB_PASSWORD=${{ secrets.DB_PASSWORD }}
COS_BUCKET=${{ secrets.COS_BUCKET }}
COS_REGION=${{ secrets.COS_REGION }}
- name: Deploy to remote server
env:
SERVER_PASSWORD: ${{ secrets.SERVER_PASSWORD }}
run: |
sudo apt-get install -y sshpass
sshpass -p "$SERVER_PASSWORD" ssh -o StrictHostKeyChecking=no root@${{ secrets.SERVER_ID }} "
cd /root/dockers
if docker ps -a --format "{{.Names}}" | grep -w "im-web"; then
docker-compose down
fi
echo '${{ secrets.DOCKERHUB_TOKEN }}' | docker login --username zhengpq --password-stdin
docker-compose pull
docker-compose up -d
"
77 changes: 77 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# # syntax=docker/dockerfile:1

# # Comments are provided throughout this file to help you get started.
# # If you need more help, visit the Dockerfile reference guide at
# # https://docs.docker.com/go/dockerfile-reference/

# ARG NODE_VERSION=18.15.0

# FROM node:${NODE_VERSION}-alpine

# # Use production node environment by default.
# ENV NODE_ENV production


# WORKDIR .

# CMD npm install

# # Download dependencies as a separate step to take advantage of Docker's caching.
# # Leverage a cache mount to /root/.npm to speed up subsequent builds.
# # Leverage a bind mounts to package.json and package-lock.json to avoid having to copy them into
# # into this layer.
# # RUN --mount=type=bind,source=package.json,target=package.json \
# # --mount=type=bind,source=package-lock.json,target=package-lock.json \
# # --mount=type=cache,target=/root/.npm \
# # npm ci --omit=dev

# # Run the application as a non-root user.
# USER node

# # Copy the rest of the source files into the image.
# # COPY . .

# # Expose the port that the application listens on.
# EXPOSE 8000

# # Run the application.
# CMD npm run dev

FROM node:18.15.0

EXPOSE 8000

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

# 安装 PM2
RUN npm install pm2 -g

# 复制项目源代码
COPY . .

# 构建项目
RUN npm run build


# 设置环境变量
ARG SECRET_ID
ARG SECRET_KEY
ARG DB_NAME
ARG DB_USER_NAME
ARG DB_PASSWORD
ARG COS_BUCKET
ARG COS_REGION
ENV SECRET_ID=$SECRET_ID
ENV SECRET_KEY=$SECRET_KEY
ENV DB_NAME=$DB_NAME
ENV DB_USER_NAME=$DB_USER_NAME
ENV DB_PASSWORD=$DB_PASSWORD
ENV COS_BUCKET=$COS_BUCKET
ENV COS_REGION=$COS_REGION

#CMD ["node", "main.js"]
CMD ["pm2-runtime", "./ecosystem.config.js", "--env production"]
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

version: "3"

services:
im-web:
image: zhengpq/im-web:latest
container_name: im-web
network_mode: "host"
18 changes: 18 additions & 0 deletions ecosystem.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
apps: [
{
name: 'im',
script: './dist/main.js',
env_production: {
NODE_ENV: 'production',
SECRET_ID: process.env.SECRET_ID,
SECRET_KEY: process.env.SECRET_KEY,
DB_NAME: process.env.DB_NAME,
DB_USER_NAME: process.env.DB_USER_NAME,
DB_PASSWORD: process.env.DB_PASSWORD,
COS_BUCKET: process.env.COS_BUCKET,
COS_REGION: process.env.COS_REGION,
},
},
],
};
8 changes: 6 additions & 2 deletions nest-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true
"deleteOutDir": true,
"assets": [
"images/**/*"
],
"watchAssets": true
}
}
}
Loading

0 comments on commit 19a5d4c

Please sign in to comment.