Skip to content

Commit b3a549d

Browse files
authored
Expose stack on functions.yaml instead of stack.yaml. (#1036)
Some contractual changes to how we expose the container contract: * We will expose `__/functions.yaml` instead of `__/stack.yaml` in the control api * Environment variables for exposing the control api changes from `STACK_CONTROL_API_PORT` to `PORT` and `FUNCTIONS_CONTROL_API` (whose value should equal `true`).
1 parent f68e629 commit b3a549d

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

scripts/bin-test/test.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ async function startBin(
8585
env: {
8686
PATH: process.env.PATH,
8787
GLCOUD_PROJECT: 'test-project',
88-
STACK_CONTROL_API_PORT: port,
88+
PORT: port,
89+
FUNCTIONS_CONTROL_API: 'true',
8990
},
9091
});
9192

@@ -95,7 +96,7 @@ async function startBin(
9596

9697
await retryUntil(async () => {
9798
try {
98-
await fetch(`http://localhost:${port}/__/stack.yaml`);
99+
await fetch(`http://localhost:${port}/__/functions.yaml`);
99100
} catch (e) {
100101
if (e?.code === 'ECONNREFUSED') {
101102
return false;
@@ -132,7 +133,7 @@ async function startBin(
132133
};
133134
}
134135

135-
describe('stack.yaml', () => {
136+
describe('functions.yaml', () => {
136137
async function runTests(tc: Testcase) {
137138
let port: number;
138139
let cleanup: () => Promise<void>;
@@ -147,14 +148,14 @@ describe('stack.yaml', () => {
147148
await cleanup?.();
148149
});
149150

150-
it('stack.yaml returns expected Manifest', async () => {
151-
const res = await fetch(`http://localhost:${port}/__/stack.yaml`);
151+
it('functions.yaml returns expected Manifest', async () => {
152+
const res = await fetch(`http://localhost:${port}/__/functions.yaml`);
152153
const text = await res.text();
153154
let parsed: any;
154155
try {
155156
parsed = yaml.load(text);
156157
} catch (err) {
157-
throw new Error('Failed to parse stack.yaml ' + err);
158+
throw new Error('Failed to parse functions.yaml ' + err);
158159
}
159160
expect(parsed).to.be.deep.equal(tc.expected);
160161
});

src/bin/firebase-functions.ts

+16-13
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,24 @@ async function handleQuitquitquit(req: express.Request, res: express.Response) {
3535

3636
app.get('/__/quitquitquit', handleQuitquitquit);
3737
app.post('/__/quitquitquit', handleQuitquitquit);
38-
app.get('/__/stack.yaml', async (req, res) => {
39-
try {
40-
const stack = await loadStack(functionsDir);
41-
res.setHeader('content-type', 'text/yaml');
42-
res.send(JSON.stringify(stack));
43-
} catch (e) {
44-
res
45-
.status(400)
46-
.send(`Failed to generate manifest from function source: ${e}`);
47-
}
48-
});
38+
39+
if (process.env.FUNCTIONS_CONTROL_API === 'true') {
40+
app.get('/__/functions.yaml', async (req, res) => {
41+
try {
42+
const stack = await loadStack(functionsDir);
43+
res.setHeader('content-type', 'text/yaml');
44+
res.send(JSON.stringify(stack));
45+
} catch (e) {
46+
res
47+
.status(400)
48+
.send(`Failed to generate manifest from function source: ${e}`);
49+
}
50+
});
51+
}
4952

5053
let port = 8080;
51-
if (process.env.STACK_CONTROL_API_PORT) {
52-
port = Number.parseInt(process.env.STACK_CONTROL_API_PORT);
54+
if (process.env.PORT) {
55+
port = Number.parseInt(process.env.PORT);
5356
}
5457

5558
console.log('Serving at port', port);

src/runtime/loader.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,9 @@ export async function loadStack(functionsDir: string): Promise<ManifestStack> {
110110

111111
extractStack(mod, endpoints, requiredAPIs);
112112

113-
const stack: ManifestStack = {
113+
return {
114114
endpoints,
115115
specVersion: 'v1alpha1',
116116
requiredAPIs: mergeRequiredAPIs(requiredAPIs),
117117
};
118-
return stack;
119118
}

0 commit comments

Comments
 (0)