Skip to content

Commit 7903b5b

Browse files
committed
Add devcontainer configuration and update Azure VM scripts with dynamic DNS labels
1 parent 7fcb471 commit 7903b5b

File tree

6 files changed

+65
-14
lines changed

6 files changed

+65
-14
lines changed

.devcontainer/devcontainer.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu
3+
{
4+
"name": "Lemoncode Dev Environment",
5+
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6+
"image": "mcr.microsoft.com/devcontainers/base:jammy",
7+
"features": {
8+
"ghcr.io/devcontainers/features/azure-cli:1": {}
9+
},
10+
"customizations": {
11+
"vscode": {
12+
"extensions": [
13+
"humao.rest-client"
14+
]
15+
}
16+
}
17+
18+
// Features to add to the dev container. More info: https://containers.dev/features.
19+
// "features": {},
20+
21+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
22+
// "forwardPorts": [],
23+
24+
// Use 'postCreateCommand' to run commands after the container is created.
25+
// "postCreateCommand": "uname -a",
26+
27+
// Configure tool-specific properties.
28+
// "customizations": {},
29+
30+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
31+
// "remoteUser": "root"
32+
}

04-cloud/azure/iaas/02-api-vm/README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Para esta pieza de la arquitectura de Tour of Heroes vamos a usar una máquina v
55
```bash
66
# API VM on Azure
77
API_VM_NAME="api-vm"
8+
API_VM_DNS_LABEL="tour-of-heroes-api-vm-$RANDOM"
89
API_VM_IMAGE="Ubuntu2204"
910
API_VM_ADMIN_USERNAME="apiadmin"
1011
API_VM_ADMIN_PASSWORD="Api@dmin-1232"
@@ -16,6 +17,7 @@ o si estás en Windows:
1617
```pwsh
1718
# API VM on Azure
1819
$API_VM_NAME="api-vm"
20+
$API_VM_DNS_LABEL="tour-of-heroes-api-vm-$RANDOM"
1921
$API_VM_IMAGE="Ubuntu2204"
2022
$API_VM_ADMIN_USERNAME="apiadmin"
2123
$API_VM_ADMIN_PASSWORD="Api@dmin1232!"
@@ -35,11 +37,11 @@ FQDN_API_VM=$(az vm create \
3537
--admin-password $API_VM_ADMIN_PASSWORD \
3638
--vnet-name $VNET_NAME \
3739
--subnet $API_SUBNET_NAME \
38-
--public-ip-address-dns-name tour-of-heroes-api-vm \
40+
--public-ip-address-dns-name $API_VM_DNS_LABEL \
3941
--nsg $API_VM_NSG_NAME \
4042
--size $VM_SIZE --query "fqdns" -o tsv)
4143

