assets

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 37 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package assets builds and publishes the assets of a cloud assembly: upstream's cdk-assets-lib, which toolkit-lib publishes with, and toolkit-lib's glue around it (H.2, H.3).

A Publisher serves one action; the work graph's asset nodes call Publisher.Build and Publisher.Publish, and its pruning calls Publisher.IsPublished (I.2). AllowCrossAccount reads whether an environment's toolkit stack lets assets go to another account's bucket, and Manifest collects the assets a deployment adds itself, such as a large template (F.3). File assets go to S3, and container images to ECR, through the docker CLI that Docker names.

Design

One Publisher serves every stack and manifest of an action, where toolkit-lib keeps one per manifest and environment (H.2-D1). Its caches key on what they are about: packaged files on the manifest's directory and the asset ID, bucket ownership on the bucket and the expected account, bucket encryption on the bucket, and each destination's account on its environment and role, while AWS access is awsauth.Access's, cached per environment, region and role. A destination is reached with its own role, assumed for writing, in its own region or else its stack's, its placeholders resolved with its stack's environment (H.1-D3), through awsauth.Access.ForDestination, which falls back to the base credentials for the right account as every other access does. S3 clients take awsauth.S3Options, for path-style addressing with S3 emulators (H.2-D7).

Publishing a file asset follows upstream's file handler: the bucket's owner is checked with GetBucketLocation, without and, when cross-account publishing is forbidden, with the expected owner, giving upstream's three errors; the existence check, unless forced, lists the key with ListObjectsV2, never HeadObject, and counts an object of 22 bytes or less as missing (H.2-D5); the bucket's default encryption, read once per bucket, gives the upload's encryption headers; then the asset is packaged and uploaded with its content type and a SHA-256 checksum. A directory is zipped into the manifest directory's .cache/<asset ID>.zip, reused when it is there; a file is uploaded as it is, with the content type mime 2.6.0 gives its name; an executable source runs, never through a shell, and the path it prints is uploaded as a zip. The upload is the port's own, on the S3 client, where upstream's is lib-storage's: one PutObject up to 5 MiB, and a multipart upload beyond, 4 parts at a time, aborted when it fails (H.2-D2).

The zip is deterministic within Go, and has the same entries as the CLI's, but not its bytes, whose deflate is zlib's (H.2-D3, ADR 0001): regular files only, symbolic links followed, dotfiles included, each with its mode, deflated, and dated 1980-01-01 00:00 with no extended timestamp, so that an empty directory gives the 22-byte empty zip. Both tools check and upload the key the asset manifest names, which synthesis hashes from the source, so each finds the other's object published whatever its bytes.

