Skip to content

Commit

Permalink
Allow create and update to take specific inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
jpreese committed Jul 4, 2020
1 parent af8c47b commit e757112
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 29 deletions.
30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Releases are also provided in the releases tab on GitHub.

## The image manifest

All commands either create, update, or read from the image manifest (`.images.yaml`).
All commands either create, update, or read from the image manifest (`.images.yaml`).

While the `create` and `update` commands assist with managing the image manifest, the `push` command will not modify the image manifest. Allowing you to manually control the manifest if desired.

Expand Down Expand Up @@ -69,16 +69,14 @@ Create an image manifest that includes a target registry and a collection of ima
$ sinker create --target mycompany.com/myteam
```
#### --target flag (required)
Specifies the target registry (and optionally a repository) to sync the images to
#### Passing in a directory or file
#### --autodetect flag (optional)
Find all image references in the file or directory that was passed in.
While this tool is not Kubernetes specific, currently the `create` and `update` commands find all Kubernetes manifests and extracts the image references from them. This includes images specified in container arguments as well as CRDs such as `Prometheus` and `Alertmanager`.
While this tool is not Kubernetes specific, currently the `create` and `update` commands can take a file or directory to find all Kubernetes manifests and extract the image references from them. This includes images specified in container arguments as well as CRDs such as `Prometheus` and `Alertmanager`.
```
$ sinker create --target mycompany.com/myteam --autodetect
$ sinker create example/bundle.yaml --target mycompany.com/myteam
```
```yaml
Expand All @@ -97,6 +95,10 @@ images:
source: quay.io
```

#### --target flag (required)

Specifies the target registry (and optionally a repository) to sync the images to

#### Push command

Push all of the images inside of the image manifest to the target registry.
Expand All @@ -111,12 +113,12 @@ The `--dryrun` flag will print out a summary of the images that do not exist at

### Update command

Updates the current image manifest to reflect new changes found in the Kubernetes manifest(s).

```
$ sinker update
$ sinker update <file|directory>
```

Updates the current manifest to reflect new changes to Kubernetes manifests.

_NOTE: The update command will ONLY update image **versions**. This allows for pinning of certain fields you want to manage yourself (source registry, auth)_

#### --target flag (optional)
Expand All @@ -125,20 +127,20 @@ If desired, you can set a new target in the image manifest by using --target dur

### List command

Prints a list of either the `source` or `target` images that exist in the image manifest. This can be useful for piping into additional tooling that acts on image urls.

```
$ sinker list target
```

Prints a list of either the `source` or `target` images. This can be useful for piping into additional tooling that acts on image urls.

#### --output flag (optional)

Outputs the list to a file (e.g. `images.txt`)

### Check command

Checks if any of the images found in the image manifest have new updates. Currently only works for the source images that are hosted on Docker Hub.

```
$ sinker check
```

Checks if any of the images found in the image manifest have new updates. Currently only works for the source images that are hosted on Docker Hub.
6 changes: 3 additions & 3 deletions internal/commands/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func newCheckCommand(ctx context.Context, logger *log.Logger) *cobra.Command {

RunE: func(cmd *cobra.Command, args []string) error {
if err := runCheckCommand(ctx, logger, "."); err != nil {
return fmt.Errorf("run check: %w", err)
return fmt.Errorf("check: %w", err)
}

return nil
Expand All @@ -40,7 +40,7 @@ func runCheckCommand(ctx context.Context, logger *log.Logger, path string) error
return fmt.Errorf("new registry: %w", err)
}

manifest, err := getManifest(path)
manifest, err := getManifest()
if err != nil {
return fmt.Errorf("get manifest: %w", err)
}
Expand All @@ -53,7 +53,7 @@ func runCheckCommand(ctx context.Context, logger *log.Logger, path string) error

imageVersion, err := version.NewVersion(image.Version)
if err != nil {
logger.Printf("Image %s weird versioning. Skipping ...", image.Source())
logger.Printf("Image %s version did not parse correctly. Skipping ...", image.Source())
continue
}

Expand Down
12 changes: 6 additions & 6 deletions internal/commands/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,12 @@ func newCreateCommand() *cobra.Command {
return fmt.Errorf("bind target flag: %w", err)
}

if err := viper.BindPFlag("autodetect", cmd.Flags().Lookup("autodetect")); err != nil {
return fmt.Errorf("bind autodetect flag: %w", err)
var path string
if len(args) > 0 {
path = args[0]
}

if err := runCreateCommand("."); err != nil {
if err := runCreateCommand(path); err != nil {
return fmt.Errorf("create: %w", err)
}

Expand All @@ -116,7 +117,6 @@ func newCreateCommand() *cobra.Command {
}

cmd.Flags().StringP("target", "t", "", "The target repository to sync images to (e.g. organization.com/repo)")
cmd.Flags().Bool("autodetect", false, "Perform autodetection when creating the image manifest")

return &cmd
}
Expand All @@ -133,7 +133,7 @@ func runCreateCommand(path string) error {
var imageManifest ImageManifest
imageManifest.Target = newTarget(viper.GetString("target"))

if viper.GetBool("autodetect") {
if path != "" {
foundImages, err := getFromKubernetesManifests(path, imageManifest.Target)
if err != nil {
return fmt.Errorf("get from kubernetes manifests: %w", err)
Expand Down Expand Up @@ -190,9 +190,9 @@ func marshalImages(images []string, target Target) ([]ContainerImage, error) {
imageReference = reference.TagNameOnly(imageReference)

imageRepository := reference.Path(imageReference)

if target.Repository != "" {
imageRepository = strings.Replace(imageRepository, target.Repository+"/", "", 1)
imageRepository = strings.Replace(imageRepository, "library/", "", 1)
} else {
imageRepository = strings.Replace(imageRepository, target.Repository, "", 1)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func newListCommand() *cobra.Command {
}

func runListCommand(path string, location string) error {
manifest, err := getManifest(path)
manifest, err := getManifest()
if err != nil {
return fmt.Errorf("get manifest: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func runPushCommand(ctx context.Context, logger *log.Logger, path string) error
return fmt.Errorf("new docker client: %w", err)
}

manifest, err := getManifest(path)
manifest, err := getManifest()
if err != nil {
return fmt.Errorf("get manifest: %w", err)
}
Expand Down
9 changes: 5 additions & 4 deletions internal/commands/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ func newUpdateCommand() *cobra.Command {
cmd := cobra.Command{
Use: "update <source>",
Short: "Update an existing image manifest",
Args: cobra.ExactArgs(1),

RunE: func(cmd *cobra.Command, args []string) error {
if err := viper.BindPFlag("target", cmd.Flags().Lookup("target")); err != nil {
return fmt.Errorf("bind target flag: %w", err)
}

if err := runUpdateCommand("."); err != nil {
return fmt.Errorf("create: %w", err)
if err := runUpdateCommand(args[0]); err != nil {
return fmt.Errorf("update: %w", err)
}

return nil
Expand All @@ -38,7 +39,7 @@ func runUpdateCommand(path string) error {
return fmt.Errorf("manifest %s not found in current directory", manifestFileName)
}

imageManifest, err := getManifest(path)
imageManifest, err := getManifest()
if err != nil {
return fmt.Errorf("get manifest: %w", err)
}
Expand All @@ -64,7 +65,7 @@ func runUpdateCommand(path string) error {
return nil
}

func getManifest(path string) (ImageManifest, error) {
func getManifest() (ImageManifest, error) {
imageManifestContents, err := ioutil.ReadFile(manifestFileName)
if err != nil {
return ImageManifest{}, fmt.Errorf("reading manifest: %w", err)
Expand Down

0 comments on commit e757112

Please sign in to comment.