简体   繁体   English

使用 Visual Studio Code 和 Docker 持续开发和部署 Django 应用程序

[英]Continuously develop and deploy a Django app with Visual Studio Code and Docker

I am developing a Django app locally with Visual Studio Code.我正在使用 Visual Studio Code 在本地开发一个 Django 应用程序。 In preparation for deployment I "dockerized" everything and now I am already able to run this container locally.在准备部署时,我将所有内容“dockerized”,现在我已经能够在本地运行这个容器了。

Before I try to build my Docker image somewhere else (I have Google Cloud Run in mind), I want to make sure that I still can debug my code.在我尝试在其他地方构建我的 Docker 图像之前(我想到了 Google Cloud Run),我想确保我仍然可以调试我的代码。

Withthe official 'Python in a container' tutorial I am able to set breakpoints and so on when my app runs locally with Docker.通过官方的“容器中的 Python”教程,当我的应用程序在 Docker 本地运行时,我可以设置断点等。

So I think the workflow will look like this:所以我认为工作流程将如下所示:

  1. I develop my app locally and debug it within Visual Studio Code.我在本地开发我的应用程序并在 Visual Studio Code 中调试它。
  2. For further debugging I can do this locally with Docker as described above.为了进一步调试,我可以如上所述使用 Docker 在本地执行此操作。
  3. When everything looks good I push this container to Google Cloud Run or whatever.当一切看起来不错时,我将这个容器推送到 Google Cloud Run 或其他任何地方。

Does that sound like a reasonable plan or did I miss something important?这听起来像是一个合理的计划还是我错过了一些重要的事情? In the end, I am looking for an easy convenient way to continuously develop (and debug) a Django app with Visual Studio Code and deploy it with Docker.最后,我正在寻找一种简单方便的方法来使用 Visual Studio Code 持续开发(和调试)Django 应用程序并使用 Docker 部署它。

I've never used Google Cloud Run or smth, but based on experience with remote servers I can advice following approach.我从未使用过 Google Cloud Run 或 smth,但根据远程服务器的经验,我可以建议采用以下方法。 You can use github actions and docker hub .您可以使用github 操作docker 集线器 Cover your application or at least critical parts of it with tests which will ensure that everything important works properly.用测试覆盖您的应用程序或至少它的关键部分,以确保一切重要的工作正常。 You can set github actions up the way that your tests will be run everytime you push to your github repo.您可以将 github 操作设置为每次推送到 github 存储库时运行测试的方式。 If tests will be passed an image of your application (usually it's name is your_app:latest) will be updated on dockerhub allowing you to build from an image.如果测试将通过,您的应用程序的图像(通常它的名称是 your_app:latest)将在 dockerhub 上更新,允许您从图像构建。 It's a good practice to have multiple images.拥有多个图像是一种很好的做法。 For example you could have a stable version, say v.1.0 and a beta version your_app:latest .例如,您可以有一个稳定版本,比如v.1.0和一个 beta 版本your_app:latest Thus you will be able to run your stable version on a production server, while beta version can be run on a development server.因此,您将能够在生产服务器上运行稳定版本,而测试版可以在开发服务器上运行。 Do not update stable versions, release new ones and keep existing ones.不要更新稳定版本,发布新版本并保留现有版本。

An example of how github actions file can look like: github 操作文件的示例:

name: your_app_workflow

on: [push]

jobs:
  tests:

  # run your tests here

  push_to_docker_hub:
    name: Push Docker image to Docker Hub
    runs-on: ubuntu-latest
    needs: tests
    steps:
      - name: Check out the repo
        uses: actions/checkout@v2

      - name: Push to Docker Hub
        uses: docker/build-push-action@v1
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
          repository: your_repository_on_dockerhub
          tag_with_ref: true

Maybe you know following, but I will mention it anyway.也许你知道以下,但我还是会提到它。 Django built in database is SQLite which is not reliable at all, thus if you are going to let others use your product, you MUST think of another database. Django 内置数据库是 SQLite 是不可靠的,所以如果你要让别人使用你的产品,你必须考虑另一个数据库。 Current standard in web industry is PostgreSQL. There are Mongo, Redis and others, but PostgreSQL is used the most. web行业目前的标准是PostgreSQL,还有Mongo、Redis等,但PostgreSQL用的最多。 Also, Django doesn't serve static and media files in production, so you will have to use proxy server such as Nginx. Nginx can not work with your Django app directly thus you will need an intermediary such as Gunicorn.此外,Django 不提供 static 和生产中的媒体文件,因此您必须使用代理服务器,例如 Nginx。Nginx 不能直接与您的 Django 应用程序一起使用,因此您需要一个中介,例如 Gunicorn。 Again, I don't know about Google Cloud Run but on a typical remote server you would do it this way.同样,我不知道 Google Cloud Run,但在典型的远程服务器上,您会这样做。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Visual Studio 部署到 Google Cloud Compute VM - Deploy To Google Cloud Compute VM With Visual Studio Angular 2 应用程序部署在 AWS 上运行的 docker 容器中 - Angular 2 app deploy in a docker Container running on AWS Django 在标准环境中部署应用引擎错误 - Django error app engine deploy in standard env 在 Visual Studio Code 上调试 Flutter 应用程序时,如何停止 MacOS 上的“钥匙串访问”权限对话框? - How to stop "keychain access" permission dialog on MacOS when debugging Flutter app on Visual Studio Code? AWS Toolkit for Visual Studio 2022 部署失败 lambda - AWS Toolkit for Visual Studio 2022 failing on deploy lambda Visual Studio Web 将 ASP.NET 应用程序发布到 Azure Web 应用程序结果为 Forbidden,除了来自一个分支、一台计算机的代码 - Visual Studio Web Publish ASP.NET app to Azure Web App results in Forbidden except for code from one branch, one computer Firebase function 由于神秘的语法错误而无法从 Visual Studio 部署(请参阅屏幕截图或屏幕录像) - Firebase function fails to deploy from visual studio due to mysterious syntax errors (see screenshot or screen recording) 还有其他人在使用 Cloud Tools for Visual Studio 部署 GKE 工作负载时遇到问题吗? - Is anyone else experiencing issues using Cloud Tools for Visual Studio to deploy GKE workloads? 如何修复通过 Visual Studio 发布的 function 应用程序中的错误 - How to fix error in function app publish through visual studio AWS Toolkit Visual Studio Code Mac 无法找到凭证 - AWS Toolkit Visual Studio Code Mac Unable to locate credentials
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM