semaphore使用_如何使用Up&Semaphore CI在数分钟内将无限可扩展的应用程序部署到AWS...

semaphore使用

by TJ Holowaychuk

由TJ Holowaychuk

如何使用Up&Semaphore CI在数分钟内将无限可扩展的应用程序部署到AWS (How to deploy infinitely scalable applications to AWS in minutes with Up & Semaphore CI)

Many Apex Up users have been asking about integration with continuous integration platforms, this post walks through staging and deploying Up to production using Semaphore CI.

许多Apex Up用户一直在询问与持续集成平台的集成,本文通过使用Semaphore CI逐步部署和部署Up到生产环境。

Serverless Up applications typically deploy in a few seconds from a laptop, however with a poor network connection you may want to consider CI, not only to improve workflow and testing, but for the improved upload speed.

通常,无服务器启动应用程序可以在便携式计算机上几秒钟内完成部署,但是,网络连接较差时,您可能需要考虑使用CI,不仅可以改善工作流程和测试,还可以提高上传速度。

Semaphore is my CI of choice — it has a clean design, lets you easily encrypt the env variables, schedule timed builds, and doesn’t require you to litter your repositories with dotfiles. With that said as long as you can define environment variables, you can choose whichever CI platform you prefer.

信号量是我选择的配置项–它的设计简洁,可让您轻松加密env变量,安排定时生成的时间,并且不需要您用dotfile填充存储库。 话虽如此,只要您可以定义环境变量,就可以选择您喜欢的任何CI平台。

应用程序 (The Application)

For this example we’ll be deploying a minimal Koa Node.js application. Create a new repository in your GitHub, and add app.js with the following code:

在此示例中,我们将部署一个最小的Koa Node.js应用程序。 在GitHub中创建一个新的存储库,并使用以下代码添加app.js

const Koa = require('koa')const app = new Koaconst { PORT = 3000 } = process.env
app.use(function *() {  this.body = "Hello\n"})
app.listen(PORT)

You can add the dependencies via npm or yarn, whichever you prefer. Deploy the app to AWS and check out that glorious “Hello”:

您可以通过npm或yarn来添加依赖项,无论哪种方式。 将应用程序部署到AWS并查看出色的“ Hello”:

$ up$ curl `up url`Hello

Now let’s set up CI.

现在让我们设置CI。

建立 (Setup)

To get started in Semaphore, you’ll first need to create a new project:

要开始使用Semaphore,您首先需要创建一个新项目:

And find the repository you created earlier in GitHub:

并找到您先前在GitHub中创建的存储库:

Now on to the good stuff — configuring the build!

现在介绍好东西-配置构建!

配置作业 (Configuring the Jobs)

One of the things I really like about Semaphore is that you don’t have to use dotfiles in your repository, simply define the jobs and commands required in the UI. If your use-case allows for it, you can even run jobs in parallel to speed things up.

我真正喜欢Semaphore的一件事是,您不必在存储库中使用点文件,只需定义UI中所需的作业和命令即可。 如果用例允许,您甚至可以并行运行作业以加快处理速度。

The “Setup” job will install NPM packages for the application, adjust the owner of /usr/local/bin since this is where Up will be installed by default, and then finally install Up itself. Up is distributed as binaries, so this process takes only a few seconds.

“设置”作业将为该应用程序安装NPM软件包,调整/usr/local/bin的所有者,因为默认情况下将在此处安装Up,然后最终自行安装Up。 Up作为二进制文件分发,因此此过程仅需几秒钟。

npm installsudo chown -R $(whoami) /usr/local/bincurl -f https://up.apex.sh/install | sh

You can define and re-order the commands, however, if you click “Edit Job” you can copy-and-paste the commands above as text. The second job in this case is used to deploy to development (up ).

您可以定义和重新排序命令,但是,如果单击“编辑作业”,则可以将上面的命令复制并粘贴为文本。 在这种情况下,第二项工作用于部署到开发( up )。

In scenarios where you run into permission issues installing to /usr/local/bin, or simply prefer to avoid this, you may provide an install path with BINDIR:

如果您在安装到/ usr / local / bin时遇到权限问题,或者只是希望避免这种情况,则可以使用BINDIR提供安装路径:

curl -sf https://up.apex.sh/install | BINDIR=. sh

Note that if you’re running Node.js using Up, you’ll want to specify 6.10.3, as this is the “native” version of Node.js supported by AWS Lambda.

请注意,如果您使用Up运行Node.js,则需要指定6.10.3 ,因为这是AWS Lambda支持的Node.js的“本机”版本。

配置您的AWS凭证 (Configuring your AWS Credentials)

After the jobs are configured just select your branch and click “Start”.

配置作业后,只需选择您的分支,然后单击“开始”即可。

The first thing you’ll see is that up fails! This is because we haven’t provided any AWS credentials, so Up doesn’t know where to deploy, and is not authorized to do so.

