1、下载code-push-server的git,
git clone https://github.com/lisong/code-push-server.git
然后运行:npm install
2、下载和配置MySql
配置全局命令
1)cd /usr/local/bin/
2)mysql —version,是否有版本信息出来
如果没法查询版本,可能需要把mysql设置全局:
sudo ln -fs /usr/local/mysql/bin/mysql mysql
初始化mysql数据库,在code-push-server的目录下运行:
./bin/db init --dbhost 127.0.0.1 --dbuser root --dbpassword你的数据库密码
可能会报:Client does not support authentication protocol requested by server;consider upgrading MySQL client
参考网址:https://blog.csdn.net/u011975949/article/details/83989733
(1)配置MySQL环境变量,在.bash_profile的末尾添加两行
alias mysql=/usr/local/mysql/bin/mysql
alias mysqladmin=/usr/local/mysql/bin/mysqladmin
(2)运行:mysql -u root -p,接着输入你的数据库密码
(3)一次运行这三行命令:
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY‘你的数据库密码’;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的数据库密码';
SELECT plugin FROM mysql.user WHERE User = 'root';
(4)退出:quit
3、修改config/config.js文件
db: {//================ 第一个地方 ============
username: process.env.RDS_USERNAME || "root",
password: process.env.RDS_PASSWORD || "root12345678",
database: process.env.DATA_BASE || "codepush"
},
local: {//================ 第二个地方 ============
// Binary files storage dir, Do not use tmpdir and it's public download dir.
storageDir: "/Users/sunny/Downloads/workspaces/storage",
// Binary files download host address which Code Push Server listen to. the files storage in storageDir.
downloadUrl: "http://127.0.0.1:3000/download",
// public static download spacename.
public: '/download'
},
common: {//================ 第三个地方 ============
// data dir for caclulate diff files. it's optimization.
dataDir: "/Users/sunny/Downloads/workspaces/data",
}
如图:修改username和password为mysql的数据库账号;host用"127.0.0.1" 就行;port默认是3306
如图:
(1)local的storageDir和common的dataDir路径,注意要改成公用的路径,例如Mac要用类似:/Users/sunny/Downloads/workspaces。
(2)common的storageType改为本地搭建的服务器”local“。
(3)tokenSecret的获取可以通过网址:https://www.grc.com/passwords.htm 获取”63 random alpha-numeric characters (a-z, A-Z, 0-9):“生成的值来赋值。
(4)downloadUrl:我用了“127.0.0.1”,到时外网的话需用外网地址来替换“127.0.0.1”。
4、修改docker的 docker-compose.yml
可参考这个网址:https://github.com/lisong/code-push-server/blob/master/docker/README.md
DOWNLOAD_URL: 目前我用了127.0.0.1地址,到时部署到外网的话需要用外网的地址来替换“127.0.0.1”
MYSQL_HOST :用127.0.0.1
MYSQL_PASSWORD:数据库的密码
REDIS_HOST :用127.0.0.1
5、修改docker的config.js
修改的地方类似code-push-server目录下的config.js。
外网地址下载路径修改地方有三处,downloadUrl的修改:
(1)conifg/config.js文件,修改local的downloadUrl: "http://x.x.x.x:3000/download",
(2)docker/docker-compose.yml,修改environment: DOWNLOAD_URL: "http://x.x.x.x:3000/download"
(3)docker/config.js文件,修改local的downloadUrl: "http://x.x.x.x:3000/download",
6、启动服务
运行:./bin/www
查看端口是否被占用:lsof -i tcp:3000
进程常驻可以试试这两种(第一种无效,建议直接用第二种):
(1)npm install pm2 -g
pm2 strat bin/www
(2)nohup ./bin/www &
杀掉进程:
(1)查看Linux当前进程 ps aux | grep node
(2)kill指定进程 kill -9 6913 ,6913是进程id
7、检查code-push-server的登录
启动完成后,打开http://127.0.0.1:3000进行登录,默认密码为admin 123456
命令:code-push login http://127.0.0.1:3000
8、为项目申请code-push key
npm install code-push-cli@2.1.9 ,要code-push的2.1.9,否则3.0.0会报login 404错误
code-push app add DigApp-Android android react-native
code-push app add DigApp-iOS ios react-native
其他按正常流程配置code-push,其中:
android的CodePush 包引进初始化时,换成:
new CodePush(getResources().getString(R.string.reactNativeCodePush_androidDeploymentKey), getApplicationContext(),BuildConfig.DEBUG,"http://192.168.10.197:3000")
ios的info.list 添加key为 CodePushServerURL,value:http://192.168.10.197:3000
开始测试,发布一个更新:
code-push release-react HongShiRN-Android android -m true --des "test 09-26 1:50" -t "1.0.0" -d Staging
速度飞快!!!
以上是参考链接:https://www.jianshu.com/p/417a165ca9d7
网友评论