rewrite

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package rewrite provides functions to rewrite Dockerfiles and docker-compose files from a Lockfile.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Flags

type Flags struct {
	LockfilePath string
	Suffix       string
	TempDir      string
	ExcludeTags  bool
	Verbose      bool
}

Flags are all possible flags to initialize a Rewriter.

func NewFlags

func NewFlags(
	lPath string,
	suffix string,
	tmpDir string,
	excludeTags bool,
	verbose bool,
) (*Flags, error)

NewFlags creates flags for a Rewriter.

type Rewriter

type Rewriter struct {
	Lockfile    *generate.Lockfile
	Suffix      string
	TempDir     string
	ExcludeTags bool
}

Rewriter is used to rewrite base images in docker and docker-compose files with their digests.

func NewRewriter

func NewRewriter(flags *Flags) (*Rewriter, error)

NewRewriter creates a Rewriter from command line flags.

func (*Rewriter) Rewrite

func (r *Rewriter) Rewrite() (err error)

Rewrite rewrites docker and docker-compose files' base images with digests from a Lockfile.

Rewrite has "transaction"-like properties to ensure all rewrites succeed or fail together. The method follows the following steps:

(1) Create a temporary directory in the system default temporary directory location or in the location supplied via the command line arg.

(2) Rewrite every file to a file in the temporary directory.

(3) If all rewrites succeed, rename each temporary file to its desired outpath. Providing a suffix ensures that the temporary file will not overwrite the original. Instead, a new file of the form Dockerfile-suffix, docker-compose-suffix.yml, or docker-compose-suffix.yaml will be written.

(4) If an error occurs during renaming, revert all files back to their original content.

(5) If reverting fails, return an error with the paths that failed to revert.

(6) Delete the temporary directory.

Note: If the Lockfile references a Dockerfile and that same Dockerfile is referenced by another docker-compose file, the Dockerfile will be rewritten according to the docker-compose file.

Jump to

Keyboard shortcuts

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