firebase-tools icon indicating copy to clipboard operation
firebase-tools copied to clipboard

Use node delegate to serve function on deploy/emulator.

Open taeold opened this issue 3 years ago • 2 comments

Use functions-framework to bootstrap python function emulator support.

With this change and given a simple python functions project that looks like:

$ tree
.
├── functions.yaml
├── main.py
└── requirements.txt

$ cat functions.yaml
{"endpoints":{"hellopy":{"platform":"gcfv2","httpsTrigger":{},"entryPoint":"hellopy"}},"specVersion":"v1alpha1","requiredAPIs":[]}

$ cat main.py
import functions_framework

@functions_framework.http
def hellopy(request):
    return "Hello python!"

$ cat requirements.txt 
click==8.1.3
cloudevents==1.6.1
deprecation==2.1.0
Flask==2.2.2
functions-framework==3.2.0
gunicorn==20.1.0
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.1
packaging==21.3
pyparsing==3.0.9
watchdog==2.1.9
Werkzeug==2.2.2

Firebase Emulator can pick up and emulate the function:

$ firebase emulators:start
i  emulators: Starting emulators: functions
⚠  functions: The following emulators are not running, calls to these services from the Functions emulator will affect production: auth, firestore, database, hosting, pubsub, storage, eventarc
i  ui: Emulator UI logging to ui-debug.log
i  functions: Watching "/Users/danielylee/google/cf3-python-demo/py" for Cloud Functions...
✔  functions: Loaded functions definitions from source: hellopy.
✔  functions[us-central1-hellopy]: http function initialized (http://localhost:5001/danielylee-test-6/us-central1/hellopy).
Issues? Report them at https://github.com/firebase/firebase-tools/issues and attach the *-debug.log files.

>   * Serving Flask app 'hellopy'
>   * Debug mode: on
>  WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
>   * Running on unix:///var/folders/73/1_gb0n1j381g2zr7td88j0nw00k707/T/fire_emu_122fc98923a5f44e.sock
>  Press CTRL+C to quit
>   * Restarting with watchdog (fsevents)
>   * Debugger is active!
>   * Debugger PIN: 292-939-551
>  <local> - - [23/Sep/2022 00:03:26] "GET /__/health HTTP/1.1" 200 -
>  <local> - - [23/Sep/2022 00:03:26] "GET / HTTP/1.1" 200 -

NOTE We rely on Flask's unix domain socket support to avoid allocating a port for the emulated function. Unfortunately, this means that this implementation cannot run on Windows.

taeold avatar Sep 09 '22 05:09 taeold

Current dependencies on/for this PR:

  • master
    • PR #4955 Graphite
      • PR #4949 Graphite
        • PR #4861 Graphite
          • PR #4867 Graphite
            • PR #4886 Graphite
              • PR #4964 Graphite 👈
              • PR #4947 Graphite

This comment was auto-generated by Graphite.

taeold avatar Sep 09 '22 05:09 taeold

Codecov Report

Base: 56.43% // Head: 56.24% // Decreases project coverage by -0.18% :warning:

Coverage data is based on head (a3bd110) compared to base (2a25c5f). Patch coverage: 31.57% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4964      +/-   ##
==========================================
- Coverage   56.43%   56.24%   -0.19%     
==========================================
  Files         315      316       +1     
  Lines       21137    21342     +205     
  Branches     4290     4348      +58     
==========================================
+ Hits        11928    12004      +76     
- Misses       8184     8299     +115     
- Partials     1025     1039      +14     
Impacted Files Coverage Δ
src/deploy/functions/prepare.ts 31.42% <0.00%> (-0.16%) :arrow_down:
...rc/deploy/functions/runtimes/discovery/v1alpha1.ts 76.62% <ø> (ø)
src/deploy/functions/runtimes/golang/index.ts 29.16% <0.00%> (+2.85%) :arrow_up:
src/deploy/functions/runtimes/node/index.ts 22.22% <0.00%> (-3.13%) :arrow_down:
src/emulator/commandUtils.ts 27.87% <0.00%> (-0.13%) :arrow_down:
src/emulator/downloadableEmulators.ts 23.88% <ø> (ø)
src/emulator/functionsEmulator.ts 7.05% <0.00%> (+0.07%) :arrow_up:
src/emulator/storage/rules/runtime.ts 11.37% <0.00%> (ø)
src/extensions/types.ts 100.00% <ø> (ø)
src/frameworks/index.ts 16.01% <0.00%> (-0.13%) :arrow_down:
... and 15 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

codecov-commenter avatar Sep 09 '22 05:09 codecov-commenter