Search code examples
djangokubernetesskaffold

Django's ./manage.py always causes a skaffold rebuild: is there a way to prevent this?


I develop in local k8s cluster with minikube and skaffold. Using Django and DRF for the API.

I'm working on a number of models.py and one thing that is starting to get annoying is anytime I run a ./manage.py command like (showmigrations, makemigrations, etc.) it triggers a skaffold rebuild of the API nodes. It takes less than 10 seconds, but getting annoying none the less.

What should I exclude/include specifically from my skaffold.yaml to prevent this?

apiVersion: skaffold/v2beta12
kind: Config
build:
  artifacts:
  - image: postgres
    context: postgres
    sync:
      manual:
      - src: "**/*.sql"
        dest: .
    docker:
      dockerfile: Dockerfile.dev
  - image: api
    context: api
    sync:
      manual:
      - src: "**/*.py"
        dest: .
    docker:
      dockerfile: Dockerfile.dev
  local:
    push: false
deploy:
  kubectl:
    manifests:
      - k8s/ingress/development.yaml 
      - k8s/postgres/development.yaml
      - k8s/api/development.yaml
    defaultNamespace: development

Solution

  • It seems that ./manage.py must be recording some state locally, and thus triggering a rebuild. You need to add these state files to your .dockerignore.

    Skaffold normally logs at a warning level, which suppresses details of what triggers sync or rebuilds. Run Skaffold with -v info and you'll see more detail:

    $ skaffold dev -v info
    ...
    [node] Example app listening on port 3000!
    INFO[0336] files added: [backend/src/foo]               
    INFO[0336] Changed file src/foo does not match any sync pattern. Skipping sync 
    Generating tags...
     - node-example -> node-example:v1.20.0-8-gc9335b0ad-dirty
    INFO[0336] Tags generated in 80.293621ms                
    Checking cache...
     - node-example: Not found. Building
    INFO[0336] Cache check completed in 1.844615ms          
    Found [minikube] context, using local docker daemon.
    Building [node-example]...