Skip to content

Commit

Permalink
feat: 增加deploy引导及移除ci调试脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
Aiden-FE authored and Aiden-FE committed Apr 10, 2023
1 parent a4b5028 commit fa412ea
Show file tree
Hide file tree
Showing 13 changed files with 2,422 additions and 32 deletions.
22 changes: 5 additions & 17 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ jobs:
- attach_workspace:
at: .
- run:
# docker tag $DOCKERHUB_USERNAME/compass:latest $DOCKERHUB_USERNAME/compass:${CIRCLE_TAG}
command: |
echo "$DOCKERHUB_ACCESS_TOKEN" | docker login -u $DOCKERHUB_USERNAME --password-stdin
docker build -t $DOCKERHUB_USERNAME/compass:latest . --build-arg COMPASS_JWT_SECRET=$COMPASS_JWT_SECRET --build-arg COMPASS_MYSQL_DATABASE_URL=$COMPASS_MYSQL_DATABASE_URL --build-arg COMPASS_REDIS_HOST=$COMPASS_REDIS_HOST --build-arg COMPASS_REDIS_PORT=$COMPASS_REDIS_PORT --build-arg COMPASS_REDIS_PASSWORD=$COMPASS_REDIS_PASSWORD --build-arg COMPASS_RECAPTCHA_SECRET=${COMPASS_RECAPTCHA_SECRET} --build-arg COMPASS_EMAIL_USER=${COMPASS_EMAIL_USER} --build-arg COMPASS_EMAIL_PASSWORD=${COMPASS_EMAIL_PASSWORD}
docker tag $DOCKERHUB_USERNAME/compass:latest $DOCKERHUB_USERNAME/compass:${CIRCLE_TAG}
docker push --all-tags $DOCKERHUB_USERNAME/compass
# Invoke jobs via workflows
Expand All @@ -77,22 +77,6 @@ workflows:
filters:
branches:
only: /.*/
- build:
requires:
- test
filters:
branches:
only: dev/publish
- publish-docker:
requires:
- build
filters:
branches:
only: dev/publish
context:
- aiden-privacy
- aiden-docker
- aiden-server
build-and-publish-image:
jobs:
- test:
Expand All @@ -117,3 +101,7 @@ workflows:
ignore: /.*/
tags:
only: /^v.*/
context:
- aiden-privacy
- aiden-docker
- aiden-server
22 changes: 11 additions & 11 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
# App config
# 环境信息
NODE_ENV=development
# 敏感数据的加盐密钥
PRIVACY_DATA_SECRET=example
COMPASS_PRIVACY_DATA_SECRET=example
# [可选] Compass 服务监听端口, 默认值: 8080
#COMPASS_LISTEN_PORT=8080
# [可选] 单IP单端口API默认全局限流的时长区间,单位秒, 默认值: 60
#COMPASS_THROTTLER_TTL=60
# [可选] 默认全局在限流时间区间内最多可以调用几次, 默认值: 20
#COMPASS_THROTTLER_LIMIT=20

# MySQL config
# mysql 连接地址
COMPASS_MYSQL_DATABASE_URL=mysql://username:password@host:port/database_name
COMPASS_MYSQL_DATABASE_URL=mysql://root:example@localhost:13306/example

# jwt config
# JWT授权密钥
Expand All @@ -16,22 +24,14 @@ COMPASS_JWT_SECRET=example
# redis 地址
COMPASS_REDIS_HOST=localhost
# redis 端口
COMPASS_REDIS_PORT=6379
COMPASS_REDIS_PORT=16379
# redis连接密码
COMPASS_REDIS_PASSWORD=example

# Google recaptcha 人机验证
## [可选] recaptcha 签发的通信密钥, 如果不提供则人机校验相关接口均会异常,需要调整为您业务所需的验证逻辑
COMPASS_RECAPTCHA_SECRET=example

# App config
# [可选] Compass 服务监听端口, 默认值: 8080
#COMPASS_LISTEN_PORT=8080
# [可选] 单IP单端口API默认全局限流的时长区间,单位秒, 默认值: 60
#COMPASS_THROTTLER_TTL=60
# [可选] 默认全局在限流时间区间内最多可以调用几次, 默认值: 20
#COMPASS_THROTTLER_LIMIT=20

# Email config
# [可选] 邮箱用户名,不提供则不启动email服务
#COMPASS_EMAIL_USER=example
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# compass-service 2.0

