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

Windows Buildpackages #116

Merged
merged 1 commit into from
Nov 20, 2020
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,17 @@ package:
include_dependencies: false
register: true
registry_token: ${{ secrets.JAVA_REGISTRY_TOKEN }}
platform:
os: linux
```

* [Example `create-package.yml`](https://github.com/paketo-buildpacks/adopt-openjdk/blob/main/.github/workflows/create-package.yml)
* [Example `test.yml`](https://github.com/paketo-buildpacks/adopt-openjdk/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).

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

#### `builder`
```yaml
builder:
Expand Down Expand Up @@ -212,10 +216,14 @@ path: ..
offline_packages:
- source: paketo-buildpacks/adopt-openjdk
target: gcr.io/tanzu-buildpacks/adopt-openjdk
platform:
os: linux
```

`offline_packages` is a list of objects that describe a `source` GitHub repository and a `target` Docker registry location. If defined, each object will create a `create-package` workflow that is responsible for detecting a new online buildpackage release and creating a matching offline buildpackage release and publishing it.

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

#### `actions`
```yaml
actions:
Expand Down
2 changes: 1 addition & 1 deletion octo/create-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ else
fi

[[ -e package.toml ]] && cp package.toml "${HOME}"/package.toml
printf '[buildpack]\nuri = "%s"' "${HOME}"/buildpack >> "${HOME}"/package.toml
printf '[buildpack]\nuri = "%s"\n\n[platform]\nos = "%s"\n' "${HOME}"/buildpack "${OS}" >> "${HOME}"/package.toml
51 changes: 27 additions & 24 deletions octo/create_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ func ContributeCreatePackage(descriptor Descriptor) (*Contribution, error) {
return nil, nil
}

file := filepath.Join(descriptor.Path, "buildpack.toml")
s, err := ioutil.ReadFile(file)
if err != nil {
return nil, fmt.Errorf("unable to read %s\n%w", file, err)
}

var b libcnb.Buildpack
if err := toml.Unmarshal(s, &b); err != nil {
return nil, fmt.Errorf("unable to decode %s\n%w", file, err)
}

w := actions.Workflow{
Name: "Create Package",
On: map[event.Type]event.Event{
Expand Down Expand Up @@ -67,6 +78,11 @@ func ContributeCreatePackage(descriptor Descriptor) (*Contribution, error) {
Run: StatikString("/install-pack.sh"),
Env: map[string]string{"PACK_VERSION": PackVersion},
},
{
Name: "Enable pack Experimental",
If: fmt.Sprintf("${{ %t }}", descriptor.Package.Platform.OS == PlatformWindows),
Run: StatikString("/enable-pack-experimental.sh"),
},
{
Uses: "actions/checkout@v2",
},
Expand All @@ -92,6 +108,7 @@ func ContributeCreatePackage(descriptor Descriptor) (*Contribution, error) {
Run: StatikString("/create-package.sh"),
Env: map[string]string{
"INCLUDE_DEPENDENCIES": strconv.FormatBool(descriptor.Package.IncludeDependencies),
"OS": descriptor.Package.Platform.OS,
"VERSION": "${{ steps.version.outputs.version }}",
},
},
Expand All @@ -113,6 +130,16 @@ func ContributeCreatePackage(descriptor Descriptor) (*Contribution, error) {
"GITHUB_TOKEN": descriptor.GitHub.Token,
},
},
{
Uses: "docker://ghcr.io/buildpacks/actions/registry:main",
If: fmt.Sprintf("${{ %t }}", descriptor.Package.Register),
With: map[string]interface{}{
"token": descriptor.Package.RegistryToken,
"id": b.Info.ID,
"version": "${{ steps.version.outputs.version }}",
"address": fmt.Sprintf("%s@${{ steps.package.outputs.digest }}", descriptor.Package.Repository),
},
},
},
},
},
Expand All @@ -121,30 +148,6 @@ func ContributeCreatePackage(descriptor Descriptor) (*Contribution, error) {
j := w.Jobs["create-package"]
j.Steps = append(NewDockerCredentialActions(descriptor.DockerCredentials), j.Steps...)
j.Steps = append(NewHttpCredentialActions(descriptor.HttpCredentials), j.Steps...)

if descriptor.Package.Register {
file := filepath.Join(descriptor.Path, "buildpack.toml")
s, err := ioutil.ReadFile(file)
if err != nil {
return nil, fmt.Errorf("unable to read %s\n%w", file, err)
}

var b libcnb.Buildpack
if err := toml.Unmarshal(s, &b); err != nil {
return nil, fmt.Errorf("unable to decode %s\n%w", file, err)
}

j.Steps = append(j.Steps, actions.Step{
Uses: "docker://ghcr.io/buildpacks/actions/registry:main",
With: map[string]interface{}{
"token": descriptor.Package.RegistryToken,
"id": b.Info.ID,
"version": "${{ steps.version.outputs.version }}",
"address": fmt.Sprintf("%s@${{ steps.package.outputs.digest }}", descriptor.Package.Repository),
},
})
}

w.Jobs["create-package"] = j

c, err := NewActionContribution(w)
Expand Down
26 changes: 24 additions & 2 deletions octo/descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,26 @@ type Dependency struct {
}

type OfflinePackage struct {
Source string
Target string
Source string
Target string
Platform Platform
}

type Package struct {
Repository string
IncludeDependencies bool `yaml:"include_dependencies"`
Register bool
RegistryToken string `yaml:"registry_token"`
Platform Platform
}

const (
PlatformLinux = "linux"
PlatformWindows = "windows"
)

type Platform struct {
OS string
}

type Test struct {
Expand Down Expand Up @@ -133,6 +144,17 @@ func NewDescriptor(path string) (Descriptor, error) {
}
}

if d.Package != nil && d.Package.Platform.OS == "" {
d.Package.Platform.OS = PlatformLinux
}

for i, o := range d.OfflinePackages {
if o.Platform.OS == "" {
o.Platform.OS = PlatformLinux
d.OfflinePackages[i] = o
}
}

if d.Test.Steps == nil {
d.Test.Steps = []actions.Step{
{
Expand Down
8 changes: 8 additions & 0 deletions octo/enable-pack-experimental.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

set -euo pipefail

echo "Enabling pack experimental features"

mkdir -p "${HOME}"/.pack
echo "experimental = true" >> "${HOME}"/.pack/config.toml
6 changes: 6 additions & 0 deletions octo/offline_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,18 @@ func contributeOfflinePackage(descriptor Descriptor, offlinePackage OfflinePacka
Run: StatikString("/install-pack.sh"),
Env: map[string]string{"PACK_VERSION": PackVersion},
},
{
Name: "Enable pack Experimental",
If: fmt.Sprintf("${{ %t }}", offlinePackage.Platform.OS == PlatformWindows),
Run: StatikString("/enable-pack-experimental.sh"),
},
{
Name: "Create Package",
If: "${{ ! steps.version.outputs.skip }}",
Run: StatikString("/create-package.sh"),
Env: map[string]string{
"INCLUDE_DEPENDENCIES": "true",
"OS": descriptor.Package.Platform.OS,
"VERSION": "${{ steps.version.outputs.version }}",
},
},
Expand Down
3 changes: 2 additions & 1 deletion octo/package-buildpack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ if [[ -n "${PUBLISH+x}" ]]; then
else
pack package-buildpack \
"${PACKAGE}:${VERSION}" \
--config "${HOME}"/package.toml
--config "${HOME}"/package.toml \
--format "${FORMAT}"
fi
2 changes: 1 addition & 1 deletion octo/statik/statik.go

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions octo/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ import (
"github.com/paketo-buildpacks/pipeline-builder/octo/actions/event"
)

const (
FormatFile = "file"
FormatImage = "image"
)

func ContributeTest(descriptor Descriptor) (*Contribution, error) {
if descriptor.OfflinePackages != nil {
return nil, nil
Expand Down Expand Up @@ -106,6 +111,11 @@ func ContributeTest(descriptor Descriptor) (*Contribution, error) {
}

if descriptor.Package != nil {
format := FormatImage
if descriptor.Package.Platform.OS == PlatformWindows {
format = FormatFile
}

j := actions.Job{
Name: "Create Package Test",
RunsOn: []actions.VirtualEnvironment{actions.UbuntuLatest},
Expand All @@ -119,6 +129,11 @@ func ContributeTest(descriptor Descriptor) (*Contribution, error) {
Run: StatikString("/install-pack.sh"),
Env: map[string]string{"PACK_VERSION": PackVersion},
},
{
Name: "Enable pack Experimental",
If: fmt.Sprintf("${{ %t }}", descriptor.Package.Platform.OS == PlatformWindows),
Run: StatikString("/enable-pack-experimental.sh"),
},
{
Uses: "actions/setup-go@v2",
With: map[string]interface{}{"go-version": GoVersion},
Expand Down Expand Up @@ -147,13 +162,15 @@ func ContributeTest(descriptor Descriptor) (*Contribution, error) {
Run: StatikString("/create-package.sh"),
Env: map[string]string{
"INCLUDE_DEPENDENCIES": "true",
"OS": descriptor.Package.Platform.OS,
"VERSION": "${{ steps.version.outputs.version }}",
},
},
{
Name: "Package Buildpack",
Run: StatikString("/package-buildpack.sh"),
Env: map[string]string{
"FORMAT": format,
"PACKAGE": "test",
"VERSION": "${{ steps.version.outputs.version }}",
},
Expand Down