Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

google_app_engine_standard_app_version ModuleNotFoundError: No module named 'hello_world.wsgi'" #5192

Closed
jjorissen52 opened this issue Dec 16, 2019 · 11 comments

Comments

@jjorissen52
Copy link

jjorissen52 commented Dec 16, 2019

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
  • If an issue is assigned to the "modular-magician" user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned to "hashibot", a community member has claimed the issue already.

Terraform Version

Terraform v0.12.10
+ provider.archive v1.3.0
+ provider.google v3.2.0
+ provider.local v1.4.0
+ provider.null v2.1.2

Affected Resource(s)

  • google_app_engine_standard_app_version

Terraform Configuration Files

data "archive_file" "hello_world_source" {
  type        = "zip"
  source_dir = "${path.module}/../../application/hello_world"
  output_path = "${path.module}/../extras/hello_world.zip"
}

resource "google_storage_bucket" "deployment_config" {
  bucket_policy_only = true
  force_destroy      = true
  name               = "deployment-config-${var.project.number}"
  requester_pays     = false
  storage_class      = "STANDARD"
}

resource "google_storage_bucket_object" "hello_world_zip" {
    source = "${path.module}/../extras/hello_world.zip"
    bucket = "${google_storage_bucket.deployment_config.name}"
    name = "hello_world.zip"

    # archive must exist first
    depends_on = ["data.archive_file.hello_world_source"]
}

resource "google_app_engine_standard_app_version" "hello_world" {
#   version_id = "v1"
  version_id = "${data.archive_file.hello_world_source.output_md5}"
  service    = "default"
  runtime    = "python37"

  entrypoint {
    shell = "gunicorn -b :$PORT hello_world.wsgi --log-level=DEBUG"
  }

  deployment {
    zip {
      source_url = "https://storage.googleapis.com/${google_storage_bucket.deployment_config.name}/${google_storage_bucket_object.hello_world_zip.name}"
    }
  }
  noop_on_destroy = true
  # archive must exist first
  depends_on = ["google_storage_bucket_object.hello_world_zip"]
}

Debug Output

Terraform creates version successfully, but the resulting App Engine instances are incapable of launching the wsgi server. The below image says that it cannot find the wsgi module
image

But the source for the application shows that it's there.
image

Expected Behavior

When I visit the app engine deployment, I should see the DisallowedHost Django debug page, which indicates that a Django app is running.

Actual Behavior

I get 502 bad gateway from NGINX.

Steps to Reproduce

  1. install python 3.7
  2. pip install Django gunicorn
  3. django-admin startproject hello_world
  4. cd hello_world && gunicorn hello_world.wsgi # application starts
  5. visit localhost:8000 and see the default launch page
  6. ^c # stop gunicorn
  7. echo -e "Django\ngunicorn" > requirements.txt # add requirements file
  8. terraform apply
  9. visit default deployment url, get 502.

Important Factoids

If I add the below app.yaml and run gcloud app deploy in the hello_world Django app created above, the app works as expected (shows "DisallowedHost" screen, as it should).

runtime: python37
entrypoint: gunicorn -b :$PORT hello_world.wsgi --log-level=DEBUG

handlers:
# This configures Google App Engine to serve the files in the app's static
# directory.
- url: /static
  static_dir: static/

# This handler routes all requests not caught above to your main app. It is
# required when static routes are defined, but can be omitted (along with
# the entire handlers section) when there are no static files defined.
- url: /.*
  script: auto
@ghost ghost added the bug label Dec 16, 2019
@jjorissen52 jjorissen52 changed the title google_app_engine_standard_app_version google_app_engine_standard_app_version ModuleNotFoundError: No module named 'hello_world.wsgi'" Dec 16, 2019
@edwardmedia edwardmedia self-assigned this Dec 17, 2019
@edwardmedia
Copy link
Contributor

@jjorissen52 do you have /hello_world.zip some place where I can download the package?

@jjorissen52
Copy link
Author

@ghost ghost removed the waiting-response label Dec 18, 2019
@edwardmedia
Copy link
Contributor

@jjorissen52 from your screenshot, it seems you did not include the app.yml from hello_world.zip. Was that on purpose? Why? You might want to take a look at the sample https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/appengine/standard_python37/django Please try to rerun tf apply for the zip file with app.yml. I don't think the error has anything to do with terraform. Please let me know if this does not help resolve the issue. Thanks

@jjorissen52
Copy link
Author

jjorissen52 commented Dec 19, 2019

It could very well not be a bug with Terraform, but I spent quite some time on this and came up dry. A minimum working example be greatly appreciated!

I did not include the app.yaml file in the screenshot because it was added afterwards when I was trying to see if it works with gcloud app deploy. This was not deliberate; it is just a consequence of the order in which I made my attempts.

If I add the below app.yaml and run gcloud app deploy in the hello_world Django app created above, the app works as expected (shows "DisallowedHost" screen, as it should).

This is that same app created with app.yaml added to the source code for the sake of consistency. Using terraform apply (doesn't work): https://5c19fb6f24161efb4131326a9024f0ea-dot-booklawyer-dev-259701.appspot.com/

image

image

And this is it using gcloud app deploy (works as expected):
https://booklawyer-dev-259701.appspot.com/

image

Same directory being zipped and uploaded, two different ways of deploying, but I can't make the terraform one work.

Does google_app_engine_standard_app_version require an app.yaml file?

@ghost ghost removed the waiting-response label Dec 19, 2019
@jjorissen52
Copy link
Author

going to @ you here @edwardmedia since I did not do so in my previous comment #5192 (comment)

@edwardmedia
Copy link
Contributor

@jjorissen52 your files inside the zip don't have exec permissions. Can you update that? Let me know if this helps. Thanks

@llicour
Copy link

llicour commented Mar 13, 2020

same problem for me in similar situation. Seems appengine is not able to load modules if deployed from terraform with a zip bucket as source.
Insteed, if each file is describe, this works

  deployment {
    # zip {
    #   source_url = "https://storage.googleapis.com/${google_storage_bucket.pypi_bucket.name}/${google_storage_bucket_object.pypi_source.name}"
    # }
    files {
      name = "__init__.py"
      source_url = "https://storage.googleapis.com/xxx.appspot.com/da39a3ee5e6b4b0d3255bfef95601890afd80709"
    }
    files {
      name = "main.py"
      source_url = "https://storage.googleapis.com/xxx.appspot.com/3ecd1fcd855f848715b858b0b7afafc0959b6306"
    }
...

gcloud app deploy use this way to deploy app

@ghost ghost removed the waiting-response label Mar 13, 2020
@edwardmedia
Copy link
Contributor

@llicour the original issue was likely what I stated earlier. For yours, it may or may not be the same. Could you create a separate issue so that helps us to track? Please also post your terraform config and state how to repro the issue.

@edwardmedia
Copy link
Contributor

@llicour I don't see your reply. Is there anything more I can assist?

@edwardmedia
Copy link
Contributor

@llicour I am closing this issue. Please feel free to reopen it if you need further assistance

@ghost
Copy link

ghost commented Jun 15, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators Jun 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants