feat(base): 优化项目基础开发环境

This commit is contained in:
zhaoyingbo 2024-11-22 11:18:43 +00:00
parent 5b1a1e25ef
commit 32edd5fb3c
12 changed files with 130 additions and 82 deletions

4
.env
View File

@ -4,6 +4,8 @@
# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
# prod envrionment needs to be set to production
NODE_ENV=dev
DATABASE_URL="mysql://root:rootpassword@localhost:3306/testdb"
# DATABASE_URL="mysql://root:rootpassword@localhost:3306/testdb"

View File

@ -1 +0,0 @@
NODE_ENV=production

View File

@ -1,5 +1,8 @@
name: CI Monitor CI/CD
on: [push]
name: Egg Gitlab CR CI/CD
on:
push:
branches:
- master
jobs:
build-image:
@ -7,43 +10,29 @@ jobs:
container: catthehacker/ubuntu:act-latest
steps:
- name: Check out repository code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: git.yingbo.im:333
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
registry: micr.cloud.mioffice.cn
username: ${{ secrets.MI_DOCKER_USERNAME }}
password: ${{ secrets.MI_DOCKER_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@v4
uses: docker/build-push-action@v6
with:
file: ./docker/deploy/Dockerfile
push: true
tags: git.yingbo.im:333/zhaoyingbo/ci_monitor:${{ github.sha }}
tags: ${{ env.DOCKER_IMAGE }}:${{ github.sha }}
deploy:
needs: build-image
refresh-image:
runs-on: ubuntu-latest
container: catthehacker/ubuntu:act-latest
steps:
# 检出代码
- name: Check out repository code
uses: actions/checkout@v3
# 使用scp命令将docker-compose.yml文件上传到服务器
- name: Upload docker-compose.yml to server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SERVER_KEY }}
port: ${{ secrets.SERVER_PORT }}
source: docker-compose.yml
target: /home/${{ secrets.SERVER_USERNAME }}/docker/ci_monitor
# 登录服务器执行docker-compose命令
- name: Login to the server and execute docker-compose command
- name: Login to the server and refresh the image
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
@ -51,7 +40,18 @@ jobs:
key: ${{ secrets.SERVER_KEY }}
port: ${{ secrets.SERVER_PORT }}
script: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} git.yingbo.im:333
cd /home/${{ secrets.SERVER_USERNAME }}/docker/ci_monitor
sed -i "s/sha/${{ github.sha }}/g" docker-compose.yml
docker compose up -d --force-recreate --no-deps ci_monitor
docker pull ${{ env.DOCKER_IMAGE }}:${{ github.sha }}
docker push ${{ env.DOCKER_IMAGE }}:${{ github.sha }}
docker rmi $(docker images | grep "${{ env.DOCKER_IMAGE }}" | grep -v "${{ github.sha }}" | awk '{print $3}')
fast-deploy:
runs-on: ubuntu-latest
container: cr.d.xiaomi.net/bigdata-fe/matrix-cli
steps:
- name: Set matrix-cli config
run: matrix-cli config set --access-key ${{ secrets.MATRIX_AK }} --secret-key ${{ secrets.MATRIX_SK }}
- name: Use matrix-cli to deploy
run: matrix-cli deploy --project 462609 --deploy-space egg-gitlab-cr-prev --reason "${{ github.event.head_commit.message }}" --deploy-percentage 1 --tag ${{ github.sha }}
env:
DOCKER_IMAGE: micr.cloud.mioffice.cn/egg/replace_me

38
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,38 @@
variables:
REGISTRY: micr.cloud.mioffice.cn
IMAGE_NAME: micr.cloud.mioffice.cn/egg/replace_me
MATRIX_PROJECT: 462609
MATRIX_SPACE: egg-gitlab-cr-prev
MATRIX_AK: CAKBCYGR0BI2BGMVUF8
stages:
- build
- deploy
default:
tags:
- fe-bj
build:
stage: build
only:
- master
image: docker:latest
services:
- docker:dind
script:
- cp $ENV .env
- docker login -u $MATRIX_AK -p $MATRIX_SK $REGISTRY
- docker build -t $IMAGE_NAME:$CI_COMMIT_SHA -f ./docker/deploy/Dockerfile .
- docker push $IMAGE_NAME:$CI_COMMIT_SHA
- docker logout $REGISTRY
- docker rmi $IMAGE_NAME:$CI_COMMIT_SHA
deploy:
stage: deploy
only:
- master
image: cr.d.xiaomi.net/bigdata-fe/matrix-cli
script:
- matrix-cli config set --access-key $MATRIX_AK --secret-key $MATRIX_SK
- matrix-cli deploy --project $MATRIX_PROJECT --deploy-space $MATRIX_SPACE --reason "$CI_COMMIT_MESSAGE" --deploy-percentage 1 --tag $CI_COMMIT_SHA

