can deploy versions of apps
This commit is contained in:
parent
66ba4e687f
commit
7b859e9d3b
File diff suppressed because one or more lines are too long
|
@ -2,24 +2,26 @@ const { tmpdir } = require("os");
|
|||
const { join } = require("path");
|
||||
const uuid = require("uuid/v1");
|
||||
const { take, takeRight } = require("lodash/fp");
|
||||
const { splitKey, $ } = require("budibase-core").common;
|
||||
const { splitKey, $, joinKey } = require("budibase-core").common;
|
||||
const { unzipTarGzPackageToRuntime } = require("../../utilities/targzAppPackage");
|
||||
const { getRuntimePackageDirectory } = require("../../utilities/runtimePackages");
|
||||
const { exists } = require("../../utilities/fsawait");
|
||||
const createInstanceDb = require("../../initialise/createInstanceDb");
|
||||
const { createWriteStream } = require("fs");
|
||||
|
||||
module.exports = (config) => ({
|
||||
initialiseInstance : async ({ instance, apis }) => {
|
||||
|
||||
const appKey = $(instance.key, [
|
||||
splitKey,
|
||||
take(2)
|
||||
take(2),
|
||||
joinKey
|
||||
]);
|
||||
|
||||
const application = await apis.recordApi.load(appKey);
|
||||
|
||||
const datastoreModule = require(`../../../datastores/datastores/${config.datastore}`);
|
||||
const dbConfig = await createInstanceDb(
|
||||
require(config.datastore),
|
||||
datastoreModule,
|
||||
config.datastoreConfig,
|
||||
application.id,
|
||||
instance.id
|
||||
|
@ -27,7 +29,8 @@ module.exports = (config) => ({
|
|||
|
||||
const versionId = $(instance.version.key, [
|
||||
splitKey,
|
||||
takeRight(1)
|
||||
takeRight(1),
|
||||
joinKey
|
||||
]);
|
||||
|
||||
const runtimeDir = getRuntimePackageDirectory(
|
||||
|
@ -35,7 +38,7 @@ module.exports = (config) => ({
|
|||
versionId);
|
||||
|
||||
if(!await exists(runtimeDir))
|
||||
await downloadAppPackage(instance, application.name, versionId);
|
||||
await downloadAppPackage(apis, instance, application.name, versionId);
|
||||
|
||||
instance.datastoreconfig = JSON.stringify(dbConfig);
|
||||
instance.isNew = false;
|
||||
|
@ -43,12 +46,11 @@ module.exports = (config) => ({
|
|||
}
|
||||
});
|
||||
|
||||
const downloadAppPackage = async (instance, appName, versionId) => {
|
||||
const inputStream = apis.recordApi.downloadFile(instance.key, "package.tar.gz");
|
||||
const downloadAppPackage = async (apis, instance, appName, versionId) => {
|
||||
const inputStream = await apis.recordApi.downloadFile(instance.version.key, "package.tar.gz");
|
||||
|
||||
const tempFilePath = join(tmpdir(), `bbpackage_${uuid()}.tar.gz`);
|
||||
const outputStream = await app.datastore.writableFileStream(
|
||||
tempFilePath);
|
||||
const outputStream = createWriteStream(tempFilePath);
|
||||
|
||||
await new Promise((resolve,reject) => {
|
||||
inputStream.pipe(outputStream);
|
||||
|
|
Binary file not shown.
|
@ -3,14 +3,8 @@ const {
|
|||
setupDatastore
|
||||
} = require("budibase-core");
|
||||
const constructHierarchy = require("../utilities/constructHierarchy");
|
||||
const getDatabaseManager = require("../utilities/databaseManager");
|
||||
const {
|
||||
getApisForUser,
|
||||
getApisWithFullAccess
|
||||
} = require("../utilities/budibaseApi");
|
||||
const getDatabaseManager = require("../utilities/databaseManager");
|
||||
const masterDbAppDefinition = require("../appPackages/master/appDefinition.json");
|
||||
const masterDbAccessLevels = require("../appPackages/master/access_levels.json");
|
||||
const { masterAppPackage } = require("../utilities/createAppPackage");
|
||||
|
||||
module.exports = async (datastoreModule, rootDatastoreConfig, appId, instanceId) => {
|
||||
try {
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{"levels":[{"name":"owner","permissions":[{"type":"create record","nodeKey":"/applications/1-{id}"},{"type":"update record","nodeKey":"/applications/1-{id}"},{"type":"delete record","nodeKey":"/applications/1-{id}"},{"type":"read record","nodeKey":"/applications/1-{id}"},{"type":"create record","nodeKey":"/applications/1-{id}/users/8-{id}"},{"type":"update record","nodeKey":"/applications/1-{id}/users/8-{id}"},{"type":"delete record","nodeKey":"/applications/1-{id}/users/8-{id}"},{"type":"read record","nodeKey":"/applications/1-{id}/users/8-{id}"},{"type":"create record","nodeKey":"/applications/1-{id}/instances/2-{id}"},{"type":"update record","nodeKey":"/applications/1-{id}/instances/2-{id}"},{"type":"delete record","nodeKey":"/applications/1-{id}/instances/2-{id}"},{"type":"read record","nodeKey":"/applications/1-{id}/instances/2-{id}"},{"type":"create record","nodeKey":"/applications/1-{id}/versions/3-{id}"},{"type":"update record","nodeKey":"/applications/1-{id}/versions/3-{id}"},{"type":"delete record","nodeKey":"/applications/1-{id}/versions/3-{id}"},{"type":"read record","nodeKey":"/applications/1-{id}/versions/3-{id}"},{"type":"create record","nodeKey":"/applications/1-{id}/sessions/16-{id}"},{"type":"update record","nodeKey":"/applications/1-{id}/sessions/16-{id}"},{"type":"delete record","nodeKey":"/applications/1-{id}/sessions/16-{id}"},{"type":"read record","nodeKey":"/applications/1-{id}/sessions/16-{id}"},{"type":"create record","nodeKey":"/sessions/17-{id}"},{"type":"update record","nodeKey":"/sessions/17-{id}"},{"type":"delete record","nodeKey":"/sessions/17-{id}"},{"type":"read record","nodeKey":"/sessions/17-{id}"},{"type":"read index","nodeKey":"/mastersessions_by_user"},{"type":"read index","nodeKey":"/all_applications"},{"type":"read index","nodeKey":"/applications/1-{id}/allinstances"},{"type":"read index","nodeKey":"/applications/1-{id}/sessions_by_user"},{"type":"read index","nodeKey":"/applications/1-{id}/user_name_lookup"},{"type":"read index","nodeKey":"/applications/1-{id}/all_versions"},{"type":"read index","nodeKey":"/applications/1-{id}/instances/2-{id}/users_on_this_instance"},{"type":"read index","nodeKey":"/applications/1-{id}/versions/3-{id}/instances_for_this_version"},{"type":"read index","nodeKey":"/applications/1-{id}/versions/3-{id}/instances_on_this_version"},{"type":"write templates"},{"type":"create user"},{"type":"set password"},{"type":"create temporary access"},{"type":"enable or disable user"},{"type":"write access levels"},{"type":"list users"},{"type":"list access levels"},{"type":"manage index"},{"type":"manage collection"},{"type":"set user access levels"}]}],"version":0}
|
File diff suppressed because one or more lines are too long
|
@ -57,6 +57,7 @@ module.exports = (app) => {
|
|||
|
||||
});
|
||||
|
||||
let instance1Key;
|
||||
it("should be able to create new instance of app", async () => {
|
||||
const master = await getmaster();
|
||||
const instance1 = master.recordApi
|
||||
|
@ -64,7 +65,11 @@ module.exports = (app) => {
|
|||
instance1.name = "instance 1";
|
||||
instance1.active = true;
|
||||
instance1.version = {key:version1Key, name:"v1"};
|
||||
instance1.datastoreconfig;
|
||||
instance1Key = instance1.key;
|
||||
|
||||
await app.post(`/_master/api/record/${instance1.key}`, instance1)
|
||||
.set("cookie", app.masterAuth.cookie)
|
||||
.expect(statusCodes.OK);
|
||||
|
||||
|
||||
});
|
||||
|
|
|
@ -11,7 +11,7 @@ const masterOwnerName = "test_master";
|
|||
const masterOwnerPassword = "test_master_pass";
|
||||
|
||||
const extraMasterPlugins = {
|
||||
main: {
|
||||
test_plugins: {
|
||||
outputToFile : ({filename, content}) => {
|
||||
fs.writeFile(`./tests/.data/${filename}`, content, {encoding:"utf8"});
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ const customizeMaster = appDefinition => {
|
|||
|
||||
appDefinition.actions.outputToFile = {
|
||||
name: 'outputToFile',
|
||||
behaviourSource: 'main',
|
||||
behaviourSource: 'test_plugins',
|
||||
behaviourName: 'outputToFile',
|
||||
initialOptions: {}
|
||||
};
|
||||
|
|
|
@ -2,7 +2,14 @@ const { join } = require("path");
|
|||
|
||||
const runtimePackagesDirectory = "./runtime_apps";
|
||||
|
||||
const getRuntimeAppsDirectory = (appName) =>
|
||||
join(runtimePackagesDirectory, appName);
|
||||
|
||||
module.exports.runtimePackagesDirectory = runtimePackagesDirectory;
|
||||
|
||||
module.exports.getRuntimePackageDirectory = (appName, versionId) =>
|
||||
join(runtimePackagesDirectory, appName, versionId);
|
||||
join(
|
||||
getRuntimeAppsDirectory(appName),
|
||||
versionId);
|
||||
|
||||
module.exports.getRuntimeAppsDirectory = getRuntimeAppsDirectory;
|
||||
|
|
|
@ -6,7 +6,7 @@ const tar = require('tar-fs');
|
|||
const zlib = require("zlib");
|
||||
const { join, dirname, sep } = require("path");
|
||||
const { exists, mkdir, unlink, stat } = require("../utilities/fsawait");
|
||||
const { getRuntimePackageDirectory } = require("./runtimePackages");
|
||||
const { getRuntimePackageDirectory, getRuntimeAppsDirectory } = require("./runtimePackages");
|
||||
|
||||
module.exports.createTarGzPackage = async (config, appName) => {
|
||||
|
||||
|
@ -29,14 +29,19 @@ module.exports.createTarGzPackage = async (config, appName) => {
|
|||
|
||||
module.exports.unzipTarGzPackageToRuntime = async (src, appName, versionId) => {
|
||||
const versionDir = getRuntimePackageDirectory(appName, versionId);
|
||||
const appDir = getRuntimeAppsDirectory(appName);
|
||||
|
||||
if(await exists(versionDir)) {
|
||||
await rimraf(versionDir);
|
||||
if(await exists(appDir)) {
|
||||
if(await exists(versionDir)) {
|
||||
await rimraf(versionDir);
|
||||
}
|
||||
} else {
|
||||
await mkdir(appDir);
|
||||
}
|
||||
|
||||
await mkdir(versionDir);
|
||||
|
||||
decompress(src, versionDir);
|
||||
await decompress(src, versionDir);
|
||||
}
|
||||
|
||||
const compress = (src, dest) => new Promise((resolve, reject) => {
|
||||
|
|
Loading…
Reference in New Issue