美文网首页
CI/CD(semaphoreCI,

CI/CD(semaphoreCI,

作者: 冫改网名 | 来源:发表于2019-02-22 12:42 被阅读0次

目的

达成的目标.png

实现思路

(第一次接触OSS和SemaphoreCI,第一反应是一脸懵逼,。。。。。)先了解SemaphoreCI阿里云OSS是什么吧!

======== 实现脚本(上传文件到哪里,怎么上传,如何控制上传文件的数量大小,) ======== 本地如何运行脚本 ======== CI上部署

实现路径

利用OSS的官方文档查看API并提取目标API(如本地上传文件API)实现脚本。阿里云OSS中包含各种API并支持各种编程语言,可根据需求选择(本次我们使用的是nodejs)。具体代码如下所示:

const OSS = require('ali-oss');
const fs = require('fs');
const child_process = require('child_process');

// 目标文件的相对路径
const remoteResourcePath = './dist';

// OSS配置
const client = new OSS({
  region: 'oss-cn-shenzhen',
  accessKeyId: process.env.ALIYUN_ACCESS_KEY_ID,
  accessKeySecret: process.env.ALIYUN_ACCESS_KEY_SECRET,
  bucket: 'xunlugaokao-school',
});

client.useBucket('xunlugaokao-school');

function adjustUploadFilesOrder(filesArray) {
  // 上传所有文件
  ...
}

function uploadStaticResource(filesArray){
  const version = child_process.execSync("git describe --tag",{shell:true,encoding:"utf8"}).replace(/[\r\n]/g,"");

  filesArray && filesArray.forEach(e => {
    const stat = fs.lstatSync(`./dist/${e}`);
    // e是文件还是文件夹
    if(stat.isDirectory()) {
      // 读static中的文件并依次上传
      const files = fs.readdirSync(`./dist/${e}`);
      files.forEach(item => {
        // 文件加上版本号
        const newName = item.split('.').splice(-1).shift() === 'html'? `${item}`:`${version}/${e}/${item}`;
        client.put(newName,`${remoteResourcePath}/${e}/${item}`);
      })
    }else {
      const newName = e.split('.').splice(-1).shift() === 'html'? `${e}`:`${version}/${e}`;
      client.put(newName,`${remoteResourcePath}/${e}`);
    }
  })
  client.put(`index_${version}.html`,`${remoteResourcePath}/index.html`);
}

function deploy() {
  try {
    const filesArray = fs.readdirSync(remoteResourcePath);
    const files = adjustUploadFilesOrder(filesArray)
    uploadStaticResource(files);
  } catch (err) {
    console.log (err);
  }
}

deploy()

脚本实现后,在本地运行验证脚本成功。。。。

package.json中配置scripts命令,npm run deploy即可运行脚本。
"deploy": "node deploy.js"

进入semaphoreCI官网,semaphoreCI是一个可以帮助你自动运行设置的命令的“小机器人”,添加project后按照文档指示添加你需要运行的命令。

CI部署,参考deploy your application实现运行脚本文件

感想

最开始的时候,是在是不知道怎么下手,完成后回头看呢,...。。。不过如此。。。。。

  1. 遇到问题,首先应该明确目的,明确后一步一步来就没想象中的那么难。
  2. 多读官方文档,仔细,认真。

相关文章

  • CI/CD(semaphoreCI,

    目的 实现思路 (第一次接触OSS和SemaphoreCI,第一反应是一脸懵逼,。。。。。)先了解Semaphor...

  • Prepare

    CI/CD The adoption of CI/CD has changed how developers an...

  • Jenkins 介绍

    Jenkins构建CI/CD CI/CD是什么? CI(Continuous integration,中文意思是持...

  • CI/CD/CD

    CI 持续集成CONTINUOUS INTEGRATION持续集成的环境中,开发人员会频繁提交代码到主干。持续集成...

  • Linux系统环境基于Docker搭建Jenkins实战

    关于CI,CD&CD CI->Continuous Integration:持续集成 CD->Continuous...

  • Auto DevOps之gitlab CI/CD

    @[toc] CI/CD介绍 CI(Continuous Integration)跟CD(Continuous D...

  • CI/CD

    CI / CD 主要指的三个概念,首先CI代表的意思是,continuous integration(持续集成)。...

  • CI/CD

    持续集成CI:代码合并,构建,部署,测试都在一起,不断的执行这个过程,并对结果反馈(针对于代码级别)持续交付CD:...

  • CI/CD

    1.jekins 平台(是一个平台,主要运行的是插件) jenkins以及持续集成简介 开发:编写代码并且进行源码...

  • GitLab CI CD实践 - .gitlab-ci.yml配

    图5.1 GitLab CI/CD流程图 GitLab CI/CD功能基于每个项目根目录下的.gitlab-ci....

网友评论

      本文标题:CI/CD(semaphoreCI,

      本文链接:https://www.haomeiwen.com/subject/wmvxtqtx.html