İş akışınızı otomatikleştirmek ve GitHub'dan Azure Uygulaması Hizmeti'ne dağıtmak için GitHub Actions'ı kullanmaya başlayın.
Önkoşullar
Uygulamayı oluştururken GitHub Actions dağıtımını ayarlama
GitHub Actions dağıtımı, varsayılan Web Uygulaması Oluşturma işlemiyle tümleştirilir. Dağıtım sekmesinde Sürekli dağıtımı Etkinleştir olarak ayarlayın ve istediğiniz kuruluşu, depoyu ve dalı yapılandırın.
Sürekli dağıtımı etkinleştirdiğinizde, uygulama oluşturma işlemi temel kimlik doğrulama seçimine göre otomatik olarak kimlik doğrulama yöntemini seçer ve uygulamanızı ve GitHub deponuzu buna göre yapılandırılır:
Dağıtım Merkezi'nden GitHub Actions dağıtımını ayarlama
Mevcut bir uygulama için App Service Dağıtım Merkezi'ni kullanarak GitHub Actions ile hızlı bir şekilde çalışmaya başlayabilirsiniz. Bu anahtar teslim yöntemi, uygulama yığınınızı temel alan bir GitHub Actions iş akışı dosyası oluşturur ve bunu GitHub deponuza işler.
Dağıtım Merkezi, kullanıcı tarafından atanan bir kimlikle daha güvenli OpenID Connect kimlik doğrulamasını kolayca yapılandırmanıza da olanak tanır. Daha fazla bilgi için kullanıcı tarafından atanan kimlik seçeneğine bakın.
Azure hesabınız gerekli izinlere sahipse, kullanıcı tarafından atanan bir kimlik oluşturabilirsiniz. Aksi takdirde, Kimlik açılan menüsünde kullanıcı tarafından atanan mevcut bir yönetilen kimliği seçebilirsiniz. Web Sitesi Katılımcısı rolüyle kullanıcı tarafından atanan bir yönetilen kimlik oluşturmak için Azure yöneticinizle birlikte çalışabilirsiniz.
Daha fazla bilgi için bkz. Azure Uygulaması Hizmetine sürekli dağıtım.
GitHub Actions iş akışını el ile ayarlama
Dağıtım Merkezi'ni kullanmadan bir iş akışı dağıtabilirsiniz. Bu durumda üç adım gerçekleştirmeniz gerekir:
-
Dağıtım kimlik bilgileri oluşturma
-
GitHub gizli dizisini yapılandırma
-
İş akışı dosyasını GitHub deponuza ekleme
Dağıtım kimlik bilgileri oluşturma
GitHub Actions için Azure Uygulaması Services ile kimlik doğrulaması yapmak için önerilen yol OpenID Connect'tir. Bu yaklaşım, kısa süreli belirteçler kullanan bir kimlik doğrulama yöntemidir. GitHub Actions ile OpenID Connect'i ayarlamak daha karmaşıktır ancak sağlamlaştırılmış güvenlik sunar.
Alternatif olarak, Kullanıcı Tarafından Atanan Yönetilen Kimlik, hizmet sorumlusu veya yayımlama profili ile kimlik doğrulaması yapabilirsiniz.
Aşağıdaki yordamda, Azure CLI deyimlerini kullanarak Microsoft Entra uygulaması, hizmet sorumlusu ve federasyon kimlik bilgileri oluşturma adımları açıklanmaktadır. Azure portalında Microsoft Entra uygulaması, hizmet sorumlusu ve federasyon kimlik bilgileri oluşturmayı öğrenmek için bkz . GitHub ve Azure'a bağlanma.
Mevcut bir uygulamanız yoksa kaynaklara erişebilen yeni bir Microsoft Entra uygulaması ve hizmet sorumlusu kaydedin. Microsoft Entra uygulamasını oluşturun.
az ad app create --display-name myApp
Bu komut, ile sizin client-id
olan bir appId
JSON döndürür. GitHub gizli dizisi olarak AZURE_CLIENT_ID
kullanılacak değeri daha sonra kaydedin.
Graph API'siyle objectId
federasyon kimlik bilgileri oluştururken değerini kullanır ve buna olarak başvurursunuz APPLICATION-OBJECT-ID
.
Hizmet sorumlusu oluşturma. değerini $appID
JSON çıkışınızdaki appId değeriyle değiştirin.
Bu komut, bir sonraki adımda kullanmak üzere farklı objectId
bir JSON çıkışı oluşturur. Yeni objectId
, şeklindedir assignee-object-id
.
appOwnerTenantId
daha sonra kullanmak üzere öğesini GitHub gizli dizisi AZURE_TENANT_ID
olarak kopyalayın.
az ad sp create --id $appId
Aboneliğe ve nesneye göre yeni bir rol ataması oluşturun. Varsayılan olarak, rol ataması varsayılan aboneliğinize bağlıdır. değerini abonelik kimliğiniz, $resourceGroupName
kaynak grubu adınız, $webappName
web uygulamanızın adı ve $assigneeObjectId
oluşturulan id
ile değiştirin$subscriptionId
. Azure CLI ile Azure aboneliklerini yönetmeyi öğrenin.
az role assignment create --role contributor --subscription $subscriptionId --assignee-object-id $assigneeObjectId --scope /subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.Web/sites/$webappName --assignee-principal-type ServicePrincipal
Entra uygulamanız için yeni bir federasyon kimliği kimlik bilgisi oluşturmak için aşağıdaki komutu çalıştırın.
değerini Active Directory uygulamanız için appId (uygulama oluşturulurken oluşturulur) ile değiştirinAPPLICATION-OBJECT-ID
.
Daha sonra başvurmak için için CREDENTIAL-NAME
bir değer ayarlayın.
öğesini subject
ayarlayın. GitHub, değerini iş akışınıza bağlı olarak tanımlar:
- GitHub Actions ortamınızdaki işler için:
repo:< Organization/Repository >:environment:< Name >
- Bir ortama bağlı olmayan işler için, iş akışını tetiklerken kullanılan başvuru yolunu temel alan dal/etiket için başvuru yolunu ekleyin:
repo:< Organization/Repository >:ref:< ref path>
. Örneğin, repo:n-username/ node_express:ref:refs/heads/my-branch
veya repo:n-username/ node_express:ref:refs/tags/my-tag
.
- Çekme isteği olayı tarafından tetiklenen iş akışları için:
repo:< Organization/Repository >:pull_request
.
az ad app federated-credential create --id <APPLICATION-OBJECT-ID> --parameters credential.json
("credential.json" contains the following content)
{
"name": "<CREDENTIAL-NAME>",
"issuer": "https://token.actions.githubusercontent.com",
"subject": "repo:organization/repository:ref:refs/heads/main",
"description": "Testing",
"audiences": [
"api://AzureADTokenExchange"
]
}
Yayımlama profili, uygulama düzeyinde bir kimlik bilgisidir. Yayımlama profilinizi GitHub gizli dizisi olarak ayarlayın.
Azure portalında uygulama hizmetinize gidin.
Genel Bakış sayfasında Yayımlama profilini indir'i seçin.
İndirilen dosyayı kaydedin. GitHub gizli dizisi oluşturmak için dosyanın içeriğini kullanın.
Not
Ekim 2020 itibarıyla Linux web uygulamalarının yayımlama profilini indirmeden önce uygulama ayarının WEBSITE_WEBDEPLOY_USE_SCM
olarak ayarlanması true
gerekir. Bu gereksinim gelecekte kaldırılacaktır.
Azure CLI'da az ad sp create-for-rbac komutuyla bir hizmet sorumlusu oluşturabilirsiniz. Azure portalında veya Cloud Shell'i Aç'ı seçerek bu komutu Azure Cloud Shell ile çalıştırın.
az ad sp create-for-rbac --name "myApp" --role contributor \
--scopes /subscriptions/<subscription-id>/resourceGroups/<group-name>/providers/Microsoft.Web/sites/<app-name> \
--json-auth
Önceki örnekte yer tutucuları abonelik kimliğiniz, kaynak grubu adınız ve uygulama adınızla değiştirin. Çıktı, aşağıdaki JSON kod parçacığına benzer şekilde App Service uygulamanıza erişim sağlayan rol atama kimlik bilgilerine sahip bir JSON nesnesidir. Bu JSON nesnesini daha sonra için kopyalayın.
{
"clientId": "<GUID>",
"clientSecret": "<GUID>",
"subscriptionId": "<GUID>",
"tenantId": "<GUID>",
(...)
}
Önemli
Minimum erişim vermek her zaman iyi bir uygulamadır. Önceki örnekteki kapsam, kaynak grubunun tamamıyla değil, belirli App Service uygulamasıyla sınırlıdır.
Azure/oturum açma eylemine uygulamanızın İstemci Kimliğini, Kiracı Kimliğini ve Abonelik Kimliğinisağlamanız gerekir. Bu değerler doğrudan iş akışında sağlanabilir veya GitHub gizli dizilerinde depolanabilir ve iş akışınızda başvurulabilir. Değerleri GitHub gizli dizileri olarak kaydetmek daha güvenli bir seçenektir.
GitHub deponuzu açın ve Ayarlar>Güvenlik>Gizli Dizileri ve değişkenler>Eylemler>Yeni depo gizli dizisi'ne gidin.
, AZURE_TENANT_ID
ve AZURE_SUBSCRIPTION_ID
için AZURE_CLIENT_ID
gizli diziler oluşturun. GitHub gizli dizileriniz için Active Directory uygulamanızdaki şu değerleri kullanın:
GitHub Gizli Dizisi |
Active Directory Uygulaması |
AZURE_CLIENT_ID |
Uygulama (istemci) kimliği |
AZURE_TENANT_ID |
Dizin (kiracı) kimliği |
AZURE_SUBSCRIPTION_ID |
Subscription ID |
Gizli dizi ekle'yi seçerek her gizli diziyi kaydedin.
GitHub'da deponuza göz atın. Ayarlar>Güvenlik>Gizli Dizileri ve değişkenler>Eylemler>Yeni depo gizli dizisi'ni seçin.
Önceki bölümde oluşturduğunuz uygulama düzeyinde kimlik bilgilerini kullanmak için indirilen yayımlama profili dosyasının içeriğini gizli dizinin değer alanına yapıştırın. Gizli diziyi AZURE_WEBAPP_PUBLISH_PROFILE
olarak adlandırın.
GitHub iş akışı dosyasını daha sonra yapılandırırken Azure Web App'i dağıtma eyleminde öğesini kullanın AZURE_WEBAPP_PUBLISH_PROFILE
. Örneğin:
- uses: azure/webapps-deploy@v2
with:
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
GitHub'da deponuza göz atın. Ayarlar>Güvenlik>Gizli Dizileri ve değişkenler>Eylemler>Yeni depo gizli dizisi'ni seçin.
Önceki bölümde oluşturduğunuz kullanıcı düzeyinde kimlik bilgilerini kullanmak için Azure CLI komutundaki JSON çıkışının tamamını gizli dizinin değer alanına yapıştırın. Gizli diziyi AZURE_CREDENTIALS
olarak adlandırın.
GitHub iş akışı dosyasını daha sonra yapılandırdığınızda, Azure/login girişi creds
için gizli diziyi kullanın. Örneğin:
- uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
İş akışı dosyasını GitHub deponuza ekleme
GitHub deponuzdaki yoldaki /.github/workflows/
bir YAML (.yml) dosyası bir iş akışı tanımlar. Bu tanım, iş akışını oluşturan çeşitli adımları ve parametreleri içerir.
İş akışı dosyasında en azından aşağıdaki ayrı adımlar bulunur:
- Oluşturduğunuz GitHub gizli dizisini kullanarak App Service ile kimlik doğrulaması yapın.
- Web uygulamasını oluşturun.
- Web uygulamasını dağıtın.
Kodunuzu bir App Service uygulamasına dağıtmak için azure/webapps-deploy@v3 eylemini kullanın. Eylem, içindeki app-name
web uygulamanızın adını ve dil yığınınıza bağlı olarak içinde dağıtılacak package
*.zip, *.war, *.jar veya klasörün yolunu gerektirir. Eylem için olası girişlerin tam listesi için azure/webapps-deploy@v3
bkz . action.yml.
Aşağıdaki örnekler, iş akışının web uygulamasını oluşturan bölümünü desteklenen farklı dillerde gösterir.
Yapılandırdığınız yönetilen kimliği kullanarak OpenID Connect ile dağıtmak için , ve anahtarlarıyla client-id
eylemi kullanınazure/login@v2
.subscription-id
tenant-id
Daha önce oluşturduğunuz GitHub gizli dizilerine başvurun.
name: .NET Core
on: [push]
permissions:
id-token: write
contents: read
env:
AZURE_WEBAPP_NAME: my-app # 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
DOTNET_VERSION: '6.0.x' # set this to the dot net version to use
jobs:
build:
runs-on: ubuntu-latest
steps:
# Checkout the repo
- uses: actions/checkout@main
- uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
# Setup .NET Core SDK
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
# Run dotnet build and publish
- name: dotnet build and publish
run: |
dotnet restore
dotnet build --configuration Release
dotnet publish -c Release --property:PublishDir='${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/myapp'
# Deploy to Azure Web apps
- name: 'Run Azure webapp deploy action using publish profile credentials'
uses: azure/webapps-deploy@v3
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }} # Replace with your app name
package: '${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/myapp'
- name: logout
run: |
az logout
Azure hizmet sorumlusu kullanarak bir ASP.NET MVC uygulaması derleyin ve Azure'a dağıtın. Örnekte , tenant-id
ve subscription-id
değerleri için client-id
GitHub gizli dizileri kullanılmaktadır. Bu değerleri doğrudan oturum açma eyleminde de geçirebilirsiniz.
name: Deploy ASP.NET MVC App deploy to Azure Web App
on: [push]
permissions:
id-token: write
contents: read
env:
AZURE_WEBAPP_NAME: my-app # 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
NUGET_VERSION: '5.3.x' # set this to the dot net version to use
jobs:
build-and-deploy:
runs-on: windows-latest
steps:
# checkout the repo
- uses: actions/checkout@main
- uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Install Nuget
uses: nuget/setup-nuget@v1
with:
nuget-version: ${{ env.NUGET_VERSION}}
- name: NuGet to restore dependencies as well as project-specific tools that are specified in the project file
run: nuget restore
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1.0.2
- name: Run MSBuild
run: msbuild .\SampleWebApplication.sln
- name: 'Run Azure webapp deploy action using publish profile credentials'
uses: azure/webapps-deploy@v3
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }} # Replace with your app name
package: '${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/SampleWebApplication/'
# Azure logout
- name: logout
run: |
az logout
Azure hizmet sorumlusu kullanarak Bir Java Spring Boot uygulaması derleyin ve Azure'a dağıtın. Örnekte , tenant-id
ve subscription-id
değerleri için client-id
GitHub gizli dizileri kullanılmaktadır. Bu değerleri doğrudan oturum açma eyleminde de geçirebilirsiniz.
name: Java CI with Maven
on: [push]
permissions:
id-token: write
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Set up JDK 1.8
uses: actions/setup-java@v3
with:
java-version: 1.8
- name: Build with Maven
run: mvn -B package --file pom.xml
working-directory: complete
- name: Azure WebApp
uses: Azure/webapps-deploy@v3
with:
app-name: my-app-name
package: my/target/*.jar
# Azure logout
- name: logout
run: |
az logout
name: Build and deploy WAR app to Azure Web App using OpenID Connect
env:
JAVA_VERSION: '11' # set this to the Java version to use
DISTRIBUTION: microsoft # set this to the Java distribution
AZURE_WEBAPP_NAME: sampleapp # set this to the name of your web app
on: [push]
permissions:
id-token: write
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Java version
uses: actions/setup-java@v3.0.0
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: ${{ env.DISTRIBUTION }}
cache: 'maven'
- name: Build with Maven
run: mvn clean install
- name: Login to Azure
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v3
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
package: '*.war'
Derleme ve dağıtım için birden çok iş kullanarak bu tam örneği bulabilirsiniz.
name: JavaScript CI
on: [push]
permissions:
id-token: write
contents: read
name: Node.js
env:
AZURE_WEBAPP_NAME: my-app # set this to your application's name
AZURE_WEBAPP_PACKAGE_PATH: 'my-app-path' # set this to the path to your web app project, defaults to the repository root
NODE_VERSION: '18.x' # set this to the node version to use
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
# checkout the repo
- name: 'Checkout GitHub Action'
uses: actions/checkout@main
- uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Setup Node ${{ env.NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: 'npm install, build, and test'
run: |
npm install
npm run build --if-present
npm run test --if-present
working-directory: my-app-path
# deploy web app using Azure credentials
- uses: azure/webapps-deploy@v3
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
# Azure logout
- name: logout
run: |
az logout
name: Python application
on:
[push]
permissions:
id-token: write
contents: read
env:
AZURE_WEBAPP_NAME: my-app # 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
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Set up Python 3.x
uses: actions/setup-python@v4
with:
python-version: 3.x
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Deploy web App using GH Action azure/webapps-deploy
uses: azure/webapps-deploy@v3
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
- name: logout
run: |
az logout
Giriş, publish-profile
daha önce oluşturduğunuz GitHub gizli dizisine başvurmalıdır AZURE_WEBAPP_PUBLISH_PROFILE
.
name: .NET Core CI
on: [push]
env:
AZURE_WEBAPP_NAME: my-app-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
DOTNET_VERSION: '6.0.x' # set this to the dot net version to use
jobs:
build:
runs-on: ubuntu-latest
steps:
# Checkout the repo
- uses: actions/checkout@main
# Setup .NET Core SDK
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
# Run dotnet build and publish
- name: dotnet build and publish
run: |
dotnet restore
dotnet build --configuration Release
dotnet publish -c Release --property:PublishDir='${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/myapp'
# Deploy to Azure Web apps
- name: 'Run Azure webapp deploy action using publish profile credentials'
uses: azure/webapps-deploy@v3
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }} # Replace with your app name
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} # Define secret variable in repository settings as per action documentation
package: '${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/myapp'
NuGet kullanan ve kimlik doğrulaması için bir ASP.NET MVC uygulaması derleyin ve publish-profile
dağıtın.
name: Deploy ASP.NET MVC App deploy to Azure Web App
on: [push]
env:
AZURE_WEBAPP_NAME: my-app # 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
NUGET_VERSION: '5.3.x' # set this to the dot net version to use
jobs:
build-and-deploy:
runs-on: windows-latest
steps:
- uses: actions/checkout@main
- name: Install Nuget
uses: nuget/setup-nuget@v1
with:
nuget-version: ${{ env.NUGET_VERSION}}
- name: NuGet to restore dependencies as well as project-specific tools that are specified in the project file
run: nuget restore
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1.0.2
- name: Run MSBuild
run: msbuild .\SampleWebApplication.sln
- name: 'Run Azure webapp deploy action using publish profile credentials'
uses: azure/webapps-deploy@v3
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }} # Replace with your app name
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} # Define secret variable in repository settings as per action documentation
package: '${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/SampleWebApplication/'
Azure yayımlama profili kullanarak Bir Java Spring Boot uygulaması derleyin ve Azure'a dağıtın. Giriş, publish-profile
daha önce oluşturduğunuz gizli diziye AZURE_WEBAPP_PUBLISH_PROFILE
başvurur.
name: Java CI with Maven
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 1.8
uses: actions/setup-java@v3
with:
java-version: 1.8
- name: Build with Maven
run: mvn -B package --file pom.xml
working-directory: my-app-path
- name: Azure WebApp
uses: Azure/webapps-deploy@v3
with:
app-name: my-app-name
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
package: my/target/*.jar
yerine bir war
jar
dağıtmak için değerini değiştirin package
.
- name: Azure WebApp
uses: Azure/webapps-deploy@v3
with:
app-name: my-app-name
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
package: my/target/*.war
Bir Azure yayımlama profili kullanarak Bir Tomcat uygulaması derleyin ve Azure'a dağıtın. Giriş, publish-profile
daha önce oluşturduğunuz gizli diziye AZURE_WEBAPP_PUBLISH_PROFILE
başvurur.
name: Build and deploy WAR app to Azure Web App using publish profile
env:
JAVA_VERSION: '11' # set this to the Java version to use
DISTRIBUTION: microsoft # set this to the Java distribution
AZURE_WEBAPP_NAME: sampleapp # set this to the name of your web app
on: [push]
permissions:
id-token: write
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Java version
uses: actions/setup-java@v3.0.0
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: ${{ env.DISTRIBUTION }}
cache: 'maven'
- name: Build with Maven
run: mvn clean install
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v3
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
package: '*.war'
Derleme ve dağıtım için birden çok iş kullanarak bu tam örneği bulabilirsiniz.
Uygulamanın yayımlama profilini kullanarak bir Node.js uygulaması derleyin ve Azure'a dağıtın. Giriş, publish-profile
daha önce oluşturduğunuz gizli diziye AZURE_WEBAPP_PUBLISH_PROFILE
başvurur.
# File: .github/workflows/workflow.yml
name: JavaScript CI
on: [push]
env:
AZURE_WEBAPP_NAME: my-app-name # set this to your application's name
AZURE_WEBAPP_PACKAGE_PATH: 'my-app-path' # set this to the path to your web app project, defaults to the repository root
NODE_VERSION: '18.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@main
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: npm install, build, and test
run: |
# Build and test the project, then
# deploy to Azure Web App.
npm install
npm run build --if-present
npm run test --if-present
working-directory: my-app-path
- name: 'Deploy to Azure WebApp'
uses: azure/webapps-deploy@v3
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
Uygulamanın yayımlama profilini kullanarak Bir Python uygulaması oluşturun ve Azure'a dağıtın. Girişin publish-profile
daha önce oluşturduğunuz gizli diziye AZURE_WEBAPP_PUBLISH_PROFILE
nasıl başvurduğunu unutmayın.
name: Python CI
on:
[push]
env:
AZURE_WEBAPP_NAME: my-web-app # 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
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.x
uses: actions/setup-python@v4
with:
python-version: 3.x
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Building web app
uses: azure/appservice-build@v2
- name: Deploy web App using GH Action azure/webapps-deploy
uses: azure/webapps-deploy@v3
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
Yapılandırdığınız hizmet sorumlusuyla dağıtmak için anahtarıyla eylemini kullanın azure/login@v2
ve daha önce oluşturduğunuz gizli diziye AZURE_CREDENTIALS
başvurun.creds
name: .NET Core
on: [push]
env:
AZURE_WEBAPP_NAME: my-app # 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
DOTNET_VERSION: '6.0.x' # set this to the dot net version to use
jobs:
build:
runs-on: ubuntu-latest
steps:
# Checkout the repo
- uses: actions/checkout@main
- uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
# Setup .NET Core SDK
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
# Run dotnet build and publish
- name: dotnet build and publish
run: |
dotnet restore
dotnet build --configuration Release
dotnet publish -c Release --property:PublishDir='${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/myapp'
# Deploy to Azure Web apps
- name: 'Run Azure webapp deploy action using Azure Credentials'
uses: azure/webapps-deploy@v3
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }} # Replace with your app name
package: '${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/myapp'
- name: logout
run: |
az logout
Azure hizmet sorumlusu kullanarak bir ASP.NET MVC uygulaması derleyin ve Azure'a dağıtın. Giriş, creds
daha önce oluşturduğunuz gizli diziye AZURE_CREDENTIALS
başvurur.
name: Deploy ASP.NET MVC App deploy to Azure Web App
on: [push]
env:
AZURE_WEBAPP_NAME: my-app # 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
NUGET_VERSION: '5.3.x' # set this to the dot net version to use
jobs:
build-and-deploy:
runs-on: windows-latest
steps:
# checkout the repo
- uses: actions/checkout@main
- uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Install Nuget
uses: nuget/setup-nuget@v1
with:
nuget-version: ${{ env.NUGET_VERSION}}
- name: NuGet to restore dependencies as well as project-specific tools that are specified in the project file
run: nuget restore
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1.0.2
- name: Run MSBuild
run: msbuild .\SampleWebApplication.sln
- name: 'Run Azure webapp deploy action using Azure Credentials'
uses: azure/webapps-deploy@v3
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }} # Replace with your app name
package: '${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/SampleWebApplication/'
# Azure logout
- name: logout
run: |
az logout
Azure hizmet sorumlusu kullanarak Bir Java Spring Boot uygulaması derleyin ve Azure'a dağıtın. Giriş, creds
daha önce oluşturduğunuz gizli diziye AZURE_CREDENTIALS
başvurur.
name: Java CI with Maven
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Set up JDK 1.8
uses: actions/setup-java@v3
with:
java-version: 1.8
- name: Build with Maven
run: mvn -B package --file pom.xml
working-directory: complete
- name: Azure WebApp
uses: Azure/webapps-deploy@v3
with:
app-name: my-app-name
package: my/target/*.jar
# Azure logout
- name: logout
run: |
az logout
Bir Azure hizmet sorumlusu kullanarak Bir Tomcat uygulaması derleyin ve Azure'a dağıtın. Giriş, creds
daha önce oluşturduğunuz gizli diziye AZURE_CREDENTIALS
başvurur.
name: Build and deploy WAR app to Azure Web App using Service Principal Connect
env:
JAVA_VERSION: '11' # set this to the Java version to use
DISTRIBUTION: microsoft # set this to the Java distribution
AZURE_WEBAPP_NAME: sampleapp # set this to the name of your web app
on: [push]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Java version
uses: actions/setup-java@v3.0.0
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: ${{ env.DISTRIBUTION }}
cache: 'maven'
- name: Build with Maven
run: mvn clean install
- name: Login to Azure
uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v3
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
package: '*.war'
Derleme ve dağıtım için birden çok iş kullanarak bu tam örneği bulabilirsiniz.
Azure hizmet sorumlusu kullanarak bir Node.js uygulaması derleyin ve Azure'a dağıtın. Giriş, creds
daha önce oluşturduğunuz gizli diziye AZURE_CREDENTIALS
başvurur.
name: JavaScript CI
on: [push]
name: Node.js
env:
AZURE_WEBAPP_NAME: my-app # set this to your application's name
AZURE_WEBAPP_PACKAGE_PATH: 'my-app-path' # set this to the path to your web app project, defaults to the repository root
NODE_VERSION: '18.x' # set this to the node version to use
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
# checkout the repo
- name: 'Checkout GitHub Action'
uses: actions/checkout@main
- uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Setup Node ${{ env.NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: 'npm install, build, and test'
run: |
npm install
npm run build --if-present
npm run test --if-present
working-directory: my-app-path
# deploy web app using Azure credentials
- uses: azure/webapps-deploy@v3
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
# Azure logout
- name: logout
run: |
az logout
Azure hizmet sorumlusu kullanarak Bir Python uygulaması derleyin ve Azure'a dağıtın. Giriş, creds
daha önce oluşturduğunuz gizli diziye AZURE_CREDENTIALS
başvurur.
name: Python application
on:
[push]
env:
AZURE_WEBAPP_NAME: my-app # 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
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Set up Python 3.x
uses: actions/setup-python@v4
with:
python-version: 3.x
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Deploy web App using GH Action azure/webapps-deploy
uses: azure/webapps-deploy@v3
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
- name: logout
run: |
az logout
Sık Sorulan Sorular
Maven eklentisi aracılığıyla bir WAR dosyası dağıtmak Nasıl yaparım??
Java Tomcat projenizi Maven eklentisiyle yapılandırmış olmanız durumunda, bu eklenti aracılığıyla Azure Uygulaması Hizmeti'ne de dağıtabilirsiniz. Azure CLI GitHub eylemini kullanırsanız Azure kimlik bilgilerinizi kullanır.
- name: Azure CLI script file
uses: azure/cli@v2
with:
inlineScript: |
mvn package azure-webapp:deploy
Maven eklentisi ve bu eklentiyi kullanma ve yapılandırma hakkında daha fazla bilgi için Azure Uygulaması Hizmeti için Maven eklentisi wiki'sine bakın.
Az CLI aracılığıyla bir WAR dosyası dağıtmak Nasıl yaparım??
App Service'e dağıtmak için Azure CLI'yı tercih ediyorsanız, Azure CLI için GitHub Eylemi'ni kullanabilirsiniz.
- name: Azure CLI script
uses: azure/cli@v2
with:
inlineScript: |
az webapp deploy --src-path '${{ github.workspace }}/target/yourpackage.war' --name ${{ env.AZURE_WEBAPP_NAME }} --resource-group ${{ env.RESOURCE_GROUP }} --async true --type war
CLI için GitHub Eylemi ve bunu kullanma ve yapılandırma hakkında daha fazla bilgi için bkz . Azure CLI GitHub eylemi.
az webapp deploy komutu, bunun nasıl kullanılacağı ve parametre ayrıntıları hakkında daha fazla bilgi için az webapp deploy belgelerine bakın.
Başlangıç dosyası Nasıl yaparım? dağıtılır?
CLI için GitHub Eylemi'ni kullanın. Örneğin:
- name: Deploy startup script
uses: azure/cli@v2
with:
inlineScript: |
az webapp deploy --src-path ${{ github.workspace }}/src/main/azure/createPasswordlessDataSource.sh --name ${{ env.AZURE_WEBAPP_NAME }} --resource-group ${{ env.RESOURCE_GROUP }} --type startup --track-status false
Kapsayıcıya dağıtım Nasıl yaparım??
Azure Web Dağıtımı eylemiyle, GitHub Actions'ı kullanarak app service'e özel kapsayıcılar dağıtmak için iş akışınızı otomatikleştirebilirsiniz. GitHub Actions kullanarak dağıtma adımları hakkında daha fazla bilgi için bkz . Kapsayıcıya dağıtma.
Dağıtımdan sonra Tomcat yapılandırmasını Nasıl yaparım? güncelleştirin?
Dağıtımdan sonra web uygulaması ayarlarınızı güncelleştirmek isterseniz App Service Ayarları eylemini kullanabilirsiniz.
- uses: azure/appservice-settings@v1
with:
app-name: 'my-app'
slot-name: 'staging' # Optional and needed only if the settings have to be configured on the specific deployment slot
app-settings-json: '[{ "name": "CATALINA_OPTS", "value": "-Dfoo=bar" }]'
connection-strings-json: '${{ secrets.CONNECTION_STRINGS }}'
general-settings-json: '{"alwaysOn": "false", "webSocketsEnabled": "true"}' #'General configuration settings as Key Value pairs'
id: settings
Bu eylem ve bunu kullanma ve yapılandırma hakkında daha fazla bilgi için bkz . App Service Ayarları deposu.
İlgili içerik
Azure GitHub Actions ve iş akışlarıyla ilgili başvurulara göz atın: