compute

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2022 License: Apache-2.0 Imports: 44 Imported by: 0

Documentation

Overview

Package compute contains commands to manage Compute@Edge packages.

Index

Constants

View Source
const ASSourceDirectory = "assembly"

ASSourceDirectory represents the source code directory.

View Source
const IgnoreFilePath = ".fastlyignore"

IgnoreFilePath is the filepath name of the Fastly ignore file.

View Source
const JSSourceDirectory = "src"

JSSourceDirectory represents the source code directory.

View Source
const JsToolchain = "npm"

JsToolchain represents the default JS toolchain.

View Source
const RustSourceDirectory = "src"

RustSourceDirectory represents the source code directory.

Variables

View Source
var InstallDir = func() string {
	if dir, err := os.UserConfigDir(); err == nil {
		return filepath.Join(dir, "fastly")
	}
	if dir, err := os.UserHomeDir(); err == nil {
		return filepath.Join(dir, ".fastly")
	}
	panic("unable to deduce user config dir or user home dir")
}()

InstallDir represents the directory where the Viceroy binary should be installed.

NOTE: This is a package level variable as it makes testing the behaviour of the package easier because the test code can replace the value when running the test suite.

View Source
var Languages = []string{"rust", "assemblyscript", "javascript", "other"}
View Source
var PackageSizeLimit int64 = 50000000

PackageSizeLimit describes the package size limit in bytes (currently 50mb) https://docs.fastly.com/products/compute-at-edge-billing-and-resource-limits#resource-limits

Functions

func CreatePackageArchive

func CreatePackageArchive(files []string, destination string) error

CreatePackageArchive packages build artifacts as a Fastly package, which must be a GZipped Tar archive such as: package-name.tar.gz.

Due to a behavior of archiver.Archive() which recursively writes all files in a provided directory to the archive we first copy our input files to a temporary directory to ensure only the specified files are included and not any in the directory which may be ignored.

func FileNameWithoutExtension

func FileNameWithoutExtension(filename string) string

FileNameWithoutExtension returns a filename with its extension stripped.

func GetCrateVersionFromMetadata

func GetCrateVersionFromMetadata(metadata CargoMetadata, crate string) (*semver.Version, error)

GetCrateVersionFromMetadata searches for a crate inside a CargoMetadata tree and returns the crates version as a semver.Version.

func GetIgnoredFiles

func GetIgnoredFiles(filePath string) (files map[string]bool, err error)

GetIgnoredFiles reads the .fastlyignore file line-by-line and expands the glob pattern into a map containing all files it matches. If no ignore file is present it returns an empty map.

func GetLatestCrateVersion

func GetLatestCrateVersion(client api.HTTPClient, name string, errlog fsterr.LogInterface) (*semver.Version, error)

GetLatestCrateVersion fetches all versions of a given Rust crate from the crates.io HTTP API and returns the latest valid semver version.

func GetNonIgnoredFiles

func GetNonIgnoredFiles(base string, ignoredFiles map[string]bool) ([]string, error)

GetNonIgnoredFiles walks a filepath and returns all files don't exist in the provided ignore files map.

func SetPackageName added in v1.7.0

func SetPackageName(name, path string) (err error)

SetPackageName into package.json manifest.

NOTE: We can't presume to know the structure of the package.json manifest, and so we use the json package to unmarshal the entire file into a generic map data structure before updating the name field and marshalling it back to json afterwards.

Types

type AssemblyScript

type AssemblyScript struct {
	JavaScript
	// contains filtered or unexported fields
}

AssemblyScript implements a Toolchain for the AssemblyScript language.

NOTE: We embed the JavaScript type as the behaviours across both languages are fundamentally the same with some minor differences. This means we don't need to duplicate the Verify() implementation, while the Build() method can be kept unique between the two languages. Additionally the JavaScript Verify() method has an extra validation step that is skipped for AssemblyScript as it doesn't set the `validateScriptBuild` field.

func NewAssemblyScript

func NewAssemblyScript(timeout int, pkgName, build string, errlog fsterr.LogInterface) *AssemblyScript

NewAssemblyScript constructs a new AssemblyScript.

func (AssemblyScript) Build

func (a AssemblyScript) Build(out, progress io.Writer, verbose bool) error

Build implements the Toolchain interface and attempts to compile the package AssemblyScript source to a Wasm binary.

type BuildCommand

type BuildCommand struct {
	cmd.Base

	// NOTE: these are public so that the "serve" and "publish" composite
	// commands can set the values appropriately before calling Exec().
	Flags    Flags
	Manifest manifest.Data
}

BuildCommand produces a deployable artifact from files on the local disk.

func NewBuildCommand

func NewBuildCommand(parent cmd.Registerer, globals *config.Data, data manifest.Data) *BuildCommand

NewBuildCommand returns a usable command registered under the parent.

func (*BuildCommand) Exec

func (c *BuildCommand) Exec(in io.Reader, out io.Writer) (err error)

Exec implements the command interface.

type CargoCrateVersion

type CargoCrateVersion struct {
	Version string `json:"num"`
}

CargoCrateVersion models a Cargo crate version returned by the crates.io API.

type CargoCrateVersions

type CargoCrateVersions struct {
	Versions []CargoCrateVersion `json:"versions"`
}

CargoCrateVersions models a Cargo crate version returned by the crates.io API.

type CargoManifest

type CargoManifest struct {
	Package CargoPackage `toml:"package"`
}

CargoManifest models the package configuration properties of a Rust Cargo manifest which we are interested in and are read from the Cargo.toml manifest file within the $PWD of the package.

func (*CargoManifest) Read

func (m *CargoManifest) Read(path string) error

Read the contents of the Cargo.toml manifest from filename.

func (*CargoManifest) SetPackageName added in v1.7.0

func (m *CargoManifest) SetPackageName(name, path string) error

SetPackageName into Cargo.toml manifest.

NOTE: We can't presume to know the structure of the Cargo manifest, and so we use the toml library's tree API to load the file into a tree structure before using the tree API to update the name field and marshalling it back to toml afterwards.

type CargoMetadata

type CargoMetadata struct {
	Package         []CargoMetadataPackage `json:"packages"`
	TargetDirectory string                 `json:"target_directory"`
}

CargoMetadata models information about the workspace members and resolved dependencies of the current package via `cargo metadata` command output.

func (*CargoMetadata) Read

func (m *CargoMetadata) Read(errlog fsterr.LogInterface) error

Read the contents of the Cargo.lock file from filename.

type CargoMetadataPackage added in v1.7.0

type CargoMetadataPackage struct {
	Name         string                 `toml:"name" json:"name"`
	Version      string                 `toml:"version" json:"version"`
	Dependencies []CargoMetadataPackage `toml:"dependencies" json:"dependencies"`
}

CargoMetadataPackage models the package structure returned when executing the command `cargo metadata`.

type CargoPackage

type CargoPackage struct {
	Name    string `toml:"name" json:"name"`
	Version string `toml:"version" json:"version"`
}

CargoPackage models the package configuration properties of a Rust Cargo package which we are interested in and is embedded within CargoManifest and CargoLock.

type DeployCommand

type DeployCommand struct {
	cmd.Base

	// NOTE: these are public so that the "publish" composite command can set the
	// values appropriately before calling the Exec() function.
	AcceptDefaults bool
	Comment        cmd.OptionalString
	Domain         string
	Manifest       manifest.Data
	Path           string
	ServiceName    cmd.OptionalServiceNameID
	ServiceVersion cmd.OptionalServiceVersion
}

DeployCommand deploys an artifact previously produced by build.

func NewDeployCommand

func NewDeployCommand(parent cmd.Registerer, globals *config.Data, data manifest.Data) *DeployCommand

NewDeployCommand returns a usable command registered under the parent.

func (*DeployCommand) Exec

func (c *DeployCommand) Exec(in io.Reader, out io.Writer) (err error)

Exec implements the command interface.

type Flags added in v1.4.0

type Flags struct {
	AcceptCustomBuild bool
	IncludeSrc        bool
	Lang              string
	PackageName       string
	SkipVerification  bool
	Timeout           int
}

Flags represents the flags defined for the command.

type InitCommand

type InitCommand struct {
	cmd.Base
	// contains filtered or unexported fields
}

InitCommand initializes a Compute@Edge project package on the local machine.

func NewInitCommand

func NewInitCommand(parent cmd.Registerer, globals *config.Data, data manifest.Data) *InitCommand

NewInitCommand returns a usable command registered under the parent.

func (*InitCommand) Exec

func (c *InitCommand) Exec(in io.Reader, out io.Writer) (err error)

Exec implements the command interface.

type JavaScript

type JavaScript struct {
	Shell
	// contains filtered or unexported fields
}

JavaScript implements a Toolchain for the JavaScript language.

func NewJavaScript

func NewJavaScript(timeout int, pkgName, build string, errlog fsterr.LogInterface) *JavaScript

NewJavaScript constructs a new JavaScript.

func (JavaScript) Build

func (j JavaScript) Build(out, progress io.Writer, verbose bool) error

Build implements the Toolchain interface and attempts to compile the package JavaScript source to a Wasm binary.

func (JavaScript) Initialize

func (j JavaScript) Initialize(out io.Writer) error

Initialize implements the Toolchain interface and initializes a newly cloned package by installing required dependencies.

func (JavaScript) Verify

func (j JavaScript) Verify(out io.Writer) error

Verify implements the Toolchain interface and verifies whether the JavaScript language toolchain is correctly configured on the host.

type Language

type Language struct {
	Name            string
	DisplayName     string
	StarterKits     []config.StarterKit
	SourceDirectory string
	IncludeFiles    []string

	Toolchain
}

Language models a Compute@Edge source language.

func NewLanguage

func NewLanguage(options *LanguageOptions) *Language

NewLanguage constructs a new Language from a LangaugeOptions.

func NewLanguages added in v0.41.0

func NewLanguages(kits config.StarterKitLanguages, d *config.Data, pkgName, customBuild string) []*Language

NewLanguages returns a list of supported programming languages.

NOTE: The 'timeout' value zero is passed into each New<Language> call as it's only useful during the `compute build` phase and is expected to be provided by the user via a flag on the build command.

type LanguageOptions

type LanguageOptions struct {
	Name            string
	DisplayName     string
	StarterKits     []config.StarterKit
	SourceDirectory string
	IncludeFiles    []string
	Toolchain       Toolchain
}

LanguageOptions models configuration options for a Language.

type Other added in v1.4.0

type Other struct {
	Shell
	// contains filtered or unexported fields
}

Other implements a Toolchain for languages without official support.

func NewOther added in v1.4.0

func NewOther(timeout int, build string, errlog fsterr.LogInterface) *Other

NewOther constructs a new unsupported language instance.

func (Other) Build added in v1.4.0

func (o Other) Build(out, progress io.Writer, verbose bool) error

Build implements the Toolchain interface and attempts to compile the package source to a Wasm binary.

func (Other) Initialize added in v1.4.0

func (o Other) Initialize(out io.Writer) error

No-op

func (Other) Verify added in v1.4.0

func (o Other) Verify(out io.Writer) error

No-op

type PackCommand

type PackCommand struct {
	cmd.Base
	// contains filtered or unexported fields
}

PackCommand takes a .wasm and builds the required tar/gzip package ready to be uploaded.

func NewPackCommand

func NewPackCommand(parent cmd.Registerer, globals *config.Data, data manifest.Data) *PackCommand

NewPackCommand returns a usable command registered under the parent.

func (*PackCommand) Exec

func (c *PackCommand) Exec(in io.Reader, out io.Writer) (err error)

Exec implements the command interface.

type PublishCommand

type PublishCommand struct {
	cmd.Base
	// contains filtered or unexported fields
}

PublishCommand produces and deploys an artifact from files on the local disk.

func NewPublishCommand

func NewPublishCommand(parent cmd.Registerer, globals *config.Data, build *BuildCommand, deploy *DeployCommand, data manifest.Data) *PublishCommand

NewPublishCommand returns a usable command registered under the parent.

func (*PublishCommand) Exec

func (c *PublishCommand) Exec(in io.Reader, out io.Writer) (err error)

Exec implements the command interface.

NOTE: unlike other non-aggregate commands that initialize a new text.Progress type for displaying progress information to the user, we don't use that in this command because the nested commands overlap the output in non-deterministic ways. It's best to leave those nested commands to handle the progress indicator.

type RootCommand

type RootCommand struct {
	cmd.Base
}

