updated storage config

This commit is contained in:
Martin Guether 2017-04-07 13:07:09 +02:00
parent bd0471dad6
commit 1426bc9c24
3 changed files with 31 additions and 14 deletions

View File

@ -1,7 +1,8 @@
{ {
"endpoint": "http://localhost:9666", "endpoint": "http://localhost:9666",
"storage_bucket": "my_spacedeck_s3_bucket", "storage_bucket": "sdeck-development",
"storage_cdn": "http://localhost:9666", "storage_cdn": "http://localhost:9123/sdeck-development",
"storage_endpoint": "http://storage:9000",
"google_access" : "", "google_access" : "",
"google_secret" : "", "google_secret" : "",
"admin_pass": "very_secret_admin_password", "admin_pass": "very_secret_admin_password",

View File

@ -9,11 +9,14 @@ services:
- MINIO_SECRET_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY - MINIO_SECRET_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
ports: ports:
- 9123:9000 - 9123:9000
command: server /export
db: db:
image: mongo image: mongo
spacedeck-open: spacedeck-open:
environment: environment:
- env=development - env=development
- MINIO_ACCESS_KEY=AKIAIOSFODNN7EXAMPLE
- MINIO_SECRET_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
build: . build: .
volumes: volumes:
- ./:/usr/src/app - ./:/usr/src/app
@ -25,3 +28,7 @@ services:
- db - db
- sync - sync
- storage - storage
links:
- storage
- db
- sync

View File

@ -6,20 +6,29 @@ AWS.config.region = 'eu-central-1';
var fs = require('fs'); var fs = require('fs');
var config = require('config'); var config = require('config');
var cdn = config.get("storage_cdn") var cdn = config.get("storage_cdn");
var storage_endpoint = 'http://storage:9000'; var storage_endpoint = config.get("storage_endpoint");
const bucketName = "sdeck-fresh-development"; const bucketName = "sdeck-fresh-development";
const ep = new AWS.Endpoint(storage_endpoint); 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({ const s3 = new AWS.S3({
endpoint: ep endpoint: ep
}); });
module.exports = { module.exports = {
removeFile: (path, callback) => { removeFile: (path, callback) => {
const s3 = new AWS.S3({ // const s3 = new AWS.S3({
region: 'eu-central-1' // region: 'eu-central-1'
}); // });
const bucket = config.get("storage_bucket"); const bucket = config.get("storage_bucket");
s3.deleteObject({ s3.deleteObject({
Bucket: bucket, Key: path Bucket: bucket, Key: path
@ -37,7 +46,7 @@ module.exports = {
callback({error:"missing path"}, null); callback({error:"missing path"}, null);
return; return;
} }
console.log("[s3] uploading", localFilePath, " to ", fileName); console.log("[storage] uploading", localFilePath, " to ", fileName);
const bucket = config.get("storage_bucket"); const bucket = config.get("storage_bucket");
const fileStream = fs.createReadStream(localFilePath); const fileStream = fs.createReadStream(localFilePath);
@ -49,9 +58,9 @@ module.exports = {
}); });
fileStream.on('open', function () { fileStream.on('open', function () {
// FIXME // FIXME
var s3 = new AWS.S3({ // var s3 = new AWS.S3({
region: 'eu-central-1' // region: 'eu-central-1'
}); // });
s3.putObject({ s3.putObject({
Bucket: bucket, Bucket: bucket,
@ -63,7 +72,7 @@ module.exports = {
console.error(err); console.error(err);
callback(err); callback(err);
}else { }else {
const url = "https://"+ config.get("storage_cdn") + "/" + fileName; const url = cdn + "/" + fileName;
console.log("[s3]" + localFilePath + " to " + url); console.log("[s3]" + localFilePath + " to " + url);
callback(null, url); callback(null, url);
} }