Skip to content

Utilizar o Compose Watch no ambiente de desenvolvimento #974

Description

@vrtornisiello

Contexto

Atualmente, montamos um volume no contêiner da api contendo o código do repositório, para refletir as mudanças em tempo real durante o desenvolvimento:

volumes: [.:/app, $HOME/.basedosdados/credentials:/app/credentials:ro]

Porém, isso gera algumas complicações, como por exemplo, a necessidade de regerar os arquivos estáticos novamente no nosso script `start-server-dev.sh:

# The compose.yaml file mounts our repository as a volume in the /app folder,
# which overwrites the static files collected during image build.
# So we need to collect the static files again at runtime.
echo "> Collecting static files"
(cd /app; python manage.py collectstatic --no-input --settings=backend.settings.base)

Proposta

Podemos utilizar o Compose Watch para refletir as mudanças no código, eliminando a necessidade de montar volumes no contêiner e sobrescrever os arquivos criados durante o build da imagem. Exemplo:

api:
  build: .
  command: poetry run /app/start-server-dev.sh
  env_file: .env
  develop:
    # Live-reload configuration for local development
    watch:
      # Sync the working directory with the `/app` directory in the container
      - action: sync
        path: .
        target: /app
        # Exclude the host virtual environment (if any) to avoid
        # platform mismatches and invalid symlinks
        ignore:
          - .venv/
      # Rebuild the image when dependencies change
      - action: rebuild
        path: ./poetry.lock
  ports:
    ...

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions