Alur kerja ditentukan oleh file YAML (.yml) di jalur /.github/workflows/ di repositori Anda. Definisi ini berisi berbagai langkah dan parameter yang membentuk alur kerja.
File memiliki tiga bagian:
Bagian
Tugas
Autentikasi
1. Tentukan prinsipal layanan atau profil penerbitan. 2. Buat rahasia GitHub.
Build
1. Siapkan lingkungan. 2. Bangun aplikasi web.
Sebarkan
1. Sebarkan aplikasi web.
Menggunakan Pusat Penyebaran
Anda dapat dengan cepat memulai GitHub Actions menggunakan Pusat Penyebaran App Service. Hal ini akan secara otomatis menghasilkan file alur kerja berdasarkan tumpukan aplikasi Anda dan menetapkannya ke repositori GitHub pada direktori yang benar.
Buka webapp Anda pada portal Microsoft Azure
Di sebelah kiri, klik Pusat Penyebaran
Pada Penyebaran Berkelanjutan (CI/CD) , pilih GitHub
Berikutnya, pilih GitHub Actions
Gunakan dropdown untuk memilih repositori, cabang, dan tumpukan aplikasi GitHub Anda
Jika cabang yang dipilih dilindungi, Anda dapat melanjutkan untuk menambahkan file alur kerja. Pastikan untuk meninjau perlindungan cabang Anda sebelum melanjutkan.
Pada layar akhir, Anda dapat meninjau pilihan Anda dan meninjau file alur kerja yang akan ditetapkan pada repositori. Jika pilihan sudah benar, klik Selesai
Ini akan menetapkan file alur kerja ke repositori. Alur kerja untuk membangun dan menyebarkan aplikasi akan segera dimulai.
Menyiapkan alur kerja secara manual
Anda juga dapat menyebarkan alur kerja tanpa menggunakan Pusat Penyebaran. Untuk melakukannya, pertama Anda perlu menghasilkan info masuk penyebaran.
Hasilkan kredensial penyebaran
Cara yang disarankan untuk mengautentikasi dengan Azure App Services untuk GitHub Actions adalah dengan profil penerbitan. Anda juga dapat mengautentikasi dengan perwakilan layanan atau Open ID Connect, tetapi prosesnya memerlukan lebih banyak langkah.
Simpan info masuk profil penerbitan atau perwakilan layanan Anda sebagai rahasia GitHub untuk mengautentikasi dengan Azure. Anda akan mengakses rahasia dalam alur kerja Anda.
Profil penerbitan adalah info masuk tingkat aplikasi. Siapkan profil penerbitan Anda sebagai rahasia GitHub.
Buka layanan aplikasi Anda di portal Microsoft Azure.
Pada halaman Ringkasan, pilih Dapatkan profil Penerbitan.
Simpan file yang diunduh. Anda akan menggunakan isi file tersebut untuk membuat rahasia GitHub.
Catatan
Mulai Oktober 2020, aplikasi web Linux akan memerlukan pengaturan aplikasi WEBSITE_WEBDEPLOY_USE_SCM untuk diatur ke truesebelum mengunduh profil penerbitan. Persyaratan ini akan dihapus di masa mendatang.
az ad sp create-for-rbac --name "myApp" --role contributor \
--scopes /subscriptions/<subscription-id>/resourceGroups/<group-name>/providers/Microsoft.Web/sites/<app-name> \
--sdk-auth
Pada contoh di atas, ganti tempat penampung dengan ID langganan, nama grup sumber daya, dan nama aplikasi Anda. Output adalah objek JSON dengan kredensial penetapan peran yang menyediakan akses ke App Service yang serupa di bawah ini. Salin objek JSON ini untuk nanti.
Ini selalu merupakan praktik yang baik untuk memberikan akses minimum. Cakupan dalam contoh sebelumnya terbatas pada aplikasi App Service tertentu dan bukan seluruh grup sumber daya.
OpenID Connect adalah metode autentikasi yang menggunakan token yang berumur pendek. Menyiapkan OpenID Connect dengan GitHub Actions merupakan proses lebih kompleks yang menawarkan keamanan yang sulit.
Perintah ini akan menghasilkan JSON dengan appId JSON yang merupakan client-id Anda. Simpan nilai untuk digunakan sebagai AZURE_CLIENT_ID GitHub rahasia di kemudian hari.
Anda akan menggunakan nilai objectId saat membuat info masuk federasi dengan Graph API dan mereferensikannya sebagai APPLICATION-OBJECT-ID.
Buat Perwakilan Layanan. Ganti $appID dengan appId dari output JSON Anda.
Perintah ini menghasilkan output JSON dengan objectId yang berbeda dan akan digunakan dalam langkah berikutnya. objectId yang baru adalah assignee-object-id.
Salin appOwnerTenantId untuk digunakan sebagai GitHub rahasia untuk AZURE_TENANT_ID nanti.
az ad sp create --id $appId
Membuat penetapan peran baru berdasarkan langganan dan objek. Secara default, penetapan peran akan terikat dengan langganan default Anda. Ganti $subscriptionId dengan ID langganan Anda, $resourceGroupName dengan nama grup sumber daya Anda, dan $assigneeObjectId dengan assignee-object-id yang dihasilkan. Pelajari cara mengelola langganan Azure dengan Azure CLI.
az role assignment create --role contributor --subscription $subscriptionId --assignee-object-id $assigneeObjectId --scopes /subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.Web/sites/--assignee-principal-type ServicePrincipal
Ganti APPLICATION-OBJECT-ID dengan objectId (dihasilkan saat membuat aplikasi) untuk aplikasi Active Directory Domain Services Anda.
Tetapkan nilai untuk CREDENTIAL-NAME untuk referensi nanti.
Set subject. Nilai ini ditentukan oleh GitHub tergantung pada alur kerja Anda:
Pekerjaan dalam lingkungan GitHub Actions Anda: repo:< Organization/Repository >:environment:< Name >
Untuk Pekerjaan yang tidak terikat dengan lingkungan, sertakan jalur referensi untuk cabang/tag berdasarkan jalur referensi yang digunakan untuk memicu alur kerja: repo:< Organization/Repository >:ref:< ref path>. Misalnya, repo:n-username/ node_express:ref:refs/heads/my-branch atau repo:n-username/ node_express:ref:refs/tags/my-tag.
Untuk alur kerja yang dipicu oleh peristiwa permintaan tarik: repo:< Organization/Repository >:pull_request.
az rest --method POST --uri 'https://graph.microsoft.com/beta/applications/<APPLICATION-OBJECT-ID>/federatedIdentityCredentials' --body '{"name":"<CREDENTIAL-NAME>","issuer":"https://token.actions.githubusercontent.com","subject":"repo:organization/repository:ref:refs/heads/main","description":"Testing","audiences":["api://AzureADTokenExchange"]}'
Untuk mempelajari cara membuat Membuat aplikasi direktori aktif, perwakilan layanan, dan informasi masuk gabungan di portal Azure, lihat Sambungkan GitHub dan Azure.
Untuk menggunakan info masuk tingkat aplikasi, tempelkan isi file profil penerbitan yang diunduh ke bidang nilai rahasia. Beri nama rahasia AZURE_WEBAPP_PUBLISH_PROFILE.
Ketika mengonfigurasi alur kerja GitHub, Anda menggunakan AZURE_WEBAPP_PUBLISH_PROFILE pada tindakan sebarkan Azure Web App. Contohnya:
Untuk menggunakan info masuk tingkat pengguna, tempelkan seluruh output JSON dari perintah Azure CLI ke dalam bidang nilai rahasia. Berikan nama pada rahasia AZURE_CREDENTIALS.
Saat Anda mengonfigurasi file alur kerja nanti, Anda menggunakan rahasia untuk input creds tindakan Masuk Azure. Contohnya:
Anda perlu menyediakan ID Klien, ID Penyewa, dan ID Langganan aplikasi Anda untuk tindakan login. Nilai ini bisa disediakan secara langsung di alur kerja atau bisa disimpan di rahasia GitHub dan direferensikan dalam alur kerja Anda. Menyimpan nilai sebagai GitHub rahasia adalah opsi yang lebih aman.
Buka repositori GitHub Anda dan buka Pengaturan.
Membuat rahasia untuk AZURE_CLIENT_ID, AZURE_TENANT_ID, dan AZURE_SUBSCRIPTION_ID. Gunakan nilai-nilai ini dari aplikasi Active Directory Domain Services Anda untuk GitHub rahasia Anda:
GitHub Rahasia
Aplikasi Active Directory Domain Services
AZURE_CLIENT_ID
ID (klien) Aplikasi
AZURE_TENANT_ID
ID direktori (penyewa)
AZURE_SUBSCRIPTION_ID
ID Langganan
Simpan setiap rahasia dengan memilih Tambahkan rahasia.
Menyiapkan lingkungan
Menyiapkan lingkungan dapat dilakukan menggunakan salah satu tindakan penyiapan.
Bahasa
Tindakan Penyiapan
.NET
actions/setup-dotnet
ASP.NET
actions/setup-dotnet
Java
actions/setup-java
JavaScript
actions/setup-node
Python
actions/setup-python
Contoh berikut menunjukkan cara menyiapkan lingkungan untuk berbagai bahasa yang didukung:
- name: Setup Java 1.8.x
uses: actions/setup-java@v1
with:
# If your pom.xml <maven.compiler.source> version is not in 1.8.x,
# change the Java version to match the version in pom.xml <maven.compiler.source>
java-version: '1.8.x'
JavaScript
env:
NODE_VERSION: '14.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@v1
with:
node-version: ${{ env.NODE_VERSION }}
Anda dapat memulihkan dependensi NuGet dan menjalankan msbuild dengan run.
- 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
Java
- name: Build with Maven
run: mvn package --file pom.xml
JavaScript
Untuk Node.js, Anda dapat mengatur working-directory atau mengubah direktori npm di pushd.
- name: npm install, build, and test
run: |
npm install
npm run build --if-present
npm run test --if-present
working-directory: my-app-folder # set to the folder with your app if it is not the root directory
Bangun dan sebarkan aplikasi .NET Core ke Azure menggunakan profil penerbitan Azure. Input publish-profile mereferensikan rahasia AZURE_WEBAPP_PUBLISH_PROFILE yang Anda buat sebelumnya.
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: '3.1.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@v1
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 -o '${{ 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@v2
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'
ASP.NET
Bangun dan sebarkan aplikasi ASP.NET MVC yang menggunakan NuGet dan publish-profile untuk autentikasi.
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@v2
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/'
Java
Bangun dan sebarkan aplikasi Java Spring ke Azure menggunakan profil penerbitan Azure. Input publish-profile mereferensikan rahasia AZURE_WEBAPP_PUBLISH_PROFILE yang Anda buat sebelumnya.
name: Java CI with Maven
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
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@v2
with:
app-name: my-app-name
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
package: my/target/*.jar
Untuk menyebarkan war alih-alih jar, ubah nilai package.
Bangun dan sebarkan aplikasi Node.js ke Azure menggunakan profil penerbitan aplikasi. Input publish-profile mereferensikan rahasia AZURE_WEBAPP_PUBLISH_PROFILE yang Anda buat sebelumnya.
# 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: '14.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@v1
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@v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
Python
Bangun dan sebarkan aplikasi Python ke Azure menggunakan profil penerbitan aplikasi. Perhatikan bagaimana input publish-profile mereferensikan rahasia AZURE_WEBAPP_PUBLISH_PROFILE yang Anda buat sebelumnya.
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@v2
- name: Set up Python 3.x
uses: actions/setup-python@v2
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@v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
.NET Core
Bangun dan sebarkan aplikasi .NET Core ke Azure menggunakan prinsipal layanan Azure. Perhatikan bagaimana input creds mereferensikan rahasia AZURE_CREDENTIALS yang Anda buat sebelumnya.
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: '3.1.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@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
# Setup .NET Core SDK
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
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 -o '${{ 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@v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }} # Replace with your app name
package: '${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/myapp'
- name: logout
run: |
az logout
ASP.NET
Bangun dan sebarkan aplikasi ASP.NET MVC ke Azure menggunakan prinsipal layanan Azure. Perhatikan bagaimana input creds mereferensikan rahasia AZURE_CREDENTIALS yang Anda buat sebelumnya.
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@v1
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 publish profile credentials'
uses: azure/webapps-deploy@v2
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
Java
Bangun dan sebarkan aplikasi Java Spring ke Azure menggunakan prinsipal layanan Azure. Perhatikan bagaimana input creds mereferensikan rahasia AZURE_CREDENTIALS yang Anda buat sebelumnya.
name: Java CI with Maven
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Set up JDK 1.8
uses: actions/setup-java@v1
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@v2
with:
app-name: my-app-name
package: my/target/*.jar
# Azure logout
- name: logout
run: |
az logout
JavaScript
Bangun dan sebarkan aplikasi Node.js ke Azure menggunakan prinsipal layanan Azure. Perhatikan bagaimana input creds mereferensikan rahasia AZURE_CREDENTIALS yang Anda buat sebelumnya.
name: JavaScript CI
on: [push]
name: Node.js
env:
AZURE_WEBAPP_NAME: my-app # set this to your application's name
NODE_VERSION: '14.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@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Setup Node ${{ env.NODE_VERSION }}
uses: actions/setup-node@v1
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@v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
# Azure logout
- name: logout
run: |
az logout
Python
Bangun dan sebarkan aplikasi Python ke Azure menggunakan prinsipal layanan Azure. Perhatikan bagaimana input creds mereferensikan rahasia AZURE_CREDENTIALS yang Anda buat sebelumnya.
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@v2
- uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Set up Python 3.x
uses: actions/setup-python@v2
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@v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
- name: logout
run: |
az logout
.NET Core
Bangun dan sebarkan aplikasi .NET Core ke Azure menggunakan prinsipal layanan Azure. Contoh ini menggunakan rahasia GitHub untuk nilai-nilai client-id, tenant-id, dan subscription-id. Anda juga dapat meneruskan nilai-nilai ini langsung dalam tindakan login.
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: '3.1.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@v1
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@v1
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 -o '${{ 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@v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }} # Replace with your app name
package: '${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/myapp'
- name: logout
run: |
az logout
ASP.NET
Bangun dan sebarkan aplikasi ASP.NET MVC ke Azure menggunakan prinsipal layanan Azure. Contoh ini menggunakan rahasia GitHub untuk nilai-nilai client-id, tenant-id, dan subscription-id. Anda juga dapat meneruskan nilai-nilai ini langsung dalam tindakan login.
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@v1
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@v2
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
Java
Bangun dan sebarkan aplikasi Java Spring ke Azure menggunakan prinsipal layanan Azure. Contoh ini menggunakan rahasia GitHub untuk nilai-nilai client-id, tenant-id, dan subscription-id. Anda juga dapat meneruskan nilai-nilai ini langsung dalam tindakan login.
Bangun dan sebarkan aplikasi Node.js ke Azure menggunakan prinsipal layanan Azure. Contoh ini menggunakan rahasia GitHub untuk nilai-nilai client-id, tenant-id, dan subscription-id. Anda juga dapat meneruskan nilai-nilai ini langsung dalam tindakan login.
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
NODE_VERSION: '14.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@v1
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@v1
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@v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
# Azure logout
- name: logout
run: |
az logout
Python
Bangun dan sebarkan aplikasi Python ke Azure menggunakan prinsipal layanan Azure. Contoh ini menggunakan rahasia GitHub untuk nilai-nilai client-id, tenant-id, dan subscription-id. Anda juga dapat meneruskan nilai-nilai ini langsung dalam tindakan login.
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@v2
- uses: azure/login@v1
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@v2
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@v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
- name: logout
run: |
az logout
Langkah berikutnya
Anda dapat menemukan set Tindakan yang dikelompokkan ke berbagai repositori pada GitHub, masing-masing berisi dokumentasi dan contoh untuk membantu Anda menggunakan GitHub untuk CI/CD dan menyebarkan aplikasi ke Azure.