配置github的开发环境_大家,请把您的整个开发环境放在Github中

配置github的开发环境

Stop me if this sounds familiar...

如果这听起来很熟悉,请阻止我...

You want to get started with a new framework/runtime. So you install said framework/runtime.

您想开始使用新的框架/运行时。 因此,您安装了所说的框架/运行时。

Then you open up the terminal and....command not found. Heavy sigh.

然后,您打开终端并找不到命令。 沉重的叹息。

You revisit the docs which suggest that you have make some changes to your profile settings. Which you aren't sure how to do so you go to StackOverflow, where you find an answer from "user92902399" which looks like it could be legit (who knows), so you copy and paste that into your terminal and hope to god it doesn't erase your hard drive and email the president your internet history.

您重新访问说明您已对个人资料设置进行一些更改的文档。 您不确定该怎么做,请转到StackOverflow,在其中找到“ user92902399”的答案, 看起来像是合法的(知道的),因此您将其复制并粘贴到终端中并希望自己理解不会删除您的硬盘驱动器,也不会通过电子邮件向总统发送您的互联网历史记录。

Now the runtime command works. But it fails. The error is cryptic.

现在,运行时命令起作用了。 但是失败了。 该错误是神秘的。

Back to Google.

返回Google。

This time there is no clear answer on StackOverflow despite several people having a similar issue. You find a Github issue that looks like it might be related. Somewhere in the middle of a mass of people saying "Thanks this works!" and "This doesn't work at all!" someone uses the word "Python".

这次,尽管有几个人有类似的问题,但是在StackOverflow上没有明确的答案。 您会发现一个可能与它相关的Github问题。 一群人中间的某个地方说:“谢谢!” 和“这根本不起作用!” 有人使用“ Python”一词。

You check your Python version and sure enough, this framework/runtime doesn't support the one you have installed. You are just about to downgrade it when you realize that the last time you even looked in the general direction of your Python install it took you a day to get it working again and you still aren't sure how you did it.

您检查您的Python版本,并且肯定地,此框架/运行时不支持您已安装的框架/运行时。 当您意识到上一次甚至没有看过Python安装的一般方向时,就将其降级。您花了一天的时间才能使它重新运行,并且您仍然不确定如何做。

You know what, this new framework/runtime probably isn't that good. It's definitely not worth all this trouble. Oh look! A blog post about how you should never use ternary statements. What were you working on before? Who cares.

您知道吗,这个新的框架/运行时可能不是很好。 绝对不值得所有这些麻烦。 哦,看! 有关如何永远不要使用三元语句的博客文章。 你以前在做什么? 谁在乎。

A little too close to home? This is what it's like to try and set up a new project, framework or runtime. Every time. This is part of the reason why every developer has at one point in time looked up at someone blankly mid-Cheeto and said, "it works on my machine".

离家太近了吗? 这就是尝试建立新项目,框架或运行时的感觉。 每次。 这是每个开发人员都在某个时候在Cheeto中间空白地抬头看着某人并说“它可以在我的机器上工作”的部分原因。

适用于所有机器 (Works on All Machines)

The root problem is that in order for code to work, there is an entire environment which has to also be configured correctly. This is a hard problem to solve. What we need is a way to isolate the development environment and then ship it with the code so that it works on all machines. And we need to do that without having to ship an entire operating system.

根本问题是,为了使代码正常工作,必须对整个环境进行正确配置。 这是一个很难解决的问题。 我们需要的是一种隔离开发环境,然后将其与代码一起发布的方法,以便它可在所有计算机上使用。 我们需要这样做,而不必交付整个操作系统。

The key lies in the word "isolate". As it turns out, we do have a way to isolate and ship entire environments. It's called, "Docker". You can create a container with any configuration and then ship that to anyone else. All you need now is a way to develop in that container like it was your local machine.

关键在于单词“ isolate”。 事实证明,我们确实有一种隔离和运送整个环境的方法。 它被称为“ Docker”。 您可以创建具有任何配置的容器,然后将其发送给其他任何人。 您现在所需要的就是在该容器中进行开发的方式,就像在您的本地计算机上一样。

You can.

您可以。

In this article, I'm going to show you how you can use a few configuration files to box up and ship your entire development environment minus your bad taste in dubstep.

在本文中,我将向您展示如何使用一些配置文件来装箱并运送整个开发环境,以消除在dubstep中的不良品味。

This is all thanks to the new Remote-Containers extension for VS Code.

这一切都要归功于VS Code的新Remote-Containers扩展

VS代码和远程容器 (VS Code and Remote-Containers)

The basic concept behind Remote-Containers is that you specify a Dockerfile which in turn specifies all of the necessary dependencies and configuration steps to get the correct development environment setup. VS Code will then spin up that container, install a little server in it and then connect back to your VS Code instance. What this means is that you are now developing inside of a pre-configured environment. But to you, it's just VS Code.

Remote-Containers的基本概念是您指定一个Dockerfile,该文件又指定了所有必要的依赖项和配置步骤,以获取正确的开发环境设置。 然后,VS Code将启动该容器,在其中安装一个小服务器,然后再连接回VS Code实例。 这意味着您现在正在预先配置的环境中进行开发。 但是对您来说,这只是VS Code。

To show you how this works, I'm going to create a container in which to develop the backend API of a project that I worked on called, theurlist.com. The backend of this project is written in C# and runs on Azure Functions. In order to run it locally, you would have to install the .NET Core runtime, Azure Functions CLI and the Azure Functions VS Code extension.

为了向您展示这是如何工作的,我将创建一个容器,用于在其中开发我所研究的项目theurlist.com的后端API。 该项目的后端使用C#编写,并在Azure Functions上运行。 为了在本地运行它,您必须安装.NET Core运行时Azure Functions CLIAzure Functions VS Code扩展

The first step is to install the Remote-Containers extension. This will add a little icon to the bottom-left corner of your VS Code.

第一步是安装Remote-Containers扩展程序 。 这将在VS Code的左下角添加一个小图标。

You're also going to need to have Docker installed. Docker containers don't run very well if you don't have Docker. You can download the Community Edition here.

您还需要安装Docker。 如果您没有Docker,则Docker容器将无法很好地运行。 您可以在此处下载社区版。

With the extension installed, I need to add the proper configuration files to this project. Namely a "Dockerfile" which specifies the container that the project will be loaded in. The extension comes with a bunch of preconfigured environments. To add one to the project, open the Command Palette and select "Remote-Containers: Add Development Container Configuration Files"

安装扩展名后,我需要向该项目中添加正确的配置文件。 即一个“ Dockerfile”,它指定将要在其中加载项目的容器。扩展名附带了一堆预配置的环境。 要将一个添加到项目中,请打开命令面板,然后选择“远程容器:添加开发容器配置文件”

This project uses Azure Functions and C#, so I'll select that container definition.

该项目使用Azure Functions和C#,因此我将选择该容器定义。

As soon as I do that, VS Code is going to add a ".deployment" folder with "Dockerfile" and a "devcontainer.json" file inside. It's also going to immediately ask if I want to re-open the project in a container. I'm gonna say no and have VS Code chill out for just a minute while we look at these files.

一旦我这样做,VS Code就会在其中添加带有“ Dockerfile”和“ devcontainer.json”文件的“ .deployment”文件夹。 它还将立即询问我是否要在容器中重新打开该项目。 我要说不,在查看这些文件时,让VS Code放松一分钟。

First let's look at the "Dockerfile" file. File file file.

首先让我们看一下“ Dockerfile”文件。 文件文件文件。

Dockerfile配置 (Dockerfile Configuration)

The "Dockerfile" specifies what will be in the container. If I open it up, you can see that there's quite a bit in there. It's a tad verbose. But we can parse out the important bits.

“ Dockerfile”指定容器中将包含的内容。 如果我打开它,您会看到里面有很多东西。 有点冗长。 但是我们可以解析出重要的部分。

The first thing it does is pull in the latest version of the .NET Core SDK.

它所做的第一件事是引入最新版本的.NET Core SDK。

Then it installs some utilities in the container. Specifically, it installs...

然后,它将一些实用程序安装在容器中。 具体来说,它会安装...

  • Git (Source Control)

    Git(源代码管理)
  • procps (process inspection utility)

    procps(过程检查实用程序)
  • curl (HTTP utility)

    curl(HTTP实用程序)
  • apt-transport-https (HTTPS utility)

    apt-transport-https(HTTPS实用程序)
  • gnupg2 (An encryption tool)

    gnupg2(加密工具)
  • lsb-release (Prints specific Linux information)

    lsb-release(打印特定的Linux信息)

All of this is to create an environment that has every obscure tool that a developer may need to run this project and be able to check it in and out of source control.