BIN
bun.lockb

Binary file not shown.

5
db/prisma/index.ts Normal file
View File

@ -0,0 +1,5 @@
import { PrismaClient } from "@prisma/client"
const prisma = new PrismaClient()
export default prisma

View File

@ -1,19 +0,0 @@
import { PrismaClient } from "@prisma/client"
const prisma = new PrismaClient()
const main = async () => {
const user = await prisma.user.create({
data: {
name: "Alice",
email: "alice@example.com",
},
})
console.log(user)
const users = await prisma.user.findMany()
console.log(users)
}
main().then(() => {
prisma.$disconnect()
})

View File

@ -1,26 +1,35 @@
export default {
languageOptions: {
ecmaVersion: 2021,
sourceType: "module",
},
ignores: ["*.js", "*.cjs", "*.mjs", "/src/Backup/*"],
plugins: ["@typescript-eslint", "simple-import-sort"],
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
],
rules: {
"@typescript-eslint/no-explicit-any": "off",
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
},
overrides: [
{
files: ["**/*.ts", "**/*.tsx"],
languageOptions: {
parser: "@typescript-eslint/parser",
},
import pluginJs from "@eslint/js"
import simpleImportSort from "eslint-plugin-simple-import-sort"
import unusedImports from "eslint-plugin-unused-imports"
import globals from "globals"
import tseslint from "typescript-eslint"
export default [
{ files: ["**/*.{js,mjs,cjs,ts}"] },
{ languageOptions: { globals: globals.browser } },
pluginJs.configs.recommended,
...tseslint.configs.recommended,
{
plugins: {
"simple-import-sort": simpleImportSort,
"unused-imports": unusedImports,
},
],
}
rules: {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-namespace": "off",
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
"no-unused-vars": "off", // Turn off base rule
"unused-imports/no-unused-imports": "error", // Enable plugin rule
"unused-imports/no-unused-vars": [
"warn",
{
vars: "all",
varsIgnorePattern: "^_",
args: "after-used",
argsIgnorePattern: "^_",
},
],
},
},
]

View File

@ -25,3 +25,9 @@ Bun.serve({
},
port: 3000,
})
// // 关闭数据库连接
// process.on("SIGINT", async () => {
// await prisma.$disconnect()
// process.exit(0)
// })

View File

@ -3,8 +3,8 @@
"module": "index.ts",
"type": "module",
"scripts": {
"start": "dotenvx run -f .env.prod -- bun run index.ts",
"dev": "dotenvx run -f .env -- bun run index.ts --watch",
"start": "bun run index.ts",
"dev": "bun run index.ts --watch",
"lint": "oxlint --fix .",
"prepare": "husky",
"prettier": "prettier --write .",
@ -13,7 +13,6 @@
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
"oxlint --fix",
"eslint --fix",
"prettier --write"
]
},
@ -28,10 +27,12 @@
"bun-types": "latest",
"eslint": "^9.2.0",
"eslint-plugin-simple-import-sort": "^12.1.0",
"eslint-plugin-unused-imports": "^4.1.4",
"husky": "^9.1.6",
"lint-staged": "^15.2.10",
"oxlint": "^0.11.1",
"prettier": "^3.3.3"
"prettier": "^3.3.3",
"typescript-eslint": "^8.15.0"
},
"peerDependencies": {
"typescript": "^5.0.0"

7
routes/event/index.ts Normal file
View File

@ -0,0 +1,7 @@
const templateFunc = () => {}
const template = {
templateFunc,
}
export default template