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:
16
.github/workflows/deploy.yml
vendored
16
.github/workflows/deploy.yml
vendored
@@ -37,7 +37,6 @@ jobs:
|
||||
DOCS_URL="https://docs.docker.com"
|
||||
DOCS_AWS_IAM_ROLE="arn:aws:iam::710015040892:role/prod-docs-docs.docker.com-20220818202218674300000001"
|
||||
DOCS_S3_BUCKET="prod-docs-docs.docker.com"
|
||||
DOCS_S3_CONFIG="s3-config.json"
|
||||
DOCS_CLOUDFRONT_ID="E228TTN20HNU8F"
|
||||
DOCS_LAMBDA_FUNCTION_REDIRECTS="DockerDocsRedirectFunction-prod"
|
||||
DOCS_SLACK_MSG="Successfully deployed docs from the main branch. $DOCS_URL"
|
||||
@@ -46,7 +45,6 @@ jobs:
|
||||
DOCS_URL="https://docs-labs.docker.com"
|
||||
DOCS_AWS_IAM_ROLE="arn:aws:iam::710015040892:role/labs-docs-docs.docker.com-20220818202218402500000001"
|
||||
DOCS_S3_BUCKET="labs-docs-docs.docker.com"
|
||||
DOCS_S3_CONFIG="s3-config.json"
|
||||
DOCS_CLOUDFRONT_ID="E1MYDYF65FW3HG"
|
||||
DOCS_LAMBDA_FUNCTION_REDIRECTS="DockerDocsRedirectFunction-labs"
|
||||
else
|
||||
@@ -63,7 +61,6 @@ jobs:
|
||||
echo "DOCS_AWS_REGION=$DOCS_AWS_REGION" >> $GITHUB_ENV
|
||||
echo "DOCS_AWS_IAM_ROLE=$DOCS_AWS_IAM_ROLE" >> $GITHUB_ENV
|
||||
echo "DOCS_S3_BUCKET=$DOCS_S3_BUCKET" >> $GITHUB_ENV
|
||||
echo "DOCS_S3_CONFIG=$DOCS_S3_CONFIG" >> $GITHUB_ENV
|
||||
echo "DOCS_CLOUDFRONT_ID=$DOCS_CLOUDFRONT_ID" >> $GITHUB_ENV
|
||||
echo "DOCS_LAMBDA_FUNCTION_REDIRECTS=$DOCS_LAMBDA_FUNCTION_REDIRECTS" >> $GITHUB_ENV
|
||||
echo "DOCS_SLACK_MSG=$DOCS_SLACK_MSG" >> $GITHUB_ENV
|
||||
@@ -111,19 +108,6 @@ jobs:
|
||||
--delete \
|
||||
--exclude "*.webp" \
|
||||
public s3://${{ env.DOCS_S3_BUCKET }}/
|
||||
-
|
||||
name: Update S3 config
|
||||
if: ${{ env.DOCS_S3_BUCKET != '' && env.DOCS_S3_CONFIG != '' }}
|
||||
uses: docker/bake-action@v6
|
||||
with:
|
||||
source: .
|
||||
files: |
|
||||
docker-bake.hcl
|
||||
targets: aws-s3-update-config
|
||||
env:
|
||||
AWS_REGION: ${{ env.DOCS_AWS_REGION }}
|
||||
AWS_S3_BUCKET: ${{ env.DOCS_S3_BUCKET }}
|
||||
AWS_S3_CONFIG: ${{ env.DOCS_S3_CONFIG }}
|
||||
-
|
||||
name: Update Cloudfront config
|
||||
if: ${{ env.DOCS_CLOUDFRONT_ID != '' }}
|
||||
|
||||
@@ -130,14 +130,6 @@ target "_common-aws" {
|
||||
provenance = false
|
||||
}
|
||||
|
||||
target "aws-s3-update-config" {
|
||||
inherits = ["_common-aws"]
|
||||
context = "hack/releaser"
|
||||
target = "aws-s3-update-config"
|
||||
no-cache-filter = ["aws-update-config"]
|
||||
output = ["type=cacheonly"]
|
||||
}
|
||||
|
||||
target "aws-lambda-invoke" {
|
||||
inherits = ["_common-aws"]
|
||||
context = "hack/releaser"
|
||||
|
||||
@@ -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