Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
Moves the binaries from libpak into a libpak-tools project. It includes a Makefile for building and packaging.

Signed-off-by: Daniel Mikusa <[email protected]>
  • Loading branch information
dmikusa committed Jul 19, 2023
0 parents commit d1509f5
Show file tree
Hide file tree
Showing 16 changed files with 2,540 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2018-2023 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

bin/
binaries/
dist/
64 changes: 64 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Go parameters
GOCMD?=go
GO_VERSION=$(shell go list -m -f "{{.GoVersion}}")
LIBPAKTOOLS_VERSION=$(shell ./scripts/version.sh)
PACKAGE_BASE=github.com/paketo-buildpacks/libpak-tools
OUTDIR=./binaries
LDFLAGS="-s -w"

all: test build-all

build-all: create-package update-build-image-dependency update-package-dependency update-buildmodule-dependency update-lifecycle-dependency

out:
mkdir -p $(OUTDIR)

create-package: out
@echo "> Building create-package..."
go build -ldflags=$(LDFLAGS) -o $(OUTDIR)/create-package create-package/main.go

update-build-image-dependency: out
@echo "> Building update-build-image-dependency..."
go build -ldflags=$(LDFLAGS) -o $(OUTDIR)/update-build-image-dependency update-build-image-dependency/main.go

update-package-dependency: out
@echo "> Building update-package-dependency..."
go build -ldflags=$(LDFLAGS) -o $(OUTDIR)/update-package-dependency update-package-dependency/main.go

update-buildmodule-dependency: out
@echo "> Building update-buildmodule-dependency..."
go build -ldflags=$(LDFLAGS) -o $(OUTDIR)/update-buildmodule-dependency update-buildmodule-dependency/main.go

update-lifecycle-dependency: out
@echo "> Building update-lifecycle-dependency..."
go build -ldflags=$(LDFLAGS) -o $(OUTDIR)/update-lifecycle-dependency update-lifecycle-dependency/main.go

