Chef Habitat scaffolding-go is a way to build a Chef Habitat plan that overrides some of the default functions that Chef Habitat uses during its build process.
For more information on how to use the scaffolding-go see below in the Use as a Tool section. Also refer to documentation
- The Core Planners: chef-core-planners@chef.io
Library package
Library packages can be set as runtime or build time dependencies, however they are typically used as buildtime dependencies. See Defining your dependencies for more information.
To add core/scaffolding-go as a dependency, you can add one of the following to your plan file.
pkg_build_deps=(core/scaffolding-go)
pkg_deps=(core/scaffolding-go)
To install this plan, run the following command:
hab pkg install core/scaffolding-go
hab pkg install core/scaffolding-go
» Installing core/scaffolding-go
☁ Determining latest version of core/scaffolding-go in the 'stable' channel
→ Found newer installed version (core/scaffolding-go/0.2.0/20200929104501) than remote version (core/scaffolding-go/0.2.0/20200824092119)
→ Using core/scaffolding-go/0.2.0/20200929104501
★ Install of core/scaffolding-go/0.2.0/20200929104501 complete with 0 new packages installed.
To view the library files first get the habitat installation directory
hab pkg path core/scaffolding-go
/hab/pkgs/core/scaffolding-go/0.2.0/20200929104501
Then list the libraries, for example:
ls -1 $(hab pkg path core/scaffolding-go)/lib
go_module.sh
gopath_mode.sh
scaffolding.sh
The go scaffolding can be used to package an application from a remote repository or from local source. It has two available modes: (1) GOPATH Mode and (2) Module Mode.
These modes will be described below followed by descriptions of scaffolding variables and callbacks.
In this mode, the Go Scaffolding will automatically configure
the GOPATH
environment variable and directory structure.
By adding the pkg_source
variable you will be telling the go scaffolding to
package the application from a remote repository.
An example of a plan.sh
:
pkg_name=hello-go
pkg_origin=afiune
pkg_version="0.1.0"
pkg_scaffolding=core/scaffolding-go
pkg_source="http://github.com/afiune/hello-go"
If you are building an application from local source, you have to avoid defining
the pkg_source
variable, this way the go scaffolding will prapare a Go Workspace
to build and package your local application.
Optionally, you can define the scaffolding_go_base_path
if you are planning to
keep your code in a source repository somewhere.
An example of a plan.sh
:
pkg_name=hello-go
pkg_origin=afiune
pkg_version="0.1.0"
pkg_scaffolding=core/scaffolding-go
scaffolding_go_base_path=github.com/afiune
This mode allows you to build your go application outside a Go
Workspace, it requires the existence of the go.mod
file.
An example of a plan.sh
:
pkg_name=hello-go
pkg_origin=afiune
pkg_version="0.1.0"
pkg_scaffolding=core/scaffolding-go
scaffolding_go_module=on
See https://www.habitat.sh/docs/concepts-scaffolding/ to learn how to get started with Scaffolding.
Variable | Type | Value | Default |
---|---|---|---|
scaffolding_go_gopath |
String | (Optional) Value for GOPATH |
$SRC_PATH |
scaffolding_go_base_path |
String | (Optional) The base path that will be used in the import path construction. Eg: github.com/myorg |
localhost/user |
scaffolding_go_build_deps |
Array | (Optional) Array of URLs to go get |
Undefined |
scaffolding_go_module |
String | (Optional) Enable or disable go module support: off or on |
auto |
scaffolding_go_get
- Executesgo get
against thepkg_source
and the contents of thescaffolding_go_build_deps
array to install any additional dependencies which would not otherwise be resolved.scaffolding_go_before
- Initialize the Go Workspace package path only if nopkg_source
was specified.scaffolding_go_download
- Calls scaffolding_go_get by default. This callback adds a callback you can use to override download behaviors.scaffolding_go_clean
- Performsgo clean -r -i
to recursively clean build and build deps.scaffolding_go_build
- This will attempt to use aMakefile
if one is found and assumes there is a default make target. If noMakefile
is found,go build
is executed against the project.scaffolding_go_install
- Installs the application and runtime deps into"${pkg_prefix}/${bin}"
The following default callbacks have overrides:
do_default_before
- Calls scaffolding_go_beforedo_default_download
- Calls scaffolding_go_downloaddo_default_clean
- Calls scaffolding_go_cleando_default_verify
- NOP -- Returns 0do_default_unpack
- NOP -- Returns 0do_default_build
- Calls scaffolding_go_builddo_default_install
Calls scaffolding_go_install