Skip to content

AssetStaging

Stages a file or directory from a location on the file system into a staging directory.

This is controlled by the context key 'aliyun:ros:disable-asset-staging' and enabled by the CLI by default in order to ensure that when the CDK app exists, all assets are available for deployment. Otherwise, if an app references assets in temporary locations, those will not be available when it exists.

The stagedPath property is a stringified token that represents the location of the file or directory after staging. It will be resolved only during the "prepare" stage and may be either the original path or the staged path depending on the context setting.

The file/directory are staged based on their content hash (fingerprint). This means that only if content was changed, copy will happen.

Initializers

import com.aliyun.ros.cdk.core.AssetStaging;
AssetStaging.Builder.create(Construct scope, java.lang.String id)
//  .exclude(java.util.List<java.lang.String>)
//  .follow(SymlinkFollowMode)
//  .ignoreMode(IgnoreMode)
//  .extraHash(java.lang.String)
//  .assetHash(java.lang.String)
//  .assetHashType(AssetHashType)
//  .bundling(BundlingOptions)
    .sourcePath(java.lang.String)
    .build();
Name Type Description
scope Construct No description.
id java.lang.String No description.
exclude java.util.List File paths matching the patterns will be excluded.
follow SymlinkFollowMode A strategy for how to handle symlinks.
ignoreMode IgnoreMode The ignore behavior to use for exclude patterns.
extraHash java.lang.String Extra information to encode into the fingerprint (e.g. build instructions and other inputs).
assetHash java.lang.String Specify a custom hash for this asset.
assetHashType AssetHashType Specifies the type of hash to calculate for this asset.
bundling BundlingOptions Bundle the asset by executing a command in a Docker container or a custom bundling provider.
sourcePath java.lang.String The source file or directory to copy from.

scopeRequired


idRequired

  • Type: java.lang.String

excludeOptional

  • Type: java.util.List
  • Default: nothing is excluded

File paths matching the patterns will be excluded.

See ignoreMode to set the matching behavior. Has no effect on Assets bundled using the bundling property.


followOptional

A strategy for how to handle symlinks.


ignoreModeOptional

The ignore behavior to use for exclude patterns.


extraHashOptional

  • Type: java.lang.String
  • Default: hash is only based on source content

Extra information to encode into the fingerprint (e.g. build instructions and other inputs).


assetHashOptional

  • Type: java.lang.String
  • Default: based on assetHashType

Specify a custom hash for this asset.

If assetHashType is set it must be set to AssetHashType.CUSTOM. For consistency, this custom hash will be SHA256 hashed and encoded as hex. The resulting hash will be the asset hash.

NOTE: the hash is used in order to identify a specific revision of the asset, and used for optimizing and caching deployment activities related to this asset such as packaging, uploading to OSS bucket, etc. If you chose to customize the hash, you will need to make sure it is updated every time the asset changes, or otherwise it is possible that some deployments will not be invalidated.


assetHashTypeOptional

  • Type: AssetHashType
  • Default: the default is AssetHashType.SOURCE, but if assetHash is explicitly specified this value defaults to AssetHashType.CUSTOM.

Specifies the type of hash to calculate for this asset.

If assetHash is configured, this option must be undefined or AssetHashType.CUSTOM.


bundlingOptional

  • Type: BundlingOptions
  • Default: uploaded as-is to OSS bucket if the asset is a regular file or a .zip file, archived into a .zip file and uploaded to OSS bucket otherwise.

Bundle the asset by executing a command in a Docker container or a custom bundling provider.

The asset path will be mounted at /asset-input. The Docker container is responsible for putting content at /asset-output. The content at /asset-output will be zipped and used as the final asset.


sourcePathRequired

  • Type: java.lang.String

The source file or directory to copy from.


Methods

Name Description
toString Returns a string representation of this construct.
synthesize Allows this construct to emit artifacts into the cloud assembly during synthesis.
relativeStagedPath Return the path to the staged asset, relative to the Cloud Assembly (manifest) directory of the given stack.

toString

public java.lang.String toString()

Returns a string representation of this construct.

synthesize

public void synthesize(ISynthesisSession session)

Allows this construct to emit artifacts into the cloud assembly during synthesis.

This method is usually implemented by framework-level constructs such as Stack and Asset as they participate in synthesizing the cloud assembly.

sessionRequired

The synthesis session.


relativeStagedPath

public java.lang.String relativeStagedPath(Stack stack)

Return the path to the staged asset, relative to the Cloud Assembly (manifest) directory of the given stack.

Only returns a relative path if the asset was staged, returns an absolute path if it was not staged.

A bundled asset might end up in the outDir and still not count as "staged"; if asset staging is disabled we're technically expected to reference source directories, but we don't have a source directory for the bundled outputs (as the bundle output is written to a temporary directory). Nevertheless, we will still return an absolute path.

A non-obvious directory layout may look like this:

   CLOUD ASSEMBLY ROOT
     +-- asset.12345abcdef/
     +-- assembly-Stage
           +-- MyStack.template.json
           +-- MyStack.assets.json <- will contain { "path": "../asset.12345abcdef" }

stackRequired


Static Functions

Name Description
isConstruct Return whether the given object is a Construct.
clearAssetHashCache Clears the asset hash cache.

isConstruct

import com.aliyun.ros.cdk.core.AssetStaging;
AssetStaging.isConstruct(java.lang.Object x)

Return whether the given object is a Construct.

xRequired

  • Type: java.lang.Object

clearAssetHashCache

import com.aliyun.ros.cdk.core.AssetStaging;
AssetStaging.clearAssetHashCache()

Clears the asset hash cache.

Properties

Name Type Description
node ConstructNode The construct tree node associated with this construct.
absoluteStagedPath java.lang.String Absolute path to the asset data.
assetHash java.lang.String A cryptographic hash of the asset.
isArchive java.lang.Boolean Whether this asset is an archive (zip or jar).
packaging FileAssetPackaging How this asset should be packaged.
sourcePath java.lang.String The absolute path of the asset as it was referenced by the user.

nodeRequired

public ConstructNode getNode();

The construct tree node associated with this construct.


absoluteStagedPathRequired

public java.lang.String getAbsoluteStagedPath();
  • Type: java.lang.String

Absolute path to the asset data.

If asset staging is disabled, this will just be the source path or a temporary directory used for bundling.

If asset staging is enabled it will be the staged path.

IMPORTANT: If you are going to call addFileAsset(), use relativeStagedPath() instead.


assetHashRequired

public java.lang.String getAssetHash();
  • Type: java.lang.String

A cryptographic hash of the asset.


isArchiveRequired

public java.lang.Boolean getIsArchive();
  • Type: java.lang.Boolean

Whether this asset is an archive (zip or jar).


packagingRequired

public FileAssetPackaging getPackaging();

How this asset should be packaged.


sourcePathRequired

public java.lang.String getSourcePath();
  • Type: java.lang.String

The absolute path of the asset as it was referenced by the user.


Constants

Name Type Description
BUNDLING_INPUT_DIR java.lang.String The directory inside the bundling container into which the asset sources will be mounted.
BUNDLING_OUTPUT_DIR java.lang.String The directory inside the bundling container into which the bundled output should be written.

BUNDLING_INPUT_DIRRequired

public java.lang.String getBundlingInputDir();
  • Type: java.lang.String

The directory inside the bundling container into which the asset sources will be mounted.


BUNDLING_OUTPUT_DIRRequired

public java.lang.String getBundlingOutputDir();
  • Type: java.lang.String

The directory inside the bundling container into which the bundled output should be written.