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

Deploy to Azure manually #24

Closed
ehmatthes opened this issue Nov 7, 2021 · 17 comments
Closed

Deploy to Azure manually #24

ehmatthes opened this issue Nov 7, 2021 · 17 comments

Comments

@ehmatthes
Copy link
Owner

Azure seems like a strong candidate for a second platform to support, because I believe it has a CLI and a reasonable free tier. Automating the DB may be an issue, but perhaps SQLite will work? We'll see, I've never used Azure.

@ehmatthes
Copy link
Owner Author

ehmatthes commented Nov 7, 2021

  • Start with a local copy of the project, with a requirements.txt file.
  • Make a free Azure account.
    • Does require credit card on file.
  • Install Azure CLI.
    • $ brew update
    • $ brew install azure-cli
    • "Will install Homebrew Python3". I hope this doesn't mess up my existing Python installation in any difficult way. :/ But I will chance it, and test my understanding of Python installations. :)
    • test with az --version
  • Log in: az login
  • Pick up here
  • az webapp up --help is really helpful
    • --sku F1: free pricing tier
    • --dryrun looks helpful! Needs to be last argument?
    • --luanch-browser as well
    • Need --os-type Linux?
    • --plan: "name of the appserviceplan associated with the webapp"?
  • az webapp up --dryrun
    • plan is my default plan, azure-username_asp_Linux_southcentralus_0
    • random name is automatically chosen, like Heroku: blue-river-8b3041a252694a85a13c59b0a5e2b6db
    • default resource group is chosen
    • default runtime is python 3.7!
    • sku is PREMIUMV2! I believe this is ~$0.11/hr, or ~$80/mo!
  • Delete app:
    • az webapp delete --name app_name
  • Show runtimes: az webapp list-runtimes, or az webapp list-runtimes --linux
    • Set with az webapp --runtime PYTHON:3.8; pipe operator confuses zsh

@ehmatthes
Copy link
Owner Author

DB questions

  • Would an sqlite file be persistent, or is it destroyed on each redeploy? That's the issue with Heroku, I believe.

@ehmatthes
Copy link
Owner Author

ehmatthes commented Nov 7, 2021

More notes

  • This process really should be reviewed by someone who knows Azure deployment better, especially free initial deployment.
  • Get info: az webapp list
  • Trying this: az webapp up --sku F1 --runtime PYTHON:3.8
    • created webapp, resource group, appserviceplan, registered 'Microsoft.Web' resource provider; "Registration succeeded".
    • Then returned Operation returned an invalid status 'Unauthorized'
    • Ran az login again, and then ran the deploy command again. Same error.
    • Redeployed with --verbose. Object of type ClientAuthenticationError is not JSON serializable
    • Redeployed with --debug instead of verbose. Seems like this is the issue: "Code":"Unauthorized","Message":"This region has quota of 0 instances for your subscription. Try selecting different region or SKU."
      • Maybe some regions don't have free plans available?
      • az account list-locations
      • Perhaps try creating an appserviceplan in the free tier first, and then specify that?
      • Using westus2 did not fail. However, I see an application error.
      • Simple az webapp delete, in same terminal session, worked. Confirmed by empty az webapp list.
        • This leaves .azure/ config directory behind. Maybe az webapp delete group?

@ehmatthes
Copy link
Owner Author

ehmatthes commented Nov 7, 2021

Next try: az webapp up --sku F1 --runtime PYTHON:3.8 --location westus2 --verbose

  • Should deploy, but result in application error. Maybe output is easier to parse than --debug?
    • It's creating a zip file of the project. Is it including the env?
    • Look at logs? Is that the same as debug?
    • az webapp log tail
      • No module named white noise
      • Add whitenoise to requirements.txt.
      • Home page appears!
      • Is there a db? Yes, it pulled my db.sqlite3 file.
      • Make a topic, redeploy. Does the topic still exist? (ie is the db ephemeral, or written over?) It still exists. I don't know why.

@ehmatthes
Copy link
Owner Author

ehmatthes commented Nov 7, 2021

Refining db approach

  • Give deployed db a unique name, so no overlap with local db?
  • How run initial migrations?
  • Specify what gets put into the zip file?

