diff --git a/docs/PIPELINES-GO.md b/docs/PIPELINES-GO.md index d1e841645..d69330153 100644 --- a/docs/PIPELINES-GO.md +++ b/docs/PIPELINES-GO.md @@ -2,46 +2,10 @@ Melange includes built-in pipelines to compile go projects. The first one, `go/build` gives authors more control on the compiler invocation while -`go/install` focuses on simplicity. To get started quickly, we offer two working examples: [go-build.yaml](https://github.com/chainguard-dev/melange/blob/main/examples/go-build.yaml) and -[go-install.yaml](https://github.com/chainguard-dev/melange/blob/main/examples/go-install.yaml) - -## Simple and quick builds with `go/install` - -For projects not needing sophisticated interactions with `go build` or control -over how source is downloaded, `go/install` provides a quick and simple way to -compile any publicly available go project. - -Internally `go/install` is an interface to the `go install` command. It will -download the source code and dependencies and build them. Any produced binaries -will be installed into the specified directory. - -Here's a sample of a one-shot compilation of an example project: - -```yaml -package: - name: hello - version: v0.0.1 - epoch: 0 - description: "A project that will greet the world infinitely" -environment: - contents: - keyring: - - https://packages.wolfi.dev/os/wolfi-signing.rsa.pub - repositories: - - https://packages.wolfi.dev/os -pipeline: - - uses: go/install - with: - package: github.com/puerco/hello - version: HEAD -``` - -(:bulb: Experiment with this code, -[download it from the examples directory](https://github.com/chainguard-dev/melange/blob/main/examples/go-install.yaml)) ## Building golang projects with `go/build` @@ -85,7 +49,7 @@ pipeline: ## Build Parameters -Both `go/install` and `go/build` support passing a few parameters to the go +`go/build` support passing a few parameters to the go compiler by setting them in the melange configuration file. As of this writing, you can define the following values: @@ -150,7 +114,6 @@ pipeline: For the most up to date supported features check the [build](https://github.com/chainguard-dev/melange/blob/main/pkg/build/pipelines/go/build.yaml), -[install](https://github.com/chainguard-dev/melange/blob/main/pkg/build/pipelines/go/install.yaml), and [bump](https://github.com/chainguard-dev/melange/blob/main/pkg/build/pipelines/go/bump.yaml), pipeline definitions. Feel free to request more features in diff --git a/examples/go-build.yaml b/examples/go-build.yaml index 8ebf1c868..94a825bae 100644 --- a/examples/go-build.yaml +++ b/examples/go-build.yaml @@ -7,8 +7,6 @@ # For more information about melange's built-in golang support check out: # https://github.com/chainguard-dev/melange/blob/main/docs/PIPELINES-GO.md # -# For an equivalent pipeline that uses go/install to build the same project -# please see go-install.yaml in this directory. package: name: hello version: 0.0.1 diff --git a/examples/go-bump.yaml b/examples/go-bump.yaml index f2eab1d47..44d8cab1f 100644 --- a/examples/go-bump.yaml +++ b/examples/go-bump.yaml @@ -6,9 +6,6 @@ # # For more information about melange's built-in golang support check out: # https://github.com/chainguard-dev/melange/blob/main/docs/PIPELINES-GO.md -# -# For an equivalent pipeline that uses go/install to build the same project -# please see go-install.yaml in this directory. package: name: hello version: 0.0.1 diff --git a/examples/go-install.yaml b/examples/go-install.yaml deleted file mode 100644 index 5bfaea1ee..000000000 --- a/examples/go-install.yaml +++ /dev/null @@ -1,29 +0,0 @@ -# SPDX-FileCopyrightText: 2022 Chainguard, Inc -# SPDX-License-Identifier: Apache-2.0 -# -# This is a sample configuration file to demonstrate how to build a software -# project using melange's built-in go/install pipeline. -# -# For more information about melange's built-in golang support check out: -# -# -# For an equivalent pipeline that uses go/install to build the same project -# please see go-install.yaml in this directory. -package: - name: hello - version: v0.0.1 - epoch: 0 - description: "A project that will greet the world infinitely" - -environment: - contents: - keyring: - - https://packages.wolfi.dev/os/wolfi-signing.rsa.pub - repositories: - - https://packages.wolfi.dev/os - -pipeline: - - uses: go/install - with: - package: github.com/puerco/hello - version: ${{package.version}} diff --git a/pkg/build/pipelines/go/README.md b/pkg/build/pipelines/go/README.md index 6b9eec979..7d02f3127 100755 --- a/pkg/build/pipelines/go/README.md +++ b/pkg/build/pipelines/go/README.md @@ -1,4 +1,5 @@ + # Pipeline Reference @@ -6,7 +7,6 @@ - [go/build](#gobuild) - [go/bump](#gobump) - [go/covdata](#gocovdata) -- [go/install](#goinstall) ## go/build @@ -62,26 +62,5 @@ Get coverage data with the covdata go tool | cover-dir | false | The GOCOVERDIR path where coverage data files have been generated. It's required to be set as environment variable as well before running the Go binary. | /home/build | | package | false | The go package to install | go | -## go/install - -Run a build using the go compiler - -### Inputs - -| Name | Required | Description | Default | -| ---- | -------- | ----------- | ------- | -| amd64 | false | GOAMD64 microarchitecture level to use | v2 | -| arm64 | false | GOARM64 microarchitecture level to use | v8.0 | -| experiments | false | A comma-separated list of Golang experiment names (ex: loopvar) to use when building the binary. | | -| go-package | false | The go package to install | go | -| install-dir | false | Directory where binaries will be installed | bin | -| ldflags | false | List of [pattern=]arg to append to the go compiler with -ldflags | | -| package | true | Import path to the package | | -| prefix | false | Prefix to relocate binaries | usr | -| strip | false | Set of strip ldflags passed to the go compiler | -w | -| tags | false | A comma-separated list of build tags to append to the go compiler | | -| toolchaintags | false | A comma-separated list of default toolchain go build tags | netgo,osusergo | -| version | false | Package version to install. This can be a version tag (v1.0.0), a commit hash or another ref (eg latest or HEAD). | | - \ No newline at end of file diff --git a/pkg/build/pipelines/go/install.yaml b/pkg/build/pipelines/go/install.yaml deleted file mode 100644 index 45b47bf26..000000000 --- a/pkg/build/pipelines/go/install.yaml +++ /dev/null @@ -1,92 +0,0 @@ -name: Run a build using the go compiler - -needs: - packages: - - ${{inputs.go-package}} - - busybox - - ca-certificates-bundle - - git - -inputs: - go-package: - description: | - The go package to install - default: go - - package: - description: | - Import path to the package - required: true - - version: - description: | - Package version to install. This can be a version tag (v1.0.0), a - commit hash or another ref (eg latest or HEAD). - - prefix: - description: | - Prefix to relocate binaries - default: usr - - install-dir: - description: | - Directory where binaries will be installed - default: bin - - ldflags: - description: - List of [pattern=]arg to append to the go compiler with -ldflags - - strip: - description: - Set of strip ldflags passed to the go compiler - # Note symbols tables are useful for cryptography audits and govulncheck - default: "-w" - - tags: - description: | - A comma-separated list of build tags to append to the go compiler - - toolchaintags: - description: | - A comma-separated list of default toolchain go build tags - default: "netgo,osusergo" - - experiments: - description: | - A comma-separated list of Golang experiment names (ex: loopvar) to use - when building the binary. - default: "" - - amd64: - description: | - GOAMD64 microarchitecture level to use - default: "v2" - - arm64: - description: | - GOARM64 microarchitecture level to use - default: "v8.0" - -pipeline: - - runs: | - LDFLAGS="${{inputs.strip}} ${{inputs.ldflags}}" - VERSION="" - - # Installed binaries will be stored in a tmp dir - export GOBIN=$(mktemp -d) - - if [ ! "${{inputs.version}}" == "" ]; then - VERSION="@${{inputs.version}}" - fi - - # Run go install - GOAMD64="${{inputs.amd64}}" GOARM64="${{inputs.arm64}}" GOEXPERIMENT="${{inputs.experiments}}" go install ${DEST_PATH} -tags "${{inputs.toolchaintags}},${{inputs.tags}}" -ldflags "${LDFLAGS}" -trimpath ${{inputs.package}}${VERSION} - mkdir -p ${{targets.contextdir}}/${{inputs.prefix}}/${{inputs.install-dir}} - - # Move all resulting files to the target dir - echo "go/install: Installing built binaries" - for f in $(ls ${GOBIN}) - do - mv -v ${GOBIN}/${f} ${{targets.contextdir}}/${{inputs.prefix}}/${{inputs.install-dir}}/${f} - done diff --git a/pkg/sca/testdata/go-fips-bin/go-fips-bin.yaml b/pkg/sca/testdata/go-fips-bin/go-fips-bin.yaml index fd3cd83bf..a23841958 100644 --- a/pkg/sca/testdata/go-fips-bin/go-fips-bin.yaml +++ b/pkg/sca/testdata/go-fips-bin/go-fips-bin.yaml @@ -23,8 +23,9 @@ environment: - https://packages.wolfi.dev/os pipeline: - - uses: go/install + - uses: go/build with: - package: . + packages: . + output: go-fips-bin # This is an approximation to the real go-fips toolchain experiments: boringcrypto