How to set environment varibles in gcloud command? - python

I'm trying to deploy an app engine Managed VM python/flask application using the gcloud command.
When developing locally I can pass environment variables to my flask server. I do this so that I can read a config file per environment. For example:
gunicorn -b :8080 --env CONFIG_FILE=config_dev.py main:app
Now, i'd like to deploy my application and use config_production.py as my config file. It seems I'd need to pass the environment variable CONFIG_FILE=config_dev.py to gcloud preview app deploy to set it. I checked the help pages but didnt see a way to set this.
Previously when I was developing on app engine sandbox I could do:
appcfg.py -E ENVIRONMENT:dev update app.yaml
Is there an equivalent argument for gcloud?

Related

How to run flask CLI command in AWS Elastic Beanstalk

I have my flask server running in AWS Elastic Beanstalk, however, I want to run some custom flask CLI commands that are listed in commands.py file of my repository. Previously when my server was hosted in Heroku, I was able to run these commands through the Heroku console, however I'm unable to figure out how to run these commands in Elastic Beanstalk or even go inside of the beanstalk environment and run my custom flask commands through the command line.
I tried using the eb cli but that seems to only allow me to mainly deploy, terminate, open the Elastic Beanstalk environment but nothing in the eb cli seems to allow me to even run flask --help inside the environment
even go inside of the beanstalk environment
If you use eb cli, then it would be eb ssh to ssh into your instance.
I'm unable to figure out how to run these commands in Elastic Beanstalk
Generally you would create .ebextentions config files with commands or container_commands to run the actual flask commands.
There are also other options, such as platform hooks.

Missing "gcc" error when trying to deploy a flask app with requirements.txt to Azure Web App from VSCode

From within VSCode, using the Azure web service extension, I can deploy a Hello-World flask app successfully to my Azure web app (linux, python 3.6 stack).
When I try to deploy my real flask app (with dependencies listed in a requirements.txt) file, and I specify "pip install --upgrade -r requirements.txt" as the web app "startup command" in the Azure portal, browsing the web app page gives an "Application Error".
The log for my web app shows the startup code failing when trying to build "psutil" due to the error unable to execute 'gcc': No such file or directory.
When the above failed, I also tried using "wheels" as part of my deployment as described here (https://blogs.msdn.microsoft.com/azureossds/2015/06/29/install-native-python-modules-on-azure-web-apps-api-apps/), but that didn't seem to change anything (same 'missing gcc' error).
Is this the correct way to deploy a flask app with python library dependencies from VSCode? I would expect that the deployment process would automatically process the requirements.txt (without having to specify the startup command) and I would expect it to be able to install the python libraries without error.
Due to you were using Azure WebApp for Linux based on Docker Container, the MSDN blog Install Python Modules on Azure App Services for Azure WebApp for Windows is not useful for your issue.
So for your issue of missing gcc error, per my experience, the solution to fix it is to configure a custom Linux container which had been pre-installed the gcc tool-chains and then to deploy your app into it from VS Code.
As references, please try to follow the documents below.
Configure a custom Linux container for Azure App Service . To install the gcc toolchains in a custom docker image via change the Docker file like install openssh as the section Enable SSH said.
Deploy to Azure using Docker from VS Code with Azure App Service extension.

How to deploy a Django production server on IBM Cloud?

I want to know how to deploy a Django production server on IBM Cloud.
Right now I have a Cloud Foundry Python app running without problems. But I'm using python manage.py runserver to start the app on the cloud.
There is a way to run the app without using the django server? Like, how we do running that kind of apps using Apache o Nginx web servers.
UPDATE:
I tried using the Procfile and gunicorn, but it gives me an error when it starts gunicorn.
This is my Procfile.
web: gunicorn my_app.wsgi --workers 2
And the error
ERR Starting gunicorn 18.0
I am using python 3.6 and django 1.11
Cloud Foundry provides out-of-the-box production quality hosting. You don’t need to configure nginx or apache. For more information on how cloud foundry works under the hood, see here
You would however normally configure the method for starting your application. The python buildback documentation describes a few options, for example:
Specify a Start Command
The Python buildpack does not generate a
default start command for your applications.
To stage with the Python buildpack and start an application, do one of
the following:
Required for Cloud Foundry v245 only: Supply a Procfile.
For more
information about Procfiles, see the Configuring a Production Server
topic. The following example Procfile specifies gunicorn as the start
command for a web app running on Gunicorn:
web: gunicorn SERVER-NAME:APP-NAME
Specify a start command with -c.
The following
example specifies waitress-serve as the start command for a web app
running on Waitress:
$ cf push python-app -c "waitress-serve --port=$PORT DJANGO-WEB-APP.wsgi:MY-APP"
Specify a start command in the application manifest by setting the command attribute.
For more
information, see the Deploying with Application Manifests topic.

Missing appcfg.py for app-engine deployment

I have inherited an app-engine project.
I try to deploy from my dev machine:
appcfg.py --oauth2 update PATH
I have installed app-engine SDK but I cannot find appcfg.py
I have googled and it seems like appcfg.py is no longer in use?
How should I deploy otherwise?
Yes, you are correct appcfg.py is no longer used to deploy.
Instead you should use the gcloud cli instead:
gcloud app deploy --project project-id --version version-number
See the reference documentation here:
https://cloud.google.com/sdk/gcloud/reference/app/deploy
Also, make sure you have an updated app.yaml in your project.
In addition to the app-engine SDK for JAVA
I had to install app-engine SDK for python
https://cloud.google.com/appengine/docs/standard/php/tools/uploadinganapp

How to add a production config when deploying a docker container?

I used to deploy Python web applications on AWS EC2 instances with Ansible.
In my development environment, I use config from a module local_config.py, but in the deployment process, I use an Ansible task to replace this file with a production-ready config.
How do I do something similar when building a Docker image?
You should copy your production-ready config file into the docker container as part of your image-building process (COPY directive in your dockerfile), and then proceed with the same deployment steps you would normally use.

Categories

Resources