travis-ci自动部署

by Amir Off

由Amir Off

如何使用Travis CI设置高级自动部署 (How to set up advanced automatic deployment with Travis CI)

This post is a sequel to my previous Advanced Web Development and Deployment Workflow tutorial. In that tutorial, I showed how I automated my development and deployment workflow. A lot has changed since then due to the rapid development of web tools and technologies — and of course due to my need to improve my workflow as a web developer.

这篇文章是我以前的Advanced Web Development and Deployment Workflow教程的续篇。 在该教程中,我展示了如何自动化开发和部署工作流。 此后,由于Web工具和技术的飞速发展,而且由于我需要改善作为Web开发人员的工作流程,因此发生了许多变化。

我的用例 (My Use Case)

I use a shared hosting service for my personal portfolio website and most of the code is comprised of front-end static assets:

我为个人投资组合网站使用共享托管服务,并且大部分代码由前端静态资产组成:

In the past, I had to run a Gulp.js task to minify, uglify and process all of the source code. It outputs it in a bundle folder along with the index.html file that is ready to be deployed to my hosting service via FTP.

过去 ,我必须运行Gulp.js任务来缩小,丑化和处理所有源代码。 它将它与index.html文件一起输出到捆绑文件夹中,该文件可以通过FTP部署到我的托管服务中。

To automate the process, I used DeployBot. It is a service which allows you to use your existing repositories and deploy to a number of locations like FTP, SFTP, Amazon etc.

为了自动化该过程,我使用了DeployBot 。 它是一项服务,允许您使用现有的存储库并部署到许多位置,例如FTP,SFTP,Amazon等。

Where DeployBot falls short for me is that it only operates like a tunnel that deploys my GitHub repository whenever a change was committed to the repository. This meant that it would require me to upload my bundled code to a separate branch — I called it “deployment” in my case — and it uploaded all the files from that branch to the hosting server via FTP.

DeployBot对我而言不足之处在于,它仅像隧道一样运行,每当将更改提交到GitHub存储库时,它就会部署我的GitHub存储库。 这意味着需要我将捆绑的代码上传到一个单独的分支(在我的情况下称为“部署”),并且它将所有文件从该分支通过FTP上传到托管服务器。

I saw this as a bad practice and a temporary comfort solution. My code on GitHub should a be “source” code and not a bunch of minified and uglified JavaScript and CSS assets and other processed files.

我认为这是一种不好的做法,是一种暂时的舒适解决方案。 我在GitHub上的代码应该是“源代码”,而不是一堆精简JavaScript和CSS资产以及其他处理的文件。

解决方案 (The Solution)

To eliminate the problem I had with DeployBot, I had to ditch it for Travis CI — a continuous integration and delivery service that integrates with GitHub. This way I was able to remove the “deployment” branch that I had in my repository and let Travis CI do all the work of running the Gulp.js tasks for me and further deploy it to my hosting server via FTP. All I had to do was push my source code and Travis CI would do the rest. No more running the Gulp.js tasks manually then checking out the “deployment” branch and pushing it manually to Github.

为了消除DeployBot带来的问题,我不得不放弃Travis CI,它是与GitHub集成的持续集成和交付服务。 这样,我可以删除存储库中的“ deployment”分支,并让Travis CI为我完成所有运行Gulp.js任务的工作,然后通过FTP将其进一步部署到我的托管服务器上。 我所要做的就是推送我的源代码,而Travis CI将完成其余的工作。 不再需要手动运行Gulp.js任务,而是检出“ deployment”分支并将其手动推送到Github。

In the code below I am defining the script file “.travis.yml” that is required for Travis CI to run:

在下面的代码中,我定义了Travis CI运行所需的脚本文件“ .travis.yml ”:

? At line 18 the FTP credentials are extracted from Travis CI

? 第18行,从Travis CI提取FTP凭证

This is a great feature since it allows me to set protected environment variables, the FTP login credentials “$FTP_USER” and “$FTP_PASSWORD” in this case. These variables are encrypted and embedded in the “.travis.yml” script file at runtime. This way I can commit my source code to GitHub without exposing any sensitive data.

