Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow to set sourceRegistry by CNPMCORE_CONFIG_SOURCE_REGISTRY #753

Merged
merged 7 commits into from
Feb 9, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
f
  • Loading branch information
fengmk2 committed Feb 9, 2025
commit bf9dc361c946116f199cfb27bbffb6dee3470ab4
9 changes: 9 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# CNPMCORE_DATABASE_TYPE=MySQL
# CNPMCORE_DATABASE_USER=root
# CNPMCORE_DATABASE_PASSWORD=
# CNPMCORE_DATABASE_NAME=cnpmcore

# CNPMCORE_DATABASE_TYPE=PostgreSQL
# CNPMCORE_DATABASE_USER=postgres
# CNPMCORE_DATABASE_PASSWORD=postgres
# CNPMCORE_DATABASE_NAME=cnpmcore
44 changes: 41 additions & 3 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
@@ -4,14 +4,32 @@

本项目的外部服务依赖有:MySQL 数据库或 PostgreSQL 数据库、Redis 缓存服务。

生成本地开发环境配置文件:

```bash
cp .env.example .env
```

可以通过 Docker 来快速启动本地开发环境:

MySQL 开发环境:

```bash
# 启动本地依赖服务 - MySQL + Redis
docker-compose -f docker-compose.yml up -d

# 关闭本地依赖服务
docker-compose -f docker-compose.yml down
```

PostgreSQL 开发环境:

```bash
# 启动本地依赖服务
docker-compose up -d
# 启动本地依赖服务 - PostgreSQL + Redis
docker-compose -f docker-compose-postgres.yml up -d

# 关闭本地依赖服务
docker-compose down
docker-compose -f docker-compose-postgres.yml down
```

> 手动初始化依赖服务参见[本地开发环境 - MySQL](./docs/setup.md) 或 [本地开发环境 - PostgreSQL](./docs/setup-with-postgresql.md)
@@ -35,6 +53,9 @@ npm run dev

# 访问
curl -v http://127.0.0.1:7001

# cnpmcore_admin 注册管理员
npm login --registry=http://127.0.0.1:7001
```

### 开发运行 - PostgreSQL
@@ -50,6 +71,23 @@ npm run dev:postgresql
curl -v http://127.0.0.1:7001
```

### 登录和测试发包

注册 cnpmcore_admin 管理员

```bash
npm login --registry=http://127.0.0.1:7001

# 验证登录
npm whoami --registry=http://127.0.0.1:7001
```

发包

```bash
npm publish --registry=http://127.0.0.1:7001
```

### 单元测试

MySQL
61 changes: 61 additions & 0 deletions docker-compose-postgres.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: cnpmcore_dev_services_postgres

services:
redis:
env_file:
- .env
image: redis:6-alpine
# command: redis-server --appendonly yes --requirepass cnpm
restart: always
volumes:
- cnpm-redis:/data
ports:
- 6379:6379
networks:
- cnpm-postgres

postgres:
env_file:
- .env
image: postgres:17
restart: always
environment:
POSTGRES_USER: ${POSTGRES_USER:-postgres}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
ports:
- 5432:5432
networks:
- cnpm-postgres
volumes:
- cnpm-postgres:/var/lib/postgresql/data

# https://github.com/khezen/compose-postgres/blob/master/docker-compose.yml
pgadmin:
env_file:
- .env
image: dpage/pgadmin4
restart: always
environment:
POSTGRES_USER: ${POSTGRES_USER:-postgres}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:-pgadmin4@pgadmin.org}
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin}
PGADMIN_CONFIG_SERVER_MODE: 'False'
volumes:
- cnpm-pgadmin:/var/lib/pgadmin
ports:
- 8888:80
networks:
- cnpm-postgres
depends_on:
- postgres

volumes:
cnpm-redis:
cnpm-postgres:
cnpm-pgadmin:

networks:
cnpm-postgres:
name: cnpm-postgres
driver: bridge
52 changes: 19 additions & 33 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
name: cnpmcore_dev_services
name: cnpmcore_dev_services_mysql

services:
redis:
env_file:
- .env
image: redis:6-alpine
# command: redis-server --appendonly yes --requirepass cnpm
restart: always
@@ -10,66 +12,50 @@ services:
ports:
- 6379:6379
networks:
- cnpm
- cnpm-mysql

mysql:
image: mariadb
env_file:
- .env
image: mysql:9
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
restart: always
environment:
MYSQL_ROOT_PASSWORD:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-}
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
# MYSQL_DATABASE: 'cnpmcore_unittest'
MYSQL_USER: user
MYSQL_PASSWORD: pass
MYSQL_DATABASE: ${MYSQL_DATABASE:-cnpmcore}
volumes:
- cnpm-mysql:/var/lib/mysql
# - ./conf.d/mysql/:/etc/mysql/conf.d
# - ./init.d/mysql/:/docker-entrypoint-initdb.d
ports:
- 3306:3306
networks:
- cnpm

postgres:
# env_file:
# - .env
image: postgres:16
ports:
- 5432:5432
networks:
- cnpm
environment:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
# POSTGRES_DB: cnpmcore
# POSTGRES_HOST: localhost
volumes:
- cnpm-postgres:/var/lib/postgresql/data
- cnpm-mysql

# database explorer
phpmyadmin:
env_file:
- .env
image: phpmyadmin
restart: always
environment:
MYSQL_ROOT_PASSWORD:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-}
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
MYSQL_USER: user
MYSQL_PASSWORD: pass
MYSQL_DATABASE: ${MYSQL_DATABASE:-cnpmcore}
# MYSQL_USER: ${MYSQL_USER:-user}
# MYSQL_PASSWORD: ${MYSQL_PASSWORD:-pass}
PMA_HOST: 'mysql'
ports:
- 8080:80
networks:
- cnpm
- cnpm-mysql
depends_on:
- mysql

volumes:
cnpm-redis:
cnpm-mysql:
cnpm-postgres:

networks:
cnpm:
name: cnpm
cnpm-mysql:
name: cnpm-mysql
driver: bridge
2 changes: 2 additions & 0 deletions prepare-database-mysql.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

# set -ex

# read variables from environment
db_host=${CNPMCORE_DATABASE_HOST:-127.0.0.1}
db_port=${CNPMCORE_DATABASE_PORT:-3306}
Loading