@ehmatthes
Copy link
Owner Author

ehmatthes commented Nov 7, 2021

Does venv affect deployment time?

  • Delete ll_env/, redeploy. Any faster?
    • Need to deploy, which takes longer. Then redeploy 2x, note those times. Then delete venv, and redeploy 2x.

@ehmatthes
Copy link
Owner Author

ehmatthes commented Nov 7, 2021

Tasks

  • When adding --platform azure option to simple_deploy, add a confirmation that this is in beta and you should confirm that your app is using the resources and plans you want it to.
  • In script, consider copying needed files to a tmp dir for push? Gets around no way to exclude directories.
  • Research: create zip file manually and push that?

@ehmatthes
Copy link
Owner Author

ehmatthes commented Nov 7, 2021

Consider git push approach

  • az webapp create --sku F1 --deployment-local-git --dryrun
    • Requires --name arg.

@ehmatthes
Copy link
Owner Author

ehmatthes commented Nov 7, 2021

Another attempt

  • with no local env
    • az webapp up --sku F1 --runtime PYTHON:3.8 --location westus2 --verbose
    • ~3min for initial deploy
  • try with db connection setting for db that doesn't exist in local dir
    • Deploys, but there's no db in production. (OperationalError debug page.)
    • Any way to run migrate?
      • https://app_name.scm.azurewebsites.net/DebugConsole, then click SSH.
      • Note: Any data outside '/home' is not persisted
      • az webapp deployment list-publishing-profiles should give username/ pw for user who can log in to console
  • Works:
    • az webapp create-remote-connection
    • This gives tunnel, then gives SSH username and password.
    • ssh root@127.0.0.1 -p 60898
    • Begins session where migrate works!
    • Might take some wrestling to get this to work from a script!!!
    • Push again, see if data persists.
    • Might need to move sqlite file to non-tmp location?

@ehmatthes
Copy link
Owner Author

Testing

  • I believe the initial request takes longer than most, because a docker container is warming up. Test script may need a longer request timeout for initial request, or several retries before giving up.

@ehmatthes
Copy link
Owner Author

ehmatthes commented Nov 7, 2021

Partial script

  • Write a bash script that pushes an already-configured django project to azure, and runs the migration, then deletes the app.
    • Deploys and opens app.
    • Runs create-remote-connection, which goes through a few waiting cycles and then gives a port number.
    • Opens remote connection shows port number, but need to find a way to issue next call instead of waiting on more in the current connection. Maybe tail output until find a port number, maybe run the remote connection in a sub shell but follow output????
    • Try: webapp create-remote-connection --port 63256 in a sub shell, then SSH to that port?

@ehmatthes
Copy link
Owner Author

ehmatthes commented Nov 8, 2021

Most promising migration approaches

  • Run a post-deployment script, that can be included in the project itself.
  • Use Kudu REST api.
  • Use expect for now, even if it only runs on macOS.
  • az webapp ssh
  • Make an app setting with POST_BUILD_COMMAND set? Might also need to set POST_BUILD_SCRIPT_PATH?

@ehmatthes
Copy link
Owner Author

ehmatthes commented Nov 8, 2021

Migration: Kudu REST api

  • Get login credentials from az webapp deployment list-publishing-profiles.
  • Make a get request to get information about the deployment.
  • Use url to submit command in a JSON format.
    • Simple command, like "echo hello"
    • Choose a known existing directory.
  • Run manage.py check
  • Where are my files??? (in directory over api)
  • I believe this will only work after a git-based deployment?

@ehmatthes
Copy link
Owner Author

Notes

@ehmatthes
Copy link
Owner Author

Now that something's working...

  • Could unset POST_BUILD_COMMAND after initial push?
    • Don't want to set user up for rerunning migrations on every deploy.

@ehmatthes ehmatthes reopened this Nov 12, 2021
@ehmatthes
Copy link
Owner Author

Not sure why I closed this, I haven't sorted out an approach to setting up the database yet.

@ehmatthes
Copy link
Owner Author

This is working in a separate, private, messy repo. I'll port that work to this project shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant