From 1426bc9c24e9cea5848eccd3245f916ad8d65130 Mon Sep 17 00:00:00 2001 From: Martin Guether Date: Fri, 7 Apr 2017 13:07:09 +0200 Subject: [PATCH] updated storage config --- config/default.json | 5 +++-- docker-compose.yml | 9 ++++++++- helpers/uploader.js | 31 ++++++++++++++++++++----------- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/config/default.json b/config/default.json index 51317c2..dc18811 100644 --- a/config/default.json +++ b/config/default.json @@ -1,7 +1,8 @@ { "endpoint": "http://localhost:9666", - "storage_bucket": "my_spacedeck_s3_bucket", - "storage_cdn": "http://localhost:9666", + "storage_bucket": "sdeck-development", + "storage_cdn": "http://localhost:9123/sdeck-development", + "storage_endpoint": "http://storage:9000", "google_access" : "", "google_secret" : "", "admin_pass": "very_secret_admin_password", diff --git a/docker-compose.yml b/docker-compose.yml index 5584bd9..4d1bf00 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,11 +9,14 @@ services: - MINIO_SECRET_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY ports: - 9123:9000 + command: server /export db: image: mongo spacedeck-open: environment: - env=development + - MINIO_ACCESS_KEY=AKIAIOSFODNN7EXAMPLE + - MINIO_SECRET_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY build: . volumes: - ./:/usr/src/app @@ -24,4 +27,8 @@ services: depends_on: - db - sync - - storage \ No newline at end of file + - storage + links: + - storage + - db + - sync \ No newline at end of file diff --git a/helpers/uploader.js b/helpers/uploader.js index 95c2b32..62f64d7 100644 --- a/helpers/uploader.js +++ b/helpers/uploader.js @@ -6,20 +6,29 @@ AWS.config.region = 'eu-central-1'; var fs = require('fs'); var config = require('config'); -var cdn = config.get("storage_cdn") -var storage_endpoint = 'http://storage:9000'; +var cdn = config.get("storage_cdn"); +var storage_endpoint = config.get("storage_endpoint"); + const bucketName = "sdeck-fresh-development"; const ep = new AWS.Endpoint(storage_endpoint); + +AWS.config.update(new AWS.Config({ + accessKeyId: process.env.MINIO_ACCESS_KEY, + secretAccessKey: process.env.MINIO_SECRET_KEY, + region: 'us-east-1', + s3ForcePathStyle: true, + signatureVersion: 'v4' +})); + const s3 = new AWS.S3({ endpoint: ep }); - module.exports = { removeFile: (path, callback) => { - const s3 = new AWS.S3({ - region: 'eu-central-1' - }); + // const s3 = new AWS.S3({ + // region: 'eu-central-1' + // }); const bucket = config.get("storage_bucket"); s3.deleteObject({ Bucket: bucket, Key: path @@ -37,7 +46,7 @@ module.exports = { callback({error:"missing path"}, null); return; } - console.log("[s3] uploading", localFilePath, " to ", fileName); + console.log("[storage] uploading", localFilePath, " to ", fileName); const bucket = config.get("storage_bucket"); const fileStream = fs.createReadStream(localFilePath); @@ -49,9 +58,9 @@ module.exports = { }); fileStream.on('open', function () { // FIXME - var s3 = new AWS.S3({ - region: 'eu-central-1' - }); + // var s3 = new AWS.S3({ + // region: 'eu-central-1' + // }); s3.putObject({ Bucket: bucket, @@ -63,7 +72,7 @@ module.exports = { console.error(err); callback(err); }else { - const url = "https://"+ config.get("storage_cdn") + "/" + fileName; + const url = cdn + "/" + fileName; console.log("[s3]" + localFilePath + " to " + url); callback(null, url); }