Skip to content

Commit

Permalink
Merge pull request #612 from paketo-buildpacks/multi-repo
Browse files Browse the repository at this point in the history
Added logic to handle multiple repositories for publishing
  • Loading branch information
pivotal-david-osullivan authored Apr 8, 2022
2 parents 98ef7a0 + 8dae9d5 commit 796c5d4
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 15 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ codeowners:
#### `package`
```yaml
package:
repository: gcr.io/paketo-buildpacks/adoptium
repository: ""
repositories: ["index.docker.io/paketobuildpacks/adoptium","gcr.io/paketo-buildpacks/adoptium"]
include_dependencies: false
register: true
registry_token: ${{ secrets.JAVA_REGISTRY_TOKEN }}
Expand All @@ -137,7 +138,11 @@ package:
* [Example `create-package.yml`](https://github.com/paketo-buildpacks/adoptium/blob/main/.github/workflows/create-package.yml)
* [Example `test.yml`](https://github.com/paketo-buildpacks/adoptium/blob/main/.github/workflows/tests.yml)

`package` is an object that describes the `repository` 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).
`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`

`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.

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

Expand Down
11 changes: 9 additions & 2 deletions octo/create_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ func ContributeCreatePackage(descriptor Descriptor) (*Contribution, error) {
return nil, nil
}

var repos string
if descriptor.Package.Repository != "" {
repos = descriptor.Package.Repository
} else {
repos = strings.Join(descriptor.Package.Repositories, " ")
}

file := filepath.Join(descriptor.Path, "buildpack.toml")
s, err := ioutil.ReadFile(file)
if err != nil {
Expand Down Expand Up @@ -118,7 +125,7 @@ func ContributeCreatePackage(descriptor Descriptor) (*Contribution, error) {
Name: "Package Buildpack",
Run: StatikString("/package-buildpack.sh"),
Env: map[string]string{
"PACKAGE": descriptor.Package.Repository,
"PACKAGES": repos,
"PUBLISH": "true",
"VERSION": "${{ steps.version.outputs.version }}",
"VERSION_MAJOR": "${{ steps.version.outputs.version-major }}",
Expand All @@ -140,7 +147,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.Repository),
"address": fmt.Sprintf("%s@${{ steps.package.outputs.digest }}", descriptor.Package.Repositories[0]),
},
},
},
Expand Down
1 change: 1 addition & 0 deletions octo/descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ type RepublishImage struct {
}

type Package struct {
Repositories []string
Repository string
IncludeDependencies bool `yaml:"include_dependencies"`
Register bool
Expand Down
21 changes: 20 additions & 1 deletion octo/package-buildpack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

set -euo pipefail


PACKAGE_LIST=($PACKAGES)
# Extract first repo (Docker Hub) as the main to package & register
PACKAGE=${PACKAGE_LIST[0]}

if [[ "${PUBLISH:-x}" == "true" ]]; then
pack buildpack package \
"${PACKAGE}:${VERSION}" \
Expand All @@ -14,9 +19,23 @@ if [[ "${PUBLISH:-x}" == "true" ]]; then
fi
crane tag "${PACKAGE}:${VERSION}" latest
echo "::set-output name=digest::$(crane digest "${PACKAGE}:${VERSION}")"

# copy to other repositories specified
for P in "${PACKAGE_LIST[@]}"
do
if [ "$P" != "$PACKAGE" ]; then
crane copy "${PACKAGE}:${VERSION}" "${P}:${VERSION}"
if [[ -n ${VERSION_MINOR:-} && -n ${VERSION_MAJOR:-} ]]; then
crane tag "${P}:${VERSION}" "${VERSION_MINOR}"
crane tag "${P}:${VERSION}" "${VERSION_MAJOR}"
fi
crane tag "${P}:${VERSION}" latest
fi
done

else
pack buildpack package \
"${PACKAGE}:${VERSION}" \
--config "${HOME}"/package.toml \
--format "${FORMAT}"
fi
fi
2 changes: 1 addition & 1 deletion octo/statik/statik.go

Large diffs are not rendered by default.

27 changes: 18 additions & 9 deletions octo/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ 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
}

w := actions.Workflow{
Name: "Tests",
On: map[event.Type]event.Event{
Expand Down Expand Up @@ -84,10 +91,10 @@ func ContributeTest(descriptor Descriptor) (*Contribution, error) {
j.Steps = append(j.Steps, descriptor.Test.Steps...)
} else {
j.Steps = append(j.Steps, actions.Step{
Name: "Install richgo",
Run: StatikString("/install-richgo.sh"),
Env: map[string]string{"RICHGO_VERSION": RichGoVersion},
},
Name: "Install richgo",
Run: StatikString("/install-richgo.sh"),
Env: map[string]string{"RICHGO_VERSION": RichGoVersion},
},
actions.Step{
Name: "Run Tests",
Run: StatikString("/run-unit-tests.sh"),
Expand Down Expand Up @@ -242,16 +249,18 @@ func ContributeTest(descriptor Descriptor) (*Contribution, error) {
Name: "Package Buildpack",
Run: StatikString("/package-buildpack.sh"),
Env: map[string]string{
"FORMAT": format,
"PACKAGE": "test",
"VERSION": "${{ steps.version.outputs.version }}",
"FORMAT": format,
"PACKAGES": "test1 test2",
"VERSION": "${{ steps.version.outputs.version }}",
},
},
},
}

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

Expand Down

0 comments on commit 796c5d4

Please sign in to comment.