Skip to content

Commit

Permalink
Windows Buildpackages
Browse files Browse the repository at this point in the history
This change adds support for windows buildpackages by adding a
Package.Platform descriptor entry.  This allows you to declare an OS which, if
not specified defaults to "linux".  It also enables the pack experimental flag
for windows buildpackages.

Signed-off-by: Ben Hale <bhale@vmware.com>
  • Loading branch information
nebhale committed Nov 18, 2020
1 parent 740d0d1 commit edba3bf
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 28 deletions.
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
2 changes: 1 addition & 1 deletion octo/statik/statik.go

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions octo/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,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,6 +152,7 @@ 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 }}",
},
},
Expand Down

0 comments on commit edba3bf

Please sign in to comment.