You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/workshop.md
+220-9Lines changed: 220 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -1639,7 +1639,7 @@ After you're done testing, you can stop the application by pressing `Ctrl+C` in
1639
1639
1640
1640
## Azure setup
1641
1641
1642
-
Azure is a cloud platform that provides a wide range of services to build, deploy, and manage applications. We'll use various Azure services inthis workshop to host our application.
1642
+
Azure is Microsoft's cloud platform. It provides a wide range of services to build, deploy, and manage applications. We'll use a few of them in this workshop to run our application.
1643
1643
1644
1644
First, you need to make sure you have an Azure account. If you don't have one, you can create a free account including Azure credits on the [Azure website](https://azure.microsoft.com/free/).
1645
1645
@@ -1662,19 +1662,151 @@ This script uses the [Azure CLI](https://learn.microsoft.com/cli/azure) and [Git
1662
1662
- Login into your GitHub account
1663
1663
- Add the `AZURE_CREDENTIALS` secret to your GitHub repository, with your the service principal token
1664
1664
1665
+
Before reading further, let's run the script that will create all the Azure resources we'll need for this workshop, as it will take a few minutes to complete (we'll explain what it does a bit later):
To run and monitor our application, we'll use various Azure services:
1678
+
1679
+
| Service | Description |
1680
+
|-------|-----------|
1681
+
| [Azure Container Apps](https://learn.microsoft.com/azure/container-apps/) | A managed service to run containers in Azure, with built-in load balancing, auto-scaling, and more. |
1682
+
| [Azure Static Web Apps](https://learn.microsoft.com/azure/static-web-apps/) | A service to host websites, with built-in authentication, serverless API functions or proxy, Edge CDN and more. |
1683
+
| [Azure Cosmos DB](https://learn.microsoft.com/azure/cosmos-db/) | A NoSQL globally distributed database, that supports SQL, MongoDB, Cassandra, Gremlin, and Azure Table storage APIs. |
1684
+
| [Azure Container Registry](https://learn.microsoft.com/azure/container-registry/) | A container registry to store and manage container images. |
1685
+
| [Azure Log Analytics](https://learn.microsoft.com/azure/log-analytics/) | A service to collect and analyze logs from your Azure resources. |
1686
+
| [Azure Monitor](https://learn.microsoft.com/azure/azure-monitor/) | A service to monitor your Azure resources, with built-in dashboards, alerts, and more. |
1687
+
1688
+
Azure Log Analytics doesn't appear in our diagram, but we'll use it to collect logs from our containers and use them to debug our application when needed. Azure Monitor isn't explicitly part of our infrastructure, but it's enabled across all Azure resources, and we'll use it to monitor our application and build a dashboard.
1689
+
1690
+
#### About Azure Container Apps
1691
+
1692
+
The primary service we'll use is [Azure Container Apps](https://learn.microsoft.com/azure/container-apps/overview), a fully managed serverless container service on Azure. It allows you to run containerized applications without worrying about orchestration or managing complex infrastructure such as Kubernetes.
1693
+
1694
+
You write code using your preferred programming language or framework (inthis workshop it's JavaScript and Node.js, but it can be anything), and build microservices with full support for [Distributed Application Runtime (Dapr)](https://dapr.io/). Then, your containers will scale dynamically based on HTTP traffic or events powered by [Kubernetes Event-Driven Autoscaling (KEDA)](https://keda.sh).
1695
+
1696
+
There are already a few compute resources on Azure: from IAAS to FAAS.
1697
+
Azure Container Apps sits between PAAS and FAAS.
1698
+
On one hand, it feels more PaaS, because you are not forced into a specific programming model and you can control the rules on which to scale out / scale in.
1699
+
On the other hand, it has quite some serverless characteristics like scaling to zero, event-driven scaling, per second pricing and the ability to leverage Dapr's event-based bindings.
1700
+
1701
+

1702
+
1703
+
Container Apps is built on top of [Azure Kubernetes Service](https://learn.microsoft.com/azure/aks/), including a deep integration with KEDA (event-driven auto scaling for Kubernetes), Dapr (distributed application runtime) and Envoy (a service proxy designed for cloud-native applications).
1704
+
The underlying complexity is completely abstracted for you.
1705
+
So, no need to configure your Kubernetes service, ingress, deployment, volume manifests... You get a very simple API and user interface to configure the desired configuration for your containerized application.
1706
+
This simplification means also less control, hence the difference withAKS.
1707
+
1708
+

1671
1709
1672
-
- Explain some of the setup: gateway public, other microservices private, SWAAPI proxy...
1710
+
Azure Container Apps has the following features:
1711
+
-*Revisions*: automatic versioning that helps to manage the application lifecycle of your container apps
1712
+
-*Traffic control*: split incoming HTTP traffic across multiple revisions for Blue/Green deployments and A/B testing
1713
+
-*Ingress*: simple HTTPS ingress configuration, without the need to worry about DNS and certificates
1714
+
-*Autoscaling*: leverage all KEDA-supported scale triggers to scale your app based on external metrics
1715
+
-*Secrets*: deploy secrets that are securely shared between containers, scale rules and Dapr sidecars
1716
+
-*Monitoring*: the standard output and error streams are automatically written to Log Analytics
1717
+
-*Dapr*: through a simple flag, you can enable native Dapr integration for your Container Apps
1718
+
1719
+
Azure Container Apps introduces the following concepts:
1720
+
-*Environment*:this is a secure boundary around a group of Container Apps.
1721
+
They are deployed in the same virtual network, these apps can easily intercommunicate easily with each other and they write logs to the same Log Analytics workspace. An environment can be compared with a Kubernetes namespace.
1722
+
1723
+
-*Container App*:this is a group ofcontainers (pod) that is deployed and scale together. They share the same disk space and network.
1724
+
1725
+
-*Revision*:this is an immutable snapshot of a Container App.
1726
+
New revisions are automatically created and are valuable forHTTP traffic redirection strategies, such as A/B testing.
1727
+
1728
+

1673
1729
1674
1730
### Creating the infrastructure
1675
1731
1676
-
- Explain IaC / Bicep
1677
-
- Use provided Bicep templates +AZCLI command to create infra
1732
+
Now that we know what we'll be using, let's create the infrastructure we'll need for this workshop.
1733
+
1734
+
You can use different ways to create Azure resources: the Azure CLI, the [Azure Portal](https://portal.azure.com), ARM templates, or even VS Code extensions or third party tools like Terraform.
1735
+
1736
+
All these tools have one thing in common: they all use the [Azure Resource Manager (ARM) API](https://docs.microsoft.com/azure/azure-resource-manager/management/overview) to create and manage Azure resources. The Azure CLI is just a wrapper around the ARM API, and the Azure Portal is a web interface to the same API.
1737
+
1738
+

1739
+
1740
+
Any resource you create in Azure is part of a **resource group**. A resource group is a logical container that holds related resources for an Azure solution, just like a folder.
1741
+
1742
+
When you ran the command `.azure/infra.sh update` earlier, it created a resource group name `rg-node-microservices-prod` with all the infrastructure for you, using Azure CLI and Infrastructure as Code (IaC) templates. We'll look at the details of the scripts later inthis section.
1743
+
1744
+
### Introducing Infrastructure as Code
1745
+
1746
+
Infrastructure as Code (IaC) is a way to manage your infrastructure using the same tools and practices you use for your application code. In other words: you write code to describe the resources you need, and this code is committed to your project repository so you can use it to create, update, and delete your infrastructure as part of your CI/CD pipeline or locally.
1747
+
1748
+
It's a great way to ensure consistency and repeatability of your infrastructure, and allows to manage the infrastructure of your project just like you manage the code of your project.
1749
+
1750
+
There are many existing tools to manage your infrastructure as code, such as Terraform, Pulumi, or [Azure Resource Manager (ARM) templates](https://learn.microsoft.com/azure/azure-resource-manager/templates/overview). ARM templates are JSON files that allows you to define and configure Azure resources.
1751
+
1752
+
In this workshop, we'll [Bicep](https://learn.microsoft.com/azure/azure-resource-manager/bicep/overview?tabs=bicep), a new language that abtracts ARM templates creation while being more concise, readable and easier to use.
1753
+
1754
+
#### What's Bicep?
1755
+
1756
+
Bicep is a Domain Specific Language (DSL) for deploying Azure resources declaratively. It aims to drastically simplify the authoring experience with a cleaner syntax, improved type safety, and better support for modularity and code re-use. It's a transparent abstraction over ARM templates, which means anything that can be done in an ARM Template can be done in Bicep.
1757
+
1758
+
Here's an example of a Bicep file that creates a Log Analytics workspace:
A resource is made of differents parts. First, you have the `resource` keyword, followed by a symbolic name of the resource that you can use to reference that resource in other parts of the template. Next to it is a string with the resource type you want to create and API version.
1774
+
1775
+
<div class="info" data-title="note">
1776
+
1777
+
> The API version is important, as it defines the version of the template used for a resource type. Different API versions can have different properties or options, and may introduce breaking changes. By specifying the API version, you ensure that your template will work regardless of the product updates, making your infrastructure more resilient over time.
1778
+
1779
+
</div>
1780
+
1781
+
Inside the resource, you then specify the name of the resource, its location, and its properties. You can also add tags to your resources, which are key/value pairs that you can use to categorize and filter your resources.
1782
+
1783
+
Bicep templates can be split into multiple files, and you can use modules to reuse common parts of your infrastructure. You can also use parameters to make your templates more flexible and reusable.
1784
+
1785
+
Have a look at the files inside the folder `./azure/infra` to see how we created the infrastructure for this workshop. The entry point is the `main.bicep` file, which is the main template that use the differents modules located in the `./azure/infra/modules` folder.
1786
+
1787
+
Writing templates from scratch can be a bit tedious, but fortunately most of the time you don't have to:
1788
+
1789
+
- You can reuse templates for the [Azure Quickstart collection](https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts)
1790
+
1791
+
- The [Bicep VS Code extension](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-bicep) help you write your templates, providing snippets, syntax highlighting, auto-completion, and validation.
1792
+
1793
+
- The [Bicep playground](https://aka.ms/bicepdemo) allows you to convert an ARM template to Bicep, and vice versa.
1794
+
1795
+
### `infra.sh` script details
1796
+
1797
+
Because entering a bunch of commands one after the other in a terminal is not very fun, we made a Bash script to automate all the heavy lifting. This is the `.azure/infra.sh` we ran earlier.
1798
+
1799
+
This script is a wrapper around Azure CLIcommands. The`update` command does the following:
1800
+
1801
+
1. Run the command `az group create` to create a resource group if it doesn't exist yet.
1802
+
1803
+
2. Run the command `az deployment group create` to create or update the resources in the resource group. This command takes a Bicep template as input, and creates or updates the resources defined in the template.
1804
+
1805
+
3. Reformat the JSON deployment output from the previous command into the file `.<environment>.env`. You should see the file `.azure/.prod.env` that was created earlier.
1806
+
1807
+
4. Run `az` commands specific to the resources created, to retrieve secrets like the connection string for database or the registry credentials, and store them in the `.env` file.
1808
+
1809
+
If you're curious, you can have a look at the script to see how it works, and reuse it for your own projects.
1678
1810
1679
1811
---
1680
1812
@@ -1686,24 +1818,63 @@ This script uses the [Azure CLI](https://learn.microsoft.com/cli/azure) and [Git
1686
1818
1687
1819
## Connecting database
1688
1820
1689
-
- Explain CosmosDB NoSQL
1821
+
After your infrastructure is ready, we'll connect our microservices their respective database to persist the data. To do that, we'll have to add a few things to our Settings and Dice services.
1822
+
1823
+
### About Azure Cosmos DB
1824
+
1825
+
Azure Cosmos DB is a fully managed NoSQL database service that offers multiple APIs, including SQL, MongoDB, Cassandra, Gremlin, and Azure Table storage. It's a globally distributed database, which means that your data can be replicated across multiple regions, and you can choose the closest region to your users to reduce latency.
1826
+
1827
+
In the previous section, we created a Cosmos DB account configured with a SQL API. Surely, that sounds a bit strange, using SQL to access a NoSQL database? But don't worry, it's not a mistake. Cosmos DB is a multi-model database, which means that it can support different ways of accessing the data. SQL is the most common way of querying data, so it feels familiar to most developers and makes it easy to get started. Still, you must not forget that it's not relational database, so you can't very complex queries and joins have to be avoided because of their performance impact.
1828
+
1829
+
### Adding database to the Settings service
1830
+
1831
+
1832
+
1690
1833
- provide connection string in env + adapt code for Settings API
1834
+
1835
+
### Adding database to the Dice service
1836
+
1691
1837
- provide connection string in env + adapt code for Dice API
1838
+
1839
+
### Testing the database locally
1692
1840
- test locally
1841
+
1842
+
### Looking at the data
1693
1843
- look in data explorer
1694
1844
1695
1845
---
1696
1846
1697
1847
## Adding CI/CD
1698
1848
1849
+
1850
+
### What's GitHub Actions?
1851
+
1699
1852
- Explain GitHub actions
1700
-
- Create Azure SP+ add secrets
1853
+
1854
+
### Adding a deployment workflow
1855
+
1701
1856
- Create GHA workflow
1857
+
- Mention Azure SP secrets
1858
+
1859
+
### Deploying the application
1860
+
1861
+
commit + push
1862
+
1702
1863
- Deploy
1864
+
1865
+
### Testing the application
1866
+
1867
+
- command to retrieve URL
1703
1868
- test
1704
1869
1705
1870
---
1706
1871
1872
+
<div class="info" data-title="skip notice">
1873
+
1874
+
> This step is entirely optional, you can skip it if you want to jump directly to the next section.
1875
+
1876
+
</div>
1877
+
1707
1878
## Monitoring and scaling
1708
1879
1709
1880
- Create dashboard cpu/memory
@@ -1722,6 +1893,12 @@ This script uses the [Azure CLI](https://learn.microsoft.com/cli/azure) and [Git
1722
1893
1723
1894
---
1724
1895
1896
+
<div class="info" data-title="skip notice">
1897
+
1898
+
> This step is entirely optional, you can skip it if you want to jump directly to the next section.
1899
+
1900
+
</div>
1901
+
1725
1902
## Logs and tracing
1726
1903
- connect to Dice API logs withAZCLI
1727
1904
- explain app/system logs
@@ -1733,4 +1910,38 @@ This script uses the [Azure CLI](https://learn.microsoft.com/cli/azure) and [Git
1733
1910
---
1734
1911
1735
1912
## Conclusion
1736
-
- clean up infra
1913
+
1914
+
This is the end of the workshop. We hope you enjoyed it, learned something newand more importantly, that you'll be able to take this knowledge back to your projects.
1915
+
1916
+
<div class="warning">
1917
+
1918
+
> If you experienced any issues during the workshop, please let us know by [creating an issue](https://github.com/Azure-Samples/nodejs-microservices/issues) on the GitHub repository.
1919
+
1920
+
</div>
1921
+
1922
+
### Cleaning up Azure resources
1923
+
1924
+
<div class="important" data-title="important">
1925
+
1926
+
> Don't forget to delete the Azure resources once you are done running the workshop, to avoid incurring unnecessary costs!
1927
+
1928
+
</div>
1929
+
1930
+
To delete the Azure resources, you can run this command:
1931
+
1932
+
```bash
1933
+
.azure/infra.sh delete
1934
+
```
1935
+
1936
+
Or directly use the Azure CLI:
1937
+
1938
+
```bash
1939
+
az group delete --name rg-node-microservices-prod
1940
+
```
1941
+
1942
+
### References
1943
+
1944
+
- This workshop URL: [aka.ms/ws/node-microservices](https://aka.ms/ws/node-microservices)
1945
+
- The source repository forthis workshop: [GitHub link](https://github.com/Azure-Samples/nodejs-microservices)
1946
+
- The base template forthis workshop: [GitHub link](https://github.com/Azure-Samples/nodejs-microservices-template)
1947
+
- If something does not work: [Report an issue](https://github.com/Azure-Samples/nodejs-microservices/issues)
0 commit comments