forked from shashirajraja/onlinebookstore
-
Notifications
You must be signed in to change notification settings - Fork 6
82 lines (72 loc) · 2.94 KB
/
azure-webapps-java-war-service-principal.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# This workflow will build and push a Java application to an Azure Web App when a commit is pushed to your default branch.
#
# This workflow assumes you have already created the target Azure App Service web app.
# For instructions see https://docs.microsoft.com/en-us/azure/app-service/quickstart-java?tabs=javase&pivots=platform-linux
#
# To configure this workflow:
#
# 1. Set up Service Principal deployment credentials for your workflow.
# For more information: https://learn.microsoft.com/en-us/azure/app-service/deploy-github-actions?tabs=userlevel%2Cjava#1-generate-deployment-credentials
#
# 2. Configure GitHub secrets AZURE_CREDENTIALS.
# For instructions on how to configure these: https://learn.microsoft.com/en-us/azure/app-service/deploy-github-actions?tabs=userlevel%2Cjava#2-configure-the-github-secret
#
# 3. AZURE_WEBAPP_NAME needs to be created in the Github repo under Settings > Environments.
# Create a new Environment 'Development', then create a new environment variable with the name 'AZURE_WEBAPP_NAME' and the webapp name as the value.
#
# 4. Optionally, change the JAVA_VERSION environment variable below.
#
# For more information on GitHub Actions for Azure: https://github.com/Azure/Actions
# For more information on the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# For more samples to get started with GitHub Action workflows to deploy to Azure: https://github.com/Azure/actions-workflow-samples
name: Build and deploy WAR app to Azure Web App using Service Principal
env:
JAVA_VERSION: '11' # set this to the Java version to use
DISTRIBUTION: microsoft # set this to the Java distribution
on:
push:
branches: [ "master" ]
workflow_dispatch:
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: Upload artifact for deployment job
uses: actions/upload-artifact@v3
with:
name: tomcat-bookstore-test
path: '${{ github.workspace }}/target/*.war'
deploy:
permissions:
contents: none
runs-on: ubuntu-latest
needs: build
environment:
name: 'Development'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v3
with:
name: tomcat-bookstore-test
- 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: ${{ vars.AZURE_WEBAPP_NAME }}
package: '*.war'