Skip to content

Commit

Permalink
Update how S3, Redis, and Docker are handled in tandem.
Browse files Browse the repository at this point in the history
  • Loading branch information
digisomni committed Sep 13, 2024
1 parent 721312c commit 222a80d
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 113 deletions.
9 changes: 9 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,18 @@ services:
REDIS_ARGS: --save 20 1
volumes:
- redis_server:/data/redis
# ports:
# - "6379:6379"
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5
logging:
driver: "json-file"
options:
max-size: "100m"

# Node API service
api:
#container_name: vircadia-metaverse-v2
Expand Down Expand Up @@ -59,6 +67,7 @@ services:
driver: "json-file"
options:
max-size: "2000m"

nginx:
image: nginx:latest
restart: unless-stopped
Expand Down
195 changes: 97 additions & 98 deletions env.default
Original file line number Diff line number Diff line change
@@ -1,98 +1,97 @@
# DB variables -------------------
DB_HOST=mongodb_container
DB_PORT=27017
DB_NAME=tester
DB_USER=metaverse
DB_PASSWORD=nooneknowsit
DB_AUTHDB=admin
DATABASE_URL=

# REDIS variables -------------------
REDIS_HOST=redis://redis_container
REDIS_PORT=6379

# Authentication variables -------------------
AUTH_SECRET=M7iszvStilkptn22GT4/NbFGY=

# Server variables ---------------
SERVER_HOST=
SERVER_PORT=3030
SERVER_VERSION=1.1.1-20200101-abcdefg

# General ------------------------
LOCAL=true

# Mode development and production -----------
APP_ENV=development
PUBLIC_PATH=./public

# Metaverse ------------------------
METAVERSE_NAME=Vircadia noobie
METAVERSE_NICK_NAME=Noobie
METAVERSE_SERVER_URL=https://api.vircadia.com:3030
DEFAULT_ICE_SERVER_URL=
DASHBOARD_URL=https://dashboard.vircadia.com
LISTEN_HOST=0.0.0.0

LISTEN_PORT=3030
ENABLE_ACCOUNT_VERIFICATION=false
ENABLE_ACCOUNT_VERIFICATION=true
START_LEVEL=1

# Client variables ---------------
APP_TITLE=Vircadia noobie
APP_LOGO=https://vircadia.com/img/logo-1.png
APP_URL=https://dashboard.vircadia.com
APP_HOST=localhost
APP_PORT=80

# - Route 53 ------------
ROUTE53_HOSTED_ZONE_ID=
ROUTE53_ACCESS_KEY_ID=
ROUTE53_ACCESS_KEY_SECRET=

# - keys
STORAGE_AWS_ACCESS_KEY_ID=
STORAGE_AWS_ACCESS_KEY_SECRET=
# --------------------------------

# - S3 ----------
STORAGE_S3_REGION=
STORAGE_S3_STATIC_RESOURCE_BUCKET=
STORAGE_S3_AVATAR_DIRECTORY=avatars
AWS_STORAGE_PROVIDER=
# Possible values:
# local - for local development,
# dev - for live development environment,
# <empty or not defined> - for production environment,
STORAGE_S3_DEV_MODE=local


# - Storage provider aws or local ------------
STORAGE_PROVIDER=aws
LOCAL_STORAGE_PROVIDER=localhost:8642
LOCAL_STORAGE_PROVIDER_PORT=8642

# - Email ----------
SMTP_HOST=smtp.gmail.com
SMTP_PORT=465
SMTP_SECURE=true
SMTP_USER=
SMTP_PASS=
SMTP_EMAIL_FROM=

# - Google Authentication Service -----------
GOOGLE_CALLBACK_URL=
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=

# - Faceebook Authentication Service ----------
FACEBOOK_CALLBACK_URL=
FACEBOOK_CLIENT_ID=
FACEBOOK_CLIENT_SECRET=

# - Blockchain ----------------
#Hardhat test account private key - replace with a real one
MINTER_PRIVATE_KEY=
#Replace with real Infura node URL
ETH_RPC_URL=
# DB variables -------------------
DB_HOST=mongodb_container
DB_PORT=27017
DB_NAME=tester
DB_USER=metaverse
DB_PASSWORD=nooneknowsit
DB_AUTHDB=admin
DATABASE_URL=

# REDIS variables -------------------
REDIS_URL=redis://redis_container:6379

# Authentication variables -------------------
AUTH_SECRET=M7iszvStilkptn22GT4/NbFGY=

# Server variables ---------------
SERVER_HOST=
SERVER_PORT=3030
SERVER_VERSION=1.1.1-20200101-abcdefg

# General ------------------------
LOCAL=true

# Mode development and production -----------
APP_ENV=development
PUBLIC_PATH=./public

# Metaverse ------------------------
METAVERSE_NAME=Vircadia noobie
METAVERSE_NICK_NAME=Noobie
METAVERSE_SERVER_URL=https://api.vircadia.com:3030
DEFAULT_ICE_SERVER_URL=
DASHBOARD_URL=https://dashboard.vircadia.com
LISTEN_HOST=0.0.0.0

LISTEN_PORT=3030
ENABLE_ACCOUNT_VERIFICATION=false
ENABLE_ACCOUNT_VERIFICATION=true
START_LEVEL=1

# Client variables ---------------
APP_TITLE=Vircadia noobie
APP_LOGO=https://vircadia.com/img/logo-1.png
APP_URL=https://dashboard.vircadia.com
APP_HOST=localhost
APP_PORT=80

# - Route 53 ------------
ROUTE53_HOSTED_ZONE_ID=
ROUTE53_ACCESS_KEY_ID=
ROUTE53_ACCESS_KEY_SECRET=

# - keys
STORAGE_AWS_ACCESS_KEY_ID=
STORAGE_AWS_ACCESS_KEY_SECRET=
# --------------------------------

# - S3 ----------
STORAGE_S3_REGION=
STORAGE_S3_STATIC_RESOURCE_BUCKET=
STORAGE_S3_AVATAR_DIRECTORY=avatars
AWS_STORAGE_PROVIDER=
# Possible values:
# local - for local development,
# dev - for live development environment,
# <empty or not defined> - for production environment,
STORAGE_S3_DEV_MODE=local


# - Storage provider aws or local ------------
STORAGE_PROVIDER=aws
LOCAL_STORAGE_PROVIDER=localhost:8642
LOCAL_STORAGE_PROVIDER_PORT=8642

# - Email ----------
SMTP_HOST=smtp.gmail.com
SMTP_PORT=465
SMTP_SECURE=true
SMTP_USER=
SMTP_PASS=
SMTP_EMAIL_FROM=

# - Google Authentication Service -----------
GOOGLE_CALLBACK_URL=
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=

# - Faceebook Authentication Service ----------
FACEBOOK_CALLBACK_URL=
FACEBOOK_CLIENT_ID=
FACEBOOK_CLIENT_SECRET=

# - Blockchain ----------------
#Hardhat test account private key - replace with a real one
MINTER_PRIVATE_KEY=
#Replace with real Infura node URL
ETH_RPC_URL=
4 changes: 2 additions & 2 deletions src/mongodb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import config from './appconfig';

export default function (app: Application): void {
let connection = '';
console.log("==>>>>>Connecting");
console.log('==>>>>>Connecting');
if (IsNotNullOrEmpty(config.database.databaseUrl)) {
connection = config.database.databaseUrl || '';
} else {
Expand All @@ -36,7 +36,7 @@ export default function (app: Application): void {
connection = `mongodb://${hostSpec}/${optionsSpec}`; //Without auth
}
const database = config.database.dbName;
console.log("==>>>>>",connection);
console.log('==>>>>>',connection);
const mongoClient = MongoClient.connect(connection).then((client) =>
client.db(database)
);
Expand Down
3 changes: 2 additions & 1 deletion src/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { Client, Entity, Schema } from 'redis-om';

const client = new Client();

client.open(`${process.env.REDIS_HOST}:${process.env.REDIS_PORT}`);
client.open(process.env.REDIS_URL);

class AuthJwt extends Entity {}

const authToken = new Schema(AuthJwt, {
Expand Down
32 changes: 20 additions & 12 deletions src/services/media/storageprovider/s3.storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ import {
StorageProviderInterface,
} from '../../../common/interfaces/storageProvider';
import { Conflict } from '@feathersjs/errors';
import { GeneralError } from '@feathersjs/errors';

export class S3Provider implements StorageProviderInterface {
bucket = config.aws.s3.staticResourceBucket;
bucket = config.aws.s3.staticResourceBucket || 'default-bucket-name';
cacheDomain = config.aws.s3.awsStorageProvider;
provider: AWS.S3 = new AWS.S3({
accessKeyId: config.aws.keys.accessKeyId,
Expand All @@ -39,17 +40,19 @@ export class S3Provider implements StorageProviderInterface {
endpoint: `https://${this.bucket}.${config.aws.s3.region}.linodeobjects.com`,
});

blob: typeof S3BlobStore = new S3BlobStore({
client: this.provider,
bucket: config.aws.s3.staticResourceBucket,
ACL: 'public-read',
});
blob: typeof S3BlobStore | null = null;

cloudfront: AWS.CloudFront = new AWS.CloudFront({
region: config.aws.s3.region,
accessKeyId: config.aws.keys.accessKeyId,
secretAccessKey: config.aws.keys.secretAccessKey,
});
constructor() {
if (this.bucket && this.bucket !== 'default-bucket-name') {
this.blob = new S3BlobStore({
client: this.provider,
bucket: this.bucket,
ACL: 'public-read',
});
} else {
console.warn('S3 bucket name not provided. Some features may not work.');
}
}

getProvider = (): StorageProviderInterface => {
return this;
Expand Down Expand Up @@ -203,7 +206,12 @@ export class S3Provider implements StorageProviderInterface {
});*/
};

getStorage = (): typeof S3BlobStore => this.blob;
getStorage = (): typeof S3BlobStore => {
if (!this.blob) {
throw new GeneralError('S3BlobStore is not initialized. Check your S3 configuration.');
}
return this.blob;
};

getSignedUrl = async (
key: string,
Expand Down

0 comments on commit 222a80d

Please sign in to comment.