Skip to content

Commit

Permalink
Release v3.0.9 (#1612)
Browse files Browse the repository at this point in the history
* Add option to deploy from zip (#1611)

* Add option to deploy from zip

* Fix crash if frontend does not exist.

* Add early return that checks if the zip option is present.

* Release v3.0.9
  • Loading branch information
vladiulianbogdan authored Dec 19, 2024
1 parent a3d5895 commit 0e68cd8
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "genezio",
"version": "3.0.8",
"version": "3.0.9",
"description": "Command line utility to interact with Genezio infrastructure.",
"exports": "./index.js",
"type": "module",
Expand Down
10 changes: 10 additions & 0 deletions src/commands/deploy/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { dockerDeploy } from "./docker/deploy.js";
import { PackageManagerType } from "../../packageManagers/packageManager.js";
import { YamlConfigurationIOController } from "../../projectConfiguration/yaml/v2.js";
import { nestJsDeploy } from "./nestjs/deploy.js";
import { zipDeploy } from "./zip/deploy.js";

export type SSRFrameworkComponent = {
path: string;
Expand Down Expand Up @@ -52,6 +53,10 @@ export async function deployCommand(options: GenezioDeployOptions) {
debugLogger.debug("Deploying Nest.js app");
await nestJsDeploy(options);
break;
case DeployType.Zip:
debugLogger.debug("Deploying zip file");
await zipDeploy(options);
break;
}
}

Expand All @@ -62,11 +67,16 @@ export enum DeployType {
Nuxt,
Docker,
Nest,
Zip,
}

async function decideDeployType(options: GenezioDeployOptions): Promise<DeployType> {
const cwd = process.cwd();

if (options.zip) {
return DeployType.Zip;
}

if (options.image) {
return DeployType.Docker;
}
Expand Down
93 changes: 93 additions & 0 deletions src/commands/deploy/zip/deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { GenezioDeployOptions } from "../../../models/commandOptions.js";
import ZipAdm from "adm-zip";
import { createTemporaryFolder } from "../../../utils/file.js";
import { getCloudAdapter } from "../genezio.js";
import { CloudProviderIdentifier } from "../../../models/cloudProviderIdentifier.js";
import { YamlConfigurationIOController } from "../../../projectConfiguration/yaml/v2.js";
import path from "path";
import { ProjectConfiguration } from "../../../models/projectConfiguration.js";
import { GenezioCloudInputType } from "../../../cloudAdapter/cloudAdapter.js";
import { reportSuccessFunctions } from "../../../utils/reporter.js";
import { log } from "../../../utils/logging.js";
import colors from "colors";

export async function zipDeploy(options: GenezioDeployOptions) {
if (!options.zip) {
throw new Error("The --zip option is required for the zip deploy command.");
}
const zipPath = options.zip;

const zip = new ZipAdm(zipPath);
const tmp = await createTemporaryFolder();
// 1. Check if the zip file exists and it is valid
const success = zip.extractEntryTo("genezio.yaml", tmp);
if (!success) {
throw new Error(
"Could not read the genezio.yaml file from the zip file. Make sure the zip file is valid and contains the genezio.yaml file.",
);
}

const configPath = path.join(tmp, "genezio.yaml");

// Read genezio.yaml
const configIOController = new YamlConfigurationIOController(configPath, {
stage: options.stage,
});
const configuration = await configIOController.read();
const projectConfiguration = new ProjectConfiguration(
configuration,
CloudProviderIdentifier.GENEZIO_CLOUD,
{
generatorResponses: [],
classesInfo: [],
},
);

if (!projectConfiguration.functions) {
throw new Error("No functions found in the project configuration");
}

const cloudAdapterDeployInput = projectConfiguration.functions.map((f) => {
return {
type: GenezioCloudInputType.FUNCTION as GenezioCloudInputType.FUNCTION,
name: f.name,
archivePath: zipPath,
unzippedBundleSize: 0,
entryFile: f.entry,
timeout: f.timeout,
instanceSize: f.instanceSize,
storageSize: f.storageSize,
maxConcurrentRequestsPerInstance: f.maxConcurrentRequestsPerInstance,
};
});

const cloudAdapter = getCloudAdapter(CloudProviderIdentifier.GENEZIO_CLOUD);
const result = await cloudAdapter.deploy(
cloudAdapterDeployInput,
projectConfiguration,
{
stage: options.stage,
},
[],
);
if (result.functions.length > 0) {
reportSuccessFunctions(result.functions);
}

const frontendUrls: string[] = [];
if (configuration.frontend) {
for (const frontend of configuration.frontend) {
const frontendUrl = await cloudAdapter.deployFrontend(
projectConfiguration.name,
projectConfiguration.region,
frontend,
options.stage,
);
frontendUrls.push(frontendUrl);
}

for (const frontendUrl of frontendUrls) {
log.info(colors.cyan(`Frontend URL: ${frontendUrl}`));
}
}
}
5 changes: 5 additions & 0 deletions src/genezio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ program
undefined,
)
.option("--env <envFile>", "Load environment variables from a given file", undefined)
.option(
"--zip <zipPath>",
"Deploy a zip file directly. The zip file must contain a valid genezio config file",
undefined,
)
.option("--stage <stage>", "Set the environment name to deploy to", "prod")
.option(
"--subdomain <subdomain>",
Expand Down
1 change: 1 addition & 0 deletions src/models/commandOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface GenezioDeployOptions extends BaseOptions {
subdomain?: string;
config: string;
image?: string;
zip?: string;
}

export interface GenezioListOptions extends BaseOptions {
Expand Down

0 comments on commit 0e68cd8

Please sign in to comment.