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

PLT-2547: feat: support snapshot install #89

Merged
merged 5 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
64 changes: 49 additions & 15 deletions bin/local-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ async function getInstalledPackages() {
return installedPackages;
}

function getPackagesToInstall(packageName, packagesMap, installedPackages, skipVersionCheck) {
function getPackagesToInstall(packageName, packagesMap, installedPackages, skipVersionCheck, temporaryInstall) {
/**
* Returns a list of all packages that need to be installed
*/
Expand All @@ -140,12 +140,24 @@ function getPackagesToInstall(packageName, packagesMap, installedPackages, skipV
throw new Error(`Package ${packageName} not found`);
}

const temporaryInstallSuffix = "-temp";

for (const dependency of Object.keys(package.dependencies)) {
const dependencyPackage = packagesMap[dependency];
let dependencyPackage = packagesMap[dependency];
if (!dependencyPackage) {
throw new Error(`Dependency ${dependency} not found`);
}

if (temporaryInstall) {
packagesToInstall.add(dependencyPackage);
if (!dependencyPackage.version.endsWith(temporaryInstallSuffix)) {
dependencyPackage.version = dependencyPackage.version + temporaryInstallSuffix;
}
} else if (dependencyPackage.version.endsWith(temporaryInstallSuffix)) {
packagesToInstall.add(dependencyPackage);
dependencyPackage.version = dependencyPackage.version.slice(0, -temporaryInstallSuffix.length);
tczhao marked this conversation as resolved.
Show resolved Hide resolved
}

if (!installedPackages[dependencyPackage.name] || dependencyPackage.isNumaflowPackage) {
packagesToInstall.add(dependencyPackage);
}
Expand All @@ -159,7 +171,8 @@ function getPackagesToInstall(packageName, packagesMap, installedPackages, skipV
dependency,
packagesMap,
installedPackages,
skipVersionCheck
skipVersionCheck,
temporaryInstall
);
packagesToInstall = new Set([...packagesToInstall, ...dependencyPackagesToInstall]);
}
Expand All @@ -177,11 +190,15 @@ function getConnectorPackages() {
//Check for type miner, utility and return for custom, connectors etc.
const packages = fs
.readdirSync(marketplacePackagesPath, { recursive: true, withFileTypes: false })
.filter(file => file.endsWith("package.json"))
.map(file => JSON.parse(fs.readFileSync(path.join(marketplacePackagesPath, file), "utf-8")))
.filter(pkg => pkg.config?.labels?.['orchestration.atlan.com/certified'] === 'true')
.filter(pkg => pkg.config?.labels?.['orchestration.atlan.com/type'] !== 'miner' && pkg.config?.labels?.['orchestration.atlan.com/type'] !== 'utility' )
.map(pkg => pkg.name);
.filter((file) => file.endsWith("package.json"))
.map((file) => JSON.parse(fs.readFileSync(path.join(marketplacePackagesPath, file), "utf-8")))
.filter((pkg) => pkg.config?.labels?.["orchestration.atlan.com/certified"] === "true")
.filter(
(pkg) =>
pkg.config?.labels?.["orchestration.atlan.com/type"] !== "miner" &&
pkg.config?.labels?.["orchestration.atlan.com/type"] !== "utility"
)
.map((pkg) => pkg.name);

return packages;
}
Expand All @@ -195,6 +212,7 @@ function installPackages(packages, extraArgs, azureArtifacts) {
const packageJSONPath = path.join(pkg.path, "package.json");
const packageJSON = JSON.parse(fs.readFileSync(packageJSONPath, "utf-8"));
packageJSON.dependencies = {};
packageJSON.version = pkg.version;

// Write back package.json
fs.writeFileSync(packageJSONPath, JSON.stringify(packageJSON, null, 2));
Expand All @@ -208,11 +226,17 @@ function installPackages(packages, extraArgs, azureArtifacts) {
}
}

async function run(packageName, azureArtifacts, bypassSafetyCheck, extraArgs, channel) {
async function run(packageName, azureArtifacts, bypassSafetyCheck, extraArgs, channel, temporaryInstall) {
const packagesMap = getAllPackagesMap();
const installedPackages = await getInstalledPackages();

const packagesToInstall = getPackagesToInstall(packageName, packagesMap, installedPackages, bypassSafetyCheck);
const packagesToInstall = getPackagesToInstall(
packageName,
packagesMap,
installedPackages,
bypassSafetyCheck,
temporaryInstall
);
console.log(
"Packages to install: " +
Array.from(packagesToInstall)
Expand All @@ -222,7 +246,9 @@ async function run(packageName, azureArtifacts, bypassSafetyCheck, extraArgs, ch

// Always install numaflow packages since delete-pipelines may have deleted them
const numaflowPackages = [...packagesToInstall].filter((pkg) => pkg.isNumaflowPackage);
const connectorPackages = [...packagesToInstall].find((pkg)=> "@atlan/connectors" === pkg.name ) ? getConnectorPackages() : [];
const connectorPackages = [...packagesToInstall].find((pkg) => "@atlan/connectors" === pkg.name)
? getConnectorPackages()
: [];
if (packageName != "@atlan/cloud-packages") {
console.log("Numaflow packages to install: " + numaflowPackages.map((pkg) => pkg.name).join(", "));
installPackages(numaflowPackages, extraArgs, azureArtifacts);
Expand All @@ -239,10 +265,12 @@ async function run(packageName, azureArtifacts, bypassSafetyCheck, extraArgs, ch
safeToInstall = false;
break;
}
if(connectorPackages.includes(runningPackage)){
if (connectorPackages.includes(runningPackage)) {
//If any of the connector packages are running, then we have to skip the installation of @atlan/connectors package.
safeToInstall = false;
console.log(`Connector package ${runningPackage} is running. Skipping installation of @atlan/connectors package`);
console.log(
`Connector package ${runningPackage} is running. Skipping installation of @atlan/connectors package`
);
break;
}
}
Expand All @@ -260,7 +288,7 @@ async function run(packageName, azureArtifacts, bypassSafetyCheck, extraArgs, ch
const argoPackages = [...packagesToInstall].filter((pkg) => !pkg.isNumaflowPackage);
console.log("Argo packages to install: " + argoPackages.map((pkg) => pkg.name).join(", "));

installPackages(argoPackages, extraArgs, azureArtifacts);
installPackages(argoPackages, extraArgs, azureArtifacts, temporaryInstall);

// Write last safe release
fs.writeFileSync(
Expand All @@ -276,7 +304,13 @@ const azureArtifacts = process.argv[4];
const bypassSafetyCheckString = process.argv[5];
const extraArgs = process.argv[6];
const channel = process.argv[7];
// Temporary install enables package install regardless of version upgrade
// It respects bypassSafetyCheck, and added a -temp suffix to the version
// For a local-install that doesn't have temporaryInstall enabled,
// any temporary packages will get overwritten regardless of version upgrade, this helps to reset the package
const temporaryInstallString = process.argv[8];

const bypassSafetyCheck = bypassSafetyCheckString === "true";
const temporaryInstall = temporaryInstallString === "true";

run(packageName, azureArtifacts, bypassSafetyCheck, extraArgs, channel);
run(packageName, azureArtifacts, bypassSafetyCheck, extraArgs, channel, temporaryInstall);
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "argopm",
"version": "0.10.17",
"version": "0.10.18",
"description": "Argo package manager",
"main": "./lib/index.js",
"scripts": {
Expand Down
Loading