Преглед на файлове

@uppy/companion: add S3 prefix env variable (#4320)

* Adds optional COMPANION_S3_PREFIX for companion

* Fixing prefix usage

* fix implementation

* add docs

---------

Co-authored-by: Will Wilson <will.wilson@asset.tv>
Mikael Finstad преди 2 години
родител
ревизия
41b8563ae2

+ 1 - 0
.env.example

@@ -22,6 +22,7 @@ COMPANION_AWS_SECRET="YOUR AWS SECRET"
 # COMPANION_AWS_SECRET_FILE="PATH/TO/AWS/SECRET/FILE"
 COMPANION_AWS_BUCKET="YOUR AWS S3 BUCKET"
 COMPANION_AWS_REGION="AWS REGION"
+COMPANION_AWS_PREFIX="OPTIONAL PREFIX"
 # to enable S3 Transfer Acceleration (default: false)
 # COMPANION_AWS_USE_ACCELERATE_ENDPOINT="false"
 # to set X-Amz-Expires query param in presigned urls (in seconds, default: 800)

+ 1 - 1
.gitignore

@@ -12,7 +12,7 @@ node_modules
 .yarn/cache
 .yarn/install-state.gz
 yarn-error.log
-
+.idea
 .env
 
 dist/

+ 1 - 0
packages/@uppy/companion/KUBERNETES.md

@@ -41,6 +41,7 @@ data:
   COMPANION_AWS_SECRET: "YOUR AWS SECRET"
   COMPANION_AWS_BUCKET: "YOUR AWS S3 BUCKET"
   COMPANION_AWS_REGION: "AWS REGION"
+  COMPANION_AWS_PREFIX: "AWS PREFIX"
   COMPANION_OAUTH_DOMAIN: "sub.domain.com"
   COMPANION_UPLOAD_URLS: "http://tusd.tusdemo.net/files/,https://tusd.tusdemo.net/files/"
 kind: Secret

+ 1 - 0
packages/@uppy/companion/env_example

@@ -38,6 +38,7 @@ COMPANION_AWS_SECRET_FILE=
 COMPANION_AWS_BUCKET=
 COMPANION_AWS_ENDPOINT=
 COMPANION_AWS_REGION=
+COMPANION_AWS_PREFIX=
 
 COMPANION_ZOOM_KEY=
 COMPANION_ZOOM_SECRET=

+ 10 - 1
packages/@uppy/companion/src/standalone/helper.js

@@ -53,6 +53,15 @@ function getCorsOrigins () {
   return undefined
 }
 
+const s3Prefix = process.env.COMPANION_AWS_PREFIX || ''
+
+/**
+ * Default getKey for Companion standalone variant
+ *
+ * @returns {string}
+ */
+const defaultStandaloneGetKey = (...args) => `${s3Prefix}${utils.defaultGetKey(...args)}`
+
 /**
  * Loads the config from environment variables
  *
@@ -107,7 +116,7 @@ const getConfigFromEnv = () => {
     },
     s3: {
       key: process.env.COMPANION_AWS_KEY,
-      getKey: utils.defaultGetKey,
+      getKey: defaultStandaloneGetKey,
       secret: getSecret('COMPANION_AWS_SECRET'),
       bucket: process.env.COMPANION_AWS_BUCKET,
       endpoint: process.env.COMPANION_AWS_ENDPOINT,

+ 3 - 1
website/src/docs/companion.md

@@ -266,6 +266,8 @@ export COMPANION_AWS_USE_ACCELERATE_ENDPOINT="false"
 export COMPANION_AWS_EXPIRES="800"
 # to set a canned ACL for uploaded objects: https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl
 export COMPANION_AWS_ACL="private"
+# to set an optional prefix for all uploaded keys
+export COMPANION_AWS_PREFIX="optional/prefix/"
 
 # corresponds to the server.oauthDomain option
 export COMPANION_OAUTH_DOMAIN="sub.domain.com"
@@ -493,7 +495,6 @@ We have [a detailed guide on running Companion in Kubernetes](https://github.com
 
 ### Running many instances
 
-
 We recommend running at least two instances in production, so that if the Node.js event loop gets blocked by one or more requests (due to a bug or spike in traffic), it doesn’t also block or slow down all other requests as well (as Node.js is single threaded).
 
 As an example for scale, one enterprise customer of Transloadit, who self-hosts Companion to power an education service that is used by many universities globally, deploys 7 Companion instances. Their earlier solution ran on 35 instances. In our general experience Companion will saturate network interface cards before other resources on commodity virtual servers (`c5d.2xlarge` for instance).
@@ -503,6 +504,7 @@ Your mileage may vary, so we recommend to add observability. You can let Prometh
 #### Using unique endpoints
 
 One option is to run many instances with each instance having its own unique endpoint. This could be on separate ports, (sub)domain names, or IPs. With this setup, you can either
+
 1. Implement your own logic that will direct each upload to a specific Companion endpoint by setting the `companionUrl` option
 2. Setting the Companion option `COMPANION_SELF_ENDPOINT`. This option will cause Companion to respond with a `i-am` HTTP header containing the value from `COMPANION_SELF_ENDPOINT`. When Uppy’s sees this header, it will pin all requests for the upload to this endpoint.