Skip to content

Commit

Permalink
Generate post-processor argument docs from code.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsomething committed Aug 23, 2023
1 parent a91130d commit 54ae34a
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!-- Code generated from the comments of the Config struct in post-processor/digitalocean-import/post-processor.go; DO NOT EDIT MANUALLY -->

- `http_retry_max` (\*int) - The maximum number of retries for requests that fail with a 429 or 500-level error.
The default value is 5. Set to 0 to disable reties.

- `http_retry_wait_max` (\*float64) - The maximum wait time (in seconds) between failed API requests. Default: 30.0

- `http_retry_wait_min` (\*float64) - The minimum wait time (in seconds) between failed API requests. Default: 1.0

- `space_object_name` (string) - The name of the key used in the Space where the image file will be copied
to for import. This is treated as a [template engine](/docs/templates/legacy_json_templates/engine).
Therefore, you may use user variables and template functions in this field.
If not specified, this will default to `packer-import-{{timestamp}}`.

- `skip_clean` (bool) - Whether we should skip removing the image file uploaded to Spaces after
the import process has completed. "true" means that we should leave it in
the Space, "false" means to clean it out. Defaults to `false`.

- `image_tags` ([]string) - A list of tags to apply to the resulting imported image.

- `image_description` (string) - The description to set for the resulting imported image.

- `image_distribution` (string) - The name of the distribution to set for the resulting imported image.

- `timeout` (duration string | ex: "1h5m2s") - The length of time in minutes to wait for individual steps in the process
to successfully complete. This includes both importing the image from Spaces
as well as distributing the resulting image to additional regions. If not
specified, this will default to 20.

<!-- End of code generated from the comments of the Config struct in post-processor/digitalocean-import/post-processor.go; -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!-- Code generated from the comments of the Config struct in post-processor/digitalocean-import/post-processor.go; DO NOT EDIT MANUALLY -->

- `api_token` (string) - A personal access token used to communicate with the DigitalOcean v2 API.
This may also be set using the `DIGITALOCEAN_TOKEN` or
`DIGITALOCEAN_ACCESS_TOKEN` environmental variables.

- `spaces_key` (string) - The access key used to communicate with Spaces. This may also be set using
the `DIGITALOCEAN_SPACES_ACCESS_KEY` environmental variable.

- `spaces_secret` (string) - The secret key used to communicate with Spaces. This may also be set using
the `DIGITALOCEAN_SPACES_SECRET_KEY` environmental variable.

- `spaces_region` (string) - The name of the region, such as `nyc3`, in which to upload the image to Spaces.

- `space_name` (string) - The name of the specific Space where the image file will be copied to for
import. This Space must exist when the post-processor is run.

- `image_name` (string) - The name to be used for the resulting DigitalOcean custom image.

- `image_regions` ([]string) - A list of DigitalOcean regions, such as `nyc3`, where the resulting image
will be available for use in creating Droplets.

<!-- End of code generated from the comments of the Config struct in post-processor/digitalocean-import/post-processor.go; -->
52 changes: 2 additions & 50 deletions docs/post-processors/digitalocean-import.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,63 +50,15 @@ There are some configuration options available for the post-processor.

Required:

- `api_token` (string) - A personal access token used to communicate with
the DigitalOcean v2 API. This may also be set using the
`DIGITALOCEAN_TOKEN` or `DIGITALOCEAN_ACCESS_TOKEN` environmental variables.
`DIGITALOCEAN_API_TOKEN` is acceptable but will be deprecated in a future release.

- `spaces_key` (string) - The access key used to communicate with Spaces.
This may also be set using the `DIGITALOCEAN_SPACES_ACCESS_KEY`
environmental variable.

- `spaces_secret` (string) - The secret key used to communicate with Spaces.
This may also be set using the `DIGITALOCEAN_SPACES_SECRET_KEY`
environmental variable.

- `spaces_region` (string) - The name of the region, such as `nyc3`, in which
to upload the image to Spaces.

- `space_name` (string) - The name of the specific Space where the image file
will be copied to for import. This Space must exist when the
post-processor is run.

- `image_name` (string) - The name to be used for the resulting DigitalOcean
custom image.

- `image_regions` (array of string) - A list of DigitalOcean regions, such
as `nyc3`, where the resulting image will be available for use in creating
Droplets.
@include 'post-processor/digitalocean-import/Config-required.mdx'

Optional:

- `image_description` (string) - The description to set for the resulting
imported image.

- `image_distribution` (string) - The name of the distribution to set for
the resulting imported image.

- `image_tags` (array of strings) - A list of tags to apply to the resulting
imported image.
@include 'post-processor/digitalocean-import/Config-required.mdx'

- `keep_input_artifact` (boolean) - if true, do not delete the source virtual
machine image after importing it to the cloud. Defaults to false.

