Skip to content

namespace-integration-demos/poetry

Repository files navigation

Caching Poetry with Namespace

Poetry in Docker

This repository contains a minimal example of a Python app managed by Poetry and fully dockerized.

The Dockerfile has been optimized to minimize build time by maximizing cache usage.

We're using a couple of tricks here:

  1. Code changes do not invalidate the dependency build cache. This is achieved by only copying selected files when building dependencies (and deferring the copy of the full app to a later stage).
  2. Dependecies remain in the cache even when adding new dependencies. We're storing dependencies in a persistent cache mount to achieve this.
  3. Minimize the size of the final docker image by only retaining the virtual environment from the build step.

Give this example a spin with:

$ nsc build . --name poetry-demo --push
Pushed:
  nscr.io/{your-workspace-id}/poetry-demo:latest


$ nsc run --image nscr.io/{your-workspace-id}/poetry-demo:latest -p 8000

  Created new ephemeral environment! ID: uqsd11c10lb72

  More at: https://cloud.namespace.so/{your-workspace-id}/cluster/uqsd11c10lb72

  Started "poetry-test-b4sv4"

    Exported 8000/tcp as https://4c2k8mg-uqsd11c10lb72.fra1.namespaced.app

If you're new to Namespace, get started at cloud.namespace.so/docs.

Poetry in GitHub Actions

The example workflow demonstrates how to cache Poetry dependencies with Namespace.

The first workflow creates the virtual env inside the central Poetry cache.

uses: snok/install-poetry@v1
with:
  installer-parallel: true
  virtualenvs-create: true
  # virtualenvs-in-project: false (as per default)

By using cache mode poetry, the env is automatically retained accross runs:

uses: namespacelabs/nscloud-cache-action@v1
with:
  cache: poetry

The second workflow creates the virtual env inside the project.

uses: snok/install-poetry@v1
with:
  installer-parallel: true
  virtualenvs-create: true
  virtualenvs-in-project: true

To cache the env, the directory has to be registered manually:

uses: namespacelabs/nscloud-cache-action@v1
with:
  cache: poetry
  path: .venv

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published