Skip to content

Commit 86745fd

Browse files
committed
chore: Enhance Azure DevOps and Angular-Nginx tutorials with detailed pipeline setup instructions and configuration examples
1 parent af2b4a0 commit 86745fd

File tree

4 files changed

+182
-48
lines changed

4 files changed

+182
-48
lines changed

content/en/templates/tutorials/angular-nginx/index.md

Lines changed: 145 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,58 @@ toc: true
1616
---
1717

1818

19-
# Setup Docker
19+
## Introduction
20+
21+
This tutorial will guide you on how to setup Angular with Nginx within a Docker container.
22+
The tutorial will use:
23+
- Angular *(Angular15)* to build the Angular app
24+
- Node.js *(Node22)* to build the Angular app
25+
- Nginx to serve the Angular app
26+
- Docker to containerize the Angular app
27+
- Azure DevOps to build and deploy the Angular app
28+
29+
## Create Nginx Configuration
30+
31+
Add a file named `nginx.conf` in the root of your project with the following content:
32+
33+
```nginx
34+
# the events block is required
35+
events{}
36+
37+
http {
38+
# include the default mime.types to map file extensions to MIME types
39+
include /etc/nginx/mime.types;
40+
41+
server {
42+
listen 80;
43+
server_name localhost;
44+
45+
# set the root directory for the server (we need to copy our
46+
# application files here)
47+
root /usr/share/nginx/html;
48+
49+
# set the default index file for the server (Angular generates the
50+
# index.html file for us and it will be in the above directory)
51+
index index.html;
52+
53+
# specify the configuration for the '/' location
54+
location / {
55+
56+
# try to serve the requested URI. if that fails then try to
57+
# serve the URI with a trailing slash. if that fails, then
58+
# serve the index.html file; this is needed in order to serve
59+
# Angular routes--e.g.,'localhost:8080/customer' will serve
60+
# the index.html file
61+
try_files $uri $uri/ /index.html;
62+
}
63+
}
64+
}
65+
```
2066

2167
## Create Dockerfile
2268

69+
Create a file named `Dockerfile` in the root of your project with the following content:
70+
2371
```dockerfile
2472
FROM node:22 AS build
2573

@@ -59,42 +107,102 @@ EXPOSE 80
59107
```
60108

61109

62-
## Create Nginx Configuration
63-
64-
65-
Add a file named `nginx.conf` in the root of your project with the following content:
66-
67-
```nginx
68-
# the events block is required
69-
events{}
70-
71-
http {
72-
# include the default mime.types to map file extensions to MIME types
73-
include /etc/nginx/mime.types;
74-
75-
server {
76-
listen 80;
77-
server_name localhost;
78-
79-
# set the root directory for the server (we need to copy our
80-
# application files here)
81-
root /usr/share/nginx/html;
82-
83-
# set the default index file for the server (Angular generates the
84-
# index.html file for us and it will be in the above directory)
85-
index index.html;
86110

87-
# specify the configuration for the '/' location
88-
location / {
111+
## Setup Azure DevOps Pipeline
112+
113+
The solution requres a pipeline to build a Docker image and push it to Azure Container Registry.
114+
The Image will be tagged with the Build Number and latest and will be pushed to the Development, UAT and Production Container Registry based on the Build Environment.
115+
116+
The Pipeline requires three Service Connections to deploy Images to Azure Container Registry
117+
1. AcrDevelopmentConnection
118+
2. AcrUATConnection
119+
3. AcrProductionConnection
120+
121+
The Pipeline requires a parameter to specify the Build Environment:
122+
1. `buildEnv`: "local" # Pass the Build Environment `local | dev | uat | prod`
123+
124+
Create a new pipeline in Azure DevOps and add the following code to the `azure-pipelines\container-ci.yml` file:
125+
126+
```yaml
127+
# ASP.NET Core (.NET Framework)
128+
# Build and test ASP.NET Core projects targeting .NET9.
129+
# Add steps that publish symbols, save build artifacts, and more:
130+
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core
131+
# The Pipeline requires three Service Connections to deploy Images to Azure Container Registry
132+
# 1. AcrDevelopmentConnection
133+
# 2. AcrUATConnection
134+
# 3. AcrProductionConnection
135+
136+
# The Pipeline requires a parameter to specify the Build Environment
137+
# 1. buildEnv: "local" # Pass the Build Environment local | dev | uat | prod
138+
139+
name: $(Build.BuildId)
140+
141+
trigger:
142+
- Develop
143+
- main
144+
145+
resources:
146+
- repo: self
147+
148+
parameters:
149+
buildEnv: "local" # Pass the Build Environment local | dev | uat | prod
150+
151+
variables:
152+
# Agent VM image name
153+
vmImageName: "ubuntu-latest"
154+
imageName: "frontend-$(buildEnv)"
155+
registry: "youracr$(buildEnv).azurecr.io"
156+
repository: "$(registry)/$(imageName)-$(buildEnv)" # yourazurecontainerregistry.azurecr.io/frontend-dev:1
157+
dockerfile: Dockerfile # Path to your Dockerfile
158+
159+
stages:
160+
- stage: BuildAndPush
161+
displayName: Build and Push Docker Image
162+
jobs:
163+
- job: Build
164+
displayName: Build Docker Image
165+
pool:
166+
vmImage: $(vmImageName)
167+
steps:
168+
- task: Docker@2
169+
displayName: Build Image
170+
inputs:
171+
command: build
172+
repository: $(repository)
173+
tags: "$(Build.BuildId),latest" # Use build number as tag
174+
Dockerfile: $(dockerfile)
175+
buildArgs: "--build-arg BUILD_ENV=$(buildEnv)" # Pass the Build Environment local | dev | uat | prod
176+
177+
- task: Docker@2
178+
displayName: Push Image To DEV
179+
condition: eq(parameters.buildEnv, 'dev')
180+
inputs:
181+
command: push
182+
containerRegistry: "AcrDevelopmentConnection"
183+
repository: $(repository)
184+
tags: "$(Build.BuildId),latest"
185+
186+
187+
- task: Docker@2
188+
displayName: Push Image To UAT
189+
condition: eq(parameters.buildEnv, 'uat')
190+
inputs:
191+
command: push
192+
containerRegistry: "AcrUATConnection"
193+
repository: $(repository)
194+
tags: "$(Build.BuildId),latest"
195+
196+
- task: Docker@2
197+
displayName: Push Image To PROD
198+
condition: eq(parameters.buildEnv, 'prod')
199+
inputs:
200+
command: push
201+
containerRegistry: "AcrProductionConnection"
202+
repository: $(repository)
203+
tags: "$(Build.BuildId),latest"
89204

90-
# try to serve the requested URI. if that fails then try to
91-
# serve the URI with a trailing slash. if that fails, then
92-
# serve the index.html file; this is needed in order to serve
93-
# Angular routes--e.g.,'localhost:8080/customer' will serve
94-
# the index.html file
95-
try_files $uri $uri/ /index.html;
96-
}
97-
}
98-
}
205+
```
99206

100-
```
207+
## Conclusion
208+
Enjoy your Angular app running in a container with Nginx.

content/en/templates/tutorials/azuredevops-project/index.md

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,32 @@ git remote delete origin
7575
```
7676

7777

78-
Build pipeline yaml file for DemoApi and DemoFE project.
78+
## Build pipeline yaml files
7979

80-
Add file `pipelines\app-service-ci.yml` to the root of the project
80+
There are two build pipeline yaml files that you can use to setup the build pipeline for the project.
81+
One is for the app service and the other is for the docker image.
82+
83+
84+
### App Service Build Pipeline
85+
86+
Before run pipeline please check the variables:
87+
88+
> **General variables**
89+
> 1. BuildConfiguration *(Release or Debug)*
90+
> {{< img src="library_variables.png" >}}
91+
>
92+
> {{< img src="library_variable.png" >}}
93+
>
94+
> **Library variables**
95+
> 1. azureSubscription *(Only for deployment to Azure)*
96+
>
97+
> **Pipeline variables**
98+
> 1. majorVer
99+
> 2. minorVer
100+
> 3. appServiceName *(Only for deployment to Azure)*
101+
----
102+
103+
Add file `azure-pipelines\app-service-ci.yml` to the root of the project
81104

82105
```yaml
83106
# ASP.NET Core (.NET Framework)
@@ -170,10 +193,13 @@ steps:
170193
# runtimeStack: 'DOTNETCORE|9.0'
171194
```
172195

173-
Deploy pipeline yaml file for DemoApi.
196+
### Docker Build Pipeline
197+
198+
The Pipeline requires a Service Connections to deploy Images to Azure Container Registry.
199+
1. `Service Connections`: AcrDevelopmentConnection
174200

175201

176-
Add file `pipelines\app-container-ci.yml` to the root of the project
202+
Add file `azure-pipelines\app-container-ci.yml` to the root of the project
177203

178204
```yaml
179205
# ASP.NET Core (.NET Framework)
@@ -192,12 +218,11 @@ resources:
192218
variables:
193219
# Agent VM image name
194220
vmImageName: "ubuntu-latest"
195-
imageName: bp.sirio.demobe # Replace with your image name
221+
imageName: backend # Replace with your image name
196222
registry: genocs # Replace with your Docker registry (e.g., Docker Hub, ACR)
197223
repository: $(registry)/$(imageName)
198-
dockerfile: dockerfile # Path to your Dockerfile
199-
buildArgValue: $(Build.BuildId) # Example: Use the build ID as the argument value
200-
patArgValue: "123ABC" # The PAT
224+
dockerfile: Dockerfile # Path to your Dockerfile
225+
buildArgValue: "--build-arg BUILD_ENV=$(buildEnv)" # Use this to pass the build environment to the Dockerfile
201226

202227
stages:
203228
- stage: BuildAndPush
@@ -215,7 +240,7 @@ stages:
215240
repository: $(repository)
216241
tags: "$(Build.BuildId),latest" # Use build number as tag
217242
Dockerfile: $(dockerfile)
218-
buildArgs: "PAT=$(patArgValue)" # Pass the PAT to the build argument
243+
buildArgs: buildArgValue # Pass the the build argument
219244
# Add other build options as needed, e.g., target, context
220245
# buildContext: . # Uncomment if your Dockerfile is not in the root of the repo
221246
# target: my-target # Uncomment if you are using multi-stage builds
@@ -224,9 +249,10 @@ stages:
224249
displayName: Push Image
225250
inputs:
226251
command: push
227-
containerRegistry: "DockerhubConnection"
252+
containerRegistry: "AcrDevelopmentConnection"
228253
repository: $(repository)
229254
tags: "$(Build.BuildId),latest"
230255
```
231256
232-
Setup deployment pipeline for DemoApi.
257+
## Conclusion
258+
Enjoy your new project on Azure DevOps!
69.8 KB
Loading
63.1 KB
Loading

0 commit comments

Comments
 (0)