Skip to content

Commit

Permalink
Merge pull request #624 from paketo-buildpacks/panic-fix
Browse files Browse the repository at this point in the history
Fixes two panics
  • Loading branch information
Daniel Mikusa authored Apr 11, 2022
2 parents bf3b40c + 74bdaf4 commit f8000e4
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 19 deletions.
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,11 @@ package:

`package` is an object that describes the `repositories` a buildpackage should be published to as well as whether to include the buildpackage's dependencies when creating it (`false` by default). If defined, a `create-package` workflow is created that creates and publishes a new package when a release is published as well as adds a `create-package` job to the tests workflow that is run on each PR and each commit. It will also add additional content to the draft release notes about the contents of the build package and will update the digest of the buildpackage in the published release notes. If `register` is `true`, after the package is created, it is registered with the [Buildpack Registry Index](https://github.com/buildpacks/registry-index).

`repository` is deprecated in favour of a list of repositories, as described below. This should be left empty if the `repositories` property is used. If a value is specified, this will take preference over `repositories`
`repository` is the primary repository. It is the repository registered with the Buildpack Registry Index. It defaults to the first entry in `repositories` so if a value is specified, this will take preference over `repositories[0]`.

`repositories` is the list of repositories that the image should be published to. The list is an array of strings, and the Docker Hub address should be be listed as the first item, as per the above example - this address will be added to the Buildpack Registry Index. The image will be copied to subsequent repository addresses specified.
`repositories` is the list of repositories that the image should be published to. The list is an array of strings. If `repository` is not set then the first registry address will be used for `repository`, which is the address that's added to the Buildpack Registry Index. When multiple repositories are set, the image will be packaged once and then copied to subsequent repository addresses specified for efficiency.

If you have a single repository to which you want to publish, using `repository` is preferred but it is the same as setting `repositories` to a single repository. If you have multiple repositories, you may set both `repository` and `repositories` but that's only necessary if you need a repository registered with the Buildpack Registry Index that's not the first in the `repositories` list.

`source_path` is the optional path to the buildpack's directory relative to the repository's root. Defaults to the repository root.

Expand Down Expand Up @@ -475,6 +477,19 @@ with:
token: ${{ secrets.GITHUB_TOKEN }}
```

### Liberty Dependency
The Liberty Dependency watches a [Maven Repository](https://repo1.maven.org/maven2) for new versions.

```yaml
uses: docker://ghcr.io/paketo-buildpacks/actions/liberty-dependency:main
with:
uri: https://repo1.maven.org/maven2
group_id: org.apache.maven
artifact_id: apache-maven
classifier: bin
packaging: tar.gz
```

### Maven Dependency
The Maven Dependency queries a [Maven Repository](https://repo1.maven.org/maven2) for new versions.

Expand Down
17 changes: 9 additions & 8 deletions octo/create_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ import (
)

func ContributeCreatePackage(descriptor Descriptor) (*Contribution, error) {
if descriptor.Package == nil {
if !descriptor.Package.Enabled {
return nil, nil
}

var repos string
if descriptor.Package.Repository != "" {
repos = descriptor.Package.Repository
} else {
repos = strings.Join(descriptor.Package.Repositories, " ")
if descriptor.Package.Repository == "" && len(descriptor.Package.Repositories) > 0 {
descriptor.Package.Repository = descriptor.Package.Repositories[0]
}

if len(descriptor.Package.Repositories) == 0 && descriptor.Package.Repository != "" {
descriptor.Package.Repositories = append(descriptor.Package.Repositories, descriptor.Package.Repository)
}

file := filepath.Join(descriptor.Path, "buildpack.toml")
Expand Down Expand Up @@ -125,7 +126,7 @@ func ContributeCreatePackage(descriptor Descriptor) (*Contribution, error) {
Name: "Package Buildpack",
Run: StatikString("/package-buildpack.sh"),
Env: map[string]string{
"PACKAGES": repos,
"PACKAGES": strings.Join(descriptor.Package.Repositories, " "),
"PUBLISH": "true",
"VERSION": "${{ steps.version.outputs.version }}",
"VERSION_MAJOR": "${{ steps.version.outputs.version-major }}",
Expand All @@ -147,7 +148,7 @@ func ContributeCreatePackage(descriptor Descriptor) (*Contribution, error) {
"token": descriptor.Package.RegistryToken,
"id": b.Info.ID,
"version": "${{ steps.version.outputs.version }}",
"address": fmt.Sprintf("%s@${{ steps.package.outputs.digest }}", descriptor.Package.Repositories[0]),
"address": fmt.Sprintf("%s@${{ steps.package.outputs.digest }}", descriptor.Package.Repository),
},
},
},
Expand Down
9 changes: 8 additions & 1 deletion octo/descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ type Package struct {
RegistryToken string `yaml:"registry_token"`
Platform Platform
SourcePath string `yaml:"source_path"`
Enabled bool
}

const (
Expand Down Expand Up @@ -159,7 +160,13 @@ func NewDescriptor(path string) (Descriptor, error) {
}
}

if d.Package != nil && d.Package.Platform.OS == "" {
if d.Package == nil {
d.Package = &Package{}
} else {
d.Package.Enabled = true
}

if d.Package.Platform.OS == "" {
d.Package.Platform.OS = PlatformLinux
}

Expand Down
17 changes: 9 additions & 8 deletions octo/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ func ContributeTest(descriptor Descriptor) (*Contribution, error) {
return nil, nil
}

var repos []string
if descriptor.Package.Repository != "" {
repos = append(repos, descriptor.Package.Repository)
} else {
repos = descriptor.Package.Repositories
if descriptor.Package.Repository == "" && len(descriptor.Package.Repositories) > 0 {
descriptor.Package.Repository = descriptor.Package.Repositories[0]
}

if len(descriptor.Package.Repositories) == 0 && descriptor.Package.Repository != "" {
descriptor.Package.Repositories = append(descriptor.Package.Repositories, descriptor.Package.Repository)
}

w := actions.Workflow{
Expand Down Expand Up @@ -189,7 +190,7 @@ func ContributeTest(descriptor Descriptor) (*Contribution, error) {
w.Jobs["create-builder"] = j
}

if descriptor.Package != nil {
if descriptor.Package.Enabled {
format := FormatImage
if descriptor.Package.Platform.OS == PlatformWindows {
format = FormatFile
Expand Down Expand Up @@ -250,14 +251,14 @@ func ContributeTest(descriptor Descriptor) (*Contribution, error) {
Run: StatikString("/package-buildpack.sh"),
Env: map[string]string{
"FORMAT": format,
"PACKAGES": "test1 test2",
"PACKAGES": "test",
"VERSION": "${{ steps.version.outputs.version }}",
},
},
},
}

for _, repo := range repos {
for _, repo := range descriptor.Package.Repositories {
if !strings.Contains(repo, "paketo-buildpacks") {
j.Steps = append(NewDockerCredentialActions(descriptor.DockerCredentials), j.Steps...)
}
Expand Down

0 comments on commit f8000e4

Please sign in to comment.