mirror of https://github.com/docker/docs.git
Merge pull request #21338 from dvdksn/fix-releaser-etoomanyredirects
releaser: get redirects from files instead of env vars
This commit is contained in:
commit
b6abee8015
|
@ -5,7 +5,7 @@ ARG GO_VERSION=1.19
|
|||
FROM scratch AS sitedir
|
||||
|
||||
FROM golang:${GO_VERSION}-alpine AS base
|
||||
RUN apk add --no-cache jq openssl
|
||||
RUN apk add --no-cache openssl
|
||||
ENV CGO_ENABLED=0
|
||||
WORKDIR /src
|
||||
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_SESSION_TOKEN \
|
||||
AWS_LAMBDA_FUNCTION_FILE=cloudfront-lambda-redirects.js \
|
||||
REDIRECTS_JSON=$(jq -c '.' /site/redirects.json) \
|
||||
REDIRECTS_PREFIXES_JSON=$(jq -c '.' redirects-prefixes.json) \
|
||||
REDIRECTS_FILE="/site/redirects.json" \
|
||||
REDIRECTS_PREFIXES_FILE="redirects-prefixes.json" \
|
||||
releaser aws cloudfront-update
|
||||
|
|
|
@ -98,17 +98,17 @@ func (s *AwsLambdaInvokeCmd) Run() error {
|
|||
type AwsCloudfrontUpdateCmd struct {
|
||||
Region string `kong:"name='region',env='AWS_REGION'"`
|
||||
Function string `kong:"name='lambda-function',env='AWS_LAMBDA_FUNCTION'"`
|
||||
FunctionFile string `kong:"name='lambda-function-file',env='AWS_LAMBDA_FUNCTION_FILE'"`
|
||||
FunctionFile string `kong:"name='lambda-function-file',env='AWS_LAMBDA_FUNCTION_FILE',type=filecontent"`
|
||||
CloudfrontID string `kong:"name='cloudfront-id',env='AWS_CLOUDFRONT_ID'"`
|
||||
RedirectsJSON string `kong:"name='redirects-json',env='REDIRECTS_JSON'"`
|
||||
RedirectsPrefixesJSON string `kong:"name='redirects-prefixes-json',env='REDIRECTS_PREFIXES_JSON'"`
|
||||
RedirectsFile string `kong:"name='redirects-file',env='REDIRECTS_FILE',type=filecontent"`
|
||||
RedirectsPrefixesFile string `kong:"name='redirects-prefixes-file',env='REDIRECTS_PREFIXES_FILE',type=filecontent"`
|
||||
}
|
||||
|
||||
func (s *AwsCloudfrontUpdateCmd) Run() error {
|
||||
var err error
|
||||
ver := time.Now().UTC().Format(time.RFC3339)
|
||||
|
||||
zipdt, err := getLambdaFunctionZip(s.FunctionFile, s.RedirectsJSON, s.RedirectsPrefixesJSON)
|
||||
zipdt, err := getLambdaFunctionZip(s.FunctionFile, s.RedirectsFile, s.RedirectsPrefixesFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot create lambda function zip: %w", err)
|
||||
}
|
||||
|
@ -228,20 +228,15 @@ func (s *AwsCloudfrontUpdateCmd) Run() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
func getLambdaFunctionZip(funcdt, redirects, redirectsPrefixes string) ([]byte, error) {
|
||||
var funcbuf bytes.Buffer
|
||||
functpl := template.Must(template.New("").Parse(string(funcdt)))
|
||||
if err = functpl.Execute(&funcbuf, struct {
|
||||
functpl := template.Must(template.New("").Parse(funcdt))
|
||||
if err := functpl.Execute(&funcbuf, struct {
|
||||
RedirectsJSON string
|
||||
RedirectsPrefixesJSON string
|
||||
}{
|
||||
redirectsJSON,
|
||||
redirectsPrefixesJSON,
|
||||
redirects,
|
||||
redirectsPrefixes,
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -12,4 +12,5 @@
|
|||
{{- $redirects.SetInMap "paths" . $target -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{ $redirects.Get "paths" | jsonify }}
|
||||
{{- $opts := dict "noHTMLEscape" true }}
|
||||
{{- $redirects.Get "paths" | jsonify $opts }}
|
||||
|
|
Loading…
Reference in New Issue