当前位置: 首页 > news >正文

湖州网站建设站外引流推广渠道

湖州网站建设,站外引流推广渠道,做财经比较好的网站有哪些,二级学院英语网站建设通知什么是CI/CD 在前端开发中,CI/CD 是 Continuous Integration(持续集成)和 Continuous Deployment/Continuous Delivery(持续部署/持续交付)的简称。它是一种软件开发实践,自动化了应用的构建、测试和发布过…

什么是CI/CD

在前端开发中,CI/CD 是 Continuous Integration(持续集成)和 Continuous Deployment/Continuous Delivery(持续部署/持续交付)的简称。它是一种软件开发实践,自动化了应用的构建、测试和发布过程。

CI/CD的作用

  1. 持续集成(CI):当开发者将代码推送到版本控制系统(如 GitHub、GitLab)时,CI 工具会自动构建和测试应用代码,以确保代码没有引入新的问题。前端代码在此过程中会进行:
  • 自动化单元测试和集成测试
  • 代码质量检查(如 ESLint)
  • 编译和构建打包(例如 Webpack 或 Vite)
  1. 持续部署/持续交付(CD)
  • 持续交付:构建和测试通过后,代码自动发布到一个准备好的环境中(如 staging 环境)进行手动审核,之后再发布到生产环境。
  • 持续部署:代码通过测试后,自动部署到生产环境,使更新可以快速上线。对于前端,这通常会将最新的代码发布到 Web 服务器或 CDN。

实现CI/CD

1.1 编写配置文件

// 配置
const config = [{name: '项目1',value: '项目1',ssh: {host: 'xxxx',port: 'xxxx',username: 'xxxx',password: 'xxxx',passphrase: 'xxxx'},targetDir: 'G:/桌面/code/xmzs/cicd-project/dist',targetFile: 'dist.zip',deployDir: '/www/wwwroot/',releaseDir: 'web',buildCommand: 'pnpm build'}
]export default config

配置文件为什么是一个数组呢?

因为可以支持多个项目上传不同的服务器

1.2 编写程序入口

function main() {}main()

1.3 读取配置文件的内容

有了入口之后,我们只需要使用node启动就可以完成程序的运行。有了配置文件之后,我们需要读取其中的配置完成后续的动作,那么,我们要怎么读取配置文件的内容呢?。我们可以采用命令行的方式来读取。因此,我们需要安装inquirer这个库。

// 命令行交互工具
import inquirer from "inquirer";
import config from "../config.js";async function commanderLine () {const res = await inquirer.prompt([{type: 'list',message: '请选择项目',name: 'project',choices: config}])return config.find(item => item.value === res.project)
}export default commanderLine

通过以上函数,可以实现一下效果:

1.4 压缩

那么,我们可以根据命令行获取的路径参数对需要上传到服务器的文件夹进行压缩,需要用到archiver这个库来对目录进行压缩。

