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@47a56f89322c810bc2ec5e962da9bdbb6f447b4c

Entrypoint

Return Type
DaggerPackerPlugin !
Example
dagger -m github.com/SolomonHD/dagger-packer-plugin@47a56f89322c810bc2ec5e962da9bdbb6f447b4c 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.

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 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

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). Automatically normalized to lowercase.
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). Automatically normalized to lowercase.
useVersionFileBoolean !falseUse VERSION file from source as version (default: false)
updateVersionFileBoolean !falseUpdate VERSION file with provided version before build (default: false)
goVersionString nullGo version for building. Auto-detected from .go-version file if not provided, defaults to 1.21
packerVersionString !"latest"Packer image version for installation (default: latest)
Example
dagger -m github.com/SolomonHD/dagger-packer-plugin@47a56f89322c810bc2ec5e962da9bdbb6f447b4c call \
 build-and-install --source DIR_PATH --git-source string --use-version-file boolean --update-version-file boolean --packer-version string
func (m *MyModule) Example(source *dagger.Directory, gitSource string, useVersionFile bool, updateVersionFile bool, packerVersion string) *dagger.Directory  {
	return dag.
			DaggerPackerPlugin().
			BuildAndInstall(source, gitSource, useVersionFile, updateVersionFile, packerVersion)
}
@function
def example(source: dagger.Directory, git_source: str, use_version_file: bool, update_version_file: bool, packer_version: str) -> dagger.Directory:
	return (
		dag.dagger_packer_plugin()
		.build_and_install(source, git_source, use_version_file, update_version_file, packer_version)
	)
@func()
example(source: Directory, gitSource: string, useVersionFile: boolean, updateVersionFile: boolean, packerVersion: string): Directory {
	return dag
		.daggerPackerPlugin()
		.buildAndInstall(source, gitSource, useVersionFile, updateVersionFile, 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.

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 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)

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). Automatically normalized to lowercase.
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). Automatically normalized to lowercase.
useVersionFileBoolean !falseUse VERSION file from source as version (default: false)
updateVersionFileBoolean !falseUpdate VERSION file with provided version before build (default: false)
goVersionString nullGo version for building. Auto-detected from .go-version file if not provided, defaults to 1.21
skipNormalizationBoolean !falseNo description provided
resolvedGoVersionString nullNo description provided
Example
dagger -m github.com/SolomonHD/dagger-packer-plugin@47a56f89322c810bc2ec5e962da9bdbb6f447b4c call \
 build-plugin --source DIR_PATH --git-source string --use-version-file boolean --update-version-file boolean --skip-normalization boolean
func (m *MyModule) Example(source *dagger.Directory, gitSource string, useVersionFile bool, updateVersionFile bool, SkipNormalization bool) *dagger.Container  {
	return dag.
			DaggerPackerPlugin().
			BuildPlugin(source, gitSource, useVersionFile, updateVersionFile, SkipNormalization)
}
@function
def example(source: dagger.Directory, git_source: str, use_version_file: bool, update_version_file: bool, skip_normalization: bool) -> dagger.Container:
	return (
		dag.dagger_packer_plugin()
		.build_plugin(source, git_source, use_version_file, update_version_file, skip_normalization)
	)
@func()
example(source: Directory, gitSource: string, useVersionFile: boolean, updateVersionFile: boolean, skipNormalization: boolean): Container {
	return dag
		.daggerPackerPlugin()
		.buildPlugin(source, gitSource, useVersionFile, updateVersionFile, skipNormalization)
}

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@47a56f89322c810bc2ec5e962da9bdbb6f447b4c 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.

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_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). Automatically normalized to lowercase.
pluginNameString nullPlugin name (auto-detected from git_source if not provided). Automatically normalized to lowercase.
packerVersionString !"latest"Packer image version to use (default: latest)
skipNormalizationBoolean !falseNo description provided
Example
dagger -m github.com/SolomonHD/dagger-packer-plugin@47a56f89322c810bc2ec5e962da9bdbb6f447b4c call \
 install-plugin --build-container IMAGE:TAG --git-source string --packer-version string --skip-normalization boolean
func (m *MyModule) Example(buildContainer *dagger.Container, gitSource string, packerVersion string, SkipNormalization bool) *dagger.Directory  {
	return dag.
			DaggerPackerPlugin().
			InstallPlugin(buildContainer, gitSource, packerVersion, SkipNormalization)
}
@function
def example(build_container: dagger.Container, git_source: str, packer_version: str, skip_normalization: bool) -> dagger.Directory:
	return (
		dag.dagger_packer_plugin()
		.install_plugin(build_container, git_source, packer_version, skip_normalization)
	)
@func()
example(buildContainer: Container, gitSource: string, packerVersion: string, skipNormalization: boolean): Directory {
	return dag
		.daggerPackerPlugin()
		.installPlugin(buildContainer, gitSource, packerVersion, skipNormalization)
}

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. Plugin name is auto-detected from go.mod module path if not provided.

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
NameTypeDefault ValueDescription
sourceDirectory !-Plugin source directory containing .gitignore (use --source=. for your project)
pluginNameString nullPlugin name override (auto-detected from go.mod if not provided). Automatically normalized to lowercase.
Example
dagger -m github.com/SolomonHD/dagger-packer-plugin@47a56f89322c810bc2ec5e962da9bdbb6f447b4c call \
 prep-gitignore --source DIR_PATH
func (m *MyModule) Example(source *dagger.Directory) *dagger.File  {
	return dag.
			DaggerPackerPlugin().
			PrepGitignore(source)
}
@function
def example(source: dagger.Directory) -> dagger.File:
	return (
		dag.dagger_packer_plugin()
		.prep_gitignore(source)
	)
@func()
example(source: Directory): File {
	return dag
		.daggerPackerPlugin()
		.prepGitignore(source)
}