- `skip_clean` (boolean) - Whether we should skip removing the image file
uploaded to Spaces after the import process has completed. "true" means
that we should leave it in the Space, "false" means to clean it out.
Defaults to `false`.

- `space_object_name` (string) - The name of the key used in the Space where
the image file will be copied to for import. This is treated as a
[template engine](/docs/templates/legacy_json_templates/engine). Therefore, you
may use user variables and template functions in this field.
If not specified, this will default to `packer-import-{{timestamp}}`.

- `timeout` (number) - The length of time in minutes to wait for individual
steps in the process to successfully complete. This includes both importing
the image from Spaces as well as distributing the resulting image to
additional regions. If not specified, this will default to 20.

## Basic Example

Here is a basic example:
Expand Down
54 changes: 40 additions & 14 deletions post-processor/digitalocean-import/post-processor.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:generate packer-sdc struct-markdown
//go:generate packer-sdc mapstructure-to-hcl2 -type Config

package digitaloceanimport
Expand Down Expand Up @@ -35,27 +36,52 @@ const BuilderId = "packer.post-processor.digitalocean-import"
type Config struct {
common.PackerConfig `mapstructure:",squash"`

APIToken string `mapstructure:"api_token"`
SpacesKey string `mapstructure:"spaces_key"`
SpacesSecret string `mapstructure:"spaces_secret"`
// A personal access token used to communicate with the DigitalOcean v2 API.
// This may also be set using the `DIGITALOCEAN_TOKEN` or
// `DIGITALOCEAN_ACCESS_TOKEN` environmental variables.
APIToken string `mapstructure:"api_token" required:"true"`
// The access key used to communicate with Spaces. This may also be set using
// the `DIGITALOCEAN_SPACES_ACCESS_KEY` environmental variable.
SpacesKey string `mapstructure:"spaces_key" required:"true"`
// The secret key used to communicate with Spaces. This may also be set using
// the `DIGITALOCEAN_SPACES_SECRET_KEY` environmental variable.
SpacesSecret string `mapstructure:"spaces_secret" required:"true"`
// The maximum number of retries for requests that fail with a 429 or 500-level error.
// The default value is 5. Set to 0 to disable reties.
HTTPRetryMax *int `mapstructure:"http_retry_max" required:"false"`
// The maximum wait time (in seconds) between failed API requests. Default: 30.0
HTTPRetryWaitMax *float64 `mapstructure:"http_retry_wait_max" required:"false"`
// The minimum wait time (in seconds) between failed API requests. Default: 1.0
HTTPRetryWaitMin *float64 `mapstructure:"http_retry_wait_min" required:"false"`

SpacesRegion string `mapstructure:"spaces_region"`
SpaceName string `mapstructure:"space_name"`
ObjectName string `mapstructure:"space_object_name"`
SkipClean bool `mapstructure:"skip_clean"`
Tags []string `mapstructure:"image_tags"`
Name string `mapstructure:"image_name"`
Description string `mapstructure:"image_description"`
Distribution string `mapstructure:"image_distribution"`
ImageRegions []string `mapstructure:"image_regions"`

// The name of the region, such as `nyc3`, in which to upload the image to Spaces.
SpacesRegion string `mapstructure:"spaces_region" required:"true"`
// The name of the specific Space where the image file will be copied to for
// import. This Space must exist when the post-processor is run.
SpaceName string `mapstructure:"space_name" required:"true"`
// The name of the key used in the Space where the image file will be copied
// to for import. This is treated as a [template engine](/docs/templates/legacy_json_templates/engine).
// Therefore, you may use user variables and template functions in this field.
// If not specified, this will default to `packer-import-{{timestamp}}`.
ObjectName string `mapstructure:"space_object_name"`
// Whether we should skip removing the image file uploaded to Spaces after
// the import process has completed. "true" means that we should leave it in
// the Space, "false" means to clean it out. Defaults to `false`.
SkipClean bool `mapstructure:"skip_clean"`
// A list of tags to apply to the resulting imported image.
Tags []string `mapstructure:"image_tags"`
// The name to be used for the resulting DigitalOcean custom image.
Name string `mapstructure:"image_name" required:"true"`
// The description to set for the resulting imported image.
Description string `mapstructure:"image_description"`
// The name of the distribution to set for the resulting imported image.
Distribution string `mapstructure:"image_distribution"`
// A list of DigitalOcean regions, such as `nyc3`, where the resulting image
// will be available for use in creating Droplets.
ImageRegions []string `mapstructure:"image_regions" required:"true"`
// The length of time in minutes to wait for individual steps in the process
// to successfully complete. This includes both importing the image from Spaces
// as well as distributing the resulting image to additional regions. If not
// specified, this will default to 20.
Timeout time.Duration `mapstructure:"timeout"`

ctx interpolate.Context
Expand Down
14 changes: 7 additions & 7 deletions post-processor/digitalocean-import/post-processor.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 54ae34a

Please sign in to comment.