mirror of
https://github.com/thegeeklab/wp-s3-action.git
synced 2024-11-10 04:40:38 +00:00
add support for website redirects
This commit is contained in:
parent
5644941fde
commit
2187920d58
18
DOCS.md
18
DOCS.md
@ -10,6 +10,7 @@ Use the S3 sync plugin to synchronize files and folders with an Amazon S3 bucket
|
|||||||
* `delete` - deletes files in the target not found in the source
|
* `delete` - deletes files in the target not found in the source
|
||||||
* `content_type` - override default mime-types to use this value
|
* `content_type` - override default mime-types to use this value
|
||||||
* `metadata` - set custom metadata
|
* `metadata` - set custom metadata
|
||||||
|
* `redirects` - targets that should redirect elsewhere
|
||||||
|
|
||||||
The following is a sample S3 configuration in your .drone.yml file:
|
The following is a sample S3 configuration in your .drone.yml file:
|
||||||
|
|
||||||
@ -87,3 +88,20 @@ publish:
|
|||||||
"*.html":
|
"*.html":
|
||||||
Cache-Control: "max-age: 1000"
|
Cache-Control: "max-age: 1000"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Additionally, you can specify redirect targets for files that don't exist by using the `redirects` key:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
publish:
|
||||||
|
s3_sync:
|
||||||
|
acl: public-read
|
||||||
|
region: "us-east-1"
|
||||||
|
bucket: "my-bucket.s3-website-us-east-1.amazonaws.com"
|
||||||
|
access_key: "970d28f4dd477bc184fbd10b376de753"
|
||||||
|
secret_key: "9c5785d3ece6a9cdefa42eb99b58986f9095ff1c"
|
||||||
|
source: folder/to/archive
|
||||||
|
target: /target/location
|
||||||
|
delete: true
|
||||||
|
redirects:
|
||||||
|
some/missing/file: /somewhere/that/actually/exists
|
||||||
|
```
|
||||||
|
18
aws.go
18
aws.go
@ -231,6 +231,24 @@ func (a *AWS) visit(path string, info os.FileInfo, err error) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *AWS) AddRedirects(redirects map[string]string) error {
|
||||||
|
for path, location := range redirects {
|
||||||
|
fmt.Printf("Adding redirect from \"%s\" to \"%s\"", path, location)
|
||||||
|
a.local = append(a.local, strings.TrimPrefix(path, "/"))
|
||||||
|
_, err := a.client.PutObject(&s3.PutObjectInput{
|
||||||
|
Bucket: aws.String(a.vargs.Bucket),
|
||||||
|
Key: aws.String(path),
|
||||||
|
WebsiteRedirectLocation: aws.String(location),
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (a *AWS) List(path string) error {
|
func (a *AWS) List(path string) error {
|
||||||
resp, err := a.client.ListObjects(&s3.ListObjectsInput{
|
resp, err := a.client.ListObjects(&s3.ListObjectsInput{
|
||||||
Bucket: aws.String(a.vargs.Bucket),
|
Bucket: aws.String(a.vargs.Bucket),
|
||||||
|
8
main.go
8
main.go
@ -51,6 +51,14 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(vargs.Redirects) > 0 {
|
||||||
|
err = client.AddRedirects(vargs.Redirects)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if vargs.Delete {
|
if vargs.Delete {
|
||||||
err = client.Cleanup()
|
err = client.Cleanup()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
1
types.go
1
types.go
@ -13,6 +13,7 @@ type PluginArgs struct {
|
|||||||
Access StringMap `json:"acl"`
|
Access StringMap `json:"acl"`
|
||||||
ContentType StringMap `json:"content_type"`
|
ContentType StringMap `json:"content_type"`
|
||||||
Metadata DeepStringMap `json:"metadata"`
|
Metadata DeepStringMap `json:"metadata"`
|
||||||
|
Redirects map[string]string `json:"redirects"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DeepStringMap struct {
|
type DeepStringMap struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user