Publishing a container image follows upstream's container image handler, once per entry: the destination's repository is found with DescribeRepositories, failing when there is none, which a build, a publish and IsPublished of the entry share, and a publish and IsPublished check its tag with DescribeImages, ImageNotFoundException meaning absent. A build logs in to the destination's registry, so that a Dockerfile can pull from it, and makes the local image, which it records for every destination of the asset; unless the destination has the image, a publish logs in, tags the recorded local image with the destination's URI, and pushes it. The local image is cdkasset-<asset ID in lower case>, built with docker build unless docker inspect finds it, its exit codes 1 (Docker) and 125 (Podman) meaning absent, or else the name an executable source prints, run in the manifest's directory. docker build's flags are upstream's, in its order, with map-valued options in sorted key order, and the platform passed through as it is (H.3-D6). Logging in runs docker login with an ECR authorization token, the password on its standard input, so that it lands where the user's Docker configuration keeps credentials, once per registry for the action, a failed login being tried again (H.3-D3); the token is decoded as the docker credential helper decodes it, strictly, a divergence the owner approved (#64): upstream's Node decoding is lenient, but ECR's real tokens are always valid base64, so the two never differ. Publish's Force doesn't apply to images, as upstream's handler ignores it: the bootstrap repository's tags are immutable.

The docker CLI is a subprocess, never a Docker SDK, so that a docker-compatible CLI such as finch or podman works, with the user's contexts, builders and credential stores (H.3-D1). The toolkit names it, from CDK_DOCKER, and passes the environment it and executable sources run with, the process's, so that the toolkit is the only reader of process globals (H.3-D2); docker build adds BUILDX_NO_DEFAULT_ATTESTATIONS=1, as upstream does. The values of --build-arg and --secret are masked wherever a command line is shown, its failure included, but not in its output, as upstream's are (H.3-D8). A docker CLI that can't be found fails with upstream's advice to install it or set CDK_DOCKER; a working directory that doesn't exist fails with the system's error, where Node reports it as the command's ENOENT, and upstream gives the same advice.

The content types come from a table generated from mime 2.6.0's type lists, which `./walle upstream mime` copies from the npm registry and `./walle check` verifies.

Messages are upstream's progress events as toolkit-lib turns them into messages: start, success and fail are CDK_ASSETS_I5270, I5275 and E5279, and the rest CDK_ASSETS_I5271, each "<stack name>: <type>: <text>", in plain text, where upstream's stack name is bold. They are sent with the host's Notify, whose error fails the action, where upstream doesn't wait for them. An executable's command line is sent, as upstream's is, and each line of its output too, where upstream discards it, and a failure carries its standard error (Epic H's EH-2); so are the command lines of docker build, tag and push and each line of their output, where upstream writes the output to the process's streams, and a container image's executable's command line and each line of its standard error (H.3-D5), while docker login and docker inspect send their command lines but not their output, as upstream does. A build's docker messages carry their type and text, as upstream's have since toolkit-lib 1.43.0; before it, upstream's were debug messages whose text was their event type, such as "debug: shell_open", which the port fixed first (H.3-D9, buildImage).

Every S3 and ECR call and command takes ctx; a zip that fails or is cancelled removes its temporary file, a cancelled command's process group is killed, docker build's included, and killed again until it is empty, so that a process forked as the first kill goes out doesn't escape it, and a failed multipart upload is aborted under context.WithoutCancel, as cleanup (G.10). A cancelled build leaves no local tag, as docker writes it only when the build finishes, and ECR writes a tag only when a push's manifest is put (both inferred, not run against a real daemon or registry). No upload starts anything the next run can't see: an object exists only once a PutObject or CompleteMultipartUpload completes, and the existence check finds one whose outcome cancellation hid.

Upstream's defects that are fixed:

  • each build and publish returns its own error, where upstream's publisher keeps every failure it has had, so that one failure fails every later build and publish of the manifest (Epic H's EH-5);
  • an asset is packaged once for the action, whatever its destinations, where upstream packages it once per destination, concurrently, racing to rename into one .cache file and running its command each time (H.2-D4, packageOnce);
  • where cross-account publishing is forbidden, IsPublished checks the bucket's owner first, as Publish does, and an object in another account's bucket isn't published, so that Publish refuses the bucket, where upstream's check reports it published and the stack is deployed from it (H.2-D5, ownedForSkipping);
  • a bucket whose default encryption is aws:kms:dsse gets aws:kms:dsse and its key ID, where upstream sends no encryption header, which an SCP requiring one denies (H.2-D6, encryptionFor);
  • each event's payload carries its entry as the asset, which upstream never sets; the entry's own progress, 0 until it finishes and 100 once it has, where upstream counts builds and publishes over the manifest's entries, passing 100; and the stack name of the call's own entry, where upstream's is the first caller's for the whole manifest (H.2-D8, publishEvent);
  • the zip's entries are sorted by name, where upstream's are in fast-glob's order, breadth first, though its comment says they are sorted; and a symbolic link that makes a cycle fails the zip, naming the link, where upstream follows the cycle as deep as the system resolves links (H.2-D3, zipEntries);
  • a zip that fails, for any reason, removes its temporary file, where upstream's leaves it beside the target (H.2-D3, zipDirectory);
  • a cancelled context is IsPublished's error, where upstream, which has no cancellation, counts any failure to check as not published (H.2-D9, notPublishedAfter);
  • logins to a registry are remembered for the action, where upstream's DockerFactory belongs to a publisher per manifest and environment, so that an app with three stacks logs in to one registry three times (H.3-D3, loginOnce);
  • a build always makes the local image, and every destination's publish tags it and pushes it, where upstream's build does nothing when the destination its node carries has the image, so that another destination's publish tags whatever local image docker images finds with the same tag, if any, and its push fails without one, as on a fresh CI runner (H.3-D4, buildImage and publishImage);
  • a container image's executable sends its command line and each line of its standard error, and one that prints no image name, or more than one line, fails naming the command, where upstream sends only its command line and fails later, at docker tag (H.3-D5, runImageExecutable);
  • a missing repository's error names the stack environment's account, where upstream's names the base credentials' (H.3-D9, repository); and an executable's message renders its argv as a command line, where upstream's joins it with commas (H.3-D9, executableMessage).

The existence check's 22-byte rule is upstream's, approved as a mirror: an object of 22 bytes or less counts as missing, whatever the asset's packaging (H.2-D5).

Upstream behaviours that are mirrored while their fixes wait for review, each in one function that names its decision:

  • the S3 endpoint path-style addressing tests is read from AWS_ENDPOINT_URL_S3 or AWS_ENDPOINT_URL (H.2-D7, in awsauth).

The legacy publishAssets for CDK v1 metadata assets isn't ported: deploy refuses such stacks (Epic E's EE-3), and the publish-assets action ignores their metadata assets, as upstream's does.

