heroku
The past few weeks, I’ve been playing around with Vapor 4, and I absolutely love it!
在过去的几周里,我一直在玩Vapor 4 ,我绝对喜欢它!
After developing a couple of services, I decided that it is time to bring my vapor app online. To see what options do I have to deploy a vapor app, I headed to the Deploy section on Vapor Documentation. Since I didn’t want to over-complicate things, I chose Heroku.
开发了几项服务之后,我决定是时候将该蒸气应用程序投入在线了。 要查看我必须部署蒸气应用程序的哪些选项,请前往“蒸气文档”上的“部署”部分。 由于我不想使事情复杂化,因此选择了Heroku 。
This is where the fun begins.
这就是乐趣的开始。
First, you need to create an account on Heroku (it’s free). Once you are done with that, you need to install heroku cli tool using your terminal.
首先,您需要在Heroku上创建一个帐户(免费)。 完成后,您需要使用终端安装heroku cli工具。
$ brew install heroku/brew/heroku
Next, you’ll need to authenticate, in your terminal type:
接下来,您需要在终端类型中进行身份验证:
$ heroku login
Head over Heroku and create a new app.
前往Heroku并创建一个新应用。
Next up you need to connect your Heroku app with the Bitbucket Repository. You just need to run.
接下来,您需要将Heroku应用程序与Bitbucket存储库连接。 您只需要运行。
$ heroku git:remote -a your-new-app-name
Heroku uses a Procfile to know how to run your app. So we are going to create this file.
Heroku使用Procfile知道如何运行您的应用程序。 因此,我们将创建此文件。
$ echo “web: Run serve — env production” \ “ — hostname 0.0.0.0 — port \$PORT” > Procfile
Heroku also needs a buildpack to determine how your app should be built. We need to add a buildpack your app.
Heroku还需要一个buildpack来确定应如何构建您的应用程序。 我们需要为您的应用添加构建包。
$ heroku buildpacks:set vapor/vapor
You can now commit and push.
您现在可以提交并推送。
$ git add Procfile
$ git commit -m "Procfile added"
$ git push
The last thing you need to run to deploy your app to Heroku is.
将应用程序部署到Heroku的最后一件事是。
$ git push heroku master
This will take a while don’t worry, and grab a coffee while you wait…
这将需要一段时间,请放心,在您等待时喝杯咖啡…
By now, you should have your app up and running. Now is time to configure our Bitbucket pipelines.
现在,您应该已启动并运行您的应用程序。 现在是时候配置我们的Bitbucket管道了。
Head over to Bitbucket, open your repository, select Pipelines and click on Start using Pipelines
前往Bitbucket,打开您的存储库,选择“管道”,然后单击“开始使用管道”
On choose a language template select other.
在选择语言模板时,选择其他。
On the right side, you have a settings option, select it. We need to add two repository variables in here.
在右侧,您可以选择一个设置选项。 我们需要在此处添加两个存储库变量。
The first one is HEROKU_API_KEY. The value for this variable comes from your Heroku account. We need to head over to Heroku, open your account settings, and if you scroll down a bit, you will find your API KEY.
第一个是HEROKU_API_KEY 。 该变量的值来自您的Heroku帐户。 我们需要转到Heroku,打开您的帐户设置,如果向下滚动一点,您将找到API KEY 。
The second variable is HEROKU_APP_NAME.
第二个变量是HEROKU_APP_NAME。
Last, you can copy this into your bitbucket-pipelines.yml file.
最后,您可以将其复制到bitbucket-pipelines.yml文件中。
image: swift:5.2-focalpipelines:
branches:
master:
- step:
name: Build
script:
- git archive --format=tar.gz master -o backend.tar.gz
artifacts:
- backend.tar.gz
- step:
name: Deploy to Heroku
script:
- pipe: atlassian/heroku-deploy:1.1.4
variables:
HEROKU_API_KEY: $HEROKU_API_KEY
HEROKU_APP_NAME: $HEROKU_APP_NAME
ZIP_FILE: backend.tar.gz
This pipeline only runs when a push is made into master. If you want to learn more about bitbucket pipelines you can head over bitbucket pipelines docs.
仅当向主服务器推送时,该管道才会运行。 如果您想了解有关位桶流水线的更多信息,可以查阅位桶流水线文档。
Thanks for reading, hope this article helps you to setup a vapor CI/CD environment, to speed up your development process.
感谢您的阅读,希望本文能帮助您设置蒸气CI / CD环境,以加快开发过程。
翻译自: https://medium.com/@sebitassg/deploy-a-vapor-4-app-to-heroku-using-bitbucket-pipelines-ae283d6c935d
heroku