Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d6648c2
chore: separate deploy from polywrap project
cbrzn Jan 13, 2023
4600b86
chore: change deploy default manifest string
cbrzn Jan 13, 2023
40bd450
chore(cli/deploy): fix manifest path in deploy command
cbrzn Jan 14, 2023
68f362d
chore(js/test-env): fix deploy on test env js
cbrzn Jan 14, 2023
e5be4d0
chore(cli/deploy): add constant as default manifest string in deploy
cbrzn Jan 14, 2023
1235221
chore(cli): remove deployer attribute from polywrap project
cbrzn Jan 14, 2023
02e7273
chore: fix plugins & deploy cli tests
cbrzn Jan 15, 2023
625c884
feat(polywrap-manifest/0.4): remove deploy from polywrap manifest
cbrzn Jan 16, 2023
b8015ac
chore(polywrap/manifest): improve migrator warn message
cbrzn Jan 16, 2023
34f82b7
js/manifest: remove deploy attribute in polywrap migration 0.4
cbrzn Jan 17, 2023
3255016
tests/cli: remove deploy attribute from manifest
cbrzn Jan 17, 2023
1c03a32
Merge branch 'origin-dev' into chore/separate-deploy-from-polywrap-pr…
cbrzn Jan 17, 2023
fe54a5a
cli: deployer & deploy module renamed
cbrzn Jan 17, 2023
89e96d0
chore: remove non necessary change
cbrzn Jan 17, 2023
61b76ea
chore: rename lib/deploy/ modules
dOrgJelli Jan 18, 2023
6d1a74a
Merge pull request #1483 from polywrap/cli/deployer-renaming
dOrgJelli Jan 18, 2023
5de86de
break: remove extensions from project manifests
dOrgJelli Jan 18, 2023
a2c54e7
chore: update js polywrap manifest bindings + migration functions
dOrgJelli Jan 18, 2023
53ba833
chore: move deployer logic into Deployer class
dOrgJelli Jan 18, 2023
d320568
chore: add back build extension
dOrgJelli Jan 18, 2023
819d263
Merge pull request #1486 from polywrap/chore/remove-project-extensions
cbrzn Jan 18, 2023
0f83999
cli/deployer: fix lint
cbrzn Jan 18, 2023
71f9eb8
manifest/polywrap: unroll version in tests and templates
cbrzn Jan 18, 2023
4e8aea6
cli/deployed: remove underscore from private functions
cbrzn Jan 18, 2023
8f2a86c
chore: unify private member naming conventions
dOrgJelli Jan 18, 2023
8be5599
chore: lint fix
dOrgJelli Jan 18, 2023
005bb3f
chore: fix zip file name sanitization
dOrgJelli Jan 18, 2023
2366e99
chore: revert zip.ts changes
dOrgJelli Jan 18, 2023
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
3 changes: 2 additions & 1 deletion packages/cli/src/__tests__/e2e/deploy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ Deploys Polywrap Projects

Options:
-m, --manifest-file <path> Path to the Polywrap Deploy manifest file
(default: polywrap.yaml | polywrap.yml)
(default: polywrap.deploy.yaml |
polywrap.deploy.yml)
-o, --output-file <path> Output file path for the deploy result
-v, --verbose Verbose output (default: false)
-q, --quiet Suppress output (default: false)
Expand Down
152 changes: 8 additions & 144 deletions packages/cli/src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,25 @@
import { Command, Program, BaseCommandOptions } from "./types";
import { createLogger } from "./utils/createLogger";
import {
defaultPolywrapManifest,
DeployPackage,
intlMsg,
parseManifestFileOption,
PolywrapProject,
DeployJob,
DeployStep,
parseLogFileOption,
Deployer,
defaultDeployManifest,
} from "../lib";

import { DeployManifest } from "@polywrap/polywrap-manifest-types-js";
import fs from "fs";
import nodePath from "path";
import path from "path";
import yaml from "yaml";
import { validate } from "jsonschema";

const defaultManifestStr = defaultPolywrapManifest.join(" | ");
const defaultManifestStr = defaultDeployManifest.join(" | ");
const pathStr = intlMsg.commands_deploy_options_o_path();

export interface DeployCommandOptions extends BaseCommandOptions {
manifestFile: string;
outputFile: string | false;
}

type ManifestJob = DeployManifest["jobs"][number];
type ManifestStep = ManifestJob["steps"][number];

export const deploy: Command = {
setup: (program: Program) => {
program
Expand All @@ -55,7 +47,7 @@ export const deploy: Command = {
await run({
manifestFile: parseManifestFileOption(
options.manifestFile,
defaultPolywrapManifest
defaultDeployManifest
),
outputFile: options.outputFile || false,
verbose: options.verbose || false,
Expand All @@ -70,81 +62,11 @@ async function run(options: Required<DeployCommandOptions>): Promise<void> {
const { manifestFile, outputFile, verbose, quiet, logFile } = options;
const logger = createLogger({ verbose, quiet, logFile });

const project = new PolywrapProject({
rootDir: nodePath.dirname(manifestFile),
polywrapManifestPath: manifestFile,
logger,
});
await project.validate();

const deployManifest = await project.getDeployManifest();

if (!deployManifest) {
throw new Error("No deploy manifest found.");
}

const allStepsFromAllJobs = Object.entries(deployManifest.jobs).flatMap(
([jobName, job]) => {
return job.steps.map((step) => ({
jobName,
...step,
}));
}
);

const packageNames = [
...new Set(allStepsFromAllJobs.map((step) => step.package)),
];

sanitizePackages(packageNames);

await project.cacheDeployModules(packageNames);

const packageMapEntries = await Promise.all(
packageNames.map(async (packageName) => {
const deployerPackage = await project.getDeployModule(packageName);
return [packageName, deployerPackage];
})
);

const packageMap = Object.fromEntries(packageMapEntries);

const stepToPackageMap: Record<
string,
DeployPackage & { jobName: string }
> = {};

for (const step of allStepsFromAllJobs) {
stepToPackageMap[step.name] = {
...packageMap[step.package],
jobName: step.jobName,
};
}

validateManifestWithExts(deployManifest, stepToPackageMap);

const jobs = Object.entries(deployManifest.jobs).map(([jobName, job]) => {
const steps: DeployStep[] = job.steps.map((step) => {
return new DeployStep({
name: step.name,
uriOrStepResult: step.uri,
deployer: stepToPackageMap[step.name].deployer,
config: step.config ?? {},
});
});

return new DeployJob({
name: jobName,
steps,
config: job.config ?? {},
logger,
});
});

const jobResults = await Promise.all(jobs.map((job) => job.run()));
const deployer = await Deployer.create(manifestFile, logger);
const jobResults = await deployer.run();

if (outputFile) {
const outputFileExt = nodePath.extname(outputFile).substring(1);
const outputFileExt = path.extname(outputFile).substring(1);
if (!outputFileExt) throw new Error("Require output file extension");
switch (outputFileExt) {
case "yaml":
Expand All @@ -164,61 +86,3 @@ async function run(options: Required<DeployCommandOptions>): Promise<void> {
}
process.exit(0);
}

function sanitizePackages(packages: string[]) {
const unrecognizedPackages: string[] = [];

const availableDeployers = fs.readdirSync(
nodePath.join(__dirname, "..", "lib", "defaults", "deploy-modules")
);

packages.forEach((p) => {
if (!availableDeployers.includes(p)) {
unrecognizedPackages.push(p);
}
});

if (unrecognizedPackages.length) {
throw new Error(
`Unrecognized packages: ${unrecognizedPackages.join(", ")}`
);
}
}

function validateManifestWithExts(
deployManifest: DeployManifest,
stepToPackageMap: Record<string, DeployPackage & { jobName: string }>
) {
const errors = Object.entries(stepToPackageMap).flatMap(
([stepName, step]) => {
const jobEntry = Object.entries(deployManifest.jobs).find(
([jobName]) => jobName === step.jobName
) as [string, ManifestJob];

const job = jobEntry[1];

const stepToValidate = job.steps.find(
(s) => s.name === stepName
) as ManifestStep;

return step.manifestExt
? validate(
{
...job.config,
...stepToValidate.config,
},
step.manifestExt
).errors
: [];
}
);

if (errors.length) {
throw new Error(
[
`Validation errors encountered while sanitizing DeployManifest format ${deployManifest.format}`,
...errors.map((error) => error.toString()),
].join("\n")
);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-require-imports */
/* eslint-disable @typescript-eslint/no-var-requires */
import { Deployer } from "../../../deploy";
import { DeployModule } from "../../../deploy";

import { Wallet } from "@ethersproject/wallet";
import { JsonRpcProvider } from "@ethersproject/providers";
Expand All @@ -13,7 +13,7 @@ import {
import { embeddedWrappers } from "@polywrap/test-env-js";
import { PolywrapClient } from "@polywrap/client-js";

class ENSRecursiveNameRegisterPublisher implements Deployer {
class ENSRecursiveNameRegisterPublisher implements DeployModule {
async execute(
uri: Uri,
config: {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/lib/defaults/deploy-modules/ens/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-require-imports */
/* eslint-disable @typescript-eslint/no-var-requires */
import { Deployer } from "../../../deploy";
import { DeployModule } from "../../../deploy";

import { Wallet } from "@ethersproject/wallet";
import { JsonRpcProvider } from "@ethersproject/providers";
Expand All @@ -15,7 +15,7 @@ import { PolywrapClient } from "@polywrap/client-js";

const contentHash = require("content-hash");

class ENSPublisher implements Deployer {
class ENSPublisher implements DeployModule {
async execute(
uri: Uri,
config: {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/lib/defaults/deploy-modules/http/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Deployer } from "../../../deploy/deployer";
import { DeployModule } from "../../../deploy";

import { Uri } from "@polywrap/core-js";
import FormData from "form-data";
Expand Down Expand Up @@ -33,7 +33,7 @@ const dirToFormData = (baseDirPath: string) => {
return formData;
};

class HTTPDeployer implements Deployer {
class HTTPDeployer implements DeployModule {
async execute(uri: Uri, config?: { postUrl: string }): Promise<Uri> {
if (!isValidUri(uri)) {
throw new Error(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Deployer } from "../../../deploy/deployer";
import { DeployModule } from "../../../deploy";

import { Uri } from "@polywrap/core-js";

class IPFSDeployer implements Deployer {
class IPFSDeployer implements DeployModule {
// eslint-disable-next-line @typescript-eslint/naming-convention
async execute(_: Uri, __: unknown): Promise<Uri> {
return new Uri(`ipfs/Qm`);
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/lib/defaults/deploy-modules/ipfs/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Deployer } from "../../../deploy/deployer";
import { DeployModule } from "../../../deploy";

import { Uri } from "@polywrap/core-js";

Expand All @@ -8,7 +8,7 @@ const { globSource } = IPFSClient;

const isValidUri = (uri: Uri) => uri.authority === "fs";

class IPFSDeployer implements Deployer {
class IPFSDeployer implements DeployModule {
async execute(uri: Uri, config?: { gatewayUri: string }): Promise<Uri> {
if (!isValidUri(uri)) {
throw new Error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"file-saver": "2.0.5",
"jszip": "3.10.1",
"fs-extra": "7.0.1",
"multer": "1.4.5-lts.1"
"multer": "1.4.5-lts.1",
"sanitize-filename": "1.6.3"
},
"devDependencies": {
"@types/express": "4.17.13",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import JSZip from "jszip";
import sanitize from "sanitize-filename";
import fse from "fs-extra";
import path from "path";

export class Zip {
private _zip: JSZip;
Expand All @@ -8,7 +10,7 @@ export class Zip {
this._zip = new JSZip();
}

private generateNodeZip(filePath: string) {
private _generateNodeZip(filePath: string) {
return new Promise<boolean>((res, rej) => {
this._zip.generateNodeStream({ type: 'nodebuffer', streamFiles: true })
.pipe(fse.createWriteStream(filePath))
Expand All @@ -25,6 +27,6 @@ export class Zip {
fse.readdirSync(sourceDir).forEach(file => {
this._zip.file(file, fse.readFileSync(`${sourceDir}/${file}`))
})
return this.generateNodeZip(outputPath);
return this._generateNodeZip(outputPath);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { DeployStep, StepName, StepResult, UriOrPrevStepResult } from "./step";
import {
DeployStep,
StepName,
StepResult,
UriOrPrevStepResult,
} from "./DeployStep";
import { Logger } from "../logging";

import { Uri } from "@polywrap/core-js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Uri } from "@polywrap/core-js";

export interface Deployer {
export interface DeployModule {
execute(uri: Uri, config?: unknown): Promise<Uri>;
}
8 changes: 8 additions & 0 deletions packages/cli/src/lib/deploy/DeployPackage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { DeployModule } from "./DeployModule";

import { Schema as JsonSchema } from "jsonschema";

export interface DeployPackage {
deployModule: DeployModule;
manifestExt: JsonSchema | undefined;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Deployer } from "./deployer";
import { DeployModule } from "./DeployModule";

import { Uri } from "@polywrap/core-js";

Expand All @@ -14,24 +14,24 @@ export interface StepResult {
interface StepArgs {
name: string;
uriOrStepResult: UriOrPrevStepResult;
deployer: Deployer;
deployModule: DeployModule;
config: Record<string, unknown>;
}

export class DeployStep {
public name: string;
public deployer: Deployer;
public deployModule: DeployModule;
public uriOrStepResult: string;
public config: Record<string, unknown>;

constructor(args: StepArgs) {
this.name = args.name;
this.deployer = args.deployer;
this.deployModule = args.deployModule;
this.uriOrStepResult = args.uriOrStepResult;
this.config = args.config;
}

public async run(uri: Uri, config: Record<string, unknown>): Promise<Uri> {
return await this.deployer.execute(uri, config);
return await this.deployModule.execute(uri, config);
}
}
Loading