所有这些都是为了创建一个环境,其中包含开发人员运行该项目可能需要的每一个晦涩的工具,并且能够检入和检出源代码控制。

Then it installs the Azure Functions Core Tools. It configures all of the necessary repository locations before the install. These are all things a developer would have to do themselves before they can even run this project.

然后,它将安装Azure Functions核心工具。 它会在安装之前配置所有必要的存储库位置。 这些都是开发人员甚至必须运行自己的所有东西,才能甚至运行此项目。

The other file in the ".devcontainer" folder is the "devcontainer.json" file.

“ .devcontainer”文件夹中的另一个文件是“ devcontainer.json”文件。

devcontainer.json文件 (The devcontainer.json file)

This file specifies some additional settings for the Remote Development environment. Specifically....

该文件为远程开发环境指定了一些其他设置。 特别....

  1. It specifies the "Dockerfile" should be used to build the container

    它指定应使用“ Dockerfile”来构建容器

2. It makes sure that port "7071" is forwarded from the container so it can be accessed at "localhost:7071". This is the port Azure Functions runs on locally.

2.确保从容器转发端口“ 7071”,以便可以在“ localhost:7071”访问它。 这是Azure Functions在本地运行的端口。

3. It specifies any extensions that should be installed in the container. Since you aren't really using VS Code locally, your extensions aren't all installed automatically. Specifying them in this file makes sure they are there when the project is opened.

3.它指定应在容器中安装的所有扩展。 由于您并不是真正在本地使用VS Code,因此您的扩展程序不会全部自动安装。 在此文件中指定它们可以确保在打开项目时它们在那里。

And with that, we can open the Command Palette and select "Remote-Containers: Reopen folder in container".

这样,我们可以打开“命令面板”,然后选择“远程容器:在容器中重新打开文件夹”。

VS Code will reload and set about building the container for this project.

VS Code将重新加载并开始为该项目构建容器。

The first time it does this, it takes a minute or two because the base images have to be pulled and built. After it's done the first time, subsequent loads are much faster as the image already exists on your machine.

第一次执行此操作需要一两分钟,因为必须拉动并构建基本图像。 第一次完成后,由于映像已经存在于您的计算机上,因此后续加载要快得多。

In the case of this project, once the container is built, VS Code sets about restoring the C# dependencies which is done with the C# Extension that was included in the "devcontainer.json" config file.

对于该项目,一旦容器被构建,VS Code就着手恢复C#依赖关系,这是通过“ devcontainer.json”配置文件中包含的C#扩展来完成的。

When it's all finished, I can run this project just by pressing F5. And just like that the app is up and running.

全部完成后,我只需按F5键即可运行该项目。 就像该应用程序已启动并正在运行一样。

Think of what we would have had to do to get this setup locally...

考虑一下要在本地进行此设置将需要做些什么...

  1. Install .NET Core

    安装.NET Core
  2. Install Functions Core Tools

    安装功能核心工具
  3. Install VS Code Functions Extension

    安装VS代码功能扩展
  4. Install VS Code C# Extension

    安装VS Code C#扩展

With Remote Containers, none of that is required. We can configure and ship an entire development environment in two text files.

使用远程容器,不需要任何操作。 我们可以在两个文本文件中配置和交付整个开发环境。

请把您的开发环境放在Github中 (Please, put your development environment in Github)

So here's my humble plea: instead of outlining 15 steps in a Github README for configuring your project to run, put your entire development environment in Github.  That means checking in that ".devcontainers" folder. If a developer using your project doesn't have VS Code or the Remote Containers extension, nothing happens. You can't lose.

因此,这是我的谦虚的恳求:无需概述Github自述文件中的15个步骤来配置要运​​行的项目,而是将整个开发环境放在Github中 。 这意味着检入该“ .devcontainers”文件夹。 如果使用您的项目的开发人员没有VS Code或Remote Containers扩展,则不会发生任何事情。 你不能输。

I'm excited because I feel like the days of configuration hell are nearing an end. And besides, think of all the people we'll save from dogmatic articles about ternary statements.

我很兴奋,因为我觉得配置地狱的日子即将结束。 此外,想一想我们将从三元陈述的教条文章中节省下来的所有人员。

有关远程容器的更多信息 (More On Remote Containers)

翻译自: https://www.freecodecamp.org/news/put-your-dev-env-in-github/

配置github的开发环境

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值