Skip to content

Commit c904249

Browse files
committed
chore: update Dockerfiles and deployment workflow for improved compatibility and CORS handling
- Upgraded Go version in Dockerfiles from 1.24 to 1.26 for better performance and security. - Modified deployment workflow to disable OCI provenance and SBOM to prevent Lambda image issues. - Enhanced CORS middleware to set the "Vary" header and changed OPTIONS response status to 200 for better browser compatibility. - Updated tests to reflect changes in CORS handling.
1 parent 12818c3 commit c904249

5 files changed

Lines changed: 17 additions & 5 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ jobs:
147147
context: api
148148
platforms: linux/arm64
149149
push: true
150+
# OCI index + attestation manifests break Lambda (InvalidImage / inactive function).
151+
provenance: false
152+
sbom: false
150153
tags: |
151154
${{ steps.ecr-login.outputs.registry }}/devsper-registry-api:latest
152155
${{ steps.ecr-login.outputs.registry }}/devsper-registry-api:${{ github.sha }}
@@ -160,6 +163,8 @@ jobs:
160163
context: web
161164
platforms: linux/arm64
162165
push: true
166+
provenance: false
167+
sbom: false
163168
tags: |
164169
${{ steps.ecr-login.outputs.registry }}/devsper-registry-web:latest
165170
${{ steps.ecr-login.outputs.registry }}/devsper-registry-web:${{ github.sha }}

api/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Stage 1: builder
2-
FROM golang:1.24-alpine AS builder
2+
FROM golang:1.26-alpine AS builder
33
RUN apk add --no-cache ca-certificates git
44
WORKDIR /app
55
COPY go.mod go.sum ./

api/Dockerfile.lambda

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
ARG BUILDPLATFORM
66
# Stage 1: builder (native platform so no exec format error on amd64 runners)
7-
FROM --platform=$BUILDPLATFORM golang:1.24-alpine AS builder
7+
FROM --platform=$BUILDPLATFORM golang:1.26-alpine AS builder
88
RUN apk add --no-cache ca-certificates git
99
WORKDIR /app
1010
COPY go.mod go.sum ./

api/internal/middleware/cors.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,16 @@ func CORSWithAllowlist(allowedOrigins ...string) func(next http.Handler) http.Ha
2727
if origin != "" && allowed[origin] {
2828
w.Header().Set("Access-Control-Allow-Origin", origin)
2929
w.Header().Set("Access-Control-Allow-Credentials", "true")
30+
// Required when reflecting Origin so caches (e.g. CloudFront) do not serve one
31+
// origin’s CORS headers to another.
32+
w.Header().Add("Vary", "Origin")
3033
}
3134
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, PATCH, DELETE, OPTIONS")
3235
w.Header().Set("Access-Control-Allow-Headers", "Authorization, Content-Type, X-Requested-With, Accept, X-API-Key")
3336
w.Header().Set("Access-Control-Max-Age", "86400")
3437
if r.Method == http.MethodOptions {
35-
w.WriteHeader(http.StatusNoContent)
38+
// 200 is more widely treated as a successful preflight than 204 by browsers and proxies.
39+
w.WriteHeader(http.StatusOK)
3640
return
3741
}
3842
next.ServeHTTP(w, r)

api/internal/middleware/middleware_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@ func TestCORSWithAllowlist_AllowedOrigin(t *testing.T) {
2222
rr := httptest.NewRecorder()
2323
handler.ServeHTTP(rr, req)
2424

25-
if rr.Code != http.StatusNoContent {
26-
t.Errorf("expected 204 for OPTIONS, got %d", rr.Code)
25+
if rr.Code != http.StatusOK {
26+
t.Errorf("expected 200 for OPTIONS, got %d", rr.Code)
2727
}
2828
if got := rr.Header().Get("Access-Control-Allow-Origin"); got != "http://localhost:3000" {
2929
t.Errorf("Allow-Origin = %q, want %q", got, "http://localhost:3000")
3030
}
31+
if got := rr.Header().Get("Vary"); got != "Origin" {
32+
t.Errorf("Vary = %q, want %q", got, "Origin")
33+
}
3134
if got := rr.Header().Get("Access-Control-Allow-Credentials"); got != "true" {
3235
t.Errorf("Allow-Credentials = %q, want %q", got, "true")
3336
}

0 commit comments

Comments
 (0)