Merge pull request #21351 from docker/revert-21338-fix-releaser-etoomanyredirects

Revert "releaser: get redirects from files instead of env vars"
This commit is contained in:
David Karlsson 2024-11-06 09:33:12 +01:00 committed by GitHub
commit 00b5254157
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 14 deletions

View File

@ -5,7 +5,7 @@ ARG GO_VERSION=1.19
FROM scratch AS sitedir FROM scratch AS sitedir
FROM golang:${GO_VERSION}-alpine AS base FROM golang:${GO_VERSION}-alpine AS base
RUN apk add --no-cache openssl RUN apk add --no-cache jq openssl
ENV CGO_ENABLED=0 ENV CGO_ENABLED=0
WORKDIR /src WORKDIR /src
COPY go.mod go.sum ./ COPY go.mod go.sum ./
@ -49,6 +49,6 @@ RUN --mount=type=bind,target=. \
--mount=type=secret,id=AWS_SECRET_ACCESS_KEY \ --mount=type=secret,id=AWS_SECRET_ACCESS_KEY \
--mount=type=secret,id=AWS_SESSION_TOKEN \ --mount=type=secret,id=AWS_SESSION_TOKEN \
AWS_LAMBDA_FUNCTION_FILE=cloudfront-lambda-redirects.js \ AWS_LAMBDA_FUNCTION_FILE=cloudfront-lambda-redirects.js \
REDIRECTS_FILE="/site/redirects.json" \ REDIRECTS_JSON=$(jq -c '.' /site/redirects.json) \
REDIRECTS_PREFIXES_FILE="redirects-prefixes.json" \ REDIRECTS_PREFIXES_JSON=$(jq -c '.' redirects-prefixes.json) \
releaser aws cloudfront-update releaser aws cloudfront-update

View File

@ -98,17 +98,17 @@ func (s *AwsLambdaInvokeCmd) Run() error {
type AwsCloudfrontUpdateCmd struct { type AwsCloudfrontUpdateCmd struct {
Region string `kong:"name='region',env='AWS_REGION'"` Region string `kong:"name='region',env='AWS_REGION'"`
Function string `kong:"name='lambda-function',env='AWS_LAMBDA_FUNCTION'"` Function string `kong:"name='lambda-function',env='AWS_LAMBDA_FUNCTION'"`
FunctionFile string `kong:"name='lambda-function-file',env='AWS_LAMBDA_FUNCTION_FILE',type=filecontent"` FunctionFile string `kong:"name='lambda-function-file',env='AWS_LAMBDA_FUNCTION_FILE'"`
CloudfrontID string `kong:"name='cloudfront-id',env='AWS_CLOUDFRONT_ID'"` CloudfrontID string `kong:"name='cloudfront-id',env='AWS_CLOUDFRONT_ID'"`
RedirectsFile string `kong:"name='redirects-file',env='REDIRECTS_FILE',type=filecontent"` RedirectsJSON string `kong:"name='redirects-json',env='REDIRECTS_JSON'"`
RedirectsPrefixesFile string `kong:"name='redirects-prefixes-file',env='REDIRECTS_PREFIXES_FILE',type=filecontent"` RedirectsPrefixesJSON string `kong:"name='redirects-prefixes-json',env='REDIRECTS_PREFIXES_JSON'"`
} }
func (s *AwsCloudfrontUpdateCmd) Run() error { func (s *AwsCloudfrontUpdateCmd) Run() error {
var err error var err error
ver := time.Now().UTC().Format(time.RFC3339) ver := time.Now().UTC().Format(time.RFC3339)
zipdt, err := getLambdaFunctionZip(s.FunctionFile, s.RedirectsFile, s.RedirectsPrefixesFile) zipdt, err := getLambdaFunctionZip(s.FunctionFile, s.RedirectsJSON, s.RedirectsPrefixesJSON)
if err != nil { if err != nil {
return fmt.Errorf("cannot create lambda function zip: %w", err) return fmt.Errorf("cannot create lambda function zip: %w", err)
} }
@ -228,15 +228,20 @@ func (s *AwsCloudfrontUpdateCmd) Run() error {
return nil return nil
} }
func getLambdaFunctionZip(funcdt, redirects, redirectsPrefixes string) ([]byte, error) { func getLambdaFunctionZip(funcFilename string, redirectsJSON string, redirectsPrefixesJSON string) ([]byte, error) {
funcdt, err := os.ReadFile(funcFilename)
if err != nil {
return nil, fmt.Errorf("failed to read lambda function file %q: %w", funcFilename, err)
}
var funcbuf bytes.Buffer var funcbuf bytes.Buffer
functpl := template.Must(template.New("").Parse(funcdt)) functpl := template.Must(template.New("").Parse(string(funcdt)))
if err := functpl.Execute(&funcbuf, struct { if err = functpl.Execute(&funcbuf, struct {
RedirectsJSON string RedirectsJSON string
RedirectsPrefixesJSON string RedirectsPrefixesJSON string
}{ }{
redirects, redirectsJSON,
redirectsPrefixes, redirectsPrefixesJSON,
}); err != nil { }); err != nil {
return nil, err return nil, err
} }

View File

@ -12,5 +12,4 @@
{{- $redirects.SetInMap "paths" . $target -}} {{- $redirects.SetInMap "paths" . $target -}}
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}
{{- $opts := dict "noHTMLEscape" true }} {{ $redirects.Get "paths" | jsonify }}
{{- $redirects.Get "paths" | jsonify $opts }}