Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Commit

Permalink
Hot fix for initializing blob data and using template in v1.4.0 (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
debuggy authored Dec 21, 2020
1 parent d48c658 commit 7f45cf9
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 37 deletions.
4 changes: 4 additions & 0 deletions rest_server/src/models/marketplace_item.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ class MarketplaceItem {
type: DataTypes.STRING,
dataType: DataTypes.STRING,
dataUrl: DataTypes.STRING,
useBlob: {
type: DataTypes.BOOLEAN,
defaultValue: false,
},
categories: DataTypes.ARRAY(DataTypes.STRING),
tags: DataTypes.ARRAY(DataTypes.STRING),
summary: DataTypes.STRING,
Expand Down
22 changes: 12 additions & 10 deletions rest_server/src/models/model_init_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,18 @@ const createTemplates = async models => {

const createStorageBlobs = async models => {
try {
const envBlob = JSON.parse(process.env.AZURE_STORAGE);
const defaultBlob = {
type: envBlob.type,
storageAccount: envBlob.storage_account,
containerName: 'marketplace',
connectionStrings: envBlob.connection_strings,
tokens: [''],
users: [''],
};
await models.Blob.orm.create(defaultBlob);
if (process.env.AZURE_STORAGE) {
const envBlob = JSON.parse(process.env.AZURE_STORAGE);
const defaultBlob = {
type: envBlob.type,
storageAccount: envBlob.storage_account,
containerName: 'marketplace',
connectionStrings: envBlob.connection_strings,
tokens: [''],
users: [''],
};
await models.Blob.orm.create(defaultBlob);
}
} catch (err) {
console.log(err.message);
}
Expand Down
2 changes: 1 addition & 1 deletion webportal/src/app/market_detail/components/summary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default function Summary(props) {

async function clickUse() {
try {
const jobProtocol = await generateJobProtocol(marketItem, user);
const jobProtocol = await generateJobProtocol(marketItem, user, marketItem.useBlob);
window.localStorage.removeItem('marketItem');
window.localStorage.setItem('marketItem', JSON.stringify(jobProtocol));
window.location.href = `/submit.html`;
Expand Down
54 changes: 28 additions & 26 deletions webportal/src/app/market_detail/utils/generate_job_protocol.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
import { getConnectionString } from 'App/utils/marketplace_api';

export async function generateJobProtocol(item, user) {
const connectionString = await getConnectionString(); // can add user as key to get connection string
const npmInstallToken = process.env.NPM_INSTALL_TOKEN;
const protocolHeaderArray = [
'curl -sL https://deb.nodesource.com/setup_10.x -o nodesource_setup.sh',
'bash nodesource_setup.sh',
'apt update',
'apt install -y nodejs',
'npm config set @swordfaith:registry https://npm.pkg.github.com/',
`echo "//npm.pkg.github.com/:_authToken=${npmInstallToken}" >> ~/.npmrc`,
'npm install -g @swordfaith/pai_copy',
`export STORAGE_CONNECTION_STRING="${connectionString}"`,
];
// pai_copy upload [filePath] [containerName] [blobFolder]
const protocolFooterArray = [
'if [ -z ${OUTPUT_DIR+x}]; then', // eslint-disable-line no-template-curly-in-string
'\techo "Not found OUTPUT_DIR environ"',
'else',
'\tpai_copy upload ${OUTPUT_DIR} paiuploadtest ${PAI_USER_NAME}/${PAI_JOB_NAME}/', // eslint-disable-line no-template-curly-in-string
'fi',
];
const taskRoleName = Object.keys(item.protocol.taskRoles)[0];
item.protocol.taskRoles[taskRoleName].commands = protocolHeaderArray.concat(
item.protocol.taskRoles[taskRoleName].commands,
protocolFooterArray,
);
export async function generateJobProtocol(item, user, useBlob) {
if (useBlob === true) {
const connectionString = await getConnectionString(); // can add user as key to get connection string
const npmInstallToken = process.env.NPM_INSTALL_TOKEN;
const protocolHeaderArray = [
'curl -sL https://deb.nodesource.com/setup_10.x -o nodesource_setup.sh',
'bash nodesource_setup.sh',
'apt update',
'apt install -y nodejs',
'npm config set @swordfaith:registry https://npm.pkg.github.com/',
`echo "//npm.pkg.github.com/:_authToken=${npmInstallToken}" >> ~/.npmrc`,
'npm install -g @swordfaith/pai_copy',
`export STORAGE_CONNECTION_STRING="${connectionString}"`,
];
// pai_copy upload [filePath] [containerName] [blobFolder]
const protocolFooterArray = [
'if [ -z ${OUTPUT_DIR+x}]; then', // eslint-disable-line no-template-curly-in-string
'\techo "Not found OUTPUT_DIR environ"',
'else',
'\tpai_copy upload ${OUTPUT_DIR} paiuploadtest ${PAI_USER_NAME}/${PAI_JOB_NAME}/', // eslint-disable-line no-template-curly-in-string
'fi',
];
const taskRoleName = Object.keys(item.protocol.taskRoles)[0];
item.protocol.taskRoles[taskRoleName].commands = protocolHeaderArray.concat(
item.protocol.taskRoles[taskRoleName].commands,
protocolFooterArray,
);
}
return item.protocol;
}

0 comments on commit 7f45cf9

Please sign in to comment.