Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sessions/8 #5

Merged
merged 5 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 103 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ Everything discussed in the Twitch live sessions for MuleSoft beginners.

## 🗓️ Next session

The next session is scheduled for `Aug 2, 2023` at `1:30pm ET`.
The next session is scheduled for `Aug 9, 2023` at `1:30pm ET`.

- API Manager
- CI/CD with GitHub Actions
- Maven
- Secured/encrypted properties
- MUnit manually
- MUnit CI/CD
- Postman
- Mention BAT CLI

---

Expand All @@ -30,6 +30,7 @@ The next session is scheduled for `Aug 2, 2023` at `1:30pm ET`.
| 5 | Develop the API in Anypoint Studio | We created a new Mule project with the scaffolded flows from the published API specification and started our API implementation / development. More info [here](https://medium.com/another-integration-blog/mulesoft-from-start-a-beginners-guide-session-5-develop-the-api-in-anypoint-studio-a7dcfc43655c). | [Full video (1h19m)](https://www.twitch.tv/videos/1864154096) | [Edited video (37m)](https://youtu.be/K9ntwKz9vds)
| 6 | Debug the Mule App in Anypoint Studio | We reviewed how to implement the articles logic, created a Postman collection with its local+dev environments, and learned how to debug our Mule application. More info [here](https://medium.com/another-integration-blog/mulesoft-from-start-a-beginners-guide-session-6-debug-the-mule-app-in-anypoint-studio-ab7602d5b788). | [Full video (1h)](https://www.twitch.tv/videos/1876220306) | [Edited video (39m)](https://youtu.be/75IJ1WFa9iA)
| 7 | Deploy the Mule App to CloudHub (Runtime Manager) | We confirmed the API works locally, so we deployed it to CloudHub (located in Runtime Manager) to test it in the dev environment. More info [here](https://medium.com/another-integration-blog/mulesoft-from-start-a-beginners-guide-session-7-deploy-the-mule-app-to-cloudhub-363fc1239b3). | - [Part 1 Full video (18m)](https://www.twitch.tv/videos/1882370337) - [Part 2 Full video (1h2m)](https://www.twitch.tv/videos/1882370336) | [Edited video (14m)](https://youtu.be/SUwnqoq8ZbI)
| 8 | Set up CI/CD & API Autodiscovery (API Manager) | We connected our Mule app from Runtime Manager to our API in API Manager to apply security policies using API Autodiscovery. We learned how to apply CI/CD pipelines to our local project and how to do them using GitHub Actions. | [Full video (1h15m)](https://www.twitch.tv/videos/1888369792) | Edited video tbd

---

Expand Down Expand Up @@ -437,12 +438,104 @@ Finish creating the rest of the requests in Postman from our API specification.

</details>

### ◻️ Session 8
### Session 8

- API Manager (Autodiscovery)
- CI/CD with GitHub Actions
- Maven
- Secured/encrypted properties
<details>
<summary>Set up CI/CD & API Autodiscovery</summary>

- Step 1: Retrieve your Anypoint Platform credentials:
- Access Management > Business Groups > select your business group > Environments > Sandbox (or your environment)
- Here you can retrieve your Client ID and Client Secret, which we'll refer to as:
- `ap.client.id` & `ap.client.secret` from the Maven command
- `anypoint.platform.client_id` & `anypoint.platform.client_secret` from the Mule app's properties
- Step 2: Retrieve your Connected App's credentials:
- Access Management > Connected Apps > Create app > App acts on it's own behalf
- Scopes:
- Design Center Developer
- View Environment
- View Organization
- Profile
- Cloudhub Organization Admin
- Create Applications
- Delete Applications
- Download Applications
- Read Applications
- Read Servers
- Retrieve Client ID and Client Secret, which we'll refer to as:
- `CONNECTED_APP_CLIENT_ID` & `CONNECTED_APP_CLIENT_SECRET` from GitHub Actions secrets
- `connectedapp.client.id` & `connectedapp.client.secret` from the Maven command
- Step 3: Modify your `pom.xml`:

```xml
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>${mule.maven.plugin.version}</version>
<extensions>true</extensions>
<!-- Deployment config start -->
<configuration>
<cloudHubDeployment>
<uri>https://anypoint.mulesoft.com</uri>
<muleVersion>4.4.0</muleVersion>
<applicationName>maxines-blog</applicationName>
<environment>Sandbox</environment>
<workerType>MICRO</workerType>
<region>us-east-2</region>
<workers>1</workers>
<objectStoreV2>true</objectStoreV2>
<connectedAppClientId>${connectedapp.client.id}</connectedAppClientId>
<connectedAppClientSecret>${connectedapp.client.secret}</connectedAppClientSecret>
<connectedAppGrantType>client_credentials</connectedAppGrantType>
<properties>
<env>dev</env>
<anypoint.platform.client_id>${ap.client.id}</anypoint.platform.client_id>
<anypoint.platform.client_secret>${ap.client.secret}</anypoint.platform.client_secret>
</properties>
</cloudHubDeployment>
</configuration>
<!-- Deployment config end -->
</plugin>
```

- Step 4: If you want to set it up with GitHub Actions, you can follow [this quick reference](https://dev.to/devalexmartinez/quick-reference-cicd-for-a-mule-app-using-a-connected-app-jlj)
- Make sure you add the actual credentials to the GitHub secrets in Settings > Secrets and variables > Actions > New repository secret
- `CONNECTED_APP_CLIENT_ID`
- `CONNECTED_APP_CLIENT_SECRET`
- `ANYPOINT_PLATFORM_CLIENT_ID`
- `ANYPOINT_PLATFORM_CLIENT_SECRET`
- And make sure you modify the maven command to include all 4 credentials. Like so:

```sh
mvn deploy -DskipMunitTests -DmuleDeploy \
-Dmule.artifact=$artifactName \
-Dconnectedapp.client.id="${{ secrets.CONNECTED_APP_CLIENT_ID }}" \
-Dconnectedapp.client.secret="${{ secrets.CONNECTED_APP_CLIENT_SECRET }}" \
-Dap.client.id="${{ secrets.ANYPOINT_PLATFORM_CLIENT_ID }}" \
-Dap.client.secret="${{ secrets.ANYPOINT_PLATFORM_CLIENT_SECRET }}"
```

- Step 5: If you want to test this locally (as we did on the session), you just have to run the Maven command in your Terminal with your actual credentials. Like so:

```sh
mvn deploy -DskipMunitTests -DmuleDeploy \
-Dconnectedapp.client.id="ae0bd2e7fd154c3adf1cc934543a07e" \
-Dconnectedapp.client.secret="2Da6676dad64640B265D9Cc35830478" \
-Dap.client.id="5e09b8bf52394797b5035978b74aee1" \
-Dap.client.secret="D4dD12915E3D29d9aB436AA0849c519"
```

</details>

<details>
<summary>Links & Resources</summary>

**Resources**

- [Deploy Applications to CloudHub Using the Mule Maven Plugin](https://docs.mulesoft.com/mule-runtime/latest/deploy-to-cloudhub)
- [Deploy Applications to CloudHub 2.0 Using the Mule Maven Plugin](https://docs.mulesoft.com/mule-runtime/latest/deploy-to-cloudhub-2)
- [Quick reference: CI/CD for a Mule app using a Connected App](https://dev.to/devalexmartinez/quick-reference-cicd-for-a-mule-app-using-a-connected-app-jlj)

</details>

### ◻️ Session 9

Expand Down
43 changes: 39 additions & 4 deletions postman/mulesoft-from-start.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"id\": 3,\n \"title\": \"The Importance of Regular Exercise\",\n \"content\": \"Lorem \",\n \"writer\": {\n \"id\": 1,\n \"name\": \"Esmeralda\",\n \"bio\": \"20+ years of experience in IT and very smart.\"\n },\n \"category\": \"Example\",\n \"comments\": [\n {\n \"id\": 1,\n \"content\": \"Hey, this was a nice post!\",\n \"author\": \"Alex Martinez\"\n }\n ],\n \"slug\": \"importance-of-regular-exercise\"\n}",
"raw": "{\n \"id\": 3,\n \"title\": \"The Importance of Regular Exercise\",\n \"content\": \"Lorem \",\n \"writer\": {\n \"id\": 1,\n \"name\": \"Esmeralda\",\n \"bio\": \"20+ years of experience in IT and very smart.\"\n },\n \"category\": \"Exercise\",\n \"comments\": [\n {\n \"id\": 1,\n \"content\": \"Hey, this was a nice post!\",\n \"author\": \"Alex Martinez\"\n }\n ],\n \"slug\": \"importance-of-regular-exercise\"\n}",
"options": {
"raw": {
"language": "json"
Expand Down Expand Up @@ -103,13 +103,13 @@
"method": "DELETE",
"header": [],
"url": {
"raw": "{{host}}/articles/8",
"raw": "{{host}}/articles/5",
"host": [
"{{host}}"
],
"path": [
"articles",
"8"
"5"
]
}
},
Expand Down Expand Up @@ -368,7 +368,7 @@
"query": [
{
"key": "categoryName",
"value": "MuleSoft",
"value": "dataweave",
"disabled": true
}
]
Expand Down Expand Up @@ -430,5 +430,40 @@
}
]
}
],
"auth": {
"type": "basic",
"basic": [
{
"key": "username",
"value": "foo1",
"type": "string"
},
{
"key": "password",
"value": "bar1",
"type": "string"
}
]
},
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
]
}
49 changes: 49 additions & 0 deletions sessions/8/in-session-mule-project/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# ------------------------------------------------------------------------------ #
# Java defaults (https://github.com/github/gitignore/blob/master/Java.gitignore) #
# ------------------------------------------------------------------------------ #
*.class

# Package Files #
*.jar
*.war
*.ear

# ------------------------------------------------------------------------------------------- #
# Eclipse-specific (https://github.com/github/gitignore/blob/master/Global/Eclipse.gitignore) #
# ------------------------------------------------------------------------------------------- #
*.pydevproject
.metadata
bin/**
tmp/**
tmp/**/*
*.tmp
*.bak
*.swp
*~.nib
# local.properties
.settings/
.loadpath
.project
.classpath

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# CDT-specific
.cproject

# PDT-specific
.buildpath

# --------------- #
# Studio-specific #
# --------------- #
target/
.mule/
.DS_Store
velocity.log
src/main/resources/application-types.xml
src/main/resources/weave
Empty file.
7 changes: 7 additions & 0 deletions sessions/8/in-session-mule-project/mule-artifact.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"minMuleVersion": "4.4.0",
"secureProperties": [
"anypoint.platform.client_id",
"anypoint.platform.client_secret"
]
}
121 changes: 121 additions & 0 deletions sessions/8/in-session-mule-project/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.mycompany</groupId>
<artifactId>maxines-blog</artifactId>
<version>1.0.3</version>
<packaging>mule-application</packaging>

<name>maxines-blog</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<app.runtime>4.4.0-20230320</app.runtime>
<mule.maven.plugin.version>3.8.2</mule.maven.plugin.version>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.2.0</version>
</plugin>
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>${mule.maven.plugin.version}</version>
<extensions>true</extensions>
<!-- Deployment config start -->
<configuration>
<cloudHubDeployment>
<uri>https://anypoint.mulesoft.com</uri>
<muleVersion>4.4.0</muleVersion>
<applicationName>maxines-blog</applicationName>
<environment>Sandbox</environment>
<workerType>MICRO</workerType>
<region>us-east-2</region>
<workers>1</workers>
<objectStoreV2>true</objectStoreV2>
<connectedAppClientId>${connectedapp.client.id}</connectedAppClientId>
<connectedAppClientSecret>${connectedapp.client.secret}</connectedAppClientSecret>
<connectedAppGrantType>client_credentials</connectedAppGrantType>
<properties>
<env>dev</env>
<anypoint.platform.client_id>${ap.client.id}</anypoint.platform.client_id>
<anypoint.platform.client_secret>${ap.client.secret}</anypoint.platform.client_secret>
</properties>
</cloudHubDeployment>
</configuration>
<!-- Deployment config end -->
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.mule.connectors</groupId>
<artifactId>mule-http-connector</artifactId>
<version>1.7.3</version>
<classifier>mule-plugin</classifier>
</dependency>
<dependency>
<groupId>org.mule.connectors</groupId>
<artifactId>mule-sockets-connector</artifactId>
<version>1.2.3</version>
<classifier>mule-plugin</classifier>
</dependency>
<dependency>
<groupId>org.mule.modules</groupId>
<artifactId>mule-apikit-module</artifactId>
<version>1.8.2</version>
<classifier>mule-plugin</classifier>
</dependency>
<dependency>
<groupId>org.mule.connectors</groupId>
<artifactId>mule-objectstore-connector</artifactId>
<version>1.2.1</version>
<classifier>mule-plugin</classifier>
</dependency>
<dependency>
<groupId>4ff8cd06-fff6-4ccb-8ac0-a74161c96108</groupId>
<artifactId>maxines-blog-api</artifactId>
<version>1.0.3</version>
<classifier>raml</classifier>
<type>zip</type>
</dependency>
</dependencies>

<repositories>
<repository>
<id>anypoint-exchange-v3</id>
<name>Anypoint Exchange</name>
<url>https://maven.anypoint.mulesoft.com/api/v3/maven</url>
<layout>default</layout>
</repository>
<repository>
<id>mulesoft-releases</id>
<name>MuleSoft Releases Repository</name>
<url>https://repository.mulesoft.org/releases/</url>
<layout>default</layout>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>mulesoft-releases</id>
<name>MuleSoft Releases Repository</name>
<layout>default</layout>
<url>https://repository.mulesoft.org/releases/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>

</project>
Loading