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 scratch AS sitedir
|
||||||
|
|
||||||
FROM golang:${GO_VERSION}-alpine AS base
|
FROM golang:${GO_VERSION}-alpine AS base
|
||||||
RUN apk add --no-cache jq openssl
|
RUN apk add --no-cache 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_JSON=$(jq -c '.' /site/redirects.json) \
|
REDIRECTS_FILE="/site/redirects.json" \
|
||||||
REDIRECTS_PREFIXES_JSON=$(jq -c '.' redirects-prefixes.json) \
|
REDIRECTS_PREFIXES_FILE="redirects-prefixes.json" \
|
||||||
releaser aws cloudfront-update
|
releaser aws cloudfront-update
|
||||||
|
|
|
@ -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'"`
|
FunctionFile string `kong:"name='lambda-function-file',env='AWS_LAMBDA_FUNCTION_FILE',type=filecontent"`
|
||||||
CloudfrontID string `kong:"name='cloudfront-id',env='AWS_CLOUDFRONT_ID'"`
|
CloudfrontID string `kong:"name='cloudfront-id',env='AWS_CLOUDFRONT_ID'"`
|
||||||
RedirectsJSON string `kong:"name='redirects-json',env='REDIRECTS_JSON'"`
|
RedirectsFile string `kong:"name='redirects-file',env='REDIRECTS_FILE',type=filecontent"`
|
||||||
RedirectsPrefixesJSON string `kong:"name='redirects-prefixes-json',env='REDIRECTS_PREFIXES_JSON'"`
|
RedirectsPrefixesFile string `kong:"name='redirects-prefixes-file',env='REDIRECTS_PREFIXES_FILE',type=filecontent"`
|
||||||
}
|
}
|
||||||
|
|
||||||
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.RedirectsJSON, s.RedirectsPrefixesJSON)
|
zipdt, err := getLambdaFunctionZip(s.FunctionFile, s.RedirectsFile, s.RedirectsPrefixesFile)
|
||||||
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,20 +228,15 @@ func (s *AwsCloudfrontUpdateCmd) Run() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getLambdaFunctionZip(funcFilename string, redirectsJSON string, redirectsPrefixesJSON string) ([]byte, error) {
|
func getLambdaFunctionZip(funcdt, redirects, redirectsPrefixes 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(string(funcdt)))
|
functpl := template.Must(template.New("").Parse(funcdt))
|
||||||
if err = functpl.Execute(&funcbuf, struct {
|
if err := functpl.Execute(&funcbuf, struct {
|
||||||
RedirectsJSON string
|
RedirectsJSON string
|
||||||
RedirectsPrefixesJSON string
|
RedirectsPrefixesJSON string
|
||||||
}{
|
}{
|
||||||
redirectsJSON,
|
redirects,
|
||||||
redirectsPrefixesJSON,
|
redirectsPrefixes,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,4 +12,5 @@
|
||||||
{{- $redirects.SetInMap "paths" . $target -}}
|
{{- $redirects.SetInMap "paths" . $target -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{ $redirects.Get "paths" | jsonify }}
|
{{- $opts := dict "noHTMLEscape" true }}
|
||||||
|
{{- $redirects.Get "paths" | jsonify $opts }}
|
||||||
|
|
Loading…
Reference in New Issue