-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
a3d5895
commit 0e68cd8
Showing
5 changed files
with
110 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters