Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CON-103] - Enable cid cache #3519

Merged
merged 4 commits into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions creator-node/compose/env/commonEnv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export creatorNodeEndpoint=CREATOR_NODE_ENDPOINT
export spOwnerWallet=SP_OWNER_WALLET
export COMPOSE_HTTP_TIMEOUT=200
export printSequelizeLogs=true
export contentCacheLayerEnabled=false
2 changes: 1 addition & 1 deletion creator-node/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ const config = convict({
doc: 'Flag to enable or disable the nginx cache layer that caches content',
format: 'BooleanCustom',
env: 'contentCacheLayerEnabled',
default: false
default: true
},
reconfigNodeWhitelist: {
doc: 'Comma separated string - list of Content Nodes to select from for reconfig. Empty string = whitelist all.',
Expand Down
38 changes: 27 additions & 11 deletions libs/initScripts/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,21 @@ if (args.length < 3) {
throwArgError()
}

const getEnvConfigPathsForService = async ({ workspace, serviceCount }) => {
const getEnvConfigPathsForContentNode = async ({ workspace, serviceCount }) => {
const { envPath, writePath, templatePath } = getEnvConfigPathsForService({ workspace, serviceCount })
fs.writeFileSync(writePath, '')

return { envPath, templatePath, writePath }
}

const getEnvConfigPathsForDiscoveryNode = async ({ workspace, serviceCount }) => {
const { envPath, writePath, templatePath } = getEnvConfigPathsForService({ workspace, serviceCount })
fs.copyFileSync(envPath, writePath)

return { templatePath, writePath }
}

const getEnvConfigPathsForService = ({ workspace, serviceCount }) => {
const tmpDir = `${workspace}/tmp`
const writePath = `${tmpDir}/shellEnv${serviceCount}.sh`
const dirExists = fs.existsSync(tmpDir)
Expand All @@ -83,8 +97,7 @@ const getEnvConfigPathsForService = async ({ workspace, serviceCount }) => {
}
const templatePath = `${workspace}/commonEnv.sh`
const envPath = `${workspace}/shellEnv${serviceCount}.sh`
fs.copyFileSync(envPath, writePath)
return { templatePath, writePath }
return { envPath, writePath, templatePath }
}

const run = async () => {
Expand Down Expand Up @@ -123,7 +136,7 @@ const run = async () => {
const serviceCount = args[3]
if (serviceCount === undefined) throw new Error('configure-discprov-wallet requires a service # as the second arg')
const workspace = '../discovery-provider/compose/env'
const { templatePath, writePath } = await getEnvConfigPathsForService({ workspace, serviceCount })
const { templatePath, writePath } = await getEnvConfigPathsForDiscoveryNode({ workspace, serviceCount })
await _configureDiscProv(ethAccounts, parseInt(serviceCount), templatePath, writePath)
break
}
Expand Down Expand Up @@ -177,13 +190,13 @@ const run = async () => {
const serviceCount = args[3]
if (serviceCount === undefined) throw new Error('update-delegate-wallet requires a service # as the second arg')
const workspace = '../creator-node/compose/env'
const { templatePath, writePath } = await getEnvConfigPathsForService({ workspace, serviceCount })
const { envPath, templatePath, writePath } = await getEnvConfigPathsForContentNode({ workspace, serviceCount })
// Local dev, delegate and owner wallet are equal
const ownerWallet = ethAccounts[parseInt(serviceCount)]
const delegateWallet = ownerWallet
const endpoint = makeCreatorNodeEndpoint(serviceCount)

await _updateCreatorNodeConfig(ownerWallet, templatePath, writePath, endpoint, /* isShell */ true, delegateWallet)
await _updateCreatorNodeConfig({ ownerWallet, templatePath, writePath, endpoint, isShell: true, delegateWallet, envPath })
break
}

Expand Down Expand Up @@ -495,7 +508,7 @@ const _updateCNodeDelegateOwnerWallet = async (ethAccounts, serviceNumber) => {
await updateServiceDelegateOwnerWallet(audiusLibs, contentNodeType, endpoint, ethAccounts[serviceNumber + 10])
}

const _updateCreatorNodeConfig = async (ownerWallet, templatePath, writePath, endpoint = null, isShell = false, delegateWallet) => {
const _updateCreatorNodeConfig = async ({ ownerWallet, templatePath, writePath, endpoint = null, isShell = false, delegateWallet, envPath = null }) => {
delegateWallet = (delegateWallet || ownerWallet).toLowerCase()
ownerWallet = ownerWallet.toLowerCase()

Expand All @@ -505,7 +518,7 @@ const _updateCreatorNodeConfig = async (ownerWallet, templatePath, writePath, en
const ownerWalletPrivKey = ganacheEthAccounts.private_keys[`${ownerWallet}`]
const delegateWalletPrivKey = ganacheEthAccounts.private_keys[`${delegateWallet}`]

await _updateCreatorNodeConfigFile(templatePath, writePath, ownerWallet, ownerWalletPrivKey, delegateWallet, delegateWalletPrivKey, endpoint, isShell)
await _updateCreatorNodeConfigFile({ templatePath, writePath, ownerWallet, ownerWalletPrivKey, delegateWallet, delegateWalletPrivKey, endpoint, isShell, envPath })
}

const _deregisterAllSPs = async (audiusLibs, ethAccounts) => {
Expand Down Expand Up @@ -539,14 +552,17 @@ const _initEthContractTypes = async (libs) => {
await addServiceType(libs, discoveryNodeType, discoveryNodeTypeMin, discoveryNodeTypeMax)
}

const writeEnvConfigFromTemplate = async ({ templatePath, writePath, replaceMap }) => {
const writeEnvConfigFromTemplate = async ({ templatePath, writePath, replaceMap, envPath }) => {
let template = fs.readFileSync(templatePath, 'utf8')
const progressReport = []
Object.entries(replaceMap).forEach(([toReplace, replacement]) => {
template = template.replace(`${toReplace}`, replacement)
progressReport.push(`${toReplace}: ${replacement}`)
})
fs.appendFileSync(writePath, template)
if (envPath) {
fs.appendFileSync(writePath, fs.readFileSync(envPath, 'utf8'))
}
console.log(`Updated ${writePath}:\n${progressReport.join('\n')}`)
}

Expand All @@ -562,14 +578,14 @@ const _configureDiscProv = async (ethAccounts, serviceNumber, templatePath, writ
}

// Write an update to shell env file for creator nodes or docker env file
const _updateCreatorNodeConfigFile = async (templatePath, writePath, ownerWallet, ownerWalletPkey, delegateWallet, delegateWalletPrivKey, endpoint, isShell) => {
const _updateCreatorNodeConfigFile = async ({ templatePath, writePath, ownerWallet, ownerWalletPkey, delegateWallet, delegateWalletPrivKey, endpoint, isShell, envPath }) => {
const replaceMap = {
DELEGATE_OWNER_WALLET: delegateWallet,
DELEGATE_PRIVATE_KEY: delegateWalletPrivKey,
CREATOR_NODE_ENDPOINT: endpoint,
SP_OWNER_WALLET: ownerWallet
}
writeEnvConfigFromTemplate({ templatePath, writePath, replaceMap })
writeEnvConfigFromTemplate({ templatePath, writePath, replaceMap, envPath })
}

const _updateUserReplicaSetManagerBootstrapConfig = async (ethAccounts) => {
Expand Down