Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tag filtering for offline_packages and republish_images #543

Merged
merged 1 commit into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ offline_packages:
- source: paketo-buildpacks/adoptium
target: gcr.io/tanzu-buildpacks/adoptium
path: subdir/adoptium
tag_prefix: my-buildpack/
platform:
os: linux
```
Expand All @@ -235,6 +236,8 @@ offline_packages:

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

`tag_prefix` is the optional prefix to filter for when detecting the buildpack's version via tags. Defaults to empty string.

`platform` describes what platform the created package should be built for. `os` can be set to `linux` or `windows` (`linux` by default).

#### `republish_images`
Expand All @@ -244,12 +247,15 @@ republish_images:
target: gcr.io/tanzu-buildpacks/bellsoft-liberica-lite
id: tanzu-buildpacks/bellsoft-liberica-lite
target_repo: paketo-buildpacks/bellsoft-liberica
tag_prefix: java/
```

`republish_images` is a list of objects that describe a `source` Docker registry location, a `target` Docker registry location, and a new buildpack id. If defined, each object will create a `republish-image` workflow that is responsible for detecting new source images, modifying the buildpack id of the image to the new id, and publishing a new target image with the modified buildpack id.

The `target_repo` setting can be used to point the workflow to a different source control repository for the target image. It's assumed to be the current repository, but for cases where you have a utility repo which is republishing multiple images you need to point the workflow to are repository from which it can read the git tags and extract the target version. The example above, points it to the source image's code repository so it'll end up with a source and target version that are in sync.

`tag_prefix` is the optional prefix to filter for when detecting the buildpack's version via tags. Defaults to empty string.

#### `actions`
```yaml
actions:
Expand Down
19 changes: 11 additions & 8 deletions octo/check-republish-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,22 @@ contains() {

IMAGES=$(crane ls "${TARGET}")

for GIT in $(git tag | sort -V -r ); do
if contains "${GIT}" "${IMAGES}"; then
echo "Found ${GIT}. Skipping."
for TAG in $(git tag -l "${TAG_PREFIX}*" | sort -V -r ); do
VERSION=${TAG#${TAG_PREFIX}}
VERSION=${VERSION#v}

if contains "${VERSION}" "${IMAGES}"; then
echo "Found ${TAG}. Skipping."
echo "::set-output name=skip::true"
exit
fi

echo "::group::Checking out ${GIT}"
echo "::group::Checking out ${TAG}"
git checkout -- .
git checkout "${GIT}"
echo "::endgroup::"
echo "::set-output name=target::${GIT#v}"
break
git checkout "${TAG}"
echo "::endgroup::"
echo "::set-output name=version::${VERSION}"
exit
done

for IMG in $(crane ls "${SOURCE}" | grep -v "latest" | sort -V -r); do
Expand Down
15 changes: 9 additions & 6 deletions octo/checkout-next-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,20 @@ contains() {

IMAGES=$(crane ls "${TARGET}")

for GIT in $(git tag | sort -V -r ); do
if contains "${GIT}" "${IMAGES}"; then
echo "Found ${GIT}. Skipping."
for TAG in $(git tag -l "${TAG_PREFIX}*" | sort -V -r ); do
VERSION=${TAG#${TAG_PREFIX}}
VERSION=${VERSION#v}

if contains "${VERSION}" "${IMAGES}"; then
echo "Found ${TAG}. Skipping."
echo "::set-output name=skip::true"
exit
fi

echo "::group::Checking out ${GIT}"
echo "::group::Checking out ${TAG}"
git checkout -- .
git checkout "${GIT}"
git checkout "${TAG}"
echo "::endgroup::"
echo "::set-output name=version::${GIT#v}"
echo "::set-output name=version::${VERSION}"
exit
done
2 changes: 2 additions & 0 deletions octo/descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,15 @@ type OfflinePackage struct {
Source string
Target string
SourcePath string `yaml:"source_path"`
TagPrefix string `yaml:"tag_prefix"`
Platform Platform
}

type RepublishImage struct {
Source string
Target string
ID string
TagPrefix string `yaml:"tag_prefix"`
TargetRepo string `yaml:"target_repo"`
}

Expand Down
5 changes: 3 additions & 2 deletions octo/lite_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ func contributeLitePackage(descriptor Descriptor, republishImage RepublishImage)
Name: "Check for next version",
Run: StatikString("/check-republish-version.sh"),
Env: map[string]string{
"SOURCE": republishImage.Source,
"TARGET": republishImage.Target,
"SOURCE": republishImage.Source,
"TARGET": republishImage.Target,
"TAG_PREFIX": republishImage.TagPrefix,
},
},
{
Expand Down
5 changes: 3 additions & 2 deletions octo/offline_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ func contributeOfflinePackage(descriptor Descriptor, offlinePackage OfflinePacka
Name: "Checkout next version",
Run: StatikString("/checkout-next-version.sh"),
Env: map[string]string{
"SOURCE": offlinePackage.Source,
"TARGET": offlinePackage.Target,
"SOURCE": offlinePackage.Source,
"TARGET": offlinePackage.Target,
"TAG_PREFIX": offlinePackage.TagPrefix,
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion octo/statik/statik.go

Large diffs are not rendered by default.