Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

feat(plugins/docker): add docker-ref plugin #3912

Merged
merged 4 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/3912.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
plugins/docker: Add new `docker-ref` for a build noop for referencing a Docker Image
```
109 changes: 109 additions & 0 deletions builtin/docker/ref/builder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package dockerref

import (
"github.com/hashicorp/go-argmapper"
"github.com/hashicorp/waypoint-plugin-sdk/docs"
"github.com/hashicorp/waypoint-plugin-sdk/terminal"
wpdocker "github.com/hashicorp/waypoint/builtin/docker"
empty "google.golang.org/protobuf/types/known/emptypb"
)

// Builder uses `docker build` to build a Docker iamge.
type Builder struct {
config BuilderConfig
}

// BuildFunc implements component.Builder
func (b *Builder) BuildFunc() interface{} {
return b.Build
}

// BuildODRFunc implements component.BuilderODR
func (b *Builder) BuildODRFunc() interface{} {
return b.Build
}

// BuilderConfig is the configuration structure for the registry.
type BuilderConfig struct {
// Image to pull
Image string `hcl:"image,attr"`
Tag string `hcl:"tag,attr"`
}

func (b *Builder) Documentation() (*docs.Documentation, error) {
doc, err := docs.New(docs.FromConfig(&BuilderConfig{}), docs.FromFunc(b.BuildFunc()))
if err != nil {
return nil, err
}

doc.Description(`
Use an existing, pre-built Docker image without modifying it.
`)

doc.Example(`
build {
use "docker-ref" {
image = "gcr.io/my-project/my-image"
tag = "abcd1234"
}
}
`)

doc.Input("component.Source")
doc.Output("docker.Image")

doc.SetField(
"image",
"The image to pull.",
docs.Summary(
"This should NOT include the tag (the value following the ':' in a Docker image).",
"Use `tag` to define the image tag.",
),
)

doc.SetField(
"tag",
"The tag of the image to pull.",
)

return doc, nil
}

// Config implements Configurable
func (b *Builder) Config() (interface{}, error) {
return &b.config, nil
}

// We use the struct form of arguments so that we can access named
// values (such as "HasRegistry").
type buildArgs struct {
argmapper.Struct

UI terminal.UI
}

func (b *Builder) Build(args buildArgs) (*wpdocker.Image, error) {
// Pull all the args out to top-level values. This is mostly done
// cause the struct was added later, but also because these are very common.
ui := args.UI
sg := ui.StepGroup()
defer sg.Wait()
step := sg.Add("")
defer func() {
if step != nil {
step.Abort()
}
}()

result := &wpdocker.Image{
Image: b.config.Image,
Tag: b.config.Tag,
Location: &wpdocker.Image_Docker{Docker: &empty.Empty{}},
}

step.Update("Using Docker image in remote registry: %s", result.Name())
step.Done()

result.Location = &wpdocker.Image_Registry{Registry: &wpdocker.Image_RegistryLocation{}}
return result, nil
}
10 changes: 10 additions & 0 deletions builtin/docker/ref/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package dockerref

import (
"github.com/hashicorp/waypoint-plugin-sdk"
)

// Options are the SDK options to use for instantiation.
var Options = []sdk.Option{
sdk.WithComponents(&Builder{}),
}
82 changes: 82 additions & 0 deletions embedJson/gen/builder-docker-ref.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"description": "\nUse an existing, pre-built Docker image without modifying it.\n",
"example": "build {\n use \"docker-ref\" {\n image = \"gcr.io/my-project/my-image\"\n tag = \"abcd1234\"\n }\n}",
"input": "component.Source",
"mappers": null,
"name": "docker-ref",
"optionalFields": null,
"output": "docker.Image",
"outputAttrs": [
{
"Field": "architecture",
"Type": "string",
"Synopsis": "",
"Summary": "",
"Optional": false,
"Default": "",
"EnvVar": "",
"Category": false,
"SubFields": null
},
{
"Field": "image",
"Type": "string",
"Synopsis": "",
"Summary": "",
"Optional": false,
"Default": "",
"EnvVar": "",
"Category": false,
"SubFields": null
},
{
"Field": "location",
"Type": "docker.isImage_Location",
"Synopsis": "",
"Summary": "",
"Optional": false,
"Default": "",
"EnvVar": "",
"Category": false,
"SubFields": null
},
{
"Field": "tag",
"Type": "string",
"Synopsis": "",
"Summary": "",
"Optional": false,
"Default": "",
"EnvVar": "",
"Category": false,
"SubFields": null
}
],
"outputAttrsHelp": "Output attributes can be used in your `waypoint.hcl` as [variables](/docs/waypoint-hcl/variables) via [`artifact`](/docs/waypoint-hcl/variables/artifact) or [`deploy`](/docs/waypoint-hcl/variables/deploy).",
"requiredFields": [
{
"Field": "image",
"Type": "string",
"Synopsis": "The image to pull.",
"Summary": "This should NOT include the tag (the value following the ':' in a Docker image). Use `tag` to define the image tag.",
"Optional": false,
"Default": "",
"EnvVar": "",
"Category": false,
"SubFields": null
},
{
"Field": "tag",
"Type": "string",
"Synopsis": "The tag of the image to pull.",
"Summary": "",
"Optional": false,
"Default": "",
"EnvVar": "",
"Category": false,
"SubFields": null
}
],
"type": "builder",
"use": "the [`use` stanza](/docs/waypoint-hcl/use) for this plugin."
}
8 changes: 8 additions & 0 deletions embedJson/gen/configsourcer-docker-ref.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"mappers": null,
"name": "docker-ref",
"optionalFields": null,
"requiredFields": null,
"type": "configsourcer",
"use": "`dynamic` for sourcing [configuration values](/docs/app-config/dynamic) or [input variable values](/docs/waypoint-hcl/variables/dynamic)."
}
8 changes: 8 additions & 0 deletions embedJson/gen/platform-docker-ref.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"mappers": null,
"name": "docker-ref",
"optionalFields": null,
"requiredFields": null,
"type": "platform",
"use": "the [`use` stanza](/docs/waypoint-hcl/use) for this plugin."
}
8 changes: 8 additions & 0 deletions embedJson/gen/registry-docker-ref.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"mappers": null,
"name": "docker-ref",
"optionalFields": null,
"requiredFields": null,
"type": "registry",
"use": "the [`use` stanza](/docs/waypoint-hcl/use) for this plugin."
}
8 changes: 8 additions & 0 deletions embedJson/gen/releasemanager-docker-ref.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"mappers": null,
"name": "docker-ref",
"optionalFields": null,
"requiredFields": null,
"type": "releasemanager",
"use": "the [`use` stanza](/docs/waypoint-hcl/use) for this plugin."
}
8 changes: 8 additions & 0 deletions embedJson/gen/task-docker-ref.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"mappers": null,
"name": "docker-ref",
"optionalFields": null,
"requiredFields": null,
"type": "task",
"use": "the [`use` stanza](/docs/waypoint-hcl/use) for this plugin."
}
2 changes: 2 additions & 0 deletions internal/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package plugin
import (
sdk "github.com/hashicorp/waypoint-plugin-sdk"
"github.com/hashicorp/waypoint-plugin-sdk/component"
dockerref "github.com/hashicorp/waypoint/builtin/docker/ref"
"github.com/hashicorp/waypoint/builtin/nomad/canary"
"github.com/hashicorp/waypoint/internal/factory"

Expand Down Expand Up @@ -40,6 +41,7 @@ var (
"pack": pack.Options,
"docker": docker.Options,
"docker-pull": dockerpull.Options,
"docker-ref": dockerref.Options,
"exec": exec.Options,
"google-cloud-run": cloudrun.Options,
"azure-container-instance": aci.Options,
Expand Down
61 changes: 61 additions & 0 deletions website/content/partials/components/builder-docker-ref.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
## docker-ref (builder)

Use an existing, pre-built Docker image without modifying it.

### Interface

- Input: **component.Source**
- Output: **docker.Image**

### Examples

```hcl
build {
use "docker-ref" {
image = "gcr.io/my-project/my-image"
tag = "abcd1234"
}
}
```

### Required Parameters

These parameters are used in the [`use` stanza](/docs/waypoint-hcl/use) for this plugin.

#### image

The image to pull.

This should NOT include the tag (the value following the ':' in a Docker image). Use `tag` to define the image tag.

- Type: **string**

#### tag

The tag of the image to pull.

- Type: **string**

### Optional Parameters

This plugin has no optional parameters.

### Output Attributes

Output attributes can be used in your `waypoint.hcl` as [variables](/docs/waypoint-hcl/variables) via [`artifact`](/docs/waypoint-hcl/variables/artifact) or [`deploy`](/docs/waypoint-hcl/variables/deploy).

#### architecture

- Type: **string**

#### image

- Type: **string**

#### location

- Type: **docker.isImage_Location**

#### tag

- Type: **string**
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## docker-ref (configsourcer)

### Required Parameters

This plugin has no required parameters.

### Optional Parameters

This plugin has no optional parameters.
11 changes: 11 additions & 0 deletions website/content/partials/components/platform-docker-ref.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## docker-ref (platform)

### Interface

### Required Parameters

This plugin has no required parameters.

### Optional Parameters

This plugin has no optional parameters.
11 changes: 11 additions & 0 deletions website/content/partials/components/registry-docker-ref.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## docker-ref (registry)

### Interface

### Required Parameters

This plugin has no required parameters.

### Optional Parameters

This plugin has no optional parameters.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## docker-ref (releasemanager)

### Interface

### Required Parameters

This plugin has no required parameters.

### Optional Parameters

This plugin has no optional parameters.
11 changes: 11 additions & 0 deletions website/content/partials/components/task-docker-ref.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## docker-ref (task)

### Interface

### Required Parameters

This plugin has no required parameters.

### Optional Parameters

This plugin has no optional parameters.
2 changes: 2 additions & 0 deletions website/content/plugins/docker.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Learn](https://learn.hashicorp.com/collections/waypoint/get-started-docker).

@include "components/builder-docker-pull.mdx"

@include "components/builder-docker-ref.mdx"

@include "components/registry-docker.mdx"

@include "components/platform-docker.mdx"
Expand Down