Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task for "github.com/markbates/pkger" Go module command #53

Merged
merged 1 commit into from
Dec 9, 2020

Conversation

svengreb
Copy link
Owner

@svengreb svengreb commented Dec 9, 2020

Resolves #52

The github.com/markbates/pkger [1] Go module provides the `pkger`
command, a tool for embedding static files into Go binaries.

To configure and run the `pkger` command, the new `task.GoModule` [2]
has been implemented in the new `pkger` [3] package that can be run
using the "gobin" command runner [4] or any other command runner [5]
that handles tasks of kind `KindGoModule` [6].

The task is customizable through the following functions:

- `WithEnv(env map[string]string) pkger.Option` - sets the task specific
  environment.
- `WithExtraArgs(extraArgs ...string) pkger.Option` - sets additional
  arguments to pass to the command.
- `WithIncludes(includes ...string) pkger.Option` - adds the relative
  paths of files and directories that should be included.
  By default the paths will be detected by `pkger` itself when used
    within any of the packages of the target Go module.
- `WithModulePath(path string) pkger.Option` - sets the module import
  path.
- `WithModuleVersion(version *semver.Version) pkger.Option` - sets the
  module version.

The "elder" reference implementation provides the new `Pkger` method
including the handling of the "monorepo" workaround (see section below).

>>> Official "Static Assets Embedding"

Please note that the "pkger" project might be superseded and
discontinued due to the official Go toolchain support for embedding
static assets (files) [7] that will most probably be released with
Go version 1.16 [8].

Please see the official draft document [9] and markbates/pkger#114 [10]
for more details.

>>> "Monorepo" Workaround

"pkger" tries to mimic the Go standard library and the way how the Go
toolchain handles modules, but is therefore also affected by its
problems and edge cases.
When the `pkger` command is used from the root of a Go module
repository, the directory where the `go.mod` file is located, and there
is no valid Go source file, the command will fail because it internally
uses the same logic like the `list` command of the Go toolchain [11]
(`go list`).
Therefore a "dummy" Go source file may need to be created as a
workaround. This is mostly only required for repositories that use a
"monorepo" layout [12] where one or more `main` packages are placed in a
subdirectory relative to the root directory, e.g. `apps` or `cmd`.
For repositories where the root directory already has a Go package,
that does not contain any build constraints/tags, or uses a "library"
layout, a "dummy" file is probably not needed.

The new `Pkger` method of the "elder" reference implementation handles
the creation of a temporary "dummy" file that gets deleted automatically
when the tasks finishes in order to avoid the need for the user to add
such a file to the repository and commit it into the VCS.

Please see markbates/pkger#109 [13] and markbates/pkger#121 [14] for
more details.

[1]: https://pkg.go.dev/github.com/markbates/pkger
[2]: https://pkg.go.dev/github.com/svengreb/wand/pkg/task#GoModule
[3]: https://pkg.go.dev/github.com/svengreb/wand/pkg/task/pkger
[4]: https://pkg.go.dev/github.com/svengreb/wand/pkg/task/gobin#Runner
[5]: https://pkg.go.dev/github.com/svengreb/wand/pkg/task#Runner
[6]: https://pkg.go.dev/github.com/svengreb/wand/pkg/task#KindGoModule
[7]: golang/go#41191
[8]: https://github.com/golang/go/milestone/145
[9]: https://go.googlesource.com/proposal/+/master/design/draft-embed.md
[10]: markbates/pkger#114
[11]: https://pkg.go.dev/cmd/go/#hdr-List_packages_or_modules
[12]: https://trunkbaseddevelopment.com/monorepos
[13]: markbates/pkger#109
[14]: markbates/pkger#121

GH-52
@svengreb svengreb added this to the Next milestone Dec 9, 2020
@svengreb svengreb self-assigned this Dec 9, 2020
@svengreb svengreb merged commit 660601d into main Dec 9, 2020
@svengreb svengreb deleted the feature/gh-52-task-pkger-go-mod-cmd branch December 9, 2020 22:19
@svengreb svengreb removed their assignment Dec 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Task for “github.com/markbates/pkger“ Go module command
1 participant