mirror of
https://github.com/docker/docs.git
synced 2026-10-23 18:09:02 +03:00
## Summary
The CloudFront redirect Lambda (`cloudfront-lambda-redirects.js`)
dropped the request query string when issuing 301 responses, so UTM tags
and other params were lost on redirected URLs. This appends the query
string to the `Location` header of both the exact-match and prefix
redirects (the directory/markdown rewrite branch already forwards the
request, so params survive there).
Adds unit tests (`node --test`, zero dependencies) that render the Go
template the same way `aws.go` does and exercise the handler. The tests
run in CI via a new `releaser-test` Dockerfile stage / bake target,
baked alongside `releaser-build` in the existing `releaser` job.
## Learnings
- The redirect Lambda source is a Go `text/template`
(`{{.RedirectsJSON}}` / `{{.RedirectsPrefixesJSON}}`), rendered and
zipped by `hack/releaser/aws.go`. To unit-test it, substitute the
placeholders the same way `aws.go` does, then evaluate the result as a
CommonJS module.
- `test-go-redirects` validates redirect *data* against the built
`public/` site, so it's the wrong host for a fast pure-JS test — the
`releaser` job, which already builds from `hack/releaser`, is the
natural home and has no Hugo dependency.
Generated by Claude Code
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
49 lines
1.5 KiB
Docker
49 lines
1.5 KiB
Docker
# syntax=docker/dockerfile:1
|
|
|
|
ARG GO_VERSION=1.26
|
|
|
|
FROM scratch AS sitedir
|
|
|
|
FROM golang:${GO_VERSION}-alpine AS base
|
|
RUN apk add --no-cache openssl
|
|
ENV CGO_ENABLED=0
|
|
WORKDIR /src
|
|
|
|
FROM base AS releaser
|
|
RUN --mount=type=bind,target=. \
|
|
--mount=type=cache,target=/go/pkg/mod \
|
|
--mount=type=cache,target=/root/.cache/go-build \
|
|
go build -o /out/releaser .
|
|
|
|
# releaser-test runs the unit tests for the CloudFront redirect Lambda function.
|
|
FROM base AS releaser-test
|
|
RUN apk add --no-cache nodejs
|
|
RUN --mount=type=bind,target=. \
|
|
node --test cloudfront-lambda-redirects.test.js
|
|
|
|
FROM base AS aws-lambda-invoke
|
|
ARG DRY_RUN=false
|
|
ARG AWS_REGION
|
|
ARG AWS_LAMBDA_FUNCTION
|
|
RUN --mount=type=bind,from=releaser,source=/out/releaser,target=/usr/bin/releaser \
|
|
--mount=type=secret,id=AWS_ACCESS_KEY_ID \
|
|
--mount=type=secret,id=AWS_SECRET_ACCESS_KEY \
|
|
--mount=type=secret,id=AWS_SESSION_TOKEN \
|
|
releaser aws lambda-invoke
|
|
|
|
FROM base AS aws-cloudfront-update
|
|
ARG DRY_RUN=false
|
|
ARG AWS_REGION
|
|
ARG AWS_LAMBDA_FUNCTION
|
|
ARG AWS_CLOUDFRONT_ID
|
|
ARG AWS_LAMBDA_FUNCTION_FILE="cloudfront-lambda-redirects.js"
|
|
ARG REDIRECTS_FILE="/site/redirects.json"
|
|
ARG REDIRECTS_PREFIXES_FILE="redirects-prefixes.json"
|
|
RUN --mount=type=bind,target=. \
|
|
--mount=type=bind,from=sitedir,target=/site \
|
|
--mount=type=bind,from=releaser,source=/out/releaser,target=/usr/bin/releaser \
|
|
--mount=type=secret,id=AWS_ACCESS_KEY_ID \
|
|
--mount=type=secret,id=AWS_SECRET_ACCESS_KEY \
|
|
--mount=type=secret,id=AWS_SESSION_TOKEN \
|
|
releaser aws cloudfront-update
|