|
1 | 1 | ---
|
2 | 2 | page_type: sample
|
3 |
| -languages: |
4 |
| -- csharp |
5 |
| -products: |
6 |
| -- dotnet |
7 |
| -description: "Add 150 character max description" |
8 |
| -urlFragment: "update-this-to-unique-url-stub" |
| 3 | +languages: Java |
| 4 | +products: GitHub |
| 5 | +description: "Deploy Spring Petclinic application using GitHub Actions" |
| 6 | +urlFragment: "https://github.com/agoncal/agoncal-application-petstore-ee7" |
9 | 7 | ---
|
10 | 8 |
|
11 |
| -# Official Microsoft Sample |
| 9 | +# Deploying a Java Web App using GitHub actions |
12 | 10 |
|
13 |
| -<!-- |
14 |
| -Guidelines on README format: https://review.docs.microsoft.com/help/onboard/admin/samples/concepts/readme-template?branch=master |
| 11 | +Learn to deploy a Java Spring app to Azure App Service and set up a CI/CD workflow using GitHub Actions |
15 | 12 |
|
16 |
| -Guidance on onboarding samples to docs.microsoft.com/samples: https://review.docs.microsoft.com/help/onboard/admin/samples/process/onboarding?branch=master |
| 13 | +## Overview |
17 | 14 |
|
18 |
| -Taxonomies for products and languages: https://review.docs.microsoft.com/new-hope/information-architecture/metadata/taxonomies?branch=master |
19 |
| ---> |
| 15 | +**GitHub Actions** gives you the flexibility to build an automated software development lifecycle workflow. You can write individual tasks ("Actions") and combine them to create a custom workflow. Workflows are configurable automated processes that you can set up in your repository to build, test, package, release, or deploy any project on GitHub. |
20 | 16 |
|
21 |
| -Give a short description for your sample here. What does it do and why is it important? |
| 17 | +With **GitHub Actions** you can build end-to-end continuous integration (CI) and continuous deployment (CD) capabilities directly in your repository. |
22 | 18 |
|
23 |
| -## Contents |
| 19 | +### Prerequisites |
24 | 20 |
|
25 |
| -Outline the file contents of the repository. It helps users navigate the codebase, build configuration and any related assets. |
| 21 | +1. You will need a **GitHub** account. If you do not have one, you can sign up for free [here](https://github.com/join) |
26 | 22 |
|
27 |
| -| File/folder | Description | |
28 |
| -|-------------------|--------------------------------------------| |
29 |
| -| `src` | Sample source code. | |
30 |
| -| `.gitignore` | Define what to ignore at commit time. | |
31 |
| -| `CHANGELOG.md` | List of changes to the sample. | |
32 |
| -| `CONTRIBUTING.md` | Guidelines for contributing to the sample. | |
33 |
| -| `README.md` | This README file. | |
34 |
| -| `LICENSE` | The license for the sample. | |
| 23 | +1. **Microsoft Azure Account**: You will need a valid and active Azure account for this lab. If you do not have one, you can sign up for a [free trial](https://azure.microsoft.com/en-us/free/). |
35 | 24 |
|
36 |
| -## Prerequisites |
37 | 25 |
|
38 |
| -Outline the required components and tools that a user might need to have on their machine in order to run the sample. This can be anything from frameworks, SDKs, OS versions or IDE releases. |
| 26 | +### Setting up the GitHub repository |
39 | 27 |
|
40 |
| -## Setup |
| 28 | +Fork this repo and open the sample app code in VS Code to get started. |
41 | 29 |
|
42 |
| -Explain how to prepare the sample once the user clones or downloads the repository. The section should outline every step necessary to install dependencies and set up any settings (for example, API keys and output folders). |
| 30 | +## Create an Azure App Service |
43 | 31 |
|
44 |
| -## Running the sample |
| 32 | +Create a web app hosted in Azure with a unique name, **Linux** as the OS and **Java 8** as the runtime. |
45 | 33 |
|
46 |
| -Outline step-by-step instructions to execute the sample and see its output. Include steps for executing the sample from the IDE, starting specific services in the Azure portal or anything related to the overall launch of the code. |
| 34 | +## Set up CI/CD workflow with GitHub Actions |
47 | 35 |
|
48 |
| -## Key concepts |
| 36 | +We'll use GitHub actions to automate our deployment workflow for this web app. |
49 | 37 |
|
50 |
| -Provide users with more context on the tools and services used in the sample. Explain some of the code that is being used and how services interact with each other. |
| 38 | +1. Navigate to the sample CI/CD workflow file `workflow.yml` in your GitHub repo under `.github/workflows/` folder path |
| 39 | + |
| 40 | +1. Modify the values of the environment variables based on your Azure app: |
| 41 | +```yaml |
| 42 | +env: |
| 43 | + AZURE_WEBAPP_NAME: your-app-name # set this to your application's name |
| 44 | + AZURE_WEBAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root |
| 45 | + JAVA_VERSION: '1.8' # set this to the Java version to use |
| 46 | + AZURE_WEBAPP_PUBLISH_PROFILE: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} # set GH repo secret with the publish profile of the web app |
| 47 | +``` |
| 48 | +
|
| 49 | +1. In the portal, Overview page, click on "Get publish profile". A publish profile is a kind of deployment credential, useful when you don't own the Azure subscription. Open the downloaded settings file in VS Code and copy the contents of the file. |
| 50 | +
|
| 51 | +  |
| 52 | +
|
| 53 | +
|
| 54 | +1. We will now add the publish profile as a secret associated with this repo. On the GitHub repository, click on the "Settings" tab. |
| 55 | +
|
| 56 | +  |
| 57 | +
|
| 58 | +
|
| 59 | +1. Go to "Secrets". Create a new secret called "AZURE_WEBAPP_PUBLISH_PROFILE" and paste the contents from the settings file. |
| 60 | +
|
| 61 | +  |
| 62 | +
|
| 63 | +1. Once you're done editing the workflow by configuring the required environment variables, click on "Start commit". Committing the file will trigger the workflow. |
| 64 | +
|
| 65 | +1. You can go back to the Actions tab, click on your workflow, and see that the workflow is queued or being deployed. Wait for the job to complete successfully. |
| 66 | +
|
| 67 | +1. Browse your app by pasting the URL of your Azure web app: https://AZURE_WEBAPP_NAME.azurewebsites.net |
| 68 | +
|
| 69 | +1. Make any changes by editing the app contents and commit the changes. Browse to the **Actions** tab in GitHub to view the live logs of your Action workflow which got triggered with the push of the commit. |
| 70 | +
|
| 71 | +1. Once the workflow successfully completes execution, browse back to your website to visualise the new changes you introduced! |
51 | 72 |
|
52 | 73 | ## Contributing
|
53 | 74 |
|
|
0 commit comments