Browse Source

Merge pull request #8 from newsdev/feature/gcs

James Thomas 7 years ago
parent
commit
10f3f412a1
2 changed files with 11 additions and 6 deletions
  1. 3 1
      Dockerfile
  2. 8 5
      lib/transports/s3/remote.js

+ 3 - 1
Dockerfile View File

8
 COPY package.json /usr/src/app/
8
 COPY package.json /usr/src/app/
9
 RUN apt-get update -y && apt-get upgrade -y && \
9
 RUN apt-get update -y && apt-get upgrade -y && \
10
     apt-get install -y nodejs npm libcairo2-dev libjpeg62-turbo-dev libpango1.0-dev libgif-dev libpng-dev build-essential g++ ffmpeg
10
     apt-get install -y nodejs npm libcairo2-dev libjpeg62-turbo-dev libpango1.0-dev libgif-dev libpng-dev build-essential g++ ffmpeg
11
-COPY ./ /usr/src/app/
11
+COPY package.json* yarn.lock* .npmrc* /usr/src/app/
12
 RUN npm install --production
12
 RUN npm install --production
13
 
13
 
14
+COPY ./ /usr/src/app/
15
+
14
 EXPOSE 8888
16
 EXPOSE 8888
15
 CMD [ "npm", "start" ]
17
 CMD [ "npm", "start" ]

+ 8 - 5
lib/transports/s3/remote.js View File

3
 
3
 
4
 module.exports = function(bucket, storagePath) {
4
 module.exports = function(bucket, storagePath) {
5
 
5
 
6
-  var s3 = new AWS.S3({ params: { Bucket: bucket } });
6
+  var s3Options = { params: { Bucket: bucket } };
7
+  if (process.env.S3_ENDPOINT) {
8
+    s3Options.endpoint = process.env.S3_ENDPOINT;
9
+  }
10
+  var s3 = new AWS.S3(s3Options);
7
 
11
 
8
   // Test credentials
12
   // Test credentials
9
   s3.headBucket({}, function(err){ if (err) { throw err; } });
13
   s3.headBucket({}, function(err){ if (err) { throw err; } });
12
 
16
 
13
     var params = {
17
     var params = {
14
       Key: storagePath + key,
18
       Key: storagePath + key,
15
-      Body: fs.createReadStream(source),
16
-      ACL: "public-read"
19
+      Body: fs.createReadStream(source)
17
     };
20
     };
18
 
21
 
19
     // gzipping results in inconsistent file size :(
22
     // gzipping results in inconsistent file size :(
20
-    s3.upload(params, cb);
23
+    s3.putObject(params, cb);
21
 
24
 
22
   }
25
   }
23
 
26
 
71
 
74
 
72
   // TODO make this more configurable
75
   // TODO make this more configurable
73
   function getURL(id) {
76
   function getURL(id) {
74
-    return "https://s3.amazonaws.com/" + bucket + "/" + storagePath + "video/" + id + ".mp4";
77
+    return "https://" + bucket + "/" + storagePath + "video/" + id + ".mp4";
75
   }
78
   }
76
 
79
 
77
   return {
80
   return {