Dagger
Search

dagger-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@0bced02dabb811bc66127e4160893706c86d650d

Entrypoint

Return Type
DaggerPackerPlugin !
Example
dagger -m github.com/SolomonHD/dagger-packer-plugin@0bced02dabb811bc66127e4160893706c86d650d call \
func (m *MyModule) Example() *dagger.DaggerPackerPlugin  {
	return dag.
			DaggerPackerPlugin()
}
@function
def example() -> dagger.DaggerPackerPlugin:
	return (
		dag.dagger_packer_plugin()
	)
@func()
example(): DaggerPackerPlugin {
	return dag
		.daggerPackerPlugin()
}

Types

DaggerPackerPlugin 🔗

Automate Packer plugin builds and installations with proper versioning.

buildAndInstall() 🔗

Build and install a Packer plugin in a single workflow.

This convenience function chains build_plugin and install_plugin, returning installation artifacts ready to export.

Args: source: Plugin source directory git_source: Git import path 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 packer_version: Packer container image version

Returns: Directory with installation artifacts (binary + checksum)

Example: dagger call build-and-install
–source=.
–git-source=github.com/user/packer-plugin-example
–version=1.0.0
export –path=.

Return Type
Directory !
Arguments
NameTypeDefault ValueDescription
sourceDirectory !-Plugin source directory containing Go code (use --source=. for your project)
gitSourceString !-Git path for the plugin (e.g., github.com/user/packer-plugin-example)
versionString nullSemantic version (e.g., 1.0.10). Required unless use_version_file is true
pluginNameString nullPlugin name override (auto-detected from git_source if not provided)
useVersionFileBoolean !falseUse VERSION file from source as version (default: false)
updateVersionFileBoolean !falseUpdate VERSION file with provided version before build (default: false)
goVersionString !"1.21"Go version for building (default: 1.21)
packerVersionString !"latest"Packer image version for installation (default: latest)
Example
dagger -m github.com/SolomonHD/dagger-packer-plugin@0bced02dabb811bc66127e4160893706c86d650d call \
 build-and-install --source DIR_PATH --git-source string --use-version-file boolean --update-version-file boolean --go-version string --packer-version string
func (m *MyModule) Example(source *dagger.Directory, gitSource string, useVersionFile bool, updateVersionFile bool, goVersion string, packerVersion string) *dagger.Directory  {
	return dag.
			DaggerPackerPlugin().
			BuildAndInstall(source, gitSource, useVersionFile, updateVersionFile, goVersion, packerVersion)
}
@function
def example(source: dagger.Directory, git_source: str, use_version_file: bool, update_version_file: bool, go_version: str, packer_version: str) -> dagger.Directory:
	return (
		dag.dagger_packer_plugin()
		.build_and_install(source, git_source, use_version_file, update_version_file, go_version, packer_version)
	)
@func()
example(source: Directory, gitSource: string, useVersionFile: boolean, updateVersionFile: boolean, goVersion: string, packerVersion: string): Directory {
	return dag
		.daggerPackerPlugin()
		.buildAndInstall(source, gitSource, useVersionFile, updateVersionFile, goVersion, packerVersion)
}

buildPlugin() 🔗

Build a Packer plugin using Go with proper ldflags.

This function compiles the plugin with ldflags that clear VersionPrerelease to avoid -dev suffixes that break Packer’s plugin discovery system.

Args: source: Plugin source directory git_source: Git import path for ldflags 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

Returns: Container with built plugin binary at /work/packer-plugin-{name}

Return Type
Container !
Arguments
NameTypeDefault ValueDescription
sourceDirectory !-Plugin source directory containing Go code (use --source=. for your project)
gitSourceString !-Git path for the plugin (e.g., github.com/user/packer-plugin-example)
versionString nullSemantic version (e.g., 1.0.10). Required unless use_version_file is true
pluginNameString nullPlugin name override (auto-detected from directory name if not provided)
useVersionFileBoolean !falseUse VERSION file from source as version (default: false)
updateVersionFileBoolean !falseUpdate VERSION file with provided version before build (default: false)
goVersionString !"1.21"Go version to use for building (default: 1.21)
Example
dagger -m github.com/SolomonHD/dagger-packer-plugin@0bced02dabb811bc66127e4160893706c86d650d call \
 build-plugin --source DIR_PATH --git-source string --use-version-file boolean --update-version-file boolean --go-version string