Index

Constants

View Source
const DockerEnv = "CDK_DOCKER"

DockerEnv names the environment variable that names the docker CLI to use, such as finch or podman: upstream's CDK_DOCKER. It is one of the process globals the library reads, through the environment the toolkit passes (H.3-D2).

Variables

This section is empty.

Functions

func AllowCrossAccount

func AllowCrossAccount(t ToolkitStack) bool

AllowCrossAccount reports whether assets may be published to a bucket another account owns, in the environment whose toolkit stack t is: upstream's determineAllowCrossAccountAssetPublishing. The caller reads the toolkit stack, so that this package needn't import bootstrap, and caches the answer per environment, as upstream does.

Publishing to another account's bucket is forbidden only when the toolkit stack has a staging bucket and a bootstrap version below 21, from which the file-publishing role refuses it itself. It is allowed when there is no staging bucket, an intentionally cross-account setup, and when the toolkit stack, its version or its bucket can't be read, as upstream fails open: organizations that make their own bootstrap resources leave nothing to check. A version of 0, which bootstrap.ToolkitInfo reads for a stack with no BootstrapVersion output, and which no real bootstrap version is, counts as unreadable, as upstream's missing output does.

Upstream sends two debug messages when it fails open; this sends none.

func DockerCommand

func DockerCommand(env []string) string

DockerCommand returns the docker command env names, as upstream's getDockerCmd does: the value of DockerEnv when it is set, even to nothing, and "docker" otherwise.

func ZipDirectory

func ZipDirectory(ctx context.Context, dir, out string) error

ZipDirectory zips dir into out as a directory asset is zipped, for tools such as `./walle compare assets` that compare the toolkit's zips with the CLI's.

Types

type Docker

type Docker struct {
	// Command is the docker CLI, or a compatible one, such as finch or podman: [DockerCommand]'s answer for the process's environment.
	Command string

	// Env is the environment the docker CLI and container image executables run with: the process's, as upstream passes them process.env; nil means the process's too.
	Env []string
}

Docker is how container image assets reach the docker CLI (H.3-D1, H.3-D2).

type Entry

type Entry struct {
	// Dir is the directory of the asset's manifest, which its source's path is relative to.
	Dir string

	// Asset is the asset and one of its destinations: a *cloudassembly.FileAssetEntry or a *cloudassembly.DockerImageAssetEntry.
	Asset cloudassembly.AssetEntry

	// Env is the environment of the stack whose asset it is, resolved, which the destination's placeholders are resolved with and whose account and region it is published to unless it names its own region.
	Env cloudassembly.Environment

	// StackName starts each message, as "<stack name>: "; empty for none.
	StackName string

	// Manifest identifies the asset manifest the entry is in, such as the manifest's file.
	Manifest string
}

