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
This commit is contained in:
Matt Steele
2020-07-28 15:17:39 -05:00
committed by GitHub
parent cb04826173
commit 87636a4183
4 changed files with 24 additions and 13 deletions

View File

@@ -81,6 +81,7 @@ type files struct {
type s3 struct { type s3 struct {
Enabled bool `yaml:"enabled"` Enabled bool `yaml:"enabled"`
Endpoint string `yaml:"endpoint"` Endpoint string `yaml:"endpoint"`
ServingEndpoint string `yaml:"servingEndpoint"`
AccessKey string `yaml:"accessKey"` AccessKey string `yaml:"accessKey"`
Secret string `yaml:"secret"` Secret string `yaml:"secret"`
Bucket string `yaml:"bucket"` Bucket string `yaml:"bucket"`

View File

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

View File

@@ -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. * 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/) ## [Wasabi cloud storage](https://wasabi.com/content-delivery/)

View File

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