Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions _releaser/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./
Expand Down Expand Up @@ -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
23 changes: 9 additions & 14 deletions _releaser/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion layouts/index.redirects.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
{{- $redirects.SetInMap "paths" . $target -}}
{{- end -}}
{{- end -}}
{{ $redirects.Get "paths" | jsonify }}
{{- $opts := dict "noHTMLEscape" true }}
{{- $redirects.Get "paths" | jsonify $opts }}
Loading