Update wrt switch from pkger to custom ZIP pkging (#889)

Signed-off-by: Matej Vasek <mvasek@redhat.com>
This commit is contained in:
Matej Vasek 2022-03-10 02:39:46 +01:00 committed by GitHub
parent ff06ed426a
commit fa17dc9e4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17973 additions and 17971 deletions

View File

@ -6,8 +6,6 @@ This document details how to get started contributing to the project. This incl
To build the core project, run `make` from the repository root. This will result in a `func` binary being generated. Run `make help` for additional targets and `./func help` for usage-centric documentation.
Building currently requires that `pkger` be available in your `$PATH`. This can be installed with `go get github.com/markbates/pkger/cmd/pkger`. See [Templates](#templates) below for more information on this dependency.
To remove built artifacts, use `make clean`.
## Testing

View File

@ -29,17 +29,17 @@ cleanup() {
trap "cleanup" EXIT SIGINT
# Save working tree state
cp -aR "${REPO_ROOT_DIR}/go.sum" "${REPO_ROOT_DIR}/pkged.go" "${REPO_ROOT_DIR}/vendor" "${TMP_DIFFROOT}"
cp -aR "${REPO_ROOT_DIR}/go.sum" "${REPO_ROOT_DIR}/zz_filesystem_generated.go" "${REPO_ROOT_DIR}/vendor" "${TMP_DIFFROOT}"
"${REPO_ROOT_DIR}/hack/update-codegen.sh"
echo "Diffing ${REPO_ROOT_DIR} against freshly generated codegen"
ret=0
diff -Nupr --no-dereference "${REPO_ROOT_DIR}/go.sum" "${TMP_DIFFROOT}/go.sum" || ret=1
diff -Nupr --no-dereference "${REPO_ROOT_DIR}/pkged.go" "${TMP_DIFFROOT}/pkged.go" || ret=1
diff -Nupr --no-dereference "${REPO_ROOT_DIR}/zz_filesystem_generated.go" "${TMP_DIFFROOT}/zz_filesystem_generated.go" || ret=1
diff -Nupr --no-dereference "${REPO_ROOT_DIR}/vendor" "${TMP_DIFFROOT}/vendor" || ret=1
# Restore working tree state
rm -fr "${REPO_ROOT_DIR}/go.sum" "${REPO_ROOT_DIR}/pkged.go" "${REPO_ROOT_DIR}/vendor"
rm -fr "${REPO_ROOT_DIR}/go.sum" "${REPO_ROOT_DIR}/zz_filesystem_generated.go" "${REPO_ROOT_DIR}/vendor"
cp -aR "${TMP_DIFFROOT}"/* "${REPO_ROOT_DIR}"
if [[ $ret -eq 0 ]]

View File

@ -2,23 +2,23 @@
## Packaging
When updates are made to these templates, they must be packaged (serialized as
a Go struture) by running `make`, and checking in the resultant `pkged.go` file.
When updates are made to these templates, they must be packaged (serialized as a Go byte array)
by running `make zz_filesystem_generated.go`, and checking in the resultant `zz_filesystem_generated.go` file.
## How it works
running `make` in turn installs the `pkger` binary, which can be installed via:
`go get github.com/markbates/pkger/cmd/pkger`
Make then invokes `pkger` before `go build`.
The resulting `pkged.go` file includes the contents of the templates directory,
encoded as a Go strucutres which is then makde available in code using an API
similar to the standard library's `os` package.
The `./generate/templates` directory contains Go program that generates `zz_filesystem_generated.go`.
The file defines byte array variable named `templatesZip`.
The variable contains ZIP representation of the templates directory.
The byte array variable is then used to instantiate exported global variable `function.EmbeddedTemplatesFS`,
which implements standard Go interfaces `fs.ReadDirFS` and `fs.StatFS`.
## Rationale
Until such time as embedding static assets in binaries is included in the
base `go build` functionality (see https://github.com/golang/go/issues/35950)
a third-party tool is required and pkger provides an API very similar
to the `os` package.
we need to use our custom serialization script (`./generate/templates/main.go`).
Native Go embedding introduced in Go 1.16 could be used for executable binary,
however it cannot be used for library.
For a library we need to generate a Go source code containing the templates.

File diff suppressed because it is too large Load Diff