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

Enable package-buildpack for windows #840

Merged

Conversation

TisVictress
Copy link
Contributor

@TisVictress TisVictress commented Sep 17, 2020

Summary

This change enables creation of Windows buildpackages. Windows buildpackages differ from Linux buildpackages in these ways:

Linux buildpackage image (no change from main)

  • The image's os property is linux
  • Image buildpack layers are tar files with entry paths at /cnb/buildpacks/...

Linux buildpackage file (no change from main)

  • The Linux buildpackage image packaged as as a standard .cnb

Windows buildpackage image (new)

Windows buildpackage file (new)

  • The Windows buildpackage image packaged as a standard .cnb

Before

The package-buildpack command always generated buildpackage files/images as Linux OCI images.

After

The package-buildpack command preserves existing behavior but supports creating files/images as Windows OCI images based on --os=windows flags or daemon-based OS detection.

Preserves existing behavior (with or without pack config experimental=true):

  • package-buildpack --format=file ... => Linux buildpackage file (No daemon required)
  • package-buildpack --format=image --publish ... => Linux buildpackage image on registry (No daemon required)
  • package-buildpack --format=image ... => Linux buildpackage image on daemon (when Linux daemon present)

With pack config experimental=true:

  • package-buildpack --format=file --os=windows ... => Windows buildpackage file (No daemon required.)
  • package-buildpack --format=image --publish --os=windows... => Windows buildpackage image on registry (No daemon required)
  • package-buildpack --format=image --os=windows ... => Windows buildpackage image on daemon (when WCOW daemon present, otherwise fail)
  • package-buildpack --format=image ... => Linux/Windows buildpackage image on daemon (when Linux/WCOW daemon present, resp)

With pack config experimental not enabled:

  • package-buildpack --os=linux => Fails with experimental support missing for "os" flag
  • package-buildpack --format=image ... => Fails with experimental support missing for Windows packages (when Windows daemon present)

Example artifacts:

cnbs/sample-package:hello-world-windows (built from draft PR):

  • hello-universe-windows.cnb (Google Drive download)
  • dive micahyoung/sample-package:hello-universe-windows (requires WCOW daemon)
┃ ● Layers ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ │ Current Layer Contents ├──────────────────────
Cmp   Size  Command                              ├── Files
     12 kB  FROM 8a4dd6e94861fde                 │   ├── Windows
    1.5 kB                                       │   │   └── System32
    1.5 kB                                       │   │       └── config
     782 B                                       │   │           ├── DEFAULT
                                                 │   │           ├── SAM
│ Layer Details ├─────────────────────────────── │   │           ├── SECURITY
                                                 │   │           ├── SOFTWARE
Tags:   (unavailable)                            │   │           └── SYSTEM
Id:     bc0d21bd19f46c9aec44955ebc8db42808a9303a │   └── cnb  
9d52e279080d281c4ba20b0d                         │       └── buildpacks
Digest: sha256:47b97ff94b56931f42be9d1b5a454751c │           ├── samples_hello-moon-windows
8a6ce95c7fdf29db54ebcefa6858787                  │           │   └── 0.0.1
Command:                                         │           │       ├── README.md
                                                 │           │       ├── bin
                                                 │           │       │   ├── build.bat
│ Image Details ├─────────────────────────────── │           │       │   └── detect.bat
                                                 │           │       └── buildpack.toml
                                                 │           ├── samples_hello-universe-windows
Total Image size: 16 kB                          │           │   └── 0.0.1
Potential wasted space: 0 B                      │           │       ├── README.md
Image efficiency score: 100 %                    │           │       └── buildpack.toml
                                                 │           └── samples_hello-world-windows
Count   Total Space  Path                        │               └── 0.0.1             
    3           0 B  /Hives                      │                   ├── README.md     
                                                 │                   ├── bin
                                                 │                   │   ├── build.bat
                                                 │                   │   └── detect.bat
                                                 │                   └── buildpack.toml
                                                 ├── Hives                
                                                 └── UtilityVM           
                                                     └── Files              
                                                         └── EFI
                                                             └── Microsoft
                                                                 └── Boot
                                                                     └── BCD

Signed-off-by: Victoria Henry [email protected]
Signed-off-by: Andrew Meyer [email protected]
Signed-off-by: Micah Young [email protected]

@TisVictress TisVictress requested a review from a team as a code owner September 17, 2020 20:11
@codecov
Copy link

codecov bot commented Sep 17, 2020

Codecov Report

Merging #840 into main will decrease coverage by 0.60%.
The diff coverage is 65.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #840      +/-   ##
==========================================
- Coverage   76.15%   75.56%   -0.59%     
==========================================
  Files          87       81       -6     
  Lines        4464     4213     -251     
==========================================
- Hits         3399     3183     -216     
+ Misses        710      690      -20     
+ Partials      355      340      -15     
Flag Coverage Δ
#os_linux 75.56% <65.00%> (-0.59%) ⬇️
#os_macos 71.97% <65.00%> (-0.79%) ⬇️
#os_windows 100.00% <ø> (?)
#unit 75.56% <65.00%> (-0.59%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

