Browse Source

Support separate S3 serving endpoint (#91)

* Add s3 serving endpoint config. Fixes #90

* Move CDN endpoint generation to GenerateRemotePlaylist

* Include HLS path

* Add docs and config

* Prefer sprintf to string concatenation

* Use config method

* gofmt
pull/105/head
Matt Steele 5 years ago committed by GitHub
parent
commit
87636a4183
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      config/config.go
  2. 17
      core/storageproviders/s3Storage.go
  3. 4
      doc/S3.md
  4. 1
      doc/config-example-full.yaml

15
config/config.go

@ -79,13 +79,14 @@ type files struct { @@ -79,13 +79,14 @@ type files struct {
//s3 is for configuring the s3 integration
type s3 struct {
Enabled bool `yaml:"enabled"`
Endpoint string `yaml:"endpoint"`
AccessKey string `yaml:"accessKey"`
Secret string `yaml:"secret"`
Bucket string `yaml:"bucket"`
Region string `yaml:"region"`
ACL string `yaml:"acl"`
Enabled bool `yaml:"enabled"`
Endpoint string `yaml:"endpoint"`
ServingEndpoint string `yaml:"servingEndpoint"`
AccessKey string `yaml:"accessKey"`
Secret string `yaml:"secret"`
Bucket string `yaml:"bucket"`
Region string `yaml:"region"`
ACL string `yaml:"acl"`
}
func (c *config) load(filePath string) error {

17
core/storageproviders/s3Storage.go

@ -2,6 +2,7 @@ package storageproviders @@ -2,6 +2,7 @@ package storageproviders
import (
"bufio"
"fmt"
"os"
"strings"
@ -21,12 +22,13 @@ type S3Storage struct { @@ -21,12 +22,13 @@ type S3Storage struct {
sess *session.Session
host string
s3Endpoint string
s3Region string
s3Bucket string
s3AccessKey string
s3Secret string
s3ACL string
s3Endpoint string
s3ServingEndpoint string
s3Region string
s3Bucket string
s3AccessKey string
s3Secret string
s3ACL string
}
//Setup sets up the s3 storage for saving the video to s3
@ -34,6 +36,7 @@ func (s *S3Storage) Setup() error { @@ -34,6 +36,7 @@ func (s *S3Storage) Setup() error {
log.Trace("Setting up S3 for external storage of video...")
s.s3Endpoint = config.Config.S3.Endpoint
s.s3ServingEndpoint = config.Config.S3.ServingEndpoint
s.s3Region = config.Config.S3.Region
s.s3Bucket = config.Config.S3.Bucket
s.s3AccessKey = config.Config.S3.AccessKey
@ -90,6 +93,8 @@ func (s *S3Storage) GenerateRemotePlaylist(playlist string, variant models.Varia @@ -90,6 +93,8 @@ func (s *S3Storage) GenerateRemotePlaylist(playlist string, variant models.Varia
fullRemotePath := variant.GetSegmentForFilename(line)
if fullRemotePath == nil {
line = ""
} else if s.s3ServingEndpoint != "" {
line = fmt.Sprintf("%s/%s/%s", s.s3ServingEndpoint, config.Config.GetPrivateHLSSavePath(), fullRemotePath.RelativeUploadPath)
} else {
line = fullRemotePath.RemoteID
}

4
doc/S3.md

@ -110,6 +110,10 @@ You should expire old segments on your S3 bucket. [Here are some instructions o @@ -110,6 +110,10 @@ You should expire old segments on your S3 bucket. [Here are some instructions o
* Ugh. CORS. [You will need to enable CORS on your bucket](https://docs.aws.amazon.com/AmazonS3/latest/dev/cors.html#how-do-i-enable-cors) so the web player can access the video.
### CDN
AWS (and other S3 compatible providers) offer a feature to change the HTTP host to support CDNs. You can configure Owncast to serve media files from this host by setting the `s3.servingEndpoint` config to your CDNed host.
## [Wasabi cloud storage](https://wasabi.com/content-delivery/)

1
doc/config-example-full.yaml

@ -70,6 +70,7 @@ files: @@ -70,6 +70,7 @@ files:
s3:
enabled: false
endpoint: https://s3.us-west-2.amazonaws.com
servingEndpoint: https://yourcdn.example
accessKey: ABC12342069
secret: lolomgqwtf49583949
region: us-west-2

Loading…
Cancel
Save