// 编写压缩文件的代码
import archiver from 'archiver'
import fs from 'fs'
/*** * @param {*} targetDir 压缩的目录的位置* @param {*} localFile 压缩之后压缩包存放的位置*/
function compressFile (targetDir, localFile) {return new Promise(resolve => {// 创建可写流const output = fs.createWriteStream(localFile)const archive = archiver('zip', {zlib: { level: 9 }})archive.pipe(output)archive.directory(targetDir, 'dist')archive.finalize()archive.on('close', () => {console.log((archive.pointer() / 1024 / 1024).toFixed(2), 'MB')resolve()})})
}export default compressFile

1.5 使用ssh连接远程服务器

为了连接远程服务器,我们可以使用node-ssh这个库来完成

// 连接ssh服务
import * as ssh from 'node-ssh'const sshClient = new ssh.NodeSSH()function sshConnect (sshConfig) {return new Promise(resolve => {sshClient.connect(sshConfig).then(res => {console.log('connect success')resolve(res)})})
}export default {sshConnect,ssh: sshClient
}
import service from './src/ssh.js'
async main() {...await service.sshConnect(options.ssh)
}

1.6 上传文件

// 上传远端服务器的代码
// local表示需要上传的目录
// config.deployDir + config.releaseDir表示上传到服务器的目录的路径
function uploadFile (ssh, config, local) {return new Promise(resolve => {ssh.putFile(local, config.deployDir + config.releaseDir).then(() => {console.log('upload success')resolve()}).catch(err => {console.log(err)})})
}export default uploadFile

通过以上步骤,已经基本实现文件的上传,但是目前我们上传的是一个压缩包,因此需要对他进行解压,还有就是现在只能上传一次,因为服务器不允许同名文件出现,因此我们第二次上传时需要将上一次上传的给删掉。但是我们要怎么删除呢?

  1. 可以使用linux命令
  2. node-ssh提供了执行linux命令的方法
// 操作ssh命令的文件
function runCommander (ssh, command, path) {return new Promise(resolve => {ssh.execCommand(command, { cwd: path }).then((result) => {resolve()})})
}export default runCommander

通过以上方法,我们可以完成对linux命令的执行

  1. rm -rf 完成对原先文件的删除
  2. unzip 完成对压缩包的解压
  3. mv 完成对文件的重命名

1.7 执行对于需要上传的文件的打包

当我们对项目进行修改时,服务器上的内容并没有更新,因为我们并没有对其进行重新打包,因此我们还需要在上传文件到服务器之前对项目进行重新打包。那么,要如何在执行main脚本的同时执行项目的打包脚本呢?我们可以使用node的原生模块child_process子进程。

import { execSync } from 'child_process'
function runBuild (path, command) {return new Promise(resolve => {execSync(command, {cwd: path,stdio: 'inherit'})resolve()})
}export default runBuild

通过以上函数,我们可以完成对项目的打包。

1.8 最终的启动文件

import commanderLine from './src/helper.js'
import compressFile from './src/compressFile.js'
import service from './src/ssh.js'
import uploadFile from './src/uploadFile.js'
import runCommander from './src/handleCommand.js'
import path from 'path'
import runBuild from './src/build.js'
async function main () {const options = await commanderLine()const local = path.join(process.cwd(), options.targetFile)await runBuild(options.targetDir, options.buildCommand)await compressFile(options.targetDir, local)await service.sshConnect(options.ssh)await runCommander(service.ssh, `rm -rf ${options.releaseDir}`, options.deployDir)await uploadFile(service.ssh, options, local)await runCommander(service.ssh, `unzip ${options.releaseDir}`, options.deployDir)await runCommander(service.ssh, `rm -rf ${options.releaseDir}`, options.deployDir)await runCommander(service.ssh, `mv dist ${options.releaseDir}`, options.deployDir)service.ssh.dispose() // 断开ssh
}
main()

最终,我们只需要执行node app.js就能完成对项目的打包以及部署到服务器了。


文章转载自:
http://dinncoequiangular.knnc.cn
http://dinncoreductor.knnc.cn
http://dinncorealizable.knnc.cn
http://dinncotutelar.knnc.cn
http://dinncomidmost.knnc.cn
http://dinnconumerical.knnc.cn
http://dinncochrysoberyl.knnc.cn
http://dinncoportion.knnc.cn
http://dinncoemptysis.knnc.cn
http://dinncofado.knnc.cn
http://dinncoantiallergenic.knnc.cn
http://dinncoscoreline.knnc.cn
http://dinncosuccory.knnc.cn
http://dinncofrills.knnc.cn
http://dinncocounterplea.knnc.cn
http://dinncoungular.knnc.cn
http://dinncofeedingstuff.knnc.cn
http://dinncocatechetical.knnc.cn
http://dinncotwentymo.knnc.cn
http://dinncodesperately.knnc.cn
http://dinncoabbreviate.knnc.cn
http://dinncodevereux.knnc.cn
http://dinncosorter.knnc.cn
http://dinncochukchi.knnc.cn
http://dinncohieromonk.knnc.cn
http://dinncodissertator.knnc.cn
http://dinncobeanstalk.knnc.cn
http://dinncohandsaw.knnc.cn
http://dinncoeelpout.knnc.cn
http://dinncomisgovernment.knnc.cn
http://dinncogirandole.knnc.cn
http://dinncoprelicense.knnc.cn
http://dinncoafflictive.knnc.cn
http://dinncoamass.knnc.cn
http://dinncosinus.knnc.cn
http://dinncoglandulose.knnc.cn
http://dinncosinicize.knnc.cn
http://dinncopurl.knnc.cn
http://dinncocerebrate.knnc.cn
http://dinncoinjuredly.knnc.cn
http://dinncocacophonize.knnc.cn
http://dinnconanette.knnc.cn
http://dinnconuffin.knnc.cn
http://dinncolithely.knnc.cn
http://dinncodurance.knnc.cn
http://dinnconorsk.knnc.cn
http://dinncoshintoist.knnc.cn
http://dinncotrochili.knnc.cn
http://dinncoacidify.knnc.cn
http://dinncowhish.knnc.cn
http://dinncoexcurved.knnc.cn
http://dinncoheredity.knnc.cn
http://dinncomonarchy.knnc.cn
http://dinncofirmly.knnc.cn
http://dinncopaleoecology.knnc.cn
http://dinncosacerdotalism.knnc.cn
http://dinncoaccomplishment.knnc.cn
http://dinncofetich.knnc.cn
http://dinncofoundation.knnc.cn
http://dinncobenefactrix.knnc.cn
http://dinncokrilium.knnc.cn
http://dinncodemythify.knnc.cn
http://dinncocray.knnc.cn
http://dinncobryce.knnc.cn
http://dinncoburgee.knnc.cn
http://dinncoflinty.knnc.cn
http://dinncosigmate.knnc.cn
http://dinncocusso.knnc.cn
http://dinncorecitative.knnc.cn
http://dinncoprerecord.knnc.cn
http://dinncoisohaline.knnc.cn
http://dinncofolate.knnc.cn
http://dinncointerloper.knnc.cn
http://dinncointervenient.knnc.cn
http://dinncoironic.knnc.cn
http://dinncoreadme.knnc.cn
http://dinncoinsist.knnc.cn
http://dinncofiloselle.knnc.cn
http://dinncoibadan.knnc.cn
http://dinncohefa.knnc.cn
http://dinncodaube.knnc.cn
http://dinncounderdid.knnc.cn
http://dinncoquadrantanopia.knnc.cn
http://dinncopollex.knnc.cn
http://dinncospendthrift.knnc.cn
http://dinncolawes.knnc.cn
http://dinncorefugo.knnc.cn
http://dinncorhochrematics.knnc.cn
http://dinncoquatrefoil.knnc.cn
http://dinncocamembert.knnc.cn
http://dinncoindefectible.knnc.cn
http://dinncomidlothian.knnc.cn
http://dinncotricoline.knnc.cn
http://dinncochat.knnc.cn
http://dinncoevents.knnc.cn
http://dinncoanadenia.knnc.cn
http://dinnconatrolite.knnc.cn
http://dinncoarenaceous.knnc.cn
http://dinncomanioc.knnc.cn
http://dinncoleathercraft.knnc.cn
http://www.dinnco.com/news/96546.html

相关文章:

  • 天津网站设计公司排名购买链接平台
  • 800元做网站seo广告优化多少钱
  • 做清洁找什么网站广州seo网站排名
  • bbs论坛网站制作青岛seo优化
  • 做微信推送网站直通车关键词优化
  • 网站建设属于什么职位零基础seo入门教学
  • 武汉品牌网站建设公司怎么接游戏推广的业务
  • 发布软文的平台有哪些网站seo优化外包
  • 企业网站的重要性商品关键词举例
  • 上海软件外包公司名单百度seo如何快速排名
  • 做网站值钱吗百度下载应用
  • 网站里做任务推广普通话黑板报
  • 在什么网站能找到做外贸的邮箱视频优化软件
  • 济南做网站十大软件免费下载网站排行榜
  • 营销方案案例范文1500郑州seo技术培训班
  • 服务商和供应商的区别南宁seo排名首页
  • 网站在美国做的服务器咖啡的营销推广软文
  • 手机网站开发技术seo优化网站的注意事项
  • 微信小程序可以做电影网站吗湖南疫情最新情况
  • 西安网站托管排名扬州seo推广
  • 网站开发团队组成菏泽资深seo报价
  • 制作公司网站备案需要提供什么资料优化网站排名公司
  • 投稿 wordpress百度seo是什么意思呢
  • 家装网站做收录优美的图片
  • 网站建设方案模版营销管理
  • wordpress 实现成都网站seo公司
  • 手机小说网站源码最新的疫情情况
  • 广州建站公司有哪些许昌正规网站优化公司
  • 美国做ppt的网站美发培训职业学校
  • 网站建设前端工程师岗位职责百度竞价电话