@TisVictress TisVictress force-pushed the feature/windows-package-buildpack-172289412 branch from 4866a02 to b25523f Compare September 17, 2020 20:24
@micahyoung
Copy link
Member

micahyoung commented Sep 17, 2020

Awesome to see this working! Just to start the discussion, is there a detailed description we can give for the behavior here? What's images are created for local, publish, file? Which layers are created in them and in which format for each case?

(and if not ready for review no worries)

@micahyoung micahyoung force-pushed the feature/windows-package-buildpack-172289412 branch from b25523f to 8b006ab Compare September 18, 2020 13:24
@TisVictress TisVictress marked this pull request as draft September 18, 2020 13:42
@micahyoung micahyoung force-pushed the feature/windows-package-buildpack-172289412 branch from 67a5e0d to c9815f7 Compare October 6, 2020 21:12
@micahyoung micahyoung force-pushed the feature/windows-package-buildpack-172289412 branch 2 times, most recently from 89e29d0 to ba9942f Compare October 12, 2020 13:16
@micahyoung micahyoung force-pushed the feature/windows-package-buildpack-172289412 branch 3 times, most recently from 5bfd35d to 881fa34 Compare October 13, 2020 12:22
@@ -346,6 +347,7 @@ func testWithoutSpecificBuilderRequirement(
"package-buildpack", packageName,
"-c", aggregatePackageToml,
"--publish",
"--os", dockerHostOS(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there's a way to infer this without a flag... I understand why we might not want to look at the dockerhost OS, as you might be cross-building. Though wouldn't that only work in a --publish scenario?

Back to the original question, is there some way we could derive this from the buildpack? Seems unlikely but thought I'd ask.

Copy link
Member

@micahyoung micahyoung Oct 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's a good thing to discuss. Right now, for backward compatibility reasons, this implementation does still always default to linux for --publish or --format=file w/o the --os flag (it emits a warning telling you this) but for local images (which is the default for package-buildpack w/o options) it will autodetect the image type (without a warning) and save it on the dameon. Also for backward compatibility, it can't require a daemon for --publish or --format=file.

With that in mind, the autodetection options for --publish or --format=file might be to detect based on a optional daemon, but depending on if your daemon is running/stopped, you have a reachable/unreachable DOCKER_HOST set, or some other environment difference, you'd generate different images with the same command. I feel like autodetecting the image type from the dameon only really feels right in the case of a local image on the daemon, where it has to match the running daemon anyways and it unlikely to be pushed up to a registry or copied around.

Detecting from a buildpack would be hard as meta buildpacks wouldn't even have binary names to check bin/build vs bin/build{.bat,.exe}. We'd need each buildpack in the package to explicitly state that they are Windows and them all to agree.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could make the os an optional field in the package config though, instead of the --os flag. Then package-buildpack would consistently generate the same image time regardless of daemon. The only potential catch there is that to-date, the package config tends to describe CNB-related things (buildpack paths and images) inside a package and not things about the way it's packaged (ex: --format is specified on the command line, not in the package.toml).

go.mod Outdated Show resolved Hide resolved
Copy link
Contributor

@ameyer-pivotal ameyer-pivotal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really good. I did notice that Windows buildpackage support seems to be missing the experimental flag requirement. Other than that, this is looking great!

@micahyoung micahyoung force-pushed the feature/windows-package-buildpack-172289412 branch 3 times, most recently from 37d87f2 to 8b22e5c Compare October 20, 2020 12:17
Anthony Emengo and others added 4 commits October 20, 2020 08:39
Signed-off-by: Anthony Emengo <[email protected]>
Signed-off-by: Andrew Meyer <[email protected]>
Signed-off-by: Victoria Henry <[email protected]>
- Important for publish scenarios to not depend on daemon

Signed-off-by: Micah Young <[email protected]>
@micahyoung micahyoung force-pushed the feature/windows-package-buildpack-172289412 branch from 8b22e5c to a4e1055 Compare October 20, 2020 12:39
@micahyoung
Copy link
Member

This looks really good. I did notice that Windows buildpackage support seems to be missing the experimental flag requirement. Other than that, this is looking great!

Great catch. Now fixed! I added the experimental flag for both --os and when Windows is autodetected for local images without the --os flag

@micahyoung micahyoung marked this pull request as ready for review October 20, 2020 12:45
@jromero jromero added this to the 0.15.0 milestone Oct 20, 2020
@jromero jromero added type/enhancement Issue that requests a new feature or improvement. experimental Issue or PR refers to an experimental feature. labels Oct 20, 2020
Copy link
Member

@jromero jromero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! Clean implementation.

@jromero jromero mentioned this pull request Oct 20, 2020
jromero added a commit that referenced this pull request Oct 20, 2020
@jromero jromero merged commit c21b8ac into buildpacks:main Oct 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
experimental Issue or PR refers to an experimental feature. type/enhancement Issue that requests a new feature or improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants