-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Required for storing images without Microsoft baselayers on WCOW daemons (i.e. buildpackages) Adds the bcdhive_gen generator for the creation of BCD file, which uses that hivex library which has tricky run-time dependencies on darwin - Replaces testhelper with implementation Signed-off-by: Micah Young <[email protected]>
- Loading branch information
Micah Young
committed
Oct 12, 2020
1 parent
cea9fc5
commit 4a5f630
Showing
14 changed files
with
633 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package layer | ||
|
||
import ( | ||
"archive/tar" | ||
"bytes" | ||
"io" | ||
) | ||
|
||
// Generate using `make generate` | ||
//go:generate docker run --rm -v $PWD:/out/ bcdhive-generator -file=/out/layer/bcdhive_generated.go -package=layer -func=BaseLayerBCD | ||
|
||
// Windows base layers must follow this pattern: | ||
// \-> UtilityVM/Files/EFI/Microsoft/Boot/BCD (file must exist and a valid BCD format - from bcdhive_gen) | ||
// \-> Files/Windows/System32/config/DEFAULT (file and must exist but can be empty) | ||
// \-> Files/Windows/System32/config/SAM (file must exist but can be empty) | ||
// \-> Files/Windows/System32/config/SECURITY (file must exist but can be empty) | ||
// \-> Files/Windows/System32/config/SOFTWARE (file must exist but can be empty) | ||
// \-> Files/Windows/System32/config/SYSTEM (file must exist but can be empty) | ||
// Refs: | ||
// https://github.com/microsoft/hcsshim/blob/master/internal/wclayer/legacy.go | ||
// https://github.com/moby/moby/blob/master/daemon/graphdriver/windows/windows.go#L48 | ||
func WindowsBaseLayer() (io.Reader, error) { | ||
bcdBytes, err := BaseLayerBCD() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
layerBuffer := &bytes.Buffer{} | ||
tw := tar.NewWriter(layerBuffer) | ||
|
||
_ = bcdBytes | ||
if err := tw.WriteHeader(&tar.Header{Name: "UtilityVM", Typeflag: tar.TypeDir}); err != nil { | ||
return nil, err | ||
} | ||
if err := tw.WriteHeader(&tar.Header{Name: "UtilityVM/Files", Typeflag: tar.TypeDir}); err != nil { | ||
return nil, err | ||
} | ||
if err := tw.WriteHeader(&tar.Header{Name: "UtilityVM/Files/EFI", Typeflag: tar.TypeDir}); err != nil { | ||
return nil, err | ||
} | ||
if err := tw.WriteHeader(&tar.Header{Name: "UtilityVM/Files/EFI/Microsoft", Typeflag: tar.TypeDir}); err != nil { | ||
return nil, err | ||
} | ||
if err := tw.WriteHeader(&tar.Header{Name: "UtilityVM/Files/EFI/Microsoft/Boot", Typeflag: tar.TypeDir}); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := tw.WriteHeader(&tar.Header{Name: "UtilityVM/Files/EFI/Microsoft/Boot/BCD", Size: int64(len(bcdBytes)), Mode: 0644}); err != nil { | ||
return nil, err | ||
} | ||
if _, err := tw.Write(bcdBytes); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := tw.WriteHeader(&tar.Header{Name: "Files", Typeflag: tar.TypeDir}); err != nil { | ||
return nil, err | ||
} | ||
if err := tw.WriteHeader(&tar.Header{Name: "Files/Windows", Typeflag: tar.TypeDir}); err != nil { | ||
return nil, err | ||
} | ||
if err := tw.WriteHeader(&tar.Header{Name: "Files/Windows/System32", Typeflag: tar.TypeDir}); err != nil { | ||
return nil, err | ||
} | ||
if err := tw.WriteHeader(&tar.Header{Name: "Files/Windows/System32/config", Typeflag: tar.TypeDir}); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := tw.WriteHeader(&tar.Header{Name: "Files/Windows/System32/config/DEFAULT", Size: 0, Mode: 0644}); err != nil { | ||
return nil, err | ||
} | ||
if err := tw.WriteHeader(&tar.Header{Name: "Files/Windows/System32/config/SAM", Size: 0, Mode: 0644}); err != nil { | ||
return nil, err | ||
} | ||
if err := tw.WriteHeader(&tar.Header{Name: "Files/Windows/System32/config/SECURITY", Size: 0, Mode: 0644}); err != nil { | ||
return nil, err | ||
} | ||
if err := tw.WriteHeader(&tar.Header{Name: "Files/Windows/System32/config/SOFTWARE", Size: 0, Mode: 0644}); err != nil { | ||
return nil, err | ||
} | ||
if err := tw.WriteHeader(&tar.Header{Name: "Files/Windows/System32/config/SYSTEM", Size: 0, Mode: 0644}); err != nil { | ||
return nil, err | ||
} | ||
|
||
return layerBuffer, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM golang:1.15-buster | ||
|
||
RUN apt update \ | ||
&& apt install -y libhivex-dev libhivex-bin libwin-hivex-perl | ||
|
||
COPY . /src | ||
|
||
WORKDIR /src | ||
|
||
RUN go generate ./ \ | ||
&& go test -parallel=1 -count=1 -v . \ | ||
&& go install . | ||
|
||
ENTRYPOINT ["/go/bin/bcdhive_gen"] |
Oops, something went wrong.