-
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.
Merge pull request #64 from micahyoung/windows-baselayer
Adds support for creating Windows scratch-equivalent baselayers
- Loading branch information
Showing
15 changed files
with
648 additions
and
113 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,6 @@ | |
|
||
# IDEs | ||
.idea/ | ||
|
||
# Build timestamp | ||
tools/bcdhive_generator/.build |
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,84 @@ | ||
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) | ||
|
||
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,15 @@ | ||
ARG go_version | ||
FROM golang:${go_version}-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.