func (m *MyModule) Example(source *dagger.Directory, gitSource string, useVersionFile bool, updateVersionFile bool, goVersion string) *dagger.Container  {
	return dag.
			DaggerPackerPlugin().
			BuildPlugin(source, gitSource, useVersionFile, updateVersionFile, goVersion)
}
@function
def example(source: dagger.Directory, git_source: str, use_version_file: bool, update_version_file: bool, go_version: str) -> dagger.Container:
	return (
		dag.dagger_packer_plugin()
		.build_plugin(source, git_source, use_version_file, update_version_file, go_version)
	)
@func()
example(source: Directory, gitSource: string, useVersionFile: boolean, updateVersionFile: boolean, goVersion: string): Container {
	return dag
		.daggerPackerPlugin()
		.buildPlugin(source, gitSource, useVersionFile, updateVersionFile, goVersion)
}

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
NameTypeDefault ValueDescription
sourceDirectory !-Plugin source directory (use --source=. for your project)
Example
dagger -m github.com/SolomonHD/dagger-packer-plugin@0bced02dabb811bc66127e4160893706c86d650d call \
 detect-version --source DIR_PATH
func (m *MyModule) Example(ctx context.Context, source *dagger.Directory) string  {
	return dag.
			DaggerPackerPlugin().
			DetectVersion(ctx, source)
}
@function
async def example(source: dagger.Directory) -> str:
	return await (
		dag.dagger_packer_plugin()
		.detect_version(source)
	)
@func()
async example(source: Directory): Promise<string> {
	return dag
		.daggerPackerPlugin()
		.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.

Args: build_container: Container with built binary from build_plugin 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
NameTypeDefault ValueDescription
buildContainerContainer !-Container with built plugin binary (from build_plugin)
gitSourceString !-Git path for plugin registration (e.g., github.com/user/packer-plugin-example)
pluginNameString nullPlugin name (auto-detected from git_source if not provided)
packerVersionString !"latest"Packer image version to use (default: latest)
Example
dagger -m github.com/SolomonHD/dagger-packer-plugin@0bced02dabb811bc66127e4160893706c86d650d call \
 install-plugin --build-container IMAGE:TAG --git-source string --packer-version string
func (m *MyModule) Example(buildContainer *dagger.Container, gitSource string, packerVersion string) *dagger.Directory  {
	return dag.
			DaggerPackerPlugin().
			InstallPlugin(buildContainer, gitSource, packerVersion)
}
@function
def example(build_container: dagger.Container, git_source: str, packer_version: str) -> dagger.Directory:
	return (
		dag.dagger_packer_plugin()
		.install_plugin(build_container, git_source, packer_version)
	)
@func()
example(buildContainer: Container, gitSource: string, packerVersion: string): Directory {
	return dag
		.daggerPackerPlugin()
		.installPlugin(buildContainer, gitSource, packerVersion)
}

prepGitignore() 🔗

Update .gitignore to exclude Packer plugin binary.

This function reads the existing .gitignore (or creates a new one) and adds an entry for the plugin binary if not already present.

Args: plugin_name: Plugin name (without packer-plugin- prefix) target: Directory with existing or new .gitignore

Returns: Updated .gitignore file

Return Type
File !
Arguments
NameTypeDefault ValueDescription
pluginNameString !-Plugin name to add to gitignore (e.g., 'docker' for packer-plugin-docker)
targetDirectory !-Target directory containing or to contain .gitignore
Example
dagger -m github.com/SolomonHD/dagger-packer-plugin@0bced02dabb811bc66127e4160893706c86d650d call \
 prep-gitignore --plugin-name string --target DIR_PATH
func (m *MyModule) Example(pluginName string, target *dagger.Directory) *dagger.File  {
	return dag.
			DaggerPackerPlugin().
			PrepGitignore(pluginName, target)
}
@function
def example(plugin_name: str, target: dagger.Directory) -> dagger.File:
	return (
		dag.dagger_packer_plugin()
		.prep_gitignore(plugin_name, target)
	)
@func()
example(pluginName: string, target: Directory): File {
	return dag
		.daggerPackerPlugin()
		.prepGitignore(pluginName, target)
}