Skip to content

Commit b6abee8

Browse files
authored
Merge pull request #21338 from dvdksn/fix-releaser-etoomanyredirects
releaser: get redirects from files instead of env vars
2 parents eee8099 + 0a3f978 commit b6abee8

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

_releaser/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ARG GO_VERSION=1.19
55
FROM scratch AS sitedir
66

77
FROM golang:${GO_VERSION}-alpine AS base
8-
RUN apk add --no-cache jq openssl
8+
RUN apk add --no-cache openssl
99
ENV CGO_ENABLED=0
1010
WORKDIR /src
1111
COPY go.mod go.sum ./
@@ -49,6 +49,6 @@ RUN --mount=type=bind,target=. \
4949
--mount=type=secret,id=AWS_SECRET_ACCESS_KEY \
5050
--mount=type=secret,id=AWS_SESSION_TOKEN \
5151
AWS_LAMBDA_FUNCTION_FILE=cloudfront-lambda-redirects.js \
52-
REDIRECTS_JSON=$(jq -c '.' /site/redirects.json) \
53-
REDIRECTS_PREFIXES_JSON=$(jq -c '.' redirects-prefixes.json) \
52+
REDIRECTS_FILE="/site/redirects.json" \
53+
REDIRECTS_PREFIXES_FILE="redirects-prefixes.json" \
5454
releaser aws cloudfront-update

_releaser/aws.go

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,17 @@ func (s *AwsLambdaInvokeCmd) Run() error {
9898
type AwsCloudfrontUpdateCmd struct {
9999
Region string `kong:"name='region',env='AWS_REGION'"`
100100
Function string `kong:"name='lambda-function',env='AWS_LAMBDA_FUNCTION'"`
101-
FunctionFile string `kong:"name='lambda-function-file',env='AWS_LAMBDA_FUNCTION_FILE'"`
101+
FunctionFile string `kong:"name='lambda-function-file',env='AWS_LAMBDA_FUNCTION_FILE',type=filecontent"`
102102
CloudfrontID string `kong:"name='cloudfront-id',env='AWS_CLOUDFRONT_ID'"`
103-
RedirectsJSON string `kong:"name='redirects-json',env='REDIRECTS_JSON'"`
104-
RedirectsPrefixesJSON string `kong:"name='redirects-prefixes-json',env='REDIRECTS_PREFIXES_JSON'"`
103+
RedirectsFile string `kong:"name='redirects-file',env='REDIRECTS_FILE',type=filecontent"`
104+
RedirectsPrefixesFile string `kong:"name='redirects-prefixes-file',env='REDIRECTS_PREFIXES_FILE',type=filecontent"`
105105
}
106106

107107
func (s *AwsCloudfrontUpdateCmd) Run() error {
108108
var err error
109109
ver := time.Now().UTC().Format(time.RFC3339)
110110

111-
zipdt, err := getLambdaFunctionZip(s.FunctionFile, s.RedirectsJSON, s.RedirectsPrefixesJSON)
111+
zipdt, err := getLambdaFunctionZip(s.FunctionFile, s.RedirectsFile, s.RedirectsPrefixesFile)
112112
if err != nil {
113113
return fmt.Errorf("cannot create lambda function zip: %w", err)
114114
}
@@ -228,20 +228,15 @@ func (s *AwsCloudfrontUpdateCmd) Run() error {
228228
return nil
229229
}
230230

231-
func getLambdaFunctionZip(funcFilename string, redirectsJSON string, redirectsPrefixesJSON string) ([]byte, error) {
232-
funcdt, err := os.ReadFile(funcFilename)
233-
if err != nil {
234-
return nil, fmt.Errorf("failed to read lambda function file %q: %w", funcFilename, err)
235-
}
236-
231+
func getLambdaFunctionZip(funcdt, redirects, redirectsPrefixes string) ([]byte, error) {
237232
var funcbuf bytes.Buffer
238-
functpl := template.Must(template.New("").Parse(string(funcdt)))
239-
if err = functpl.Execute(&funcbuf, struct {
233+
functpl := template.Must(template.New("").Parse(funcdt))
234+
if err := functpl.Execute(&funcbuf, struct {
240235
RedirectsJSON string
241236
RedirectsPrefixesJSON string
242237
}{
243-
redirectsJSON,
244-
redirectsPrefixesJSON,
238+
redirects,
239+
redirectsPrefixes,
245240
}); err != nil {
246241
return nil, err
247242
}

layouts/index.redirects.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@
1212
{{- $redirects.SetInMap "paths" . $target -}}
1313
{{- end -}}
1414
{{- end -}}
15-
{{ $redirects.Get "paths" | jsonify }}
15+
{{- $opts := dict "noHTMLEscape" true }}
16+
{{- $redirects.Get "paths" | jsonify $opts }}

0 commit comments

Comments
 (0)