pipenvinstall

package module
v0.6.19 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

README

Pipenv Install Cloud Native Buildpack

The Paketo Buildpack for Pipenv Install is a Cloud Native Buildpack that installs packages using pipenv and makes it available to the application.

The buildpack is published for consumption at gcr.io/paketo-buildpacks/pipenv-install and paketobuildpacks/pipenv-install.

Behavior

This buildpack participates if Pipfile exists at the root of the app.

The buildpack will do the following:

  • Installs the application packages to a layer made available to the app.
  • Prepends the layer site-packages onto PYTHONPATH.
  • Prepends the layer's bin directory to the PATH.

This buildpack speeds up the build process by reusing (the layer of) installed packages from a previous build if it exists, and later cleaning up any unused packages. For apps that do not have a Pipfile.lock, clean-up is not performed to avoid the overhead of generating a lock file. Users of such apps should either include a lock file with their app, or clear their build cache during a rebuild to avoid any unused packages in the built image.

Integration

The Pipenv Install CNB provides site-packages as a dependency. Downstream buildpacks can require the site-packages dependency by generating a [Build Plan TOML] (https://github.com/buildpacks/spec/blob/master/buildpack.md#build-plan-toml) file that looks like the following:

[[requires]]

  # The name of the dependency provided by the Pipenv Install Buildpack is
  # "site-packages". This value is considered part of the public API for the
  # buildpack and will not change without a plan for deprecation.
  name = "site-packages"

  # The Pipenv Install buildpack supports some non-required metadata options.
  [requires.metadata]

    # Set the build flag to true to make the site-packages dependency available on the $PYTHONPATH/$PATH
    # for subsequent buildpacks during their build phase.
    build = true

    # Set the launch flag to true to make the site-packages dependency available on the $PYTHONPATH/$PATH
    # for the running application.
    launch = true

SBOM

This buildpack can generate a Software Bill of Materials (SBOM) for the dependencies of an application.

However, this feature only works if the application already has a Pipfile.lock file. This is due to a limitation in the upstream SBOM generation library (Syft).

Applications that declare their dependencies via a Pipfile but do not include a Pipfile.lock will result in an empty SBOM. Check out the Paketo SBOM documentation for more information about how to access the SBOM.

Usage

To package this buildpack for consumption:

$ ./scripts/package.sh --version x.x.x

This will create a buildpackage.cnb file under the build directory which you can use to build your app as follows:

pack build <app-name> \
  --path <path-to-app> \
  --buildpack <cpython buildpack> \
  --buildpack <pipenv buildpack> \
  --buildpack build/buildpackage.cnb \
  --buildpack <other-buildpacks..>

To run the unit and integration tests for this buildpack:

$ ./scripts/unit.sh && ./scripts/integration.sh

Documentation

Index

Constants

View Source
const CPython = "cpython"

CPython is the name of the python runtime dependency provided by the CPython buildpack: https://github.com/paketo-buildpacks/cpython.

View Source
const CacheLayerName = "cache"

The layer name for cache layer. This layer holds the pipenv cache.

View Source
const PackagesLayerName = "packages"

The layer name for packages layer. This layer is where dependencies are installed to.

View Source
const Pipenv = "pipenv"

Pipenv is the name of the dependency provided by the Pipenv buildpack: https://github.com/paketo-buildpacks/pipenv.

View Source
const SitePackages = "site-packages"

SitePackages is the name of the dependency provided by the Pipenv Install buildpack.

Variables

This section is empty.

Functions

func Build

func Build(
	installProcess InstallProcess,
	siteProcess SitePackagesProcess,
	venvDirLocator VenvDirLocator,
	sbomGenerator SBOMGenerator,
	clock chronos.Clock,
	logger scribe.Emitter,
) packit.BuildFunc

Build will return a packit.BuildFunc that will be invoked during the build phase of the buildpack lifecycle.

Build will install the pipenv dependencies by using the Pipfile to a packages layer. It also makes use of a cache layer to reuse the pipenv cache.

func Detect

func Detect(pipfileParser, pipfileLockParser Parser) packit.DetectFunc

Detect will return a packit.DetectFunc that will be invoked during the detect phase of the buildpack lifecycle.

Detection will contribute a Build Plan that provides site-packages, and requires cpython and pipenv at build.

Types

type BuildPlanMetadata

type BuildPlanMetadata struct {
	// Build denotes the dependency is needed at build-time.
	Build bool `toml:"build"`
	// Version denotes the version to request.
	Version string `toml:"version"`
	// VersionSource denotes the source of version request.
	VersionSource string `toml:"version-source"`
}

BuildPlanMetadata is the buildpack-specific data included in build plan requirements.

type Executable

type Executable interface {
	Execute(pexec.Execution) error
}

Executable defines the interface for invoking an executable.

type InstallProcess

type InstallProcess interface {
	Execute(workingDir string, targetLayer, cacheLayer packit.Layer) error
}

InstallProcess defines the interface for installing the pipenv dependencies.

type Parser

type Parser interface {
	ParseVersion(path string) (version string, err error)
}

Parser will parse python version out of Pipfile.lock.

type PipenvInstallProcess

type PipenvInstallProcess struct {
	// contains filtered or unexported fields
}

PipenvInstallProcess implements the InstallProcess interface.

func NewPipenvInstallProcess

func NewPipenvInstallProcess(executable Executable, logger scribe.Emitter) PipenvInstallProcess

NewPipenvInstallProcess creates an instance of the PipenvInstallProcess given an Executable.

func (PipenvInstallProcess) Execute

func (p PipenvInstallProcess) Execute(workingDir string, targetLayer, cacheLayer packit.Layer) error

Execute installs the pipenv dependencies from workingDir/Pipfile into the targetLayer. The cacheLayer is used for the pipenv cache directory.

type PipfileLockParser

type PipfileLockParser struct{}

func NewPipfileLockParser

func NewPipfileLockParser() PipfileLockParser

func (PipfileLockParser) ParseVersion

func (p PipfileLockParser) ParseVersion(path string) (version string, err error)

type PipfileParser

type PipfileParser struct{}

func NewPipfileParser

func NewPipfileParser() PipfileParser

func (PipfileParser) ParseVersion

func (p PipfileParser) ParseVersion(path string) (version string, err error)

type SBOMGenerator added in v0.5.0

type SBOMGenerator interface {
	Generate(dir string) (sbom.SBOM, error)
}

type SitePackagesProcess added in v0.4.0

type SitePackagesProcess interface {
	Execute(layerPath string) (sitePackagesPath string, err error)
}

SitePackagesProcess defines the interface for determining the site-packages path.

type SiteProcess added in v0.4.0

type SiteProcess struct {
	// contains filtered or unexported fields
}

SiteProcess implements the Executable interface.

func NewSiteProcess added in v0.4.0

func NewSiteProcess(executable Executable) SiteProcess

NewSiteProcess creates an instance of the SiteProcess given an Executable that runs `python`

func (SiteProcess) Execute added in v0.4.0

func (p SiteProcess) Execute(layerPath string) (string, error)

Execute runs a python command to locate the site packages within the pip targetLayerPath.

type VenvDirLocator added in v0.4.0

type VenvDirLocator interface {
	LocateVenvDir(path string) (venvDir string, err error)
}

VenvDirLocator defines the interface for locating the virtual environment directory under a given path

type VenvLocator added in v0.4.0

type VenvLocator struct {
}

func NewVenvLocator added in v0.4.0

func NewVenvLocator() VenvLocator

func (VenvLocator) LocateVenvDir added in v0.4.0

func (v VenvLocator) LocateVenvDir(path string) (string, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL