未来都会转向云原生吗
I recently found myself in need of a laptop or netbook which I’ve somehow managed to go without for years. I settled on a Samsung Chromebook because the price was right and I’m fond of Google. I knew going into this purchase that the Chromebook was designed without a hard drive and is intended more for casual web surfers rather than power users, but that didn’t stop me. I also knew I wanted to take full advantage of the Chromium OS as an on-the-go platform so installing a LAMP-based development environment or tinkering with the system would just defeat the purpose. I decided it was time for change, time for liberation!
最近,我发现自己需要一台笔记本电脑或上网本,多年来我一直设法做到这一点。 我选择了三星Chromebook,因为价格合适,而且我喜欢Google。 我知道这次购买时,Chromebook的设计没有硬盘驱动器,并且更适合休闲网络冲浪者而不是高级用户使用,但这并没有阻止我。 我也知道我想充分利用Chromium OS作为移动平台的优势,因此安装基于LAMP的开发环境或对系统进行修补只会使目标无法实现。 我决定是时候改变了,解放了!
In this article I’ll share with you how I made the transition from a familiar desktop environment to Cloud-based web development.
在本文中,我将与您分享如何从熟悉的桌面环境过渡到基于云的Web开发。
The Cloud is nothing new. It’s just yet another buzzword for something you’re already quite familiar with – the Internet. The only technical difference between the Cloud (err, the Internet) and the Internet is how you use it.
云并不新鲜。 对于您已经非常熟悉的事物,它只是另一个流行语-互联网。 云(错误,Internet)和Internet之间的唯一技术区别是使用方式。
In the Cloud, all of your tools and information reside “out there” on the Internet rather than on your local machine. This allows you to easily access your files from anywhere and from almost any device with a browser and Internet connection. If your computer crashes or is otherwise damaged, all of your tools and data are safe. In other words, moving to the Cloud is simply a matter of changing where you save your data and how you access it.
在云中,您所有的工具和信息都位于Internet上的“那里”,而不是本地计算机上。 这使您可以从几乎任何具有浏览器和Internet连接的设备,从任何地方,几乎任何位置轻松访问文件。 如果您的计算机崩溃或损坏,则所有工具和数据都是安全的。 换句话说,迁移到云只是改变存储数据的位置和访问方式的问题。
Moving forward, forget that you have a hard drive. Close your eyes and take a moment to clear it from your mind… Breathe… Relax, you can still keep your memory cards and USB sticks; people still need to carry data with them every once in a while.
继续前进,请忘记您有硬盘驱动器。 闭上你的眼睛,花点时间清除它。呼吸……放松,您仍然可以保留存储卡和USB记忆棒; 人们仍然需要不时地随身携带数据。
The first step in making the transition to the Cloud was to find a version control system to manage my code base. If you’ve never used version control before, there’s nothing to it. Version control software lets you:
过渡到云的第一步是找到一个版本控制系统来管理我的代码库。 如果您以前从未使用过版本控制,则没有什么用。 版本控制软件可让您:
Checkout your code 签出您的代码 Track revisions 跟踪修订 Roll back 回滚 Document the development process 记录开发过程 Work with others without overwriting each other’s work 与他人一起工作而不覆盖彼此的工作 And more 和更多It really is a tool that no developer, professional or hobbyist, should be without.
这确实是任何开发人员,专业人士或业余爱好者都不应该缺少的工具。
There are several offerings to choose from, Mercurial and Subversion amongst others, but I chose Git. Git was originally created by Linus Torvalds and is very easy to use. Although I was installing Git on my local desktop for when I’m developing at home in the comfort of my LAMP environment, there are browser-based Git clients so I wouldn’t need to install it again on any other device I happen to be using.
有许多产品可供选择, Mercurial和Subversion等,但我选择了Git。 Git最初是由Linus Torvalds创建的,非常易于使用。 尽管我是为了在舒适的LAMP环境中在家中进行开发而在本地桌面上安装Git,但由于有基于浏览器的Git客户端,因此无需在我碰巧是的其他任何设备上再次安装Git使用。
A detailed explanation of using Git is beyond the scope of the article, but feel free to read the following sources if you’d like to learn more:
使用Git的详细说明超出了本文的范围,但是如果您想了解更多信息,可以随时阅读以下资源:
Introduction to Git, Part 1
Git简介,第1部分
Introduction to Git, Part 2
Git简介,第2部分
Introduction to Git – Round 2 (Advanced)
Git简介–第2轮(高级)
On my Linux desktop, I install Git by executing the following commands:
在我的Linux桌面上,我通过执行以下命令来安装Git:
sudo apt-get install git git config --global user.name "First_name Last_name" git config --global user.email "email@example.com"For Windows or Mac, you can download the appropriate installer. After installing, open the program and execute the last two configuration lines above.
对于Windows或Mac,您可以下载相应的安装程序 。 安装后,打开程序并执行上面的最后两个配置行。
With Git up and running the next step was to find a new home for my code base to reside, preferably at no additional cost. I already pay for hosting complete with a control panel and web-based file manager, but that would be a pain to do any serious editing and it’s a good idea to keep development and production code in separate locations.
随着Git的启动和运行,下一步就是为我的代码库找到一个新的住所,最好不要增加任何费用。 我已经为使用控制面板和基于Web的文件管理器完成托管而支付了费用,但是进行任何认真的编辑都会很痛苦,并且将开发和生产代码保存在单独的位置是个好主意。
Some obvious choices were Dropbox or Google Drive. I also considered GitHub, but as much as I am an advocate of open source I didn’t like the fact that they force the free repositories to be public. I might not want to share a work in progress with the rest of the world.
一些明显的选择是Dropbox或Google Drive 。 我也考虑过GitHub ,但是尽管我是开源的拥护者,但我不喜欢他们强迫免费存储库公开。 我可能不想与世界其他地方分享正在进行的工作。
In the end I chose to go with Bitbucket although any of the aforementioned options will work with Git.
最后,我选择使用Bitbucket,尽管上述任何选项都可以与Git一起使用。
After registering a free account and creating a private repository I was ready to transfer my development code, but first I needed to make sure that files containing sensitive information were ignored. To do this, I created a file named .gitignore in my project directory root with the following contents:
注册一个免费帐户并创建一个私有存储库后,我准备转移我的开发代码,但是首先我需要确保忽略包含敏感信息的文件。 为此,我在项目目录根目录中创建了一个名为.gitignore的文件,其内容如下:
# files to ignore lib/config.phpNext, I created a file lib/example.config.php just for reference. Using the terminal, I then navigated to the code directory on my local machine, initialized it with Git, added all of the files to source control, and committed the code:
接下来,我创建了一个文件lib/example.config.php ,仅供参考。 然后,使用终端,导航到本地计算机上的代码目录,使用Git对其进行初始化,将所有文件添加到源代码管理中,并提交代码:
cd /var/www/my_project git init git add . git commit -m "adding source control to my project"On the dashboard of my new Bitbucket repository, I located the getting started panel and chose “I have code I want to import.”
在新的Bitbucket存储库的仪表板上,找到了入门面板,然后选择“我有要导入的代码”。
The site gave me a few more commands to execute in my terminal, for example:
该站点为我提供了一些在终端中执行的命令,例如:
git remote add origin https://username@bitbucket.org/username/repo_name.git git push -u origin --all # to push up the repo for the first timeNow I had a full copy of my code saved on Bitbucket.
现在,我已将代码的完整副本保存在Bitbucket上。
As someone who started out with Windows’ Notepad I’m not partial to any particular IDE; if it has line numbering and syntax highlighting, I’m more than happy. However, since now I was searching for a good browser based IDE, it would be nice to have a few specific features:
作为开始使用Windows记事本的人,我并不喜欢任何特定的IDE。 如果它具有行号和语法突出显示,我会很高兴。 但是,从现在开始,我一直在寻找基于浏览器的IDE,因此拥有一些特定功能将是一件很不错的事情:
Integration with Git out of the box 开箱即用与Git集成 Built-in server for testing PHP 内置服务器,用于测试PHP The ability to upload files to my production server 能够将文件上传到生产服务器In considering Dropbox and Google Drive, the best IDE I could find was ShiftEdit, but the only way to test server-side code appears to be limited to FTP and that feels so 1990s. I found Codenvy, but as with GitHub they force all of the projects to be public unless you want to pay up.
在考虑Dropbox和Google Drive时,我能找到的最好的IDE是ShiftEdit ,但是测试服务器端代码的唯一方法似乎仅限于FTP,而且这种感觉在1990年代是如此。 我找到了Codenvy ,但是和GitHub一样,除非您想付款,否则它们会强制所有项目公开。
I finally settled on Cloud 9 which allows one free private project, and that’s all I really needed. As an added bonus, once you’re signed up and viewing your dashboard you can tie your account to Bitbucket and it will automatically import your projects.
我最终选择了Cloud 9 ,它允许一个免费的私人项目,而这正是我真正需要的。 作为额外的奖励,一旦您注册并查看仪表板,您便可以将您的帐户绑定到Bitbucket,它将自动导入您的项目。
There are a few options available when creating a new project in Cloud 9. I created a hosted PHP project which gives me access to a virtual machine with a built-in terminal to execute Unix commands so I can edit php.ini, change which version of PHP I’m using, install MySQL, etc.
在Cloud 9中创建新项目时,有几个选项可用。我创建了一个托管PHP项目,该项目使我可以访问带有内置终端的虚拟机以执行Unix命令,从而可以编辑php.ini ,更改版本我正在使用PHP版本,安装MySQL等
For now it appears to meet all of my requirements. I can setup a similar environment to my production server and test run code straight from the IDE, upload code to my production server via FTP, and I can push source code changes back to Bitbucket to make sure my repository is always up to date. Awesome!
目前看来,它可以满足我的所有要求。 我可以为生产服务器设置一个类似的环境,并直接从IDE测试运行代码,通过FTP将代码上传到生产服务器,然后可以将源代码更改推送回Bitbucket以确保我的存储库始终是最新的。 太棒了!
git pull origin # make sure I'm working with the latest version of my code git status # see if any modified files need to be added or committed git push # update repositoryIn this article I shared with you how I installed Git for version control, transferred my code from a local development environment to a remote code repository, and how I can access the repository from a browser-based IDE, all in an effort to make the transition from local to Cloud-based development.
在本文中,我与您分享了如何安装Git进行版本控制,如何将代码从本地开发环境转移到远程代码存储库以及如何从基于浏览器的IDE访问存储库,所有这些都是为了使从本地开发过渡到基于云的开发。
If you’ve transitioned to working in the Cloud, or have experience with any of the tools I mentioned (or other tools I may not have mentioned), please share in the comments!
如果您已经过渡到在云中工作,或者对我提到的任何工具(或我可能没有提及的其他工具)有经验,请在评论中分享!
Image via Fotolia
图片来自Fotolia
翻译自: https://www.sitepoint.com/moving-to-cloud-based-web-development/
未来都会转向云原生吗