RootCommand is the parent command for all subcommands in this package. It should be installed under the primary root command.

func NewRootCommand

func NewRootCommand(parent cmd.Registerer, globals *config.Data) *RootCommand

NewRootCommand returns a new command registered in the parent.

func (*RootCommand) Exec

func (c *RootCommand) Exec(in io.Reader, out io.Writer) error

Exec implements the command interface.

type Rust

type Rust struct {
	Shell
	// contains filtered or unexported fields
}

Rust implements a Toolchain for the Rust language.

func NewRust

func NewRust(client api.HTTPClient, config config.Rust, errlog fsterr.LogInterface, timeout int, pkgName, build string) *Rust

NewRust constructs a new Rust.

func (*Rust) Build

func (r *Rust) Build(out, progress io.Writer, verbose bool) error

Build implements the Toolchain interface and attempts to compile the package Rust source to a Wasm binary.

func (Rust) IncludeFiles

func (r Rust) IncludeFiles() []string

IncludeFiles implements the Toolchain interface and returns a list of additional files to include in the package archive for Rust packages.

func (Rust) Initialize

func (r Rust) Initialize(out io.Writer) error

Initialize implements the Toolchain interface and initializes a newly cloned package. It is a noop for Rust as the Cargo toolchain handles these steps.

func (*Rust) Verify

func (r *Rust) Verify(out io.Writer) (err error)

Verify implements the Toolchain interface and verifies whether the Rust language toolchain is correctly configured on the host.

NOTE: Steps for validation are:

1. Validate `rustc` installed. 2. Validate `rustc --version` meets the constraint. 3. Validate `wasm32-wasi` target is added to the relevant toolchain. 4. Validate `cargo` is installed. 5. Validate `fastly-sys` crate version. 6. Validate `fastly` crate version (optional upgrade suggestion).

type ServeCommand

type ServeCommand struct {
	cmd.Base
	// contains filtered or unexported fields
}

ServeCommand produces and runs an artifact from files on the local disk.

func NewServeCommand

func NewServeCommand(parent cmd.Registerer, globals *config.Data, build *BuildCommand, viceroyVersioner update.Versioner, data manifest.Data) *ServeCommand

NewServeCommand returns a usable command registered under the parent.

func (*ServeCommand) Build added in v1.1.0

func (c *ServeCommand) Build(in io.Reader, out io.Writer) error

Build constructs and executes the build logic.

func (*ServeCommand) Exec

func (c *ServeCommand) Exec(in io.Reader, out io.Writer) (err error)

Exec implements the command interface.

type Shell added in v1.3.0

type Shell struct{}

Shell represents a subprocess shell used by `compute` environment where `[scripts.build]` has been defined within fastly.toml manifest.

func (Shell) Build added in v1.3.0

func (s Shell) Build(command string) (cmd string, args []string)

Build expects a command that can be prefixed with an appropriate subprocess shell.

Example: build = "yarn install && yarn build"

Should be converted into a command such as (on unix): sh -c "yarn install && yarn build"

type Toolchain

type Toolchain interface {
	Initialize(out io.Writer) error
	Verify(out io.Writer) error
	Build(out, progress io.Writer, verbose bool) error
}

Toolchain abstracts a Compute@Edge source language toolchain.

type UpdateCommand

type UpdateCommand struct {
	cmd.Base
	// contains filtered or unexported fields
}

UpdateCommand calls the Fastly API to update packages.

func NewUpdateCommand

func NewUpdateCommand(parent cmd.Registerer, globals *config.Data, data manifest.Data) *UpdateCommand

NewUpdateCommand returns a usable command registered under the parent.

func (*UpdateCommand) Exec

func (c *UpdateCommand) Exec(in io.Reader, out io.Writer) (err error)

Exec invokes the application logic for the command.

type ValidateCommand

type ValidateCommand struct {
	cmd.Base
	// contains filtered or unexported fields
}

ValidateCommand validates a package archive.

func NewValidateCommand

func NewValidateCommand(parent cmd.Registerer, globals *config.Data) *ValidateCommand

NewValidateCommand returns a usable command registered under the parent.

func (*ValidateCommand) Exec

func (c *ValidateCommand) Exec(in io.Reader, out io.Writer) error

Exec implements the command interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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