From 91d5e3941fa09e73683ec3c370c4d1c7c05b07c6 Mon Sep 17 00:00:00 2001 From: eugene Date: Tue, 13 Aug 2024 08:14:07 +0800 Subject: [PATCH 01/10] chore: lazy loading --- src/storeonwheels.client/src/app/app.config.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/storeonwheels.client/src/app/app.config.ts b/src/storeonwheels.client/src/app/app.config.ts index 5e51d5d..e02c5cc 100644 --- a/src/storeonwheels.client/src/app/app.config.ts +++ b/src/storeonwheels.client/src/app/app.config.ts @@ -1,9 +1,7 @@ import { ApplicationConfig, isDevMode } from "@angular/core"; import { - PreloadAllModules, provideRouter, withComponentInputBinding, - withPreloading, } from "@angular/router"; import { routes } from "./app.routes"; import { @@ -18,7 +16,6 @@ export const appConfig: ApplicationConfig = { provideRouter( routes, withComponentInputBinding(), - withPreloading(PreloadAllModules) ), provideHttpClient(withInterceptorsFromDi()), provideAnimationsAsync(), From 2a677bbf7e0314b69d7053408117f919c42fb488 Mon Sep 17 00:00:00 2001 From: eugene Date: Tue, 13 Aug 2024 08:17:28 +0800 Subject: [PATCH 02/10] chore: add preloading --- src/storeonwheels.client/src/app/app.config.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/storeonwheels.client/src/app/app.config.ts b/src/storeonwheels.client/src/app/app.config.ts index e02c5cc..5e51d5d 100644 --- a/src/storeonwheels.client/src/app/app.config.ts +++ b/src/storeonwheels.client/src/app/app.config.ts @@ -1,7 +1,9 @@ import { ApplicationConfig, isDevMode } from "@angular/core"; import { + PreloadAllModules, provideRouter, withComponentInputBinding, + withPreloading, } from "@angular/router"; import { routes } from "./app.routes"; import { @@ -16,6 +18,7 @@ export const appConfig: ApplicationConfig = { provideRouter( routes, withComponentInputBinding(), + withPreloading(PreloadAllModules) ), provideHttpClient(withInterceptorsFromDi()), provideAnimationsAsync(), From fd1a0c9b603d4684aca3b956a376808a47095b2c Mon Sep 17 00:00:00 2001 From: eugene Date: Tue, 13 Aug 2024 08:35:23 +0800 Subject: [PATCH 03/10] chore: tf-2 --- src/storeonwheels.client/src/app/app.config.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/storeonwheels.client/src/app/app.config.ts b/src/storeonwheels.client/src/app/app.config.ts index 5e51d5d..61d4d37 100644 --- a/src/storeonwheels.client/src/app/app.config.ts +++ b/src/storeonwheels.client/src/app/app.config.ts @@ -18,6 +18,7 @@ export const appConfig: ApplicationConfig = { provideRouter( routes, withComponentInputBinding(), + // https://dev.to/this-is-angular/optimize-your-angular-apps-user-experience-with-preloading-strategies-3ie7 withPreloading(PreloadAllModules) ), provideHttpClient(withInterceptorsFromDi()), From ccbe177e2b921141fbe829aa1aa66107a075b40b Mon Sep 17 00:00:00 2001 From: eugene Date: Fri, 16 Aug 2024 21:22:11 +0800 Subject: [PATCH 04/10] chore: fmt --- Makefile | 18 ++++++++--------- infra/Terraform/container-app.tf | 33 ++++++++++++++++++-------------- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index 49204fd..4b8fc1a 100644 --- a/Makefile +++ b/Makefile @@ -14,15 +14,15 @@ format: cd src/storeonwheels.client && npm run fmt # mimicks the right click docker build in visual studio, simplified in docker-compose.yml -docker: - docker build \ - --file ./src/StoreOnWheels.Server/Dockerfile \ - --progress=plain \ - --force-rm -t storeonwheelsserver \ - --build-arg "BUILD_CONFIGURATION=Debug" \ - --label "com.microsoft.created-by=visual-studio" \ - --label "com.microsoft.visual-studio.project-name=StoreOnWheels.Server" \ - src +# docker: +# docker build \ +# --file ./src/StoreOnWheels.Server/Dockerfile \ +# --progress=plain \ +# --force-rm -t storeonwheelsserver \ +# --build-arg "BUILD_CONFIGURATION=Debug" \ +# --label "com.microsoft.created-by=visual-studio" \ +# --label "com.microsoft.visual-studio.project-name=StoreOnWheels.Server" \ +# src compose: docker compose rm -fsv && docker compose up -d diff --git a/infra/Terraform/container-app.tf b/infra/Terraform/container-app.tf index 3b288bf..94b5b77 100644 --- a/infra/Terraform/container-app.tf +++ b/infra/Terraform/container-app.tf @@ -1,6 +1,7 @@ # Azure Container Registry (ACR) resource "azurerm_container_registry" "acr" { - name = "acrStoreonwheelsProdSea" + # acrStoreonwheelsProdSea + name = "acrstoreonwheelsprodsea" resource_group_name = azurerm_resource_group.rg.name location = azurerm_resource_group.rg.location sku = "Basic" @@ -12,22 +13,24 @@ locals { } resource "null_resource" "build_docker_image" { - provisioner "remote-exec" { - inline = [ - "IMAGE=${local.image}", - "cd ../..", - "docker compose build" - ] + provisioner "local-exec" { + environment = { + "IMAGE" = local.image + } + command = <<-EOT + cd ../.. + docker compose build + EOT } depends_on = [azurerm_container_registry.acr] } resource "null_resource" "push_docker_image" { - provisioner "remote-exec" { - inline = [ - "az acr login --name ${azurerm_container_registry.acr.name}", - "docker push ${azurerm_container_registry.acr.login_server}/storeonwheels.server", - ] + provisioner "local-exec" { + command = <<-EOT + az acr login --name ${azurerm_container_registry.acr.name} + docker push ${azurerm_container_registry.acr.login_server}/storeonwheels.server + EOT } depends_on = [null_resource.build_docker_image] } @@ -47,7 +50,7 @@ resource "azurerm_container_app" "app" { template { container { - name = "storeonwheels.server" + name = local.image image = "nginx:latest" cpu = 0.5 memory = "0.5Gi" @@ -57,10 +60,12 @@ resource "azurerm_container_app" "app" { ingress { allow_insecure_connections = false external_enabled = true - target_port = 80 + target_port = 4000 # ws connection not distributed to message queues yet traffic_weight { percentage = 100 } } + + depends_on = [null_resource.push_docker_image] } From 95aed4f95a94d88e9f9c122e2c5e997677bb5e9c Mon Sep 17 00:00:00 2001 From: eugene Date: Sat, 17 Aug 2024 20:05:14 +0800 Subject: [PATCH 05/10] chore: tf-2 --- infra/Terraform/container-app.tf | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/infra/Terraform/container-app.tf b/infra/Terraform/container-app.tf index 94b5b77..9c4fc22 100644 --- a/infra/Terraform/container-app.tf +++ b/infra/Terraform/container-app.tf @@ -9,7 +9,7 @@ resource "azurerm_container_registry" "acr" { } locals { - image = "${azurerm_container_registry.acr.login_server}/storeonwheelsserver:latest" + image = "storeonwheelsserver:latest" } resource "null_resource" "build_docker_image" { @@ -17,10 +17,8 @@ resource "null_resource" "build_docker_image" { environment = { "IMAGE" = local.image } - command = <<-EOT - cd ../.. - docker compose build - EOT + working_dir = "../.." + command = "docker compose build" } depends_on = [azurerm_container_registry.acr] } @@ -29,7 +27,7 @@ resource "null_resource" "push_docker_image" { provisioner "local-exec" { command = <<-EOT az acr login --name ${azurerm_container_registry.acr.name} - docker push ${azurerm_container_registry.acr.login_server}/storeonwheels.server + docker push "${azurerm_container_registry.acr.login_server}/${local.image}" EOT } depends_on = [null_resource.build_docker_image] @@ -50,8 +48,8 @@ resource "azurerm_container_app" "app" { template { container { - name = local.image - image = "nginx:latest" + name = "storeonwheelsserver" + image = "${azurerm_container_registry.acr.login_server}/${local.image}" cpu = 0.5 memory = "0.5Gi" } From 69fe4f16c6999dd5b950398e05b04ec1f4079f69 Mon Sep 17 00:00:00 2001 From: eugene Date: Sat, 17 Aug 2024 22:18:12 +0800 Subject: [PATCH 06/10] fix: docker --- infra/Terraform/container-app.tf | 71 ++++++++++++++++---------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/infra/Terraform/container-app.tf b/infra/Terraform/container-app.tf index 9c4fc22..43e4c14 100644 --- a/infra/Terraform/container-app.tf +++ b/infra/Terraform/container-app.tf @@ -9,16 +9,16 @@ resource "azurerm_container_registry" "acr" { } locals { - image = "storeonwheelsserver:latest" + image = "storeonwheelsserver" } resource "null_resource" "build_docker_image" { provisioner "local-exec" { environment = { - "IMAGE" = local.image + "IMAGE" = "${local.image}:latest" } working_dir = "../.." - command = "docker compose build" + command = "docker compose build" } depends_on = [azurerm_container_registry.acr] } @@ -26,44 +26,45 @@ resource "null_resource" "build_docker_image" { resource "null_resource" "push_docker_image" { provisioner "local-exec" { command = <<-EOT - az acr login --name ${azurerm_container_registry.acr.name} - docker push "${azurerm_container_registry.acr.login_server}/${local.image}" + az acr login --name ${azurerm_container_registry.acr.name} + docker tag storeonwheelsserver "${azurerm_container_registry.acr.login_server}/${local.image}" + docker push "${azurerm_container_registry.acr.login_server}/${local.image}:latest" EOT } depends_on = [null_resource.build_docker_image] } -resource "azurerm_container_app_environment" "env" { - name = "ca-env-storeonwheels-prod-sea" - location = azurerm_resource_group.rg.location - resource_group_name = azurerm_resource_group.rg.name - log_analytics_workspace_id = azurerm_log_analytics_workspace.analytics.id -} +# resource "azurerm_container_app_environment" "env" { +# name = "ca-env-storeonwheels-prod-sea" +# location = azurerm_resource_group.rg.location +# resource_group_name = azurerm_resource_group.rg.name +# log_analytics_workspace_id = azurerm_log_analytics_workspace.analytics.id +# } -resource "azurerm_container_app" "app" { - name = "ca-storeonwheels-prod-sea" - container_app_environment_id = azurerm_container_app_environment.env.id - resource_group_name = azurerm_resource_group.rg.name - revision_mode = "Single" +# resource "azurerm_container_app" "app" { +# name = "ca-storeonwheels-prod-sea" +# container_app_environment_id = azurerm_container_app_environment.env.id +# resource_group_name = azurerm_resource_group.rg.name +# revision_mode = "Single" - template { - container { - name = "storeonwheelsserver" - image = "${azurerm_container_registry.acr.login_server}/${local.image}" - cpu = 0.5 - memory = "0.5Gi" - } - } +# template { +# container { +# name = "storeonwheelsserver" +# image = "${azurerm_container_registry.acr.login_server}/${local.image}" +# cpu = 0.5 +# memory = "1Gi" +# } +# } - ingress { - allow_insecure_connections = false - external_enabled = true - target_port = 4000 - # ws connection not distributed to message queues yet - traffic_weight { - percentage = 100 - } - } +# ingress { +# allow_insecure_connections = false +# external_enabled = true +# target_port = 4000 +# # ws connection not distributed to message queues yet +# traffic_weight { +# percentage = 100 +# } +# } - depends_on = [null_resource.push_docker_image] -} +# depends_on = [null_resource.push_docker_image] +# } From fc5b558935c6cedd0292a4e179c7c57e62be2cb8 Mon Sep 17 00:00:00 2001 From: eugene Date: Sat, 17 Aug 2024 23:53:44 +0800 Subject: [PATCH 07/10] fix: docker --- infra/Terraform/container-app.tf | 64 ++++++++++++++++---------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/infra/Terraform/container-app.tf b/infra/Terraform/container-app.tf index 43e4c14..9ea9d18 100644 --- a/infra/Terraform/container-app.tf +++ b/infra/Terraform/container-app.tf @@ -15,7 +15,7 @@ locals { resource "null_resource" "build_docker_image" { provisioner "local-exec" { environment = { - "IMAGE" = "${local.image}:latest" + "IMAGE" = "${local.image}" } working_dir = "../.." command = "docker compose build" @@ -28,43 +28,43 @@ resource "null_resource" "push_docker_image" { command = <<-EOT az acr login --name ${azurerm_container_registry.acr.name} docker tag storeonwheelsserver "${azurerm_container_registry.acr.login_server}/${local.image}" - docker push "${azurerm_container_registry.acr.login_server}/${local.image}:latest" + docker push "${azurerm_container_registry.acr.login_server}/${local.image}" EOT } depends_on = [null_resource.build_docker_image] } -# resource "azurerm_container_app_environment" "env" { -# name = "ca-env-storeonwheels-prod-sea" -# location = azurerm_resource_group.rg.location -# resource_group_name = azurerm_resource_group.rg.name -# log_analytics_workspace_id = azurerm_log_analytics_workspace.analytics.id -# } +resource "azurerm_container_app_environment" "env" { + name = "ca-env-storeonwheels-prod-sea" + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + log_analytics_workspace_id = azurerm_log_analytics_workspace.analytics.id +} -# resource "azurerm_container_app" "app" { -# name = "ca-storeonwheels-prod-sea" -# container_app_environment_id = azurerm_container_app_environment.env.id -# resource_group_name = azurerm_resource_group.rg.name -# revision_mode = "Single" +resource "azurerm_container_app" "app" { + name = "ca-storeonwheels-prod-sea" + container_app_environment_id = azurerm_container_app_environment.env.id + resource_group_name = azurerm_resource_group.rg.name + revision_mode = "Single" -# template { -# container { -# name = "storeonwheelsserver" -# image = "${azurerm_container_registry.acr.login_server}/${local.image}" -# cpu = 0.5 -# memory = "1Gi" -# } -# } + template { + container { + name = "storeonwheelsserver" + image = "${azurerm_container_registry.acr.login_server}/${local.image}" + cpu = 0.5 + memory = "1Gi" + } + } -# ingress { -# allow_insecure_connections = false -# external_enabled = true -# target_port = 4000 -# # ws connection not distributed to message queues yet -# traffic_weight { -# percentage = 100 -# } -# } + ingress { + allow_insecure_connections = false + external_enabled = true + target_port = 4000 + # ws connection not distributed to message queues yet + traffic_weight { + percentage = 100 + } + } -# depends_on = [null_resource.push_docker_image] -# } + depends_on = [null_resource.push_docker_image] +} From d9103e85c88a075c9cb9a4ec65464f5a5d87061f Mon Sep 17 00:00:00 2001 From: Eugene Tham Date: Tue, 20 Aug 2024 07:52:05 +0100 Subject: [PATCH 08/10] chore: remove rm -rf --- Makefile | 18 +++++++++--------- src/StoreOnWheels.Server/Dockerfile | 1 + src/storeonwheels.client/package.json | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 4b8fc1a..49204fd 100644 --- a/Makefile +++ b/Makefile @@ -14,15 +14,15 @@ format: cd src/storeonwheels.client && npm run fmt # mimicks the right click docker build in visual studio, simplified in docker-compose.yml -# docker: -# docker build \ -# --file ./src/StoreOnWheels.Server/Dockerfile \ -# --progress=plain \ -# --force-rm -t storeonwheelsserver \ -# --build-arg "BUILD_CONFIGURATION=Debug" \ -# --label "com.microsoft.created-by=visual-studio" \ -# --label "com.microsoft.visual-studio.project-name=StoreOnWheels.Server" \ -# src +docker: + docker build \ + --file ./src/StoreOnWheels.Server/Dockerfile \ + --progress=plain \ + --force-rm -t storeonwheelsserver \ + --build-arg "BUILD_CONFIGURATION=Debug" \ + --label "com.microsoft.created-by=visual-studio" \ + --label "com.microsoft.visual-studio.project-name=StoreOnWheels.Server" \ + src compose: docker compose rm -fsv && docker compose up -d diff --git a/src/StoreOnWheels.Server/Dockerfile b/src/StoreOnWheels.Server/Dockerfile index c7c1ebb..660959f 100644 --- a/src/StoreOnWheels.Server/Dockerfile +++ b/src/StoreOnWheels.Server/Dockerfile @@ -20,6 +20,7 @@ COPY ["StoreOnWheels.Server/StoreOnWheels.Server.csproj", "StoreOnWheels.Server/ RUN dotnet restore "./StoreOnWheels.Server/StoreOnWheels.Server.csproj" COPY . . RUN ls storeonwheels.client +RUN ls StoreOnWheels.Server WORKDIR "/src/StoreOnWheels.Server" RUN dotnet build "./StoreOnWheels.Server.csproj" -c $BUILD_CONFIGURATION -o /app/build diff --git a/src/storeonwheels.client/package.json b/src/storeonwheels.client/package.json index 3386c10..e9f4910 100644 --- a/src/storeonwheels.client/package.json +++ b/src/storeonwheels.client/package.json @@ -4,7 +4,7 @@ "scripts": { "ng": "ng", "start": "run-script-os", - "build": "rm -rf dist && ng build --optimization", + "build": "ng build --optimization", "watch": "ng build --watch --configuration development", "clear": "npx npkill", "test": "ng test", From a8683345223dd11fdf259427da0f2992eb726658 Mon Sep 17 00:00:00 2001 From: eugene Date: Sun, 25 Aug 2024 19:46:35 +0800 Subject: [PATCH 09/10] fix: multi provisioners --- infra/Terraform/container-app.tf | 85 ++++++++++++++++++-------------- infra/Terraform/outputs.tf | 9 ++++ 2 files changed, 56 insertions(+), 38 deletions(-) create mode 100644 infra/Terraform/outputs.tf diff --git a/infra/Terraform/container-app.tf b/infra/Terraform/container-app.tf index 9ea9d18..cd48182 100644 --- a/infra/Terraform/container-app.tf +++ b/infra/Terraform/container-app.tf @@ -12,6 +12,7 @@ locals { image = "storeonwheelsserver" } +# https://developer.hashicorp.com/terraform/language/resources/provisioners/syntax#multiple-provisioners resource "null_resource" "build_docker_image" { provisioner "local-exec" { environment = { @@ -20,51 +21,59 @@ resource "null_resource" "build_docker_image" { working_dir = "../.." command = "docker compose build" } - depends_on = [azurerm_container_registry.acr] -} -resource "null_resource" "push_docker_image" { provisioner "local-exec" { - command = <<-EOT - az acr login --name ${azurerm_container_registry.acr.name} - docker tag storeonwheelsserver "${azurerm_container_registry.acr.login_server}/${local.image}" - docker push "${azurerm_container_registry.acr.login_server}/${local.image}" - EOT + command = "az acr login --name ${azurerm_container_registry.acr.name}" } - depends_on = [null_resource.build_docker_image] -} - -resource "azurerm_container_app_environment" "env" { - name = "ca-env-storeonwheels-prod-sea" - location = azurerm_resource_group.rg.location - resource_group_name = azurerm_resource_group.rg.name - log_analytics_workspace_id = azurerm_log_analytics_workspace.analytics.id -} -resource "azurerm_container_app" "app" { - name = "ca-storeonwheels-prod-sea" - container_app_environment_id = azurerm_container_app_environment.env.id - resource_group_name = azurerm_resource_group.rg.name - revision_mode = "Single" + provisioner "local-exec" { + command = < Date: Sun, 25 Aug 2024 19:54:32 +0800 Subject: [PATCH 10/10] chore: tf-2 --- infra/Terraform/container-app.tf | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/infra/Terraform/container-app.tf b/infra/Terraform/container-app.tf index cd48182..34d1d66 100644 --- a/infra/Terraform/container-app.tf +++ b/infra/Terraform/container-app.tf @@ -12,7 +12,7 @@ locals { image = "storeonwheelsserver" } -# https://developer.hashicorp.com/terraform/language/resources/provisioners/syntax#multiple-provisioners +# [Use multiple provisoners to run multiple commands in local exec](https://tinyurl.com/mrjw6rkf) resource "null_resource" "build_docker_image" { provisioner "local-exec" { environment = { @@ -27,9 +27,7 @@ resource "null_resource" "build_docker_image" { } provisioner "local-exec" { - command = <