这是一个很棒的功能,因为它允许我设置受保护的环境变量,即FTP登录凭据“ $ FTP_USER ” 在这种情况下为“ $ FTP_PASSWORD ”。 这些变量在运行时被加密并嵌入到“ .travis.yml ”脚本文件中。 这样,我可以将源代码提交到GitHub,而不会暴露任何敏感数据。

For them to work I had to use a package called vinyl-ftp. It’s described as,

为了让他们工作,我必须使用一个名为Vinyl-ftp的软件包。 它被描述为

A vinyl adapter for FTP. Supports parallel transfers, conditional transfers, buffered or streamed files, and more. Often performs better than your favorite desktop FTP client.

用于FTP的乙烯基适配器。 支持并行传输,条件传输,缓冲或流式文件等等。 通常,性能要比您喜欢的台式机FTP客户端好。

? At line 9 and 10, the deploy task parses the user and password from the argument options that the Travis CI script runs:

? 在第9和10行,部署任务从Travis CI脚本运行的参数选项中解析用户和密码:

$ gulp deploy --user $FTP_USER --password $FTP_PASSWORD

I had to install another popular npm package called minimist to be able to parse the “user” and “password ” arguments like in the CLI above.

我必须安装另一个名为minimist的流行npm软件包,才能像上面的CLI一样解析“ user”和“ password”自变量。

In addition to installing the previous two npm packages, I had to refactor my Gulp.js tasks file to allow me to run a development build so that I could work on code locally. Continuous production deployment is great, but I still wanted to be able to run my code locally and still have an actual development environment with an actual development build. ?

除了安装前两个npm软件包之外,我还必须重构Gulp.js任务文件,以允许我运行开发版本,以便可以在本地处理代码。 持续的生产部署很棒,但是我仍然希望能够在本地运行我的代码,并且仍然拥有一个具有实际开发版本的实际开发环境。 ?

? At line 2, I check for build arguments then run the build task accordingly.

? 在第2行中,我检查了构建参数,然后相应地运行了构建任务。

If the task detects the “prod” argument like in the Travis CI build script:

如果任务在Travis CI构建脚本中检测到“ prod ”参数,则:

$ gulp build --prod

it skips the development task which is designed for local development builds and runs the production task instead.

它跳过了专为本地开发构建而设计的开发任务,而是运行生产任务。

Executing the build without the “prod” argument will trigger the development task that watches for file changes and reloads the page —very much like any development environment.

在没有“ prod ”参数的情况下执行构建将触发开发任务,该任务监视文件更改并重新加载页面,这与任何开发环境都非常相似。

$ gulp build

结论 (Conclusion)

No more switching between branches and manually copying and pushing bundled assets to GitHub. I can just work locally and push to GitHub and Travis CI takes care of the rest.

无需在分支之间进行切换,也无需手动将捆绑的资产复制并推送到GitHub。 我可以在本地工作,然后推送到GitHub,其余部分由Travis CI负责。

I hope you enjoyed reading! Please follow and share for more tech stuff ??

希望您喜欢阅读! 请关注分享更多的技术资料?

翻译自: https://www.freecodecamp.org/news/advanced-automatic-deployment-with-travis-ci-1da32f7930ce/

travis-ci自动部署