42-
echo -e "Api VM created"
44+
echo -e "API VM created"
4345
```
4446

4547
o si estás en Windows:
@@ -55,7 +57,7 @@ $FQDN_API_VM=az vm create `
5557
--admin-password $API_VM_ADMIN_PASSWORD `
5658
--vnet-name $VNET_NAME `
5759
--subnet $API_SUBNET_NAME `
58-
--public-ip-address-dns-name tour-of-heroes-api-vm `
60+
--public-ip-address-dns-name $API_VM_DNS_LABEL `
5961
--nsg $API_VM_NSG_NAME `
6062
--size $VM_SIZE --query "fqdns" -o tsv
6163
@@ -119,8 +121,16 @@ az network nsg rule create `
119121

120122
Si instalas la extensión REST Client en tu Visual Studio Code, puedes ejecutar la peticiones que aparecen el fichero [api.http](04-cloud/azure/iaas/02-api-vm/api.http).
121123

122-
Para comprobar que la API funciona correctamente podemos acceder a la URL http://tour-of-heroes-api-vm.uksouth.cloudapp.azure.com/api/hero, en este ejemplo (en tu despliegue deberías modificarla por la que corresponda) y deberías ver un listado de héroes en formato JSON.
124+
Para comprobar que la API funciona correctamente podemos acceder a la URL:
125+
126+
```bash
127+
echo "http://$API_VM_DNS_LABEL.$LOCATION.cloudapp.azure.com/api/hero"
128+
```
129+
130+
En este ejemplo (en tu despliegue deberías modificarla por la que corresponda) y deberías ver un listado de héroes en formato JSON.
123131

124132
El resultado hasta ahora debería ser el siguiente:
125133

126-
![VM para la API](/04-cloud/azure/iaas/images/api-vm-y-db-vm.png)
134+
![VM para la API](/04-cloud/azure/iaas/images/api-vm-y-db-vm.png)
135+
136+
Y con esto ya tendríamos la API desplegada en una máquina virtual de Azure. Ahora vamos a desplegar el frontend en otra máquina virtual de Azure. Puedes continuar en el siguiente [paso](../03-frontend-vm/README.md).

04-cloud/azure/iaas/02-api-vm/api.http

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
@base_url = http://tour-of-heroes-api-vm.uksouth.cloudapp.azure.com/api/hero
1+
#@base_url = http://tour-of-heroes-api-vm-<TU_NUMERO_RANDOM>.uksouth.cloudapp.azure.com/api/hero
2+
@base_url = http://tour-of-heroes-api-vm-6203.uksouth.cloudapp.azure.com/api/hero
23

34
GET {{base_url}} HTTP/1.1
45

04-cloud/azure/iaas/03-frontend-vm/README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# Crear una máquina virtual para el frontend en Angular
2+
23
Ahora vamos a crear la máquina virtual para el frontend. Para ello, vamos a necesitar las siguientes variables de entorno:
34

45
```bash
56
# Frontend VM on Azure
67
FRONTEND_VM_NAME="frontend-vm"
8+
FRONTEND_DNS_LABEL="tour-of-heroes-frontend-vm-$RANDOM"
79
FRONTEND_VM_IMAGE="MicrosoftWindowsServer:WindowsServer:2022-Datacenter:latest"
810
FRONTEND_VM_ADMIN_USERNAME="frontendadmin"
911
FRONTEND_VM_ADMIN_PASSWORD="fr0nt#nd@dmin123"
@@ -34,7 +36,7 @@ FQDN_FRONTEND_VM=$(az vm create \
3436
--admin-password $FRONTEND_VM_ADMIN_PASSWORD \
3537
--vnet-name $VNET_NAME \
3638
--subnet $FRONTEND_SUBNET_NAME \
37-
--public-ip-address-dns-name tour-of-heroes-frontend-vm \
39+
--public-ip-address-dns-name $FRONTEND_DNS_LABEL \
3840
--nsg $FRONTEND_VM_NSG_NAME \
3941
--size $VM_SIZE --query "fqdns" -o tsv)
4042
```
@@ -52,7 +54,7 @@ $FQDN_FRONTEND_VM=az vm create `
5254
--admin-password $FRONTEND_VM_ADMIN_PASSWORD `
5355
--vnet-name $VNET_NAME `
5456
--subnet $FRONTEND_SUBNET_NAME `
55-
--public-ip-address-dns-name tour-of-heroes-frontend-vm `
57+
--public-ip-address-dns-name $FRONTEND_DNS_LABEL `
5658
--nsg $FRONTEND_VM_NSG_NAME `
5759
--size $VM_SIZE --query "fqdns" -o tsv
5860
```
@@ -82,7 +84,7 @@ az vm run-command invoke `
8284
--parameters "api_url=http://$FQDN_API_VM/api/hero" "release_url=https://github.com/0GiS0/tour-of-heroes-angular/releases/download/1.1.4/dist.zip"
8385
```
8486

85-
En este ejemplo he desplegado la aplicación en otro puerto, en el 8080, para que no haya conflicto con el IIS que se instala por defecto en el puerto 80. Para elloutilizamos el script [install-tour-of-heroes-angular.ps1](04-cloud/azure/iaas/scripts/install-tour-of-heroes-angular.ps1) que se encuentra en la carpeta **scripts** de este repositorio.
87+
En este ejemplo he desplegado la aplicación en otro puerto, en el 8080, para que no haya conflicto con el IIS que se instala por defecto en el puerto 80. Para ello utilizamos el script [install-tour-of-heroes-angular.ps1](04-cloud/azure/iaas/scripts/install-tour-of-heroes-angular.ps1) que se encuentra en la carpeta **scripts** de este repositorio.
8688

8789
Lo último que nos queda es habilitar los puertos 80 y 8080 en el NSG de la máquina virtual del frontend:
8890

@@ -128,7 +130,13 @@ az network nsg rule create `
128130
--direction Inbound
129131
```
130132

131-
Para probar que todo funciona, abre un navegador y accede a la dirección [http://tour-of-heroes-frontend-vm.uksouth.cloudapp.azure.com:8080](http://tour-of-heroes-frontend-vm.uksouth.cloudapp.azure.com:8080) y deberías ver la aplicación Angular funcionando.
133+
Para probar que todo funciona, abre un navegador y accede a la dirección:
134+
135+
```bash
136+
echo http://$FRONTEND_DNS_LABEL.$LOCATION.cloudapp.azure.com:8080
137+
```
138+
139+
y deberías ver la aplicación Angular funcionando.
132140

133141
Ahora la arquitectura de nuestra aplicación en Azure debería ser la siguiente:
134142

04-cloud/azure/iaas/04-load-balancer/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ En este caso, vamos a utilizar un balanceador de carga público para poder acced
1212

1313
```bash
1414
LOAD_BALANCER_NAME="frontend-lb"
15-
LB_IP_NAME="tour-of-heroes-lb-ip"
15+
LB_IP_NAME="tour-of-heroes-lb-ip-$RANDOM"
1616
PROBE_NAME="frontend-probe"
1717
BACKEND_POOL_NAME="tour-of-heroes-backend-pool"
1818
````
@@ -197,7 +197,7 @@ echo -e "Try to access the front end VM using the public IP address of the load
197197

198198
FRONTEND_LB_PUBLIC_IP=$(az network public-ip show \
199199
--resource-group $RESOURCE_GROUP \
200-
--name $PUBLIC_IP_NAME \
200+
--name $LB_IP_NAME \
201201
--query ipAddress \
202202
--output tsv)
203203

@@ -231,7 +231,7 @@ FQDN_FRONTEND_VM_2=$(az vm create \
231231
--admin-password $FRONTEND_VM_ADMIN_PASSWORD \
232232
--vnet-name $VNET_NAME \
233233
--subnet $FRONTEND_SUBNET_NAME \
234-
--public-ip-address-dns-name tour-of-heroes-frontend-vm \
234+
--public-ip-address-dns-name $FRONTEND_DNS_LABEL-2 \
235235
--nsg "${FRONTEND_VM_NSG_NAME}-2" \
236236
--size $VM_SIZE --query "fqdns" -o tsv)
237237

04-cloud/azure/iaas/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ RESOURCE_GROUP="tour-of-heroes-on-vms"
2020
LOCATION="uksouth"
2121
VM_SIZE="Standard_B2s"
2222

23-
STORAGE_ACCOUNT_NAME="tourofheroesbackups"
23+
STORAGE_ACCOUNT_NAME="tourofheroesbackups$RANDOM"
2424
```
2525

2626
o si estás en Windows:

0 commit comments

Comments
 (0)