## 项目启动
> 首次启动请先参考下方 Prisma 部分同步数据库架构
> 首次启动请先参考下方 [Prisma ORM 管理](./README.md#Prisma ORM 管理) 部分同步数据库架构
>
> 如果您不具备可用的mysql,redis或是可选的postgres环境,可以参考[部署基础环境](./deploy/README.md#部署基础环境)一键启动基础环境
`npm install` 安装依赖

Expand Down Expand Up @@ -170,7 +172,7 @@ export class ExampleController {
}
```

### Prisma ORM 支持
### Prisma ORM 管理
> 请确保.env文件配置已经就绪
#### 如果你是新数据库
Expand Down
39 changes: 39 additions & 0 deletions deploy/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# MySQL 配置
# mysql镜像版本
MYSQL_IMAGE_VERSION=8.0.32
# mysql root用户密码
MYSQL_ROOT_PASSWORD=example
# mysql 配置挂载卷
MYSQL_VOLUMES_CONF_DIR=./mysql/config
# mysql 数据挂载卷
MYSQL_VOLUMES_DATA_DIR=./mysql/data
# mysql 初始数据库的名称
MYSQL_DATABASE=example
# mysql 宿主端口
MYSQL_PORT=13306

# Redis 配置
# redis镜像版本
REDIS_IMAGE_VERSION=7.0.10-alpine
# redis配置文件
REDIS_VOLUMES_CONF=./redis/config/redis.conf
# redis持久化挂载卷
REDIS_VOLUMES_DATA_DIR=./redis/data
# redis 连接密码
REDIS_PASSWORD=example
# redis 宿主端口
REDIS_PORT=16379

# Postgres 配置
# postgres 镜像版本
POSTGRES_IMAGE_VERSION=15.2-alpine
# postgres 初始用户
POSTGRES_USER=example
# postgres 初始用户的密码
POSTGRES_PASSWORD=example
# postgres 默认数据库
POSTGRES_DB=example
# postgres 端口
POSTGRES_PORT=15432
# postgres 挂载卷
POSTGRES_VOLUMES_DATA_DIR=./postgres/data
3 changes: 3 additions & 0 deletions deploy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
redis/data
mysql/data
postgres/data
15 changes: 15 additions & 0 deletions deploy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Deploy
> 部署环境,作为迅速搭建项目依赖环境使用
## 部署基础环境

当前目录下创建 `.env` 文件并把.env.example文件内容复制进去,按需调整.

`docker compose up -d` 一键启动mysql, redis, postgres容器环境,也可修改`docker-compose.yml`文件,按需启动所需容器

## 数据库数据初始化
> 执行前需要确保已经同步Prisma数据库架构,如未同步请参考 [Prisma ORM](../README.md#Prisma ORM 管理)
根据需要调整当前目录下的 `constants.ts` 文件

项目根目录执行 `npm run seed` 进行数据初始化, 如果有问题需要回滚可执行 `npm run seed:rollback`.
File renamed without changes.
44 changes: 44 additions & 0 deletions deploy/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
version: "3"
networks:
local_network:
driver: bridge
services:
mysql:
image: mysql:${MYSQL_IMAGE_VERSION}
restart: always
networks:
- local_network
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
volumes:
- ${MYSQL_VOLUMES_CONF_DIR}:/etc/mysql/conf.d
- ${MYSQL_VOLUMES_DATA_DIR}:/var/lib/mysql
ports:
- "${MYSQL_PORT}:3306"

redis:
image: redis:${REDIS_IMAGE_VERSION}
restart: always
networks:
- local_network
command: [ "redis-server", "/usr/local/etc/redis/redis.conf", "--requirepass", $REDIS_PASSWORD ]
volumes:
- ${REDIS_VOLUMES_CONF}:/usr/local/etc/redis/redis.conf
- ${REDIS_VOLUMES_DATA_DIR}:/data
ports:
- ${REDIS_PORT}:6379

postgres:
image: postgres:${POSTGRES_IMAGE_VERSION}
restart: always
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
networks:
- local_network
volumes:
- ${POSTGRES_VOLUMES_DATA_DIR}:/var/lib/postgresql/data
ports:
- ${POSTGRES_PORT}:5432
10 changes: 10 additions & 0 deletions deploy/mysql/config/config-file.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[mysqld]
# character-set-server=utf8mb4
# collation-server=utf8mb4_unicode_ci
default-time-zone='+08:00'

[mysql]
# default-character-set = utf8

[client]
# default-character-set = utf8
Loading

0 comments on commit fa412ea

Please sign in to comment.