Coder Social home page Coder Social logo

pythonmysqlissue's Introduction

Deploy Django app to Azure App Service on Linux using GitHub Actions

This app is based off the official django tutorial. Using GitHub Actions, we can deploy this app directly to App Service after changes are pushed to the repo.

Prerequisites

  1. You need an Azure subscription to complete the tutorial. You can create a free account to start with: https://azure.microsoft.com/en-us/free/.

  2. You need to create a Python 3.7 Linux Web App.

  3. This web app requires a MySQL Server (django.db.backends.mysql) as the backend, you can also use PostgreSQL server as the backend. You can easily create a Azure Database for MySQL using Azure portal https://ms.portal.azure.com/#create/Microsoft.MySQLServer.

Prep the code

  1. Get the source code onto your dev machine:

    git clone https://github.com/yiliaomsft/pycon19-django.git 
  2. Load the local source code repo into VSCode:

    cd pycon19-django
    code
  3. Create a virtual environment

    # Linux/MacOS:
    python3 -m venv venv
    
    # Windows:
    py -m venv venv
  4. Install modules

    pip3 install -r requirements.txt
  5. Start the virtual environment

    # Linux/MacOS
    source env/bin/activate
    
    # Windows
    .\venv\Scripts\activate
  6. Start the app locally

    py manage.py runserver

Update database connection strings

The app currently uses a local SQLite database for local dev and test. You can deploy it with this, or wire it up to a proper MySQL database by editing settings.py to include your own database connection strings.

DATABASES = {
    'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': '<database name>',
            'USER': '<database user name>',
            'PASSWORD': 'database password',
            'HOST': 'database host',
    }
}

Deploy the django app to Linux App Service

Finally, get your Publish Profile of your webapp from the Azure Portal and add it as a secret in the GitHub web UI. The secret should be named "PUBLISH_PROFILE", to match the string in the workflow YAML.

pythonmysqlissue's People

Contributors

kichalla avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.