Skip to content

Commit

Permalink
fix: split platform code copy and extract into separate steps for bet…
Browse files Browse the repository at this point in the history
…ter tracking

Signed-off-by: Lenin Mehedy <lenin.mehedy@swirldslabs.com>
  • Loading branch information
leninmehedy committed Jan 22, 2024
1 parent 6a4226c commit ec8dd5c
Showing 1 changed file with 35 additions and 13 deletions.
48 changes: 35 additions & 13 deletions fullstack-network-manager/src/core/platform_installer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -72,35 +72,52 @@ export class PlatformInstaller {
}
}

async copyPlatform (podName, buildZipFile) {
async copyPlatform (podName, buildZipSrc) {
if (!podName) throw new MissingArgumentError('podName is required')
if (!buildZipFile) throw new MissingArgumentError('buildZipFile is required')
if (!fs.statSync(buildZipFile).isFile()) throw new IllegalArgumentError('buildZipFile does not exists', buildZipFile)
if (!buildZipSrc) throw new MissingArgumentError('buildZipSrc is required')
if (!fs.statSync(buildZipSrc).isFile()) throw new IllegalArgumentError('buildZipFile does not exists', buildZipSrc)

try {
const extractScriptName = 'extract-jar.sh'
const extractScriptSrc = path.join(constants.RESOURCES_DIR, extractScriptName)
const extractScript = path.join(constants.HEDERA_USER_HOME_DIR, extractScriptName) // inside the container
await this.copyFiles(podName, [buildZipSrc], constants.HEDERA_USER_HOME_DIR)
return true
} catch (e) {
throw new FullstackTestingError(`failed to copy platform code in to pod '${podName}': ${e.message}`, e)
}
}

async extractPlatform (podName, buildZipSrc) {
if (!podName) throw new MissingArgumentError('podName is required')
if (!buildZipSrc) throw new MissingArgumentError('buildZipSrc is required')

const buildZipFileName = path.basename(buildZipSrc)
const buildZip = path.join(constants.HEDERA_USER_HOME_DIR, buildZipFileName) // inside the container
const extractScriptName = 'extract-jar.sh'
const extractScriptSrc = path.join(constants.RESOURCES_DIR, extractScriptName)
const extractScript = path.join(constants.HEDERA_USER_HOME_DIR, extractScriptName) // inside the container

const buildZipFileName = path.basename(buildZipFile)
const buildZip = path.join(constants.HEDERA_USER_HOME_DIR, buildZipFileName) // inside the container
this.logger.debug(`Extracting platform code in pod ${podName}`, {
extractScript,
buildZip,
dest: constants.HEDERA_HAPI_PATH
})

await this.kubectl2.copyTo(podName, constants.ROOT_CONTAINER, extractScriptSrc, constants.HEDERA_USER_HOME_DIR)
await this.kubectl2.copyTo(podName, constants.ROOT_CONTAINER, buildZipFile, constants.HEDERA_USER_HOME_DIR)
try {
await this.copyFiles(podName, [extractScriptSrc], constants.HEDERA_USER_HOME_DIR)
await this.kubectl2.execContainer(podName, constants.ROOT_CONTAINER, `chmod +x ${extractScript}`)
await this.setupHapiDirectories(podName)
await this.kubectl2.execContainer(podName, constants.ROOT_CONTAINER, [extractScript, buildZip, constants.HEDERA_HAPI_PATH])

return true
} catch (e) {
throw new FullstackTestingError(`failed to copy platform code to pod '${podName}': ${e.message}`, e)
throw new FullstackTestingError(`failed to extract platform code in this pod '${podName}': ${e.message}`, e)
}
}

async copyFiles (podName, srcFiles, destDir, container = constants.ROOT_CONTAINER) {
const self = this
try {
for (const srcPath of srcFiles) {
self.logger.debug(`Copying files into ${podName}: ${srcPath} -> ${destDir}`)
self.logger.debug(`Copying file into ${podName}: ${srcPath} -> ${destDir}`)
await this.kubectl2.copyTo(podName, container, srcPath, destDir)
}

Expand Down Expand Up @@ -345,7 +362,12 @@ export class PlatformInstaller {
const self = this
return new Listr([
{
title: 'Copy platform',
title: 'Copy platform zip file',
task: (_, task) =>
self.copyPlatform(podName, buildZipFile)
},
{
title: 'Extract platform zip file',
task: (_, task) =>
self.copyPlatform(podName, buildZipFile)
},
Expand Down

0 comments on commit ec8dd5c

Please sign in to comment.