packer-plugin
This module automates the complete Packer plugin build and installation process:- Detects version management patterns (VERSION file, hardcoded, ldflags)
- Builds plugins with proper ldflags to eliminate -dev suffixes
- Installs plugins using HashiCorp Packer container
- Manages .gitignore entries for plugin binaries
Key features:
- Auto-detect plugin name from directory structure
- Support any git hosting service (GitHub, GitLab, private servers)
- Containerized operations for reproducibility
- Single workflow combining build and install phases
Installation
dagger install github.com/solomonhd/dagger-packer-plugin@v2.0.0Entrypoint
Return Type
PackerPlugin ! Example
dagger -m github.com/solomonhd/dagger-packer-plugin@fc1679f17d2c20938c4b45676ebc60bf5a539c98 call \
func (m *MyModule) Example() *dagger.PackerPlugin {
return dag.
PackerPlugin()
}@function
def example() -> dagger.PackerPlugin:
return (
dag.packer_plugin()
)@func()
example(): PackerPlugin {
return dag
.packerPlugin()
}Types
PackerPlugin 🔗
Automate Packer plugin builds and installations with proper versioning.
buildArtifacts() 🔗
Build complete production-ready plugin artifacts (binary + checksum + metadata).
This is the recommended workflow for most use cases. It builds the plugin binary,
creates checksum files, and packages everything according to Packer plugin
distribution conventions. The output is ready for distribution or local installation
via packer plugins install --path.
For development workflows where you only need the compiled binary without checksums, consider using build_binary() instead.
Supports cross-compilation by setting GOOS and GOARCH environment variables. When building for Windows (target_os=windows), the binary will have .exe extension.
Git source is determined by priority: 1. Explicit –git-source parameter 2. Auto-detected from go.mod module path 3. Error (git-source is required)
Go version is determined by priority: 1. Explicit –go-version parameter 2. .go-version file in source directory 3. Default fallback (1.21)
Note: git_source and plugin_name are automatically normalized to lowercase per HashiCorp Packer’s requirements. A warning is output if normalization occurs.
Args: source: Plugin source directory git_source: Git import path (auto-detected from go.mod if not provided) version: Semantic version string plugin_name: Override auto-detected plugin name use_version_file: Read version from VERSION file update_version_file: Update VERSION file before build go_version: Go container image version (auto-detected from .go-version if not provided) packer_version: Packer container image version target_os: Target OS for cross-compilation (linux, darwin, windows) target_arch: Target architecture for cross-compilation (amd64, arm64, 386)
Returns: Directory with complete plugin artifacts (binary + checksum + metadata) ready for distribution
Example:
dagger call build-artifacts
–source=.
–use-version-file
export –path=.
Return Type
Directory !Arguments
| Name | Type | Default Value | Description |
|---|---|---|---|
| source | Directory ! | - | Plugin source directory containing Go code (use --source=. for your project) |
| gitSource | String | null | Git path for the plugin. Auto-detected from go.mod if not provided. Automatically normalized to lowercase. |
| version | String | null | Semantic version (e.g., 1.0.10). Required unless use_version_file is true |
| pluginName | String | null | Plugin name override (auto-detected from git_source if not provided). Automatically normalized to lowercase. |
| useVersionFile | Boolean ! | false | Use VERSION file from source as version (default: false) |
| updateVersionFile | Boolean ! | false | Update VERSION file with provided version before build (default: false) |
| goVersion | String | null | Go version for building. Auto-detected from .go-version file if not provided, defaults to 1.21 |
| packerVersion | String ! | "latest" | Packer image version for installation (default: latest) |
| targetOs | String ! | "linux" | Target operating system for cross-compilation (default: linux) |
| targetArch | String ! | "amd64" | Target CPU architecture for cross-compilation (default: amd64) |
Example
dagger -m github.com/solomonhd/dagger-packer-plugin@fc1679f17d2c20938c4b45676ebc60bf5a539c98 call \
build-artifacts --source DIR_PATH --use-version-file boolean --update-version-file boolean --packer-version string --target-os string --target-arch stringfunc (m *MyModule) Example(source *dagger.Directory, useVersionFile bool, updateVersionFile bool, packerVersion string, targetOs string, targetArch string) *dagger.Directory {
return dag.
PackerPlugin().
BuildArtifacts(source, useVersionFile, updateVersionFile, packerVersion, targetOs, targetArch)
}@function
def example(source: dagger.Directory, use_version_file: bool, update_version_file: bool, packer_version: str, target_os: str, target_arch: str) -> dagger.Directory:
return (
dag.packer_plugin()
.build_artifacts(source, use_version_file, update_version_file, packer_version, target_os, target_arch)
)@func()
example(source: Directory, useVersionFile: boolean, updateVersionFile: boolean, packerVersion: string, targetOs: string, targetArch: string): Directory {
return dag
.packerPlugin()
.buildArtifacts(source, useVersionFile, updateVersionFile, packerVersion, targetOs, targetArch)
}buildBinary() 🔗
Build only the raw Go binary for a Packer plugin (intermediate/development use).
This function compiles the plugin binary with proper ldflags that clear VersionPrerelease to avoid -dev suffixes. It returns a container with only the compiled binary - no checksums or metadata files. This is useful for development workflows or when you need just the binary.
For production use, consider using build_artifacts() instead, which creates the complete plugin package (binary + checksum + metadata) ready for distribution or installation.
Supports cross-compilation by setting GOOS and GOARCH environment variables. When building for Windows (target_os=windows), the binary will have .exe extension.
Git source is determined by priority: 1. Explicit –git-source parameter 2. Auto-detected from go.mod module path 3. Error (git-source is required)
Go version is determined by priority: 1. Explicit –go-version parameter 2. .go-version file in source directory 3. Default fallback (1.21)
Note: git_source and plugin_name are automatically normalized to lowercase per HashiCorp Packer’s requirements. A warning is output if normalization occurs.
Args: source: Plugin source directory git_source: Git import path for ldflags (auto-detected from go.mod if not provided) version: Semantic version string plugin_name: Override auto-detected plugin name use_version_file: Read version from VERSION file update_version_file: Update VERSION file before build go_version: Go container image version (auto-detected from .go-version if not provided) target_os: Target OS for cross-compilation (linux, darwin, windows) target_arch: Target architecture for cross-compilation (amd64, arm64, 386)
Returns: Container with built plugin binary at /work/packer-plugin-{name}[.exe]
Return Type
Container !Arguments
| Name | Type | Default Value | Description |
|---|---|---|---|
| source | Directory ! | - | Plugin source directory containing Go code (use --source=. for your project) |
| gitSource | String | null | Git path for the plugin. Auto-detected from go.mod if not provided. Automatically normalized to lowercase. |
| version | String | null | Semantic version (e.g., 1.0.10). Required unless use_version_file is true |
| pluginName | String | null | Plugin name override (auto-detected from directory name if not provided). Automatically normalized to lowercase. |
| useVersionFile | Boolean ! | false | Use VERSION file from source as version (default: false) |
| updateVersionFile | Boolean ! | false | Update VERSION file with provided version before build (default: false) |
| goVersion | String | null | Go version for building. Auto-detected from .go-version file if not provided, defaults to 1.21 |
| targetOs | String ! | "linux" | Target operating system for cross-compilation (default: linux) |
| targetArch | String ! | "amd64" | Target CPU architecture for cross-compilation (default: amd64) |
Example
dagger -m github.com/solomonhd/dagger-packer-plugin@fc1679f17d2c20938c4b45676ebc60bf5a539c98 call \
build-binary --source DIR_PATH --use-version-file boolean --update-version-file boolean --target-os string --target-arch stringfunc (m *MyModule) Example(source *dagger.Directory, useVersionFile bool, updateVersionFile bool, targetOs string, targetArch string) *dagger.Container {
return dag.
PackerPlugin().
BuildBinary(source, useVersionFile, updateVersionFile, targetOs, targetArch)
}@function
def example(source: dagger.Directory, use_version_file: bool, update_version_file: bool, target_os: str, target_arch: str) -> dagger.Container:
return (
dag.packer_plugin()
.build_binary(source, use_version_file, update_version_file, target_os, target_arch)
)@func()
example(source: Directory, useVersionFile: boolean, updateVersionFile: boolean, targetOs: string, targetArch: string): Container {
return dag
.packerPlugin()
.buildBinary(source, useVersionFile, updateVersionFile, targetOs, targetArch)
}detectVersion() 🔗
Analyze plugin source code to detect how version information is managed.
Returns JSON report with version_source, version_file, current_version, and version_package fields.
Args: source: Plugin source directory containing Go code
Returns: JSON string with detection results
Return Type
String !Arguments
| Name | Type | Default Value | Description |
|---|---|---|---|
| source | Directory ! | - | Plugin source directory (use --source=. for your project) |
Example
dagger -m github.com/solomonhd/dagger-packer-plugin@fc1679f17d2c20938c4b45676ebc60bf5a539c98 call \
detect-version --source DIR_PATHfunc (m *MyModule) Example(ctx context.Context, source *dagger.Directory) string {
return dag.
PackerPlugin().
DetectVersion(ctx, source)
}@function
async def example(source: dagger.Directory) -> str:
return await (
dag.packer_plugin()
.detect_version(source)
)@func()
async example(source: Directory): Promise<string> {
return dag
.packerPlugin()
.detectVersion(source)
}installPlugin() 🔗
Install a built Packer plugin using HashiCorp Packer container.
This function runs packer plugins install to register the plugin
and generate checksum files, then returns the installation artifacts.
Note: git_source and plugin_name are automatically normalized to lowercase per HashiCorp Packer’s requirements. A warning is output if normalization occurs.
Args: build_container: Container with built binary from build_binary git_source: Git path for plugin registration plugin_name: Plugin name override packer_version: Packer container image version
Returns: Directory containing installation artifacts (binary + checksum)
Return Type
Directory !Arguments
| Name | Type | Default Value | Description |
|---|---|---|---|
| buildContainer | Container ! | - | Container with built plugin binary (from build_binary) |
| gitSource | String ! | - | Git path for plugin registration (e.g., github.com/user/packer-plugin-example). Automatically normalized to lowercase. |
| pluginName | String | null | Plugin name (auto-detected from git_source if not provided). Automatically normalized to lowercase. |
| packerVersion | String ! | "latest" | Packer image version to use (default: latest) |
Example
dagger -m github.com/solomonhd/dagger-packer-plugin@fc1679f17d2c20938c4b45676ebc60bf5a539c98 call \
install-plugin --build-container IMAGE:TAG --git-source string --packer-version stringfunc (m *MyModule) Example(buildContainer *dagger.Container, gitSource string, packerVersion string) *dagger.Directory {
return dag.
PackerPlugin().
InstallPlugin(buildContainer, gitSource, packerVersion)
}@function
def example(build_container: dagger.Container, git_source: str, packer_version: str) -> dagger.Directory:
return (
dag.packer_plugin()
.install_plugin(build_container, git_source, packer_version)
)@func()
example(buildContainer: Container, gitSource: string, packerVersion: string): Directory {
return dag
.packerPlugin()
.installPlugin(buildContainer, gitSource, packerVersion)
}prepGitignore() 🔗
Update .gitignore to exclude Packer plugin build artifacts.
This function reads the existing .gitignore (or creates a new one) and adds entries for plugin binaries and checksum files if not already present. Plugin name is auto-detected from go.mod module path if not provided.
Patterns added: - packer-plugin-{name} (base binary) - packer-plugin-{name}_v* (versioned binaries for all OS/arch combinations) - *_SHA256SUM (checksum files)
Note: plugin_name is automatically normalized to lowercase per HashiCorp Packer’s requirements.
Args: source: Plugin source directory with existing or new .gitignore plugin_name: Plugin name override (without packer-plugin- prefix)
Returns: Updated .gitignore file
Return Type
File !Arguments
| Name | Type | Default Value | Description |
|---|---|---|---|
| source | Directory ! | - | Plugin source directory containing .gitignore (use --source=. for your project) |
| pluginName | String | null | Plugin name override (auto-detected from go.mod if not provided). Automatically normalized to lowercase. |
Example
dagger -m github.com/solomonhd/dagger-packer-plugin@fc1679f17d2c20938c4b45676ebc60bf5a539c98 call \
prep-gitignore --source DIR_PATHfunc (m *MyModule) Example(source *dagger.Directory) *dagger.File {
return dag.
PackerPlugin().
PrepGitignore(source)
}@function
def example(source: dagger.Directory) -> dagger.File:
return (
dag.packer_plugin()
.prep_gitignore(source)
)@func()
example(source: Directory): File {
return dag
.packerPlugin()
.prepGitignore(source)
}