Skip to content

Commit f0f450f

Browse files
committed
refactor: update frontend deployment workflow and add Azure storage resources
1 parent 1b791a5 commit f0f450f

File tree

6 files changed

+118
-18
lines changed

6 files changed

+118
-18
lines changed

.github/workflows/frontend-deploy.yml

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ jobs:
2626
cd frontend
2727
npm install
2828
29-
- name: Inject VITE_API_BASE_URL and build frontend
29+
- name: Build frontend
3030
run: |
31-
echo "window.env = { VITE_API_BASE_URL: '${{ secrets.VITE_API_BASE_URL }}' };" > frontend/dist/env.js
3231
cd frontend
3332
npm run build
3433
@@ -37,17 +36,3 @@ jobs:
3736
with:
3837
name: frontend-dist
3938
path: frontend/dist
40-
41-
- name: Setup Terraform
42-
uses: hashicorp/setup-terraform@v3
43-
44-
- name: Terraform Apply - Frontend Infra Only
45-
working-directory: ./infra-frontend
46-
run: |
47-
terraform init
48-
terraform apply -auto-approve
49-
env:
50-
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
51-
ARM_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
52-
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
53-
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}

infra/backend/main.tf

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,33 @@ resource "azurerm_linux_web_app" "backend" {
6262
"SPRING_DATASOURCE_PASSWORD" = var.db_password
6363
"JWT_SECRET" = var.jwt_secret
6464
}
65-
}
65+
}
66+
67+
resource "azurerm_storage_account" "frontend" {
68+
name = "blogfrontend"
69+
resource_group_name = azurerm_resource_group.rg.name
70+
location = azurerm_resource_group.rg.location
71+
account_tier = "Standard"
72+
account_replication_type = "LRS"
73+
74+
static_website {
75+
index_document = "index.html"
76+
error_404_document = "index.html"
77+
}
78+
}
79+
80+
resource "azurerm_storage_blob" "frontend_build" {
81+
for_each = fileset("${path.module}/../frontend/dist", "**/*")
82+
83+
name = each.value
84+
type = "Block"
85+
source = "${path.module}/../frontend/dist/${each.value}"
86+
storage_account_name = azurerm_storage_account.frontend.name
87+
storage_container_name = "$web"
88+
content_type = lookup(
89+
var.mime_types,
90+
regex("\\.([^.]+)$", each.value)[0],
91+
"application/octet-stream"
92+
)
93+
94+
}

infra/backend/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ output "postgres_fqdn" {
77
description = "PostgreSQL database FQDN"
88
value = azurerm_postgresql_flexible_server.db.fqdn
99
}
10+
11+
output "frontend_url" {
12+
description = "The URL of the deployed frontend static website"
13+
value = azurerm_storage_account.frontend.primary_web_endpoint
14+
}

infra/backend/variables.tf

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,25 @@ variable "jwt_secret" {
1818
description = "JWT secret key"
1919
type = string
2020
sensitive = true
21-
}
21+
}
22+
23+
variable "vite_api_base_url" {
24+
description = "The base URL of the backend API for the frontend to consume"
25+
type = string
26+
}
27+
28+
variable "mime_types" {
29+
description = "Map of file extensions to MIME types"
30+
type = map(string)
31+
default = {
32+
html = "text/html"
33+
css = "text/css"
34+
js = "application/javascript"
35+
json = "application/json"
36+
png = "image/png"
37+
svg = "image/svg+xml"
38+
jpg = "image/jpeg"
39+
jpeg = "image/jpeg"
40+
ico = "image/x-icon"
41+
}
42+
}

infra/frontend/.terraform.lock.hcl

Lines changed: 59 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

infra/frontend/dist/env.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
window.env = { VITE_API_BASE_URL: "https://blog-platform-api.azurewebsites.net/" };

0 commit comments

Comments
 (0)