你会看到的第一件事情是, up失败! 这是因为我们没有提供任何AWS凭证,所以Up不知道在哪里部署,也没有授权这样做。

If you head over to the “Environment Variables” tab in the sidebar, you can add plain text or encrypted env vars. You’ll need two variables, the AWS_ACCESS_KEY_ID and AWS_SECRET_KEY_ID . The first may be plain text, however the second should be encrypted, when in doubt, just encrypt.

如果转到侧边栏中的“环境变量”选项卡,则可以添加纯文本或加密的环境变量。 您将需要两个变量, AWS_ACCESS_KEY_IDAWS_SECRET_KEY_ID 。 第一个可能是纯文本,但是第二个应该加密,如有疑问,只需加密即可。

Now when you perform a new build you should have a passing CI pipeline!

现在,当您执行新的构建时,您应该已经通过了CI管道!

You can read more the options for AWS credentials in the Up documentation. Also make sure to never use your root credentials in external services such as CI.

您可以在Up文档中阅读有关AWS凭证的更多选项。 此外,请确保不要在CI等外部服务中使用您的根凭据。

使用Up Pro部署到生产 (Deploying to Production with Up Pro)

The Pro version of Up is in early-access — only $10/mo with the discount for unlimited use in your organization — providing encrypted env variables, alerting, and more goodies soon!

Up版本Pro版本可进行早期试用-每月仅需$ 10,并可以在组织中无限使用该折扣-很快提供加密的env变量,警报和更多功能!

After subscribing to Up Pro you’ll need to authenticate in order to install the Pro binary. Run the following command to copy the credentials to your clipboard.

订阅Up Pro后,您需要进行身份验证才能安装Pro二进制文件。 运行以下命令将凭据复制到剪贴板。

$ up team ci --copy

Add a new encrypted environment variable named UP_CONFIG :

添加一个名为UP_CONFIG的新的加密环境变量:

Next you’ll need to add up upgrade after the installation of Up, this will install the Pro version, as it detects UP_CONFIG . Note that the “Deploy” job has been changed to deploy to production rather than development. Changing this command allows you to map GIT branches to the various stages, so you can utilize CI for pushing to development, staging, or production.

接下来,在安装Up之后,您需要添加up upgrade ,这将安装Pro版本,因为它将检测到UP_CONFIG 。 请注意,“部署”作业已更改为部署到生产而不是开发。 更改此命令可以将GIT分支映射到各个阶段,因此您可以利用CI进行开发,登台或生产。

Note you may upgrade to a specific version of Up via up upgrade -t 0.5.4 to “lock” the version.

请注意,您可以通过up upgrade -t 0.5.4升级到Up的特定版本,以“锁定”该版本。

Try changing the “Hello\n” string in app.js to “Hello from Semaphore CI\n” and push the commit to GitHub.

尝试将app.js中的“ Hello \ n”字符串更改为“ Semaphore CI \ n的Hello”,然后将提交推送到GitHub。

app.use(function *() {  this.body = "Hello from Semaphore CI\n"})

In a minute or less you should see the lovely leafy green of success! There is no remote build on the AWS side, once it’s green, your application is live and serving requests, in under a minute.

在一分钟或更短的时间内,您应该会看到可爱的绿叶成荫的成功! AWS端没有远程构建,一旦运行成绿色,您的应用程序就会在不到一分钟的时间内启动并可以处理请求。

If deploying apps, apis, and sites to your own AWS account in a single command sounds helpful, take a look at Apex Up — and check out Semaphore CI for creating organization-wide continuous integration workflows.

如果在单个命令中将应用程序,API和站点部署到自己的AWS帐户听起来很有帮助,请查看Apex Up —并查看Semaphore CI以创建组织范围的连续集成工作流。

EDIT: Note that with recent versions of Up you may also upgrade the binary in-place, as to avoid permission issues or changes to /usr/local/bin , and optionally pass a specific version to “pin” the version of Up Pro via -t x.x.x

编辑 :请注意,使用Up的最新版本,您还可以就地升级二进制文件,以避免权限问题或对/usr/local/bin更改,并可以选择通过以下方式传递特定版本以“固定” Up Pro的版本: -t xxx

curl -f https://up.apex.sh/install | BINDIR=. sh./up upgrade -t 0.5.8./up production

I reached out to Semaphore CI and they offered to provide a 30% discount for the first 3 months to Up users, using the coupon “SEMAPHORE330”. Note that it’s redeemable until the 31st of December.

我联系了Semaphore CI,他们使用优惠券“ SEMAPHORE330 ”为Up用户提供了前三个月30%的折扣。 请注意,它可以兑换到12月31日。

翻译自: https://www.freecodecamp.org/news/deploy-infinitely-scalable-applications-in-minutes-with-up-semaphore-ci-c2a60f821207/

semaphore使用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值