From 2eeb32316e62532bdf0f89e579621e15e7aad614 Mon Sep 17 00:00:00 2001 From: vimtor Date: Thu, 18 Dec 2025 17:52:49 +0100 Subject: [PATCH 1/5] fix aws bucket file upload order --- examples/aws-angular/angular.json | 3 ++ pkg/server/resource/aws-bucket-files.go | 44 ++++++++++++++++++++----- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/examples/aws-angular/angular.json b/examples/aws-angular/angular.json index e928c0184f..0d1539bd49 100644 --- a/examples/aws-angular/angular.json +++ b/examples/aws-angular/angular.json @@ -92,5 +92,8 @@ } } } + }, + "cli": { + "analytics": false } } \ No newline at end of file diff --git a/pkg/server/resource/aws-bucket-files.go b/pkg/server/resource/aws-bucket-files.go index fecf8367d4..63767c95fc 100644 --- a/pkg/server/resource/aws-bucket-files.go +++ b/pkg/server/resource/aws-bucket-files.go @@ -2,7 +2,9 @@ package resource import ( "bytes" + "log/slog" "os" + "strings" "sync" "github.com/aws/aws-sdk-go-v2/aws" @@ -118,6 +120,38 @@ func (r *BucketFiles) upload(client *s3.Client, bucketName string, files []Bucke oldFilesMap[f.Key] = f } + // Split files into HTML and non-HTML to upload non-HTML first. + // This avoids a race condition where CloudFront serves new HTML + // referencing assets that haven't been uploaded yet. + var htmlFiles, nonHtmlFiles []BucketFile + for _, file := range files { + oldFile, exists := oldFilesMap[file.Key] + if exists && oldFile.Hash != nil && *oldFile.Hash == *file.Hash && + oldFile.CacheControl == file.CacheControl && + oldFile.ContentType == file.ContentType { + continue + } + if strings.HasSuffix(file.Key, ".html") { + htmlFiles = append(htmlFiles, file) + } else { + nonHtmlFiles = append(nonHtmlFiles, file) + } + } + + slog.Info("uploading files") + + if err := r.uploadFiles(client, bucketName, nonHtmlFiles); err != nil { + return err + } + + return r.uploadFiles(client, bucketName, htmlFiles) +} + +func (r *BucketFiles) uploadFiles(client *s3.Client, bucketName string, files []BucketFile) error { + if len(files) == 0 { + return nil + } + // Create channels for work distribution and error collection filesChan := make(chan BucketFile) errChan := make(chan error, len(files)) @@ -131,7 +165,6 @@ func (r *BucketFiles) upload(client *s3.Client, bucketName string, files []Bucke defer wg.Done() // Each worker processes files from the channel for file := range filesChan { - // write start timestamp with nanoseconds to file content, err := os.ReadFile(file.Source) if err != nil { errChan <- err @@ -152,15 +185,9 @@ func (r *BucketFiles) upload(client *s3.Client, bucketName string, files []Bucke }() } - // Send files that need uploading to the channel + // Send files to the channel go func() { for _, file := range files { - oldFile, exists := oldFilesMap[file.Key] - if exists && oldFile.Hash != nil && *oldFile.Hash == *file.Hash && - oldFile.CacheControl == file.CacheControl && - oldFile.ContentType == file.ContentType { - continue - } filesChan <- file } close(filesChan) @@ -200,4 +227,3 @@ func (r *BucketFiles) purge(client *s3.Client, bucketName string, files []Bucket return nil } - From 480a297323b3d3dbf6642844e304e76c5fc1a769 Mon Sep 17 00:00:00 2001 From: vimtor Date: Thu, 18 Dec 2025 17:54:21 +0100 Subject: [PATCH 2/5] untrack file --- examples/aws-angular/angular.json | 99 ------------------------------- 1 file changed, 99 deletions(-) delete mode 100644 examples/aws-angular/angular.json diff --git a/examples/aws-angular/angular.json b/examples/aws-angular/angular.json deleted file mode 100644 index 0d1539bd49..0000000000 --- a/examples/aws-angular/angular.json +++ /dev/null @@ -1,99 +0,0 @@ -{ - "$schema": "./node_modules/@angular/cli/lib/config/schema.json", - "version": 1, - "newProjectRoot": "projects", - "projects": { - "aws-angular": { - "projectType": "application", - "schematics": {}, - "root": "", - "sourceRoot": "src", - "prefix": "app", - "architect": { - "build": { - "builder": "@ngx-env/builder:application", - "options": { - "outputPath": "dist/aws-angular", - "index": "src/index.html", - "browser": "src/main.ts", - "polyfills": [ - "zone.js" - ], - "tsConfig": "tsconfig.app.json", - "assets": [ - { - "glob": "**/*", - "input": "public" - } - ], - "styles": [ - "src/styles.css" - ], - "scripts": [] - }, - "configurations": { - "production": { - "budgets": [ - { - "type": "initial", - "maximumWarning": "500kB", - "maximumError": "1MB" - }, - { - "type": "anyComponentStyle", - "maximumWarning": "2kB", - "maximumError": "4kB" - } - ], - "outputHashing": "all" - }, - "development": { - "optimization": false, - "extractLicenses": false, - "sourceMap": true - } - }, - "defaultConfiguration": "production" - }, - "serve": { - "builder": "@ngx-env/builder:dev-server", - "configurations": { - "production": { - "buildTarget": "aws-angular:build:production" - }, - "development": { - "buildTarget": "aws-angular:build:development" - } - }, - "defaultConfiguration": "development" - }, - "extract-i18n": { - "builder": "@ngx-env/builder:extract-i18n" - }, - "test": { - "builder": "@ngx-env/builder:karma", - "options": { - "polyfills": [ - "zone.js", - "zone.js/testing" - ], - "tsConfig": "tsconfig.spec.json", - "assets": [ - { - "glob": "**/*", - "input": "public" - } - ], - "styles": [ - "src/styles.css" - ], - "scripts": [] - } - } - } - } - }, - "cli": { - "analytics": false - } -} \ No newline at end of file From 89f0509fb3bbae941a0c9bfcb22a4208c2c9cdb3 Mon Sep 17 00:00:00 2001 From: vimtor Date: Thu, 18 Dec 2025 17:54:48 +0100 Subject: [PATCH 3/5] untrack file --- examples/aws-angular/angular.json | 87 +++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 examples/aws-angular/angular.json diff --git a/examples/aws-angular/angular.json b/examples/aws-angular/angular.json new file mode 100644 index 0000000000..d55ba303df --- /dev/null +++ b/examples/aws-angular/angular.json @@ -0,0 +1,87 @@ +{ + "$schema": "./node_modules/@angular/cli/lib/config/schema.json", + "version": 1, + "newProjectRoot": "projects", + "projects": { + "aws-angular": { + "projectType": "application", + "schematics": {}, + "root": "", + "sourceRoot": "src", + "prefix": "app", + "architect": { + "build": { + "builder": "@ngx-env/builder:application", + "options": { + "outputPath": "dist/aws-angular", + "index": "src/index.html", + "browser": "src/main.ts", + "polyfills": ["zone.js"], + "tsConfig": "tsconfig.app.json", + "assets": [ + { + "glob": "**/*", + "input": "public" + } + ], + "styles": ["src/styles.css"], + "scripts": [] + }, + "configurations": { + "production": { + "budgets": [ + { + "type": "initial", + "maximumWarning": "500kB", + "maximumError": "1MB" + }, + { + "type": "anyComponentStyle", + "maximumWarning": "2kB", + "maximumError": "4kB" + } + ], + "outputHashing": "all" + }, + "development": { + "optimization": false, + "extractLicenses": false, + "sourceMap": true + } + }, + "defaultConfiguration": "production" + }, + "serve": { + "builder": "@ngx-env/builder:dev-server", + "configurations": { + "production": { + "buildTarget": "aws-angular:build:production" + }, + "development": { + "buildTarget": "aws-angular:build:development" + } + }, + "defaultConfiguration": "development" + }, + "extract-i18n": { + "builder": "@ngx-env/builder:extract-i18n" + }, + "test": { + "builder": "@ngx-env/builder:karma", + "options": { + "polyfills": ["zone.js", "zone.js/testing"], + "tsConfig": "tsconfig.spec.json", + "assets": [ + { + "glob": "**/*", + "input": "public" + } + ], + "styles": ["src/styles.css"], + "scripts": [] + } + } + } + } + } +} From bba12e5bfbeaf68cc6034f375cd6e6a5e53bd006 Mon Sep 17 00:00:00 2001 From: vimtor Date: Thu, 18 Dec 2025 17:57:04 +0100 Subject: [PATCH 4/5] fix untracked file --- examples/aws-angular/angular.json | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/examples/aws-angular/angular.json b/examples/aws-angular/angular.json index d55ba303df..e928c0184f 100644 --- a/examples/aws-angular/angular.json +++ b/examples/aws-angular/angular.json @@ -16,7 +16,9 @@ "outputPath": "dist/aws-angular", "index": "src/index.html", "browser": "src/main.ts", - "polyfills": ["zone.js"], + "polyfills": [ + "zone.js" + ], "tsConfig": "tsconfig.app.json", "assets": [ { @@ -24,7 +26,9 @@ "input": "public" } ], - "styles": ["src/styles.css"], + "styles": [ + "src/styles.css" + ], "scripts": [] }, "configurations": { @@ -69,7 +73,10 @@ "test": { "builder": "@ngx-env/builder:karma", "options": { - "polyfills": ["zone.js", "zone.js/testing"], + "polyfills": [ + "zone.js", + "zone.js/testing" + ], "tsConfig": "tsconfig.spec.json", "assets": [ { @@ -77,11 +84,13 @@ "input": "public" } ], - "styles": ["src/styles.css"], + "styles": [ + "src/styles.css" + ], "scripts": [] } } } } } -} +} \ No newline at end of file From cedbab1bce201f75f225629cba8699b2ca32476d Mon Sep 17 00:00:00 2001 From: vimtor Date: Thu, 18 Dec 2025 18:00:52 +0100 Subject: [PATCH 5/5] remove log from bucket files --- pkg/server/resource/aws-bucket-files.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/pkg/server/resource/aws-bucket-files.go b/pkg/server/resource/aws-bucket-files.go index 63767c95fc..fb65f0ece7 100644 --- a/pkg/server/resource/aws-bucket-files.go +++ b/pkg/server/resource/aws-bucket-files.go @@ -2,7 +2,6 @@ package resource import ( "bytes" - "log/slog" "os" "strings" "sync" @@ -138,8 +137,6 @@ func (r *BucketFiles) upload(client *s3.Client, bucketName string, files []Bucke } } - slog.Info("uploading files") - if err := r.uploadFiles(client, bucketName, nonHtmlFiles); err != nil { return err }