Heroku にデプロイする
Bitbucket Pipelines から Heroku にアプリケーションをデプロイします。
Pipelines と Pipes を使用した Heroku へのデプロイをハンズオンで確認したい場合、このリポジトリで完全なエンドツーエンドのサンプルを利用できます。
ステップ 1: Heroku の API トークンとアプリ名を環境変数として追加する
To define the following two variables for your Heroku repository, select More actions (…) next to the name of your repository in the left sidebar, then select Settings, then select Repository variables under the Pipeline section:
名前 | 値 |
|---|---|
| Heroku から生成された API トークン。マスクおよび暗号化されるよう、保護された変数を使用します。 |
| Heroku のアプリ名 |
これらの変数は、デプロイメント環境、リポジトリ、またはワークスペース レベルで定義できます。
ステップ 2: フル クローンを実行するように Pipelines を設定する
Heroku deployments require a full Git clone. By default, Pipelines clones your repository with a depth of 50 to shorten your build time. You can configure your Pipeline to do a full Git clone in your bitbucket-pipelines.yml file.
例 — depth オプションを使用して、パイプラインの各ステップのフル複製を実行する
clone:
depth: full
pipelines:
default:
- step:
script:
- ls $BITBUCKET_CLONE_DIR例 — depth オプションを使用して、1 つのステップのフル複製を実行する
pipelines:
default:
- step:
clone:
depth: full
script:
- ls $BITBUCKET_CLONE_DIRステップ 3: パイプを使用して Heroku にデプロイする
Deploy your application to Heroku using the Heroku deploy pipe. The pipe repository contains more usage examples, which variables you can use, and support information. Below is a sample bitbucket-pipelines.yml configuration that deploys an application to Heroku. This example also provides insights on some best practices, like having separate steps for building and deploying an application and also using Bitbucket Deployments to deploy to different environments.
# This is a sample build configuration for Python.
# Check our guides at https://ja.confluence.atlassian.com/x/x4UWN for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: python:3.7.2
pipelines:
default:
- step:
name: Test
script:
- cd sample-python-app
- pip install -r requirements.txt
- ./manage.py test
- step:
name: Build
script:
- cd sample-python-app
- git archive --format=tar.gz main -o sample-app.tar.gz
artifacts:
- sample-python-app/sample-app.tar.gz
- step:
name: Deploy to production
deployment: production
caches:
- pip
script:
- pipe: atlassian/heroku-deploy:0.1.1
variables:
HEROKU_API_KEY: $HEROKU_API_KEY
HEROKU_APP_NAME: $HEROKU_APP_NAME
ZIP_FILE: sample-python-app/sample-app.tar.gzbitbucket-pipelines.yml ファイルはオンライン バリデーターで確認できます。
この内容はお役に立ちましたか?