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@8c93bcc73bbbaa686fff85071136a4982ee95c04Entrypoint
Return Type
DaggerPackerPlugin ! Example
dagger -m github.com/SolomonHD/dagger-packer-plugin@8c93bcc73bbbaa686fff85071136a4982ee95c04 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
| Name | Type | Default Value | Description |
|---|---|---|---|
| source | Directory ! | - | Plugin source directory containing Go code (use --source=. for your project) |
| gitSource | String ! | - | Git path for the plugin (e.g., github.com/user/packer-plugin-example) |
| 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) |
| 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 ! | "1.21" | Go version for building (default: 1.21) |
| packerVersion | String ! | "latest" | Packer image version for installation (default: latest) |
Example
dagger -m github.com/SolomonHD/dagger-packer-plugin@8c93bcc73bbbaa686fff85071136a4982ee95c04 call \
build-and-install --source DIR_PATH --git-source string --use-version-file boolean --update-version-file boolean --go-version string --packer-version stringfunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| source | Directory ! | - | Plugin source directory containing Go code (use --source=. for your project) |
| gitSource | String ! | - | Git path for the plugin (e.g., github.com/user/packer-plugin-example) |
| 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) |
| 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 ! | "1.21" | Go version to use for building (default: 1.21) |
Example
dagger -m github.com/SolomonHD/dagger-packer-plugin@8c93bcc73bbbaa686fff85071136a4982ee95c04 call \
build-plugin --source DIR_PATH --git-source string --use-version-file boolean --update-version-file boolean --go-version stringfunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| source | Directory ! | - | Plugin source directory (use --source=. for your project) |
Example
dagger -m github.com/SolomonHD/dagger-packer-plugin@8c93bcc73bbbaa686fff85071136a4982ee95c04 call \
detect-version --source DIR_PATHfunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| buildContainer | Container ! | - | Container with built plugin binary (from build_plugin) |
| gitSource | String ! | - | Git path for plugin registration (e.g., github.com/user/packer-plugin-example) |
| pluginName | String | null | Plugin name (auto-detected from git_source if not provided) |
| packerVersion | String ! | "latest" | Packer image version to use (default: latest) |
Example
dagger -m github.com/SolomonHD/dagger-packer-plugin@8c93bcc73bbbaa686fff85071136a4982ee95c04 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.
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. Plugin name is auto-detected from go.mod module path if not provided.
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) |
Example
dagger -m github.com/SolomonHD/dagger-packer-plugin@8c93bcc73bbbaa686fff85071136a4982ee95c04 call \
prep-gitignore --source DIR_PATHfunc (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)
}