FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Preserve existing environment variables when deploying functions. (#3… · firebase/firebase-tools@341cdcd · GitHub

Commit 341cdcd

Browse files
authored
Preserve existing environment variables when deploying functions. (#3266)
Today, we unexpectedly delete environment variables on existing Cloud Functions when updating functions via `firebase deploy --only functions` command #3226. This regression was introduced in #3132. ### Scenarios Tested 1. Manually setup an environment variable using Google Cloud Console on a firebase function. 2. Run `firebase deploy --only functions` to update the existing function. 3. Notice that existing environment variable isn't wiped out as a result of the new deploy.
1 parent a0ceb45 commit 341cdcd

2 files changed

Lines changed: 76 additions & 0 deletions

File tree

‎src/deploy/functions/deploymentPlanner.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ export function createDeploymentPlan(
147147
if (matchingExistingFunction) {
148148
// Check if this is an invalid change of trigger type.
149149
checkForInvalidChangeOfTrigger(fn, matchingExistingFunction);
150+
// Preserve existing environment variables.
151+
fn.environmentVariables = {
152+
...matchingExistingFunction.environmentVariables,
153+
...fn.environmentVariables,
154+
};
150155
regionalDeployment.functionsToUpdate.push(fn);
151156
existingFnsCopy = existingFnsCopy.filter((exFn: CloudFunctionTrigger) => {
152157
return exFn.name !== fn.name;

‎src/test/deploy/functions/deploymentPlanner.spec.ts‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ describe("deploymentPlanner", () => {
505505
};
506506
expect(deploymentPlan).to.deep.equal(expected);
507507
});
508+
508509
it("should only create, update, and delete matching functions if filters are passed in.", () => {
509510
const regionMap: deploymentPlanner.RegionMap = {
510511
"us-east1": [
@@ -586,5 +587,75 @@ describe("deploymentPlanner", () => {
586587
};
587588
expect(deploymentPlan).to.deep.equal(expected);
588589
});
590+
591+
it("should preserve existing environment variables", () => {
592+
const regionMap: deploymentPlanner.RegionMap = {
593+
"us-east1": [
594+
{
595+
name: "projects/a/locations/us-east1/functions/a",
596+
labels: {},
597+
environmentVariables: {},
598+
entryPoint: "",
599+
},
600+
],
601+
"us-west1": [
602+
{
603+
name: "projects/a/locations/us-west1/functions/b",
604+
labels: {},
605+
environmentVariables: {},
606+
entryPoint: "",
607+
},
608+
],
609+
};
610+
const existingFunctions: deploymentPlanner.CloudFunctionTrigger[] = [
611+
{
612+
name: "projects/a/locations/us-west1/functions/b",
613+
labels: {},
614+
environmentVariables: { FOO: "bar" },
615+
entryPoint: "",
616+
},
617+
];
618+
const filters: string[][] = [];
619+
620+
const deploymentPlan = deploymentPlanner.createDeploymentPlan(
621+
regionMap,
622+
existingFunctions,
623+
filters
624+
);
625+
626+
const expected: deploymentPlanner.DeploymentPlan = {
627+
regionalDeployments: [
628+
{
629+
region: "us-east1",
630+
functionsToCreate: [
631+
{
632+
name: "projects/a/locations/us-east1/functions/a",
633+
labels: {},
634+
environmentVariables: {},
635+
entryPoint: "",
636+
},
637+
],
638+
functionsToUpdate: [],
639+
schedulesToUpsert: [],
640+
},
641+
{
642+
region: "us-west1",
643+
functionsToCreate: [],
644+
functionsToUpdate: [
645+
{
646+
name: "projects/a/locations/us-west1/functions/b",
647+
labels: {},
648+
environmentVariables: { FOO: "bar" },
649+
entryPoint: "",
650+
},
651+
],
652+
schedulesToUpsert: [],
653+
},
654+
],
655+
functionsToDelete: [],
656+
schedulesToDelete: [],
657+
};
658+
expect(deploymentPlan).to.deep.equal(expected);
659+
});
589660
});
590661
});

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL