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

Chore/tf 2 #41

Merged
merged 10 commits into from
Aug 25, 2024
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
101 changes: 56 additions & 45 deletions infra/Terraform/container-app.tf
Original file line number Diff line number Diff line change
@@ -1,66 +1,77 @@
# 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"
admin_enabled = true
}

locals {
image = "${azurerm_container_registry.acr.login_server}/storeonwheelsserver:latest"
image = "storeonwheelsserver"
}

# [Use multiple provisoners to run multiple commands in local exec](https://tinyurl.com/mrjw6rkf)
resource "null_resource" "build_docker_image" {
provisioner "remote-exec" {
inline = [
"IMAGE=${local.image}",
"cd ../..",
"docker compose build"
]
provisioner "local-exec" {
environment = {
"IMAGE" = "${local.image}"
}
working_dir = "../.."
command = "docker compose build"
}
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 = "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 = "docker tag ${local.image} ${azurerm_container_registry.acr.login_server}/${local.image}"
}

template {
container {
name = "storeonwheels.server"
image = "nginx:latest"
cpu = 0.5
memory = "0.5Gi"
}
provisioner "local-exec" {
command = "docker image ls"
}

ingress {
allow_insecure_connections = false
external_enabled = true
target_port = 80
# ws connection not distributed to message queues yet
traffic_weight {
percentage = 100
}
provisioner "local-exec" {
command = "docker push ${azurerm_container_registry.acr.login_server}/${local.image}"
}

depends_on = [azurerm_container_registry.acr]
}

# 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"

# 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
# }
# }

# depends_on = [null_resource.push_docker_image]
# }
9 changes: 9 additions & 0 deletions infra/Terraform/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
output "acr_name" {
description = "Name of ACR"
value = azurerm_container_registry.acr.name
}

output "login_server" {
description = "acr docker repo url"
value = azurerm_container_registry.acr.login_server
}
1 change: 1 addition & 0 deletions src/StoreOnWheels.Server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/storeonwheels.client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/storeonwheels.client/src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
Loading