Home > OS >  Attempting to deploy flask app to GAE using gcloud app deploy through Gitlab CI/CD. Logs show Module
Attempting to deploy flask app to GAE using gcloud app deploy through Gitlab CI/CD. Logs show Module

Time:06-16

I have a Flask app which is able to be deployed to my localhost. Unfortunately, when attempting to deploy it to Google App Engine I run into an error. When I follow the link specified in the console after the gcloud --project $PROJECT_ID app deploy app.yaml call in my .gitlab-ci.yml file, I recieve a 500 server error. To debug this I used the gcloud app logs read which show a long error ending with:

    File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed    File 
    "/srv/main.py", line 1, in <module>      from flask import Flask, request, jsonify, 
    abort  ModuleNotFoundError: No module named 'flask'

My app.yaml file reads:

entrypoint: "gunicorn -b:$PORT main:app"
service_account: app-engine-admin@###########.iam.gserviceaccount.com
runtime_config:
  python_version: 3

handlers:
- url: .*
  script: main.app

my requirements.txt reads:

firebase_admin==5.2.0
Flask==2.1.2

and the called section of my .gitlab-ci.yml reads:

gcloud-deploy:
  image: google/cloud-sdk:alpine
  stage: deploy
  only:
    - dev2
  script:
    - echo $SERVICE_ACCOUNT > /tmp/$CI_PIPELINE_ID.json
    - gcloud auth activate-service-account --key-file /tmp/$CI_PIPELINE_ID.json
    - gcloud --project $PROJECT_ID app deploy app.yaml
    - rm /tmp/$CI_PIPELINE_ID.json

This error is confusing me as I thought that all libraries listed in the requirements.txt file would be imported by GAE during deployment. If someone has run into this or could point me in the right direction it would be greatly appreciated!

CodePudding user response:

The answer to this ended up being pretty simple. I was just missing a few packages in the requirements.txt file. The main one being the gunicorn package. Because it was not installed, the web server was never actually spooled up. This led to the issues I ran into. I solved this by using pipenv lock -r > requirements.txt.

  • Related