Skip to content

Commit

Permalink
Merge pull request #1385 from Genez-io/dev
Browse files Browse the repository at this point in the history
Release 2.6.0
  • Loading branch information
costinsin authored Sep 23, 2024
2 parents 67fa21f + 02d9562 commit c99059f
Show file tree
Hide file tree
Showing 13 changed files with 1,284 additions and 2,005 deletions.
2,999 changes: 1,161 additions & 1,838 deletions package-lock.json

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"license": "GPL-3",
"dependencies": {
"@amplitude/analytics-node": "^1.3.5",
"@aws-sdk/client-cloudformation": "^3.645.0",
"@aws-sdk/client-cloudformation": "^3.654.0",
"@aws-sdk/client-s3": "^3.637.0",
"@babel/core": "^7.25.2",
"@babel/parser": "^7.24.4",
Expand Down Expand Up @@ -77,7 +77,7 @@
"dotenv": "^16.4.5",
"esbuild": "^0.18.20",
"esbuild-node-externals": "^1.14.0",
"execa": "^9.3.0",
"execa": "^9.3.1",
"express": "^4.19.2",
"fs-extra": "^11.2.0",
"glob": "^8.0.3",
Expand All @@ -89,7 +89,7 @@
"lodash": "^4.17.21",
"log-update": "^6.1.0",
"loglevel-plugin-prefix": "^0.8.4",
"memfs": "^4.9.3",
"memfs": "^4.11.1",
"mime-types": "^2.1.35",
"mustache": "^4.2.0",
"node-abort-controller": "^3.1.1",
Expand All @@ -98,7 +98,7 @@
"ora": "^8.0.1",
"semver": "^7.6.2",
"tslog": "^4.9.2",
"typescript": "^5.4.4",
"typescript": "^5.6.2",
"unique-names-generator": "^4.7.1",
"uuid": "^10.0.0",
"whatwg-mimetype": "~3.0.0",
Expand Down Expand Up @@ -149,21 +149,21 @@
"pre-commit": "^1.2.2",
"prettier": "^3.3.3",
"shx": "^0.3.4",
"vitest": "^1.6.0"
"vitest": "^2.1.1"
},
"optionalDependencies": {
"@rollup/rollup-android-arm-eabi": "4.21.2",
"@rollup/rollup-android-arm64": "4.21.0",
"@rollup/rollup-darwin-arm64": "4.20.0",
"@rollup/rollup-android-arm-eabi": "4.22.4",
"@rollup/rollup-android-arm64": "4.21.3",
"@rollup/rollup-darwin-arm64": "4.21.3",
"@rollup/rollup-darwin-x64": "4.18.0",
"@rollup/rollup-linux-arm-gnueabihf": "4.21.2",
"@rollup/rollup-linux-arm64-gnu": "4.19.0",
"@rollup/rollup-linux-arm64-musl": "4.18.0",
"@rollup/rollup-linux-arm64-musl": "4.22.4",
"@rollup/rollup-linux-riscv64-gnu": "4.21.2",
"@rollup/rollup-linux-x64-gnu": "4.18.0",
"@rollup/rollup-linux-x64-musl": "4.21.0",
"@rollup/rollup-win32-arm64-msvc": "4.21.2",
"@rollup/rollup-win32-ia32-msvc": "4.18.0",
"@rollup/rollup-win32-ia32-msvc": "4.22.4",
"@rollup/rollup-win32-x64-msvc": "4.21.2"
},
"prettier": {
Expand Down
10 changes: 5 additions & 5 deletions src/bundlers/node/lambdaHandlerGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ if (!genezioClass) {
handler = async function (event, context) {
await sendSentryError(error);
return {
statusCode: 500,
statusCode: 400,
body: JSON.stringify({
jsonrpc: "2.0",
error: {
Expand Down Expand Up @@ -170,7 +170,7 @@ if (!genezioClass) {
} catch (error) {
console.error(error);
return {
statusCode: 500,
statusCode: 400,
body: JSON.stringify({ error: error.message }),
headers: { "Content-Type": "application/json", 'X-Powered-By': 'genezio' },
};
Expand Down Expand Up @@ -237,7 +237,7 @@ if (!genezioClass) {
console.error(err);
await sendSentryError(err);
resolve({
statusCode: 200,
statusCode: 400,
body: JSON.stringify({
jsonrpc: "2.0",
error: prepareForSerialization(err),
Expand Down Expand Up @@ -270,7 +270,7 @@ if (!genezioClass) {
console.error(err);
await sendSentryError(err);
return {
statusCode: 200,
statusCode: 400,
body: JSON.stringify({
jsonrpc: "2.0",
error: prepareForSerialization(err),
Expand All @@ -286,7 +286,7 @@ if (!genezioClass) {
console.error(err);
await sendSentryError(err);
return {
statusCode: 200,
statusCode: 400,
body: JSON.stringify({
jsonrpc: "2.0",
error: prepareForSerialization(err),
Expand Down
76 changes: 28 additions & 48 deletions src/commands/deploy/genezio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,14 @@ import {
uploadEnvVarsFromFile,
enableAuthentication,
uploadUserCode,
evaluateResource,
setAuthenticationEmailTemplates,
} from "./utils.js";
import {
disableEmailIntegration,
enableEmailIntegration,
getProjectIntegrations,
} from "../../requests/integration.js";
import { findAnEnvFile } from "../../utils/environmentVariables.js";
import { expandEnvironmentVariables, findAnEnvFile } from "../../utils/environmentVariables.js";
import { getProjectEnvFromProjectByName } from "../../requests/getProjectInfoByName.js";

export async function genezioDeploy(options: GenezioDeployOptions) {
Expand Down Expand Up @@ -237,33 +236,22 @@ export async function genezioDeploy(options: GenezioDeployOptions) {
await doAdaptiveLogAction(
`Running frontend ${index + 1} deploy script`,
async () => {
const environment = frontend.environment;
if (environment) {
const newEnvObject: Record<string, string> = {};

await Promise.all(
Object.keys(environment).map(async (key) => {
const resolvedValue = await evaluateResource(
configuration,
environment[key],
options.stage,
/* envFile */ undefined,
);
newEnvObject[key] = resolvedValue;
}),
);
debugLogger.debug(
`Environment variables: ${JSON.stringify(newEnvObject)}`,
);
return await runScript(
frontend.scripts?.deploy,
frontend.path || process.cwd(),
newEnvObject,
);
}
const newEnvObject = await expandEnvironmentVariables(
frontend.environment,
configuration,
options.stage,
/* envFile */ undefined,
/* options */ undefined,
);

debugLogger.debug(
`Environment variables injected for frontend.scripts.deploy:`,
JSON.stringify(newEnvObject),
);
return await runScript(
frontend.scripts?.deploy,
frontend.path || process.cwd(),
newEnvObject,
);
},
);
Expand Down Expand Up @@ -667,28 +655,20 @@ export async function deployFrontend(
}

await doAdaptiveLogAction(`Building frontend ${index + 1}`, async () => {
const environment = frontend.environment;
if (environment) {
const newEnvObject: Record<string, string> = {};

await Promise.all(
Object.keys(environment).map(async (key) => {
const resolvedValue = await evaluateResource(
configuration,
environment[key],
stage,
/* envFile */ undefined,
);
newEnvObject[key] = resolvedValue;
}),
);
debugLogger.debug(
`Environment variables for frontend: ${JSON.stringify(newEnvObject)}`,
);
await runScript(frontend.scripts?.build, frontend.path, newEnvObject);
} else {
await runScript(frontend.scripts?.build, frontend.path);
}
const newEnvObject = await expandEnvironmentVariables(
frontend.environment,
configuration,
options.stage,
/* envFile */ undefined,
/* options */ undefined,
);

debugLogger.debug(
`Environment variables injected for frontend.scripts.build:`,
JSON.stringify(newEnvObject),
);

await runScript(frontend.scripts?.build, frontend.path, newEnvObject);
});

// check if the frontend publish path exists
Expand Down
3 changes: 2 additions & 1 deletion src/commands/deploy/nuxt/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export async function nuxtNitroDeploy(
stdio: "inherit",
env: { NITRO_PRESET: "aws_lambda" },
})`npx nuxi build --preset=aws_lambda`.catch(() => {
throw new UserError("Failed to build the Nuxt project. Check the logs above.");
throw new UserError(`Failed to build the Nuxt project. Check the logs above.
Note: If your Nuxt project was not migrated to Nuxt 3, please visit https://v2.nuxt.com/lts for guidance on migrating your project. Genezio supports only Nuxt 3 projects.`);
});
break;
case DeployType.Nitro:
Expand Down
18 changes: 6 additions & 12 deletions src/commands/deploy/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import {
getUnsetEnvironmentVariables,
parseConfigurationVariable,
promptToConfirmSettingEnvironmentVariables,
resolveEnvironmentVariable,
} from "../../utils/environmentVariables.js";
import inquirer from "inquirer";
import { existsSync, readFileSync } from "fs";
Expand Down Expand Up @@ -305,7 +304,7 @@ export async function getOrCreateDatabase(
log.info(colors.green(`Database ${createDatabaseReq.name} created successfully.`));
log.info(
displayHint(
`You can reference the connection URI in your \`genezio.yaml\` file using \${{services.database.${createDatabaseReq.name}.uri}}`,
`You can reference the connection URI in your \`genezio.yaml\` file using \${{services.databases.${createDatabaseReq.name}.uri}}`,
),
);
return {
Expand Down Expand Up @@ -698,21 +697,16 @@ export async function uploadEnvVarsFromFile(
const environmentVariablesToBePushed: EnvironmentVariable[] = (
await Promise.all(
unsetEnvVarKeys.map(async (envVarKey) => {
const variable = await parseConfigurationVariable(environment[envVarKey]);
const resolvedVariable = await resolveEnvironmentVariable(
const value = await evaluateResource(
configuration,
variable,
envVarKey,
envFile,
environment[envVarKey],
stage,
envFile,
);
if (!resolvedVariable) {
return undefined;
}
return resolvedVariable;
return value ? { name: envVarKey, value } : undefined;
}),
)
).filter((item): item is EnvironmentVariable => item !== undefined);
).filter(Boolean) as EnvironmentVariable[];

if (environmentVariablesToBePushed.length > 0) {
debugLogger.debug(
Expand Down
39 changes: 16 additions & 23 deletions src/commands/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,12 @@ import fsExtra from "fs-extra/esm";
import { DeployCodeFunctionResponse } from "../models/deployCodeResponse.js";
import {
enableAuthentication,
evaluateResource,
getOrCreateDatabase,
getOrCreateEmptyProject,
} from "./deploy/utils.js";
import { displayHint } from "../utils/strings.js";
import { enableEmailIntegration, getProjectIntegrations } from "../requests/integration.js";
import { findAnEnvFile } from "../utils/environmentVariables.js";
import { expandEnvironmentVariables, findAnEnvFile } from "../utils/environmentVariables.js";

type UnitProcess = {
process: ChildProcess;
Expand Down Expand Up @@ -158,6 +157,7 @@ export async function prepareLocalBackendEnvironment(

const databaseConnectionUrlKey = `${remoteDatabase.name.replace(/-/g, "_").toUpperCase()}_DATABASE_URL`;
configurationEnvVars = {
...configurationEnvVars,
[databaseConnectionUrlKey]: remoteDatabase.connectionUrl,
};

Expand Down Expand Up @@ -356,28 +356,21 @@ async function startFrontends(

await Promise.all(
frontendConfiguration.map(async (frontend) => {
const environment = frontend.environment;
const newEnvObject: Record<string, string> = {};
if (environment) {
Object.keys(environment).forEach(async (key) => {
const resolvedValue = await evaluateResource(
configuration,
environment[key],
stage,
/* envFile */ undefined,
{
isLocal: true,
port,
},
);
const newEnvObject = await expandEnvironmentVariables(
frontend.environment,
configuration,
stage,
/* envFile */ undefined,
{
isLocal: true,
port: port,
},
);

newEnvObject[key] = resolvedValue;
});
debugLogger.debug(
`Environment variables for frontend ${frontend.name}:`,
JSON.stringify(newEnvObject),
);
}
debugLogger.debug(
`Environment variables injected for frontend.scripts.local:`,
JSON.stringify(newEnvObject),
);

await runFrontendStartScript(
frontend.scripts?.start,
Expand Down
3 changes: 2 additions & 1 deletion src/models/requests.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import {
AuthenticationDatabaseType,
AuthenticationEmailTemplateType,
DatabaseType,
} from "../projectConfiguration/yaml/models.js";
import { ProjectDetailsEnvElement } from "../requests/models.js";

export interface CreateDatabaseRequest {
name: string;
region: string;
type?: string;
type: DatabaseType;
}

export interface CreateDatabaseResponse {
Expand Down
1 change: 1 addition & 0 deletions src/projectConfiguration/yaml/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export enum AuthenticationDatabaseType {

export enum DatabaseType {
neon = "postgres-neon",
mongo = "mongo-atlas",
}

export enum TriggerType {
Expand Down
Loading

0 comments on commit c99059f

Please sign in to comment.