travis-ci自动部署_如何使用Travis CI设置高级自动部署相关推荐

  1. travis-ci自动部署_如何使用Travis CI部署(几乎)零恐惧的Cloud Foundry应用

    travis-ci自动部署 by Robin Bobbitt 罗宾·波比(Robin Bobbitt) 如何使用Travis CI部署(几乎)零恐惧的Cloud Foundry应用 (How to d ...

  2. java project 部署_关于Java Project项目在Linux下部署步骤及注意事项

    出了某几点细小的差别,跟Windows的部署是完全一致的,具备通用性 首先,介绍一下部署步骤: 第一:安装jdk 第二:安装tomcat 第三:配置环境变量:在/etc/profile的最后追加: e ...

  3. wps临时文件不自动删除_电脑:让 Windows 10 系统自动清理临时文件

    不少朋友在系统用久了以后,都会用一些软件来帮忙清理系统中没用的文件,其中包括一些临时文件.无用文件等. 但其实在 Windows 10 中,系统已经内置了自动定期清理临时文件的功能了.你还不知道?跟着 ...

  4. svn增量打包部署_持续集成、持续交付、持续部署(CI/CD)简介

    >>>推荐阅读<<< 1.性能测试学习笔记-场景设计 2.性能测试的重要意义 3.性能分析流程及方法 4.应用系统性能调优之性能分析 概述: 软件开发周期中需要一些 ...

  5. gitlab ci 自动化部署_前端gitLab加jenkins自动化构建和部署,以及服务器常用的linux命令行操作,免密登录...

    常用的linux命令行操作 将项目部署到服务器后,需要查看文件是否已经部署成功,已经对文件进行增删改查操作,就需要用到命令行操作,常用操作如下: ll 罗列出当前文件或目录的详细信息,含有时间.读写权 ...

  6. scrapyd部署_如何通过 Scrapyd + ScrapydWeb 简单高效地部署和监控分布式爬虫项目

    来自 Scrapy 官方账号的推荐 需求分析 初级用户: 只有一台开发主机 能够通过 Scrapyd-client 打包和部署 Scrapy 爬虫项目,以及通过 Scrapyd JSON API 来控 ...

  7. excel自动筛选_在Excel 2007中按选择自动筛选

    excel自动筛选 在Excel 2007中按选择自动筛选 (AutoFilter by Selection in Excel 2007) A couple of weeks ago I descri ...

  8. excel自动筛选_具有范围内条件的Excel自动筛选

    excel自动筛选 In Excel 2003, and earlier versions, an AutoFilter allows only two criteria for each colum ...

  9. vue.js部署_如何将安全Vue.js应用程序部署到AWS

    vue.js部署 本文最初发布在Okta开发人员博客上 . 感谢您支持使SitePoint成为可能的合作伙伴. 编写Vue应用程序直观,直接,快捷. Vue具有较低的进入门槛,基于组件的方法以及诸如热 ...

最新文章

  1. Freemarker整合Spring
  2. 各个大厂APP,如何保护打工人的隐私信息?
  3. C语言 | 快排双向扫描:快速排序双向扫描分区法(源代码)
  4. 【NLP】ACL2020 | 词向量性别偏见
  5. c语言学指针变量,C语言指针变量学习五
  6. Jquery 每天记一点2009-7-2
  7. TypeScript 2019 路线图:更效率,更易用!
  8. C++之继承探究(五):子类对象作父类对象使用
  9. c++如何实现对硬盘的操作_如何使用Python实现自动化点击鼠标和操作键盘?
  10. ajax简单实例代码,分享Ajax创建简单实例代码
  11. qq批量登录软件_20191228分享,雪藏了几天的软件合集分享,心痛一小编,开心一大家。...
  12. android 修改imei源码,Android 修改imei、gps等信息分析
  13. js 如何实现点击一键复制文本
  14. 商贸宝显示连接不到服务器,登录T1商贸宝就提示 服务器链接失败 请重新登录 这个怎么解决?...
  15. python3精简笔记(三)——高级特性
  16. 基于GIS、、geosever插件实现当地旅游资源网格化管理系统的架构
  17. transforms.Compose,transforms.ToTensor(),transforms.Normalize()的含义与原理
  18. 谴责那些没有良知的人
  19. FastDFS单机部署安装
  20. Asynctask源码级解析,深度探索源码之旅

热门文章

  1. linux umount 时出现device is busy 的处理方法--fuser
  2. 【C++面向对象】类的静态成员函数(static member functions)
  3. 首个windowsForm应用项目 1123
  4. S/4HANA生产订单增强WORKORDER_UPDATE方法BEFORE_UPDATE参数分析 1
  5. 在QLabel上点击获得的效果
  6. 【已作废】基于Freeswitch的ASTPP计费系统的安装 (CentOS 7)
  7. docker从容器里面拷文件到宿主机或从宿主机拷文件到docker容器里面
  8. centos 7 firewalld 设置
  9. linux文件目录与管理
  10. Quick cocos2dx学习笔记