Merge remote-tracking branch 'origin/master'

# Conflicts:
#	package.json
This commit is contained in:
iVampireSP.com 2023-10-24 19:07:05 +08:00
commit 4d84f44ea4
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
7 changed files with 198560 additions and 7 deletions

38
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,38 @@
docker-build:
image: docker:latest
stage: build
before_script:
- docker login "$DOCKER_REGISTRY" -u "$DOCKER_USER" -p "$DOCKER_PASSWORD"
script:
- |
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
tag=""
echo "Running on default branch '$CI_DEFAULT_BRANCH': tag = 'latest'"
else
tag=":$CI_COMMIT_REF_SLUG"
echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag"
fi
- docker build --pull -t "$CI_REGISTRY_IMAGE${tag}" .
- docker push "$CI_REGISTRY_IMAGE${tag}"
# Run this job in a branch where a Dockerfile exists
rules:
- if: $CI_COMMIT_BRANCH
exists:
- Dockerfile
kubectl:
image: bitnami/kubectl
stage: build
tags:
- k8s
before_script:
- kubectl get pods -n foo
script:
- |
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
tag=""
echo "Running on default branch '$CI_DEFAULT_BRANCH': tag = 'latest'"
else
tag=":$CI_COMMIT_REF_SLUG"
echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag"
fi
- echo test

19
Dockerfile Normal file
View File

@ -0,0 +1,19 @@
FROM node:20
LABEL authors="ivamp"
WORKDIR /app
# 忽略 node_modules 目录
COPY src /app/src
COPY package.json /app/package.json
COPY .env.example /app/.env.example
COPY main.ts /app/main.ts
RUN npm config set registry https://registry.npm.taobao.org/
RUN npm install
CMD [ "npm", "run", "migrate" ]
CMD [ "npm", "run", "start" ]
EXPOSE 8080

198482
dist/index.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -3,7 +3,6 @@
"version": "1.0.0",
"main": "main.ts",
"license": "MIT",
"bin": "./main.ts",
"dependencies": {
"express": "^4.18.2",
"express-jwt": "^8.4.1",
@ -17,7 +16,6 @@
"@types/express": "^4.17.20",
"@types/morgan": "^1.9.7",
"@types/node": "^16.11.10",
"pkg": "^5.8.1",
"ts-node": "^10.9.1",
"typescript": "4.5.2"
},

View File

@ -7,12 +7,9 @@ if (!is_loaded) {
// 检测运行目录下是否有 .env 文件,如果没有,则创建
const envPath = process.cwd()
console.log(envPath)
if (!fs.existsSync(envPath)) {
// 如果没有,则创建
if (!fs.existsSync(envPath)) {
console.log('create .env file at ' + envPath)
fs.writeFileSync(envPath, '')
}
}

View File

@ -4,4 +4,9 @@ typeorm.initialize().then(async () => {
console.log("Datasource initialized.")
}).catch(error => console.log(error))
typeorm.runMigrations().then(async () => {
console.log("Migration run successfully.")
}).catch(error => console.log(error))
export default typeorm.manager

View File

@ -1,6 +1,15 @@
import "reflect-metadata"
import { DataSource } from "typeorm"
import "./env"
import {CreateUsersTable1698126666203} from "../migration/1698126666203-create_users_table";
// const pwd = process.cwd()
//
// const migration_path = pwd + '/src/migration'
//
// // 检测当前目录下有无 migration 文件夹
// if (!fs.existsSync(pwd + '/src/migration')) {
// }
const typeorm = new DataSource({
type: "mysql",
@ -11,8 +20,13 @@ const typeorm = new DataSource({
database: process.env.DB_DATABASE,
synchronize: false,
logging: false,
entities: ["src/entity/*.ts"],
migrations: ["src/migration/*.ts"],
// entities: ["src/entity/*.ts"],
// migrations: ["src/migration/*.ts"],
entities: [
],
migrations: [
CreateUsersTable1698126666203
],
subscribers: [],
})