package: OUTDIR=./bin
package: clean build-all
@echo "> Packaging up binaries..."
mkdir -p dist/
tar czf dist/libpak-tools-$(LIBPAKTOOLS_VERSION).tgz $(OUTDIR)/*
rm -rf ./bin

install-goimports:
@echo "> Installing goimports..."
cd tools && $(GOCMD) install golang.org/x/tools/cmd/goimports

format: install-goimports
@echo "> Formating code..."
@goimports -l -w -local ${PACKAGE_BASE} .

install-golangci-lint:
@echo "> Installing golangci-lint..."
cd tools && $(GOCMD) install github.com/golangci/golangci-lint/cmd/golangci-lint

lint: install-golangci-lint
@echo "> Linting code..."
@golangci-lint run -c golangci.yaml

test: format lint
$(GOCMD) test -parallel=1 -count=1 -v ./...

clean:
rm -rf ./bin/
rm -rf ./binaries/
110 changes: 110 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# Tools for Buildpacks

This repository pulls together and publishes a number of helpful tools for the management and release of buildpacks.

## `create-package``

The `create-package` tool creates a `libpak.Package` and calls `libpak.Package.Create()`. This takes a Paketo buildpack written in Go and packages is it into a buildpack. That involves compiling the source code, possibly copying in additional resource files, and generating the buildpack in the given output directory.

```
> create-package -h
Usage of Create Package:
-cache-location string
path to cache downloaded dependencies (default: $PWD/dependencies)
-dependency-filter value
one or more filters that are applied to exclude dependencies
-destination string
path to the build package destination directory
-include-dependencies
whether to include dependencies (default: false)
-source string
path to build package source directory (default: $PWD) (default "/Users/dmikusa/Code/OSS/paketo-buildpacks/libpak-tools")
-strict-filters
require filter to match all data or just some data (default: false)
-version string
version to substitute into buildpack.toml/extension.toml
```

## `update-build-image-dependency`

The `update-build-image-dependency` tool is used to update depenencies in a build image dependency in a builder configuration file. It takes as an argument the builder configuration file and the new version.

```
> update-build-image-dependency -h
Usage of Update Build Image Dependency:
-builder-toml string
path to builder.toml
-version string
the new version of the dependency
```

## `update-package-dependency`

The `update-package-dependency` tool is used to update package dependencies, which are references to other buildpacks, in a builder definition (i.e. `builder.toml`), package definition (i.e. `package.toml`), or a buildpack definition (i.e. `buildpack.toml`, but only if it is a composite buildpack).

```
> update-package-dependency -h
Usage of Update Package Dependency:
-builder-toml string
path to builder.toml
-buildpack-toml string
path to buildpack.toml
-id string
the id of the dependency
-package-toml string
path to package.toml
-version string
the new version of the dependency
```

## `update-buildmodule-dependency`

The `update-buildmodule-dependency` tool is used to update binary dependencies that are tracked in the build module metadata (i.e. `buildpack.toml` or `extension.toml` in the `[metadata.dependencies] block`). It allows you to update specific fields as the dependency changes.

```
> update-buildmodule-dependency -h
Usage of Update Build Module Dependency:
-buildmodule-toml string
path to buildpack.toml or extension.toml
-cpe string
the new version use in all CPEs, if not set defaults to version
-cpe-pattern string
the cpe version pattern of the dependency, if not set defaults to version-pattern
-id string
the id of the dependency
-purl string
the new purl version of the dependency, if not set defaults to version
-purl-pattern string
the purl version pattern of the dependency, if not set defaults to version-pattern
-sha256 string
the new sha256 of the dependency
-uri string
the new uri of the dependency
-version string
the new version of the dependency
-version-pattern string
the version pattern of the dependency
```

## `update-lifecycle-dependency`

The `update-lifecycle-dependency` tool is used to update the lifecycle dependency in a builder configuration (i.e. `builder.toml`).

```
> update-lifecycle-dependency -h
Usage of Update Lifecycle Dependency:
-builder-toml string
path to builder.toml
-version string
the new version of the dependency
```

## Notes

All of the binaries use Go's `flag` module to parse arguments which defaults to a single dash prefixing arguments (i.e. `-some-arg`), but also supports the more common double-dash format (i.e. `--some-arg`).

## License

This library is released under version 2.0 of the [Apache License][a].

[a]: https://www.apache.org/licenses/LICENSE-2.0
64 changes: 64 additions & 0 deletions create-package/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright 2018-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package main

import (
"flag"
"fmt"
"log"
"os"

"github.com/paketo-buildpacks/libpak/carton"

"github.com/paketo-buildpacks/libpak-tools/internal"
)

func main() {
var dependencyFilters internal.ArrayFlags

p := carton.Package{}

flagSet := flag.NewFlagSet("Create Package", flag.ExitOnError)
flagSet.StringVar(&p.CacheLocation, "cache-location", "", "path to cache downloaded dependencies (default: $PWD/dependencies)")
flagSet.StringVar(&p.Destination, "destination", "", "path to the build package destination directory")
flagSet.BoolVar(&p.IncludeDependencies, "include-dependencies", false, "whether to include dependencies (default: false)")
flagSet.Var(&dependencyFilters, "dependency-filter", "one or more filters that are applied to exclude dependencies")
flagSet.BoolVar(&p.StrictDependencyFilters, "strict-filters", false, "require filter to match all data or just some data (default: false)")
flagSet.StringVar(&p.Source, "source", defaultSource(), "path to build package source directory (default: $PWD)")
flagSet.StringVar(&p.Version, "version", "", "version to substitute into buildpack.toml/extension.toml")

if err := flagSet.Parse(os.Args[1:]); err != nil {
log.Fatal(fmt.Errorf("unable to parse flags\n%w", err))
}

if p.Destination == "" {
log.Fatal("destination must be set")
}

p.DependencyFilters = dependencyFilters

p.Create()
}

func defaultSource() string {
s, err := os.Getwd()
if err != nil {
log.Fatal(fmt.Errorf("unable to get working directory\n%w", err))
}

return s
}
20 changes: 20 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module github.com/paketo-buildpacks/libpak-tools

go 1.20

require github.com/paketo-buildpacks/libpak v1.66.1-0.20230707152440-cd6875914a49

require (
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/buildpacks/libcnb v1.24.1-0.20230717131530-4f8f92a58cca // indirect
github.com/creack/pty v1.1.18 // indirect
github.com/heroku/color v0.0.6 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect
github.com/onsi/gomega v1.27.8 // indirect
golang.org/x/sys v0.10.0 // indirect
)
46 changes: 46 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/CycloneDX/cyclonedx-go v0.7.1 h1:5w1SxjGm9MTMNTuRbEPyw21ObdbaagTWF/KfF0qHTRE=
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
github.com/buildpacks/libcnb v1.24.1-0.20230717131530-4f8f92a58cca h1:G1uSkl8vEW3zvM4+XeRDY6mETJMRh9wtdIsxdaBKHug=
github.com/buildpacks/libcnb v1.24.1-0.20230717131530-4f8f92a58cca/go.mod h1:01dTIt3kZYQM6qWvvF+/wvPPA1ByaVMBH7pnfMwO9pI=
github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY=
github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/heroku/color v0.0.6 h1:UTFFMrmMLFcL3OweqP1lAdp8i1y/9oHqkeHjQ/b/Ny0=
github.com/heroku/color v0.0.6/go.mod h1:ZBvOcx7cTF2QKOv4LbmoBtNl5uB17qWxGuzZrsi1wLU=
github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4=
github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mitchellh/hashstructure/v2 v2.0.2 h1:vGKWl0YJqUNxE8d+h8f6NJLcCJrgbhC4NcD46KavDd4=
github.com/mitchellh/hashstructure/v2 v2.0.2/go.mod h1:MG3aRVU/N29oo/V/IhBX8GR/zz4kQkprJgF2EVszyDE=
github.com/onsi/gomega v1.27.8 h1:gegWiwZjBsf2DgiSbf5hpokZ98JVDMcWkUiigk6/KXc=
github.com/onsi/gomega v1.27.8/go.mod h1:2J8vzI/s+2shY9XHRApDkdgPo1TKT7P2u6fXeJKFnNQ=
github.com/paketo-buildpacks/libpak v1.66.1-0.20230707152440-cd6875914a49 h1:t/1JPeLKsBkGCfE09MU3s2Er018NorSuxhBI1Y1IrYE=
github.com/paketo-buildpacks/libpak v1.66.1-0.20230707152440-cd6875914a49/go.mod h1:NQIzZJXFMp8MxVjBjWl6htjCMTcC3oirC4r3NOLQmew=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/sclevine/spec v1.4.0 h1:z/Q9idDcay5m5irkZ28M7PtQM4aOISzOpj4bUPkDee8=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
28 changes: 28 additions & 0 deletions golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
run:
timeout: 6m

linters:
disable-all: true
enable:
- bodyclose
- dogsled
- exportloopref
- gocritic
- goimports
- gosec
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- revive
- staticcheck
- stylecheck
- typecheck
- unconvert
- unused
- whitespace

linters-settings:
goimports:
local-prefixes: github.com/paketo-buildpacks/libpak-tools
14 changes: 14 additions & 0 deletions internal/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package internal

import "strings"

type ArrayFlags []string

func (i *ArrayFlags) String() string {
return strings.Join(*i, ",")
}

func (i *ArrayFlags) Set(value string) error {
*i = append(*i, value)
return nil
}
9 changes: 9 additions & 0 deletions scripts/version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -eo pipefail

VERSION=$(git describe --tags --exact-match 2>/dev/null || echo "")
if [ -z "$VERSION" ]; then
VERSION=$(git rev-parse --short HEAD)
fi

echo "$VERSION"
Loading

0 comments on commit d1509f5

Please sign in to comment.