| Server IP : 34.87.99.72 / Your IP : 216.73.217.31 Web Server : Apache/2.4.46 (Unix) OpenSSL/1.1.1n System : Linux zlock-bitnami-lamp-prod-v2-vm 4.19.0-16-cloud-amd64 #1 SMP Debian 4.19.181-1 (2021-03-19) x86_64 User : bitnami ( 1000) PHP Version : 7.4.18 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /opt/bitnami/nami/node_modules/provisioner/lib/recipes/ |
Upload File : |
/// <reference path="../../typings-recipe.d.ts" />
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
(() => {
const SYSTEM_USERNAME = "bitnami";
// Define the mount point from the definition if present. Defaults to namiDataPath ('/bitnami')
const mountPoint = provisioner.stackDefinition.defaultSharedDiskMountPoint || platform.pathInfo.namiDataPath;
/**
* Helper function to add extra conditions in order to decide whether to create and mount a shared disk
*/
function skipSharedDisk() {
// Skip if it's airflow and a DAGs repository is provided
return provisioner.stackDefinition.details.key === "airflow" && provisioner.appRepository ? true : false;
}
/**
* Install azure-cli and cifs
* https://docs.microsoft.com/en-us/cli/azure/install-azure-cli
*/
recipes.register({
id: "shared-disk-packages-azure",
on: { provisionMachine: { depends: ["system-packages"] } },
conditions: {
tierTags: { any: ["requires-shared-disk"] },
platformTags: { any: ["debian"] },
cloudTags: { any: ["azure"] },
shouldInvoke: () => !skipSharedDisk(),
},
recipeHandler: function (input) {
return __awaiter(this, void 0, void 0, function* () {
let signingKey = "";
yield utils.retry(() => {
signingKey = $os.runProgram("curl", ["-L", "https://packages.microsoft.com/keys/microsoft.asc"]);
});
$os.runProgram("apt-key", ["add", "-"], { input: signingKey });
$file.write("/etc/apt/sources.list.d/azure-cli.list", "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ stretch main\n");
yield utils.retry(() => {
// Only update this specific source
$os.runProgram("apt-get", ["update"]);
});
yield utils.retry(() => {
platform.installPackages("azure-cli", "cifs-utils");
});
});
}
});
/**
* Install packages for EFS support (Elastic File System)
* https://docs.aws.amazon.com/efs/latest/ug/mounting-fs.html#mounting-fs-install-nfsclient
*/
recipes.register({
id: "shared-disk-packages-aws",
on: { provisionMachine: { depends: ["system-packages"] } },
conditions: {
tierTags: { any: ["requires-shared-disk"] },
platformTags: { any: ["debian"] },
cloudTags: { any: ["aws"] },
shouldInvoke: () => !skipSharedDisk(),
},
recipeHandler: function (input) {
return __awaiter(this, void 0, void 0, function* () {
yield utils.retry(() => {
platform.installPackages("nfs-common");
});
});
}
});
/**
* Create and mount shared file system
*/
recipes.register({
id: "shared-disk-azure",
on: { beforeInitialize: {} },
conditions: {
tierTags: { any: ["requires-shared-disk"] },
cloudTags: { any: ["azure"] },
shouldInvoke: () => !skipSharedDisk(),
},
recipeHandler: function (input) {
return __awaiter(this, void 0, void 0, function* () {
const mountConfig = yield cloud.createSharedDisk("shareddisk", {
storageAccountName: provisioner.storageAccountName,
storageAccountKey: provisioner.storageAccountKey
});
// Specify more options
mountConfig.mountPoint = mountPoint;
Object.assign(mountConfig.options, {
uid: SYSTEM_USERNAME,
gid: SYSTEM_USERNAME,
file_mode: "0664",
dir_mode: "0775",
serverino: true
});
platform.mount(mountConfig, { addToFstab: true });
});
}
});
/**
* Mount shared file system
*/
recipes.register({
id: "shared-disk-aws",
on: { beforeInitialize: {} },
conditions: {
instanceTier: { not: ["main"] },
tierTags: { any: ["requires-shared-disk"] },
cloudTags: { any: ["aws"] },
shouldInvoke: () => !skipSharedDisk(),
},
recipeHandler: function (input) {
return __awaiter(this, void 0, void 0, function* () {
// TODO Improve mount options for better performance
const efsUri = yield cloud.getUserData("PROVISIONER_EFS_URI");
const mountConfig = {
device: efsUri,
mountPoint,
type: "nfs4",
options: {
nfsvers: "4.1",
rsize: 1048576,
wsize: 1048576,
hard: true,
}
};
platform.mount(mountConfig, { addToFstab: true });
});
}
});
const initializingFile = $file.join(mountPoint, ".initializing");
const initializedFile = $file.join(mountPoint, ".initialized");
/**
* Try to lock the shared disk to perform the first initialization.
*/
recipes.register({
id: "shared-disk-lock-initialization",
on: { beforeInitialize: { depends: ["shared-disk-aws", "shared-disk-azure"] } },
conditions: {
tierTags: { any: ["requires-shared-disk"] },
shouldInvoke: () => { return !skipSharedDisk() && !$file.exists(initializedFile); },
},
recipeHandler: function (input) {
return __awaiter(this, void 0, void 0, function* () {
const waitUntilInitialized = function () {
return __awaiter(this, void 0, void 0, function* () {
yield utils.retry(() => {
if (!$file.exists(initializedFile)) {
throw new Error(`Timeout: ${initializedFile} does not exist`);
}
}, {
attempts: 120,
delay: 5,
});
});
};
yield utils.delayMs(Math.random() * 30000); // [0,30] seconds
if ($file.exists(initializingFile)) {
logger.debug("The initializing lock file already exists");
yield waitUntilInitialized();
}
else {
logger.debug("The initializing lock file does not exist yet. Trying to lock for initialization");
const contentCheck = Math.random().toString();
$file.write(initializingFile, contentCheck);
yield utils.delayMs(3000); // Wait 3 seconds; assuming 3 > max sync time in the shared disk
if ($file.read(initializingFile) !== contentCheck) {
logger.debug("Could not lock for initialization.");
yield waitUntilInitialized();
}
}
});
}
});
/**
* Free the shared disk and mark it as initialized. The order in the initialization is already granted.
*/
recipes.register({
id: "shared-disk-free-initialization",
on: { afterInitialize: {}, afterFailedInitialize: {} },
conditions: {
tierTags: { any: ["requires-shared-disk"] },
shouldInvoke: () => { return !skipSharedDisk() && !$file.exists(initializedFile); },
},
recipeHandler: function (input) {
return __awaiter(this, void 0, void 0, function* () {
if (input.eventName === "afterInitialize") {
$file.touch(initializedFile);
}
$file.delete(initializingFile);
});
}
});
})();