Entry is an asset entry with what building and publishing it needs.

type Manifest

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

Manifest collects the file assets a deployment adds before it creates its change set, such as a template too large to pass to CloudFormation, which F.3 uploads: upstream's AssetManifestBuilder. It satisfies cfnstack.AssetManifest. Its zero value is an empty manifest.

func (*Manifest) AddFileAsset

func (m *Manifest) AddFileAsset(id string, source cloudassembly.FileSource, destination cloudassembly.FileDestination)

AddFileAsset adds a file asset with id, to publish source to destination, as the asset's one destination, "current", as upstream's builder names it. An asset added again with the same id replaces the first.

func (*Manifest) Entries

func (m *Manifest) Entries() []cloudassembly.AssetEntry

Entries returns an entry for each asset added, in the order added.

type PublishOptions

type PublishOptions struct {
	// AllowCrossAccount allows publishing to a bucket another account owns: [AllowCrossAccount]'s answer for the stack's environment.
	// Its zero value forbids it, where upstream's default allows it; the toolkit always passes upstream's answer.
	AllowCrossAccount bool

	// Force uploads the asset even when the destination has it already.
	Force bool
}

PublishOptions are the options for Publisher.Publish.

type Publisher

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

Publisher builds and publishes the assets of one action: upstream's AssetPublishing, its file and container image handlers, and toolkit-lib's PublishingAws and cachedPublisher. One Publisher serves every stack and manifest of the action (H.2-D1). It is safe for concurrent use; the work graph's workers share it.

func New

func New(io *iohelper.Helper, access *awsauth.Access, docker Docker) *Publisher

New returns a publisher that sends its messages with io, reaches each destination through access, and builds and pushes container images with docker.

func (*Publisher) Build

func (p *Publisher) Build(ctx context.Context, e Entry) error

Build builds e's asset, sending a start message and then a success or failure message, as upstream's buildEntry does. Building a file asset does nothing: packaging happens when it is published, as upstream's does. Building a container image logs in to the destination's registry and makes the local image, which every destination's publish tags and pushes, whether or not a destination has the image already (H.3-D4).

A failure is a cdkerr.KindToolkit error with Code "AssetBuildFailed", which wraps this entry's error only, where upstream's carries every failure the manifest's publisher has had (Epic H's EH-5).

func (*Publisher) IsPublished

func (p *Publisher) IsPublished(ctx context.Context, e Entry, allowCrossAccount bool) (bool, error)

IsPublished reports whether e's destination has its asset already, as upstream's isEntryPublished does; the work graph's pruning calls it before a run (I.2). allowCrossAccount is AllowCrossAccount's answer for the stack's environment.

A failure to check counts as not published, after a debug message, as upstream's does; only a failure to send a message is returned, and, for a file asset, a failure to resolve the destination's placeholders.

func (*Publisher) Publish

func (p *Publisher) Publish(ctx context.Context, e Entry, opts PublishOptions) error

Publish publishes e's asset to its destination, sending a start message and then a success or failure message, as upstream's publishEntry does.

A failure is a cdkerr.KindToolkit error with Code "AssetPublishFailed", which wraps this entry's error only (Epic H's EH-5).

type ToolkitStack

type ToolkitStack interface {
	// Found reports whether the environment has a toolkit stack.
	Found() bool

	// BucketName returns the name of the stack's staging bucket, from its BucketName output.
	BucketName() (string, error)

	// Version returns the stack's bootstrap version, from its BootstrapVersion output, or 0 when it has none.
	Version() (int, error)
}

ToolkitStack is the toolkit stack of an environment, which AllowCrossAccount reads; *bootstrap.ToolkitInfo satisfies it.

Jump to

Keyboard shortcuts

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