Note: GitHub Actions was available for GitHub Enterprise Server 2.22 as a limited beta. The beta has ended. GitHub Actions is now generally available in GitHub Enterprise Server 3.0 or later. For more information, see the GitHub Enterprise Server 3.0 release notes.
- For more information about upgrading to GitHub Enterprise Server 3.0 or later, see "Upgrading GitHub Enterprise Server."
- For more information about configuring GitHub Actions after you upgrade, see the documentation for GitHub Enterprise Server 3.0.
Note: GitHub-hosted runners are not currently supported on GitHub Enterprise Server. You can see more information about planned future support on the GitHub public roadmap.
はじめに
このガイドでは、アプリケーションをビルド、テスト、Azure App ServiceへデプロイするためのGitHub Actionsの使い方を説明します。
Azure App Serviceではいくつかの言語でWebアプリケーションを動作させることができますが、このガイドでは既存のNode.jsプロジェクトをデプロイする方法を示します。
必要な環境
GitHub Actionsワークフローを作成する前に、まず以下のセットアップのステップを完了しておかなければなりません。
-
Azure App Serviceプランの作成
たとえば、Azure CLIを使って新しいApp Serviceのプランを作成できます。
Shell az appservice plan create \ --resource-group MY_RESOURCE_GROUP \ --name MY_APP_SERVICE_PLAN \ --is-linux
上のコマンドで、
MY_RESOURCE_GROUP
はすでに存在するAzure Resource Groupに、MY_APP_SERVICE_PLAN
はApp Serviceプランの新しい名前に置き換えてください。Azure CLIの使いからに関する詳しい情報については、Azureのドキュメンテーションを参照してください。
- 認証については「Sign in with Azure CLIを参照してください。
- 新しいリソースグループを作成しなければならない場合は、「az group」を参照してください。
-
Webアプリケーションの作成
たとえば、Azure CLIを使ってnodeのランタイムを持つAzure App Service Webアプリケーションを作成できます。
Shell az webapp create \ --name MY_WEBAPP_NAME \ --plan MY_APP_SERVICE_PLAN \ --resource-group MY_RESOURCE_GROUP \ --runtime "node|10.14"
上のコマンドで、パラメータは自分の値で置き換えてください。
MY_WEBAPP_NAME
はWebアプリケーションの新しい名前です。 -
Azure公開プロフィールを設定して、
AZURE_WEBAPP_PUBLISH_PROFILE
シークレットを作成してください。公開されたプロフィールを使って、Azureのデプロイ資格情報を生成してください。 詳しい情報については、Azureのドキュメンテーションの「デプロイ資格情報を生成する」を参照してください。
GitHubリポジトリで、公開されたプロフィールの内容を含む
AZURE_WEBAPP_PUBLISH_PROFILE
という名前のシークレットを生成してください。 シークレットの作成に関する詳しい情報については「暗号化されたシークレット」を参照してください。
ワークフローの作成
必要な環境を整えたら、ワークフローの作成に進むことができます。
以下の例のワークフローは、Node.jsのプロジェクトをビルド、テストし、Azure App Serviceへデプロイする方法を示します。
ワークフローのenv
キー中のAZURE_WEBAPP_NAME
を、作成したWebアプリケーションの名前に設定してください。
on:
release:
types: [created]
env:
AZURE_WEBAPP_NAME: MY_WEBAPP_NAME # set this to your application's name
AZURE_WEBAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
NODE_VERSION: '10.x' # set this to the node version to use
jobs:
build-and-deploy:
name: Build and Deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v1
with:
node-version: ${{ env.NODE_VERSION }}
- name: npm install, build, and test
run: |
# プロジェクトをビルドしてテストし、続いて
# Azure Web Appにデプロイする。
npm install
npm run build --if-present
npm run test --if-present
- name: 'Deploy to Azure WebApp'
uses: azure/webapps-deploy@v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
追加リソース
以下のリソースも役に立つでしょう。
- オリジナルのスターターワークフローについては、GitHub Actions
starter-workflows
リポジトリ中のazure.yml
を参照してください。 - Webアプリケーションのデプロイに使われたアクションは、公式のAzure
Azure/webapps-deploy
アクションです。 - Azure web appドキュメンテーション中の「Azure で Node.js Web アプリを作成する」クイックスタートは、Azure App ServiceエクステンションとともにVS Codeを利用する方法を示しています。