mirror of
https://github.com/docker/docs.git
synced 2026-03-27 06:18:55 +07:00
releaser: remove s3-config handling
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
@@ -18,18 +18,6 @@ RUN --mount=type=bind,target=. \
|
||||
--mount=type=cache,target=/root/.cache/go-build \
|
||||
go build -o /out/releaser .
|
||||
|
||||
FROM base AS aws-s3-update-config
|
||||
ARG DRY_RUN=false
|
||||
ARG AWS_REGION
|
||||
ARG AWS_S3_BUCKET
|
||||
ARG AWS_S3_CONFIG
|
||||
RUN --mount=type=bind,target=. \
|
||||
--mount=type=bind,from=releaser,source=/out/releaser,target=/usr/bin/releaser \
|
||||
--mount=type=secret,id=AWS_ACCESS_KEY_ID \
|
||||
--mount=type=secret,id=AWS_SECRET_ACCESS_KEY \
|
||||
--mount=type=secret,id=AWS_SESSION_TOKEN \
|
||||
releaser aws s3-update-config
|
||||
|
||||
FROM base AS aws-lambda-invoke
|
||||
ARG DRY_RUN=false
|
||||
ARG AWS_REGION
|
||||
|
||||
@@ -3,7 +3,6 @@ package main
|
||||
import (
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
@@ -18,66 +17,13 @@ import (
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"github.com/aws/aws-sdk-go/service/cloudfront"
|
||||
"github.com/aws/aws-sdk-go/service/lambda"
|
||||
"github.com/aws/aws-sdk-go/service/s3"
|
||||
)
|
||||
|
||||
type AwsCmd struct {
|
||||
S3UpdateConfig AwsS3UpdateConfigCmd `kong:"cmd,name=s3-update-config"`
|
||||
LambdaInvoke AwsLambdaInvokeCmd `kong:"cmd,name=lambda-invoke"`
|
||||
CloudfrontUpdate AwsCloudfrontUpdateCmd `kong:"cmd,name=cloudfront-update"`
|
||||
}
|
||||
|
||||
type AwsS3UpdateConfigCmd struct {
|
||||
Region string `kong:"name='region',env='AWS_REGION'"`
|
||||
S3Bucket string `kong:"name='s3-bucket',env='AWS_S3_BUCKET'"`
|
||||
S3Config string `kong:"name='s3-website-config',env='AWS_S3_CONFIG'"`
|
||||
DryRun bool `kong:"name='dry-run',env='DRY_RUN'"`
|
||||
}
|
||||
|
||||
func (s *AwsS3UpdateConfigCmd) Run() error {
|
||||
if s.DryRun {
|
||||
log.Printf("INFO: Dry run mode enabled. Configuration:\nRegion: %s\nS3Bucket: %s\nS3Config: %s\n", s.Region, s.S3Bucket, s.S3Config)
|
||||
return nil
|
||||
}
|
||||
|
||||
file, err := os.ReadFile(s.S3Config)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read s3 config file %s: %w", s.S3Config, err)
|
||||
}
|
||||
|
||||
data := s3.WebsiteConfiguration{}
|
||||
err = json.Unmarshal(file, &data)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to parse JSON from %s: %w", s.S3Config, err)
|
||||
}
|
||||
|
||||
sess, err := session.NewSession(&aws.Config{
|
||||
Credentials: awsCredentials(),
|
||||
Region: aws.String(s.Region),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create session: %w", err)
|
||||
}
|
||||
|
||||
svc := s3.New(sess)
|
||||
|
||||
// Create SetBucketWebsite parameters based on the JSON file input
|
||||
params := s3.PutBucketWebsiteInput{
|
||||
Bucket: aws.String(s.S3Bucket),
|
||||
WebsiteConfiguration: &data,
|
||||
}
|
||||
|
||||
// Set the website configuration on the bucket.
|
||||
// Replacing any existing configuration.
|
||||
_, err = svc.PutBucketWebsite(¶ms)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to set bucket %q website configuration: %w", s.S3Bucket, err)
|
||||
}
|
||||
|
||||
log.Printf("INFO: successfully set bucket %q website configuration\n", s.S3Bucket)
|
||||
return nil
|
||||
}
|
||||
|
||||
type AwsLambdaInvokeCmd struct {
|
||||
Region string `kong:"name='region',env='AWS_REGION'"`
|
||||
LambdaFunction string `kong:"name='lambda-function',env='AWS_LAMBDA_FUNCTION'"`
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"ErrorDocument": {
|
||||
"Key": "404.html"
|
||||
},
|
||||
"IndexDocument": {
|
||||
"Suffix": "index.html"
|
||||
},
|
||||
"RedirectAllRequestsTo": null
|
||||
}
|
||||
Reference in New Issue
Block a user