Commit 4eff318f authored by Dania Kodeih (Microsoft)'s avatar Dania Kodeih (Microsoft)
Browse files

Merge branch 'azure' into 'master'

Azure Pipeline Build Support

See merge request !2
parents 943af0eb 7892d0a8
Pipeline #1512 passed with stages
in 8 minutes and 53 seconds
......@@ -30,3 +30,6 @@ build/
### VS Code ###
.vscode/
### .env ###
.envrc*
variables:
AZURE_SERVICE: entitlements
AZURE_OSDU_TENANT: opendes
AZURE_COMPANY_DOMAIN: contoso.com
AZURE_VALID_GROUPNAME: integ.test.data.creator
AZURE_INVALID_GROUPNAME: InvalidTestAdmin
include:
- project: 'osdu/platform/ci-cd-pipelines'
ref: 'master'
file: 'service.gitlab-ci.yml'
file: 'standard-setup.yml'
- project: 'osdu/platform/ci-cd-pipelines'
ref: 'master'
file: 'build/maven.yml'
- project: 'osdu/platform/ci-cd-pipelines'
ref: 'master'
file: 'cloud-providers/azure.yml'
\ No newline at end of file
## All Submissions:
-------------------------------------
* [YES/NO] Have you followed our code review [guidelines](https://github.com/microsoft/code-with-engineering-playbook/blob/master/pull-requests/code-reviews/readme.md)?
* [YES/NO] Have you added an explanation of what your changes do and why you'd like us to include them?
* [YES/NO] I have updated the documentation accordingly.
* [YES/NO/NA] I have added tests to cover my changes.
* [YES/NO/NA] All new and existing tests passed.
* [YES/NO/NA] My code follows the code style of this project.
* [YES/NO/NA] I ran lint checks locally prior to submission.
## What is the current behavior?
-------------------------------------
<!-- Please describe the current behavior that you are modifying, or link to a relevant issue. -->
Issue: Remember to link the workitem to this pull request.
## What is the new behavior?
-------------------------------------
<!-- Please describe the behavior or changes that are being added by this PR. -->
-
-
-
## Does this introduce a breaking change?
-------------------------------------
- [YES/NO]
<!-- If this introduces a breaking change, please describe the impact and migration path for existing applications below. -->
## Any relevant logs, error output, etc?
-------------------------------------
(If it’s long, please paste to https://ghostbin.com/ and insert the link here.)
## Other information
-------------------------------------
<!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. -->
......@@ -26,7 +26,7 @@ This project uses [Lombok](https://projectlombok.org/) for code generation. You
- [VSCode configuration](https://projectlombok.org/setup/vscode)
### Environment Variables
### Understanding Environment Variables
In order to run the service locally, you will need to have the following environment variables defined.
......@@ -79,7 +79,7 @@ Java version: 1.8.0_212, vendor: AdoptOpenJDK, runtime: /usr/lib/jvm/jdk8u212-b0
...
```
You will need to configure access to the remote maven repository that holds the OSDU dependencies. This file should live within `~/.m2/settings.xml`:
You may need to configure access to the remote maven repository that holds the OSDU dependencies. A default file should live within `~/.m2/settings.xml`:
```bash
$ cat ~/.m2/settings.xml
<?xml version="1.0" encoding="UTF-8"?>
......@@ -98,7 +98,9 @@ $ cat ~/.m2/settings.xml
</settings>
```
### Build and run the application
_A settings file is also conveniently located in ./.mvn/community-maven.settings.xml which is also used for CI/CD processes._
### Build, Run and Test the application Locally
After configuring your environment as specified above, you can follow these steps to build and run the application
......@@ -108,19 +110,16 @@ $ mvn clean package
...
[INFO] BUILD SUCCESS
# run service
# run service locally **REQUIRES SPECIFIC ENVIRONMENT VARIABLES SET**
$ java -jar $(find ./target/ -name '*.jar')
# Test the application **REQUIRES SPECIFIC ENVIRONMENT VARIABLES SET**
$ mvn clean test -f integration-tests/pom.xml
```
### Test the application
_After the service has started it should be accessible via a web browser by visiting [http://localhost:8080/swagger-ui.html](http://localhost:8080/swagger-ui.html). If the request does not fail, you can then run the integration tests._
After the service has started it should be accessible via a web browser by visiting [http://localhost:8080/swagger-ui.html](http://localhost:8080/swagger-ui.html). If the request does not fail, you can then run the integration tests.
```bash
$ mvn clean test -f integration-tests/pom.xml
...
[INFO] BUILD SUCCESS
```
## Debugging
......@@ -165,68 +164,66 @@ As of now, the management APIs that enable user entitlements to be configured ar
}
```
## Deploying service to Azure
## Deploying the Service
Service deployments into Azure are standardized to make the process the same for all services. The steps to deploy into
Service deployments into Azure are standardized to make the process the same for all services if using ADO. The steps to deploy into
Azure can be [found here](https://github.com/Azure/osdu-infrastructure/blob/master/docs/osdu/SERVICE_DEPLOYMENTS.md)
### Manual Deployment
### Manual Deployment Steps
#### Environment Settings
__Environment Settings__
The following environment variables are necessary to properly deploy a service to an Azure OSDU Environment.
```bash
export TENANT_ID=""
export SUBSCRIPTION_ID=""
export ENV_PRINCIPAL_ID=""
export ENV_PRINCIPAL_SECRET=""
export ENV_UNIQUE=""
export ENV_SERVICE_UNIQUE=""
export OSDU_SERVICE="entitlements"
# ------------------------------------------------------------------------------------------------------
# DEPLOYMENT VARIABLES
# ------------------------------------------------------------------------------------------------------
export AZURE_TENANT_ID="${TENANT_ID}"
export AZURE_SUBSCRIPTION_ID="${SUBSCRIPTION_ID}"
export AZURE_CLIENT_ID="${ENV_PRINCIPAL_ID}"
export AZURE_CLIENT_SECRET="${ENV_PRINCIPAL_SECRET}"
export AZURE_RESOURCE_GROUP="${ENV_UNIQUE}-osdu-r2-app-rg"
export AZURE_APPSERVICE_PLAN="${ENV_UNIQUE}-osdu-r2-sp"
export AZURE_APPSERVICE_NAME="${ENV_SERVICE_UNIQUE}-au-${OSDU_SERVICE}"
```
#### Maven Settings
Deployment is performed using the [azure-webapp-maven-plugin](https://github.com/microsoft/azure-maven-plugins/wiki/Azure-Web-App).
It is important that the [settings.xml](https://maven.apache.org/settings.html#servers) file has a server block that is used by the plugin for authentication.
Settings File: _(.mvn/community-maven.settings.xml)_
```xml
<server>
<id>azure-auth</id>
<configuration>
<tenant>${env.AZURE_TENANT_ID}</tenant>
<client>${env.AZURE_CLIENT_ID}</client>
<key>${env.AZURE_CLIENT_SECRET}</key>
<environment>AZURE</environment>
</configuration>
</server>
# Group Level Variables
export AZURE_TENANT_ID=""
export AZURE_SUBSCRIPTION_ID=""
export AZURE_SUBSCRIPTION_NAME=""
export AZURE_PRINCIPAL_ID=""
export AZURE_PRINCIPAL_SECRET=""
export AZURE_APP_ID=""
export AZURE_NO_ACCESS_ID=""
export AZURE_NO_ACCESS_SECRET=""
export AZURE_OTHER_APP_ID=""
export AZURE_BASENAME_21=""
export AZURE_BASENAME=""
export AZURE_BASE=""
export AZURE_INVALID_JWT=""
# Pipeline Level Variable
export AZURE_SERVICE="entitlements"
export AZURE_OSDU_TENANT="opendes"
export AZURE_COMPANY_DOMAIN="contoso.com"
export AZURE_VALID_GROUPNAME="integ.test.data.creator"
export AZURE_INVALID_GROUPNAME="InvalidTestAdmin"
# Required for Azure Deployment
export AZURE_CLIENT_ID="${AZURE_PRINCIPAL_ID}"
export AZURE_CLIENT_SECRET="${AZURE_PRINCIPAL_SECRET}"
export AZURE_RESOURCE_GROUP="${AZURE_BASENAME}-osdu-r2-app-rg"
export AZURE_APPSERVICE_PLAN="${AZURE_BASENAME}-osdu-r2-sp"
export AZURE_APPSERVICE_NAME="${AZURE_BASENAME_21}-au-${AZURE_SERVICE}"
# Required for Testing
export ENTITLEMENT_URL="https://${AZURE_BASENAME_21}-au-entitlements.azurewebsites.net/"
export AZURE_AD_TENANT_ID="${AZURE_TENANT_ID}"
export INTEGRATION_TESTER="${AZURE_PRINCIPAL_ID}"
export ENTITLEMENT_MEMBER_NAME_VALID="${AZURE_PRINCIPAL_ID}"
export AZURE_TESTER_SERVICEPRINCIPAL_SECRET="${AZURE_PRINCIPAL_SECRET}"
export AZURE_AD_APP_RESOURCE_ID="${AZURE_APP_ID}"
export AZURE_AD_OTHER_APP_RESOURCE_ID="${AZURE_OTHER_APP_ID}"
export EXPIRED_TOKEN="${AZURE_INVALID_JWT}"
export DOMAIN="${AZURE_COMPANY_DOMAIN}"
export MY_TENANT="${AZURE_OSDU_TENANT}"
export ENTITLEMENT_GROUP_NAME_VALID="${AZURE_VALID_GROUPNAME}"
export ENTITLEMENT_MEMBER_NAME_INVALID="${AZURE_INVALID_GROUPNAME}"
```
### Maven Package and Deploy
__Azure Service Deployment__
The service is typically built by the CI/CD Pipeline with the jar file is deployed into the Project Level Package Repository. This is configured in the pom.xml file _distributionManagement_ block. It is possible _(not recommened)_ to build and deploy the package into a repository manually using a PAT Token with a sufficent authorization level configured as an environment variable `COMMUNITY_MAVEN_TOKEN`.
```bash
export COMMUNITY_MAVEN_TOKEN="<your_personal_access_token>"
mvn --settings .mvn/community-maven.settings.xml clean package deploy
```
### Azure Deploy
Manually deploy the service using the Maven Plugin
1. Deploy the service using the Maven Plugin _(azure_deploy)_
```bash
mvn --settings .mvn/community-maven.settings.xml azure-webapp:deploy \
......@@ -239,13 +236,15 @@ mvn --settings .mvn/community-maven.settings.xml azure-webapp:deploy \
-Dazure.appservice.appname=$AZURE_APPSERVICE_NAME
```
Set the Web App Configuration to start the deployed SpringBoot Application
2. Configure the Web App to start the SpringBoot Application _(azure_config)_
```bash
az login --service-principal -u $AZURE_CLIENT_ID -p $AZURE_CLIENT_SECRET --tenant $AZURE_TENANT_ID
# Set the JAR FILE as required
JAR_FILE="entitlements-0.0.3-SNAPSHOT.jar"
TARGET=$(find ./target/ -name '*.jar')
JAR_FILE=${TARGET##*/}
JAVA_COMMAND="java -jar /home/site/wwwroot/${JAR_FILE}"
JSON_TEMPLATE='{"appCommandLine":"%s"}'
......@@ -255,6 +254,13 @@ echo $(printf "$JSON_TEMPLATE" "$JAVA_COMMAND") > $JSON_FILE
az webapp config set --resource-group $AZURE_RESOURCE_GROUP --name $AZURE_APPSERVICE_NAME --generic-configurations @$JSON_FILE
```
3. Execute the Integration Tests against the Service Deployment _(azure_test)_
```bash
mvn --settings ./.mvn/community-maven.settings.xml clean test -f integration-tests/pom.xml
```
## License
Copyright © Microsoft Corporation
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment