Windows - Host Compute Service Shim
Перейти к файлу
Hamza El-Saawy 925fb1e044
Consolidate Go installation step (#2244)
Create composite action to call `actions/setup-go` with common values
and logic across different jobs and workflows to reduce duplication and
make sure workflows all use the same Go version.

Specifically, the action defaults to `oldstable` for the Go version,
uses both `go.sum` and `test/go.sum` for the cache dependency, and
allows pre-filling the Go module cache after installing Go.

It exposes the same outputs as `actions/setup-go` as well.

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
2024-08-23 15:54:57 -04:00
.github Consolidate Go installation step (#2244) 2024-08-23 15:54:57 -04:00
boot always scrub logs in SNP mode (#2143) 2024-05-16 12:02:38 -07:00
cmd Merge pull request #2207 from katiewasnothere/kabaldau/runhcs_higher_memory 2024-07-18 17:24:23 -07:00
computestorage Update go-winio to v0.6.2 & fix lint errors 2024-04-19 14:10:56 -07:00
ext4 Update pre-go1.21 code (#2054) 2024-03-06 13:58:22 -05:00
hack Remove godeps from makefile (#1750) 2023-05-04 16:07:42 -04:00
hcn Modifying network flag EnableIov. 2024-07-15 12:23:49 -07:00
init Remove kernel panic if ftw returns an error 2024-08-19 20:34:37 -07:00
internal Use `atomic` types instead of raw values (#2241) 2024-08-22 14:42:04 -04:00
osversion Create UVM honoring NUMA configuration parameters (#2198) 2024-07-17 11:05:20 +05:30
pkg Upgrade deps to resolve CVEs (#2225) 2024-08-05 16:31:56 -04:00
scripts [test] Log to ETW for benchmarks; retry layer removal (#1947) 2023-10-25 11:07:12 -04:00
test Use `atomic` types instead of raw values (#2241) 2024-08-22 14:42:04 -04:00
tools Create tools package to isolate dependencies (#1840) 2023-07-18 11:39:36 -04:00
vendor Bump opa/containerd to latest versions 2024-08-16 09:37:47 -07:00
vsockexec
.gitattributes
.gitignore Use `gh` cli to download releases (#1792) 2023-05-30 13:34:04 -04:00
.golangci.yml Lint common error wrapping issues, update README (#1969) 2023-12-11 13:57:32 -05:00
CODEOWNERS
LICENSE
Makefile Add support for loading modules in init script when makefile variable 2024-06-12 15:33:38 -07:00
Makefile.bootfiles verity-boot: append hash device to rootfs (#2142) 2024-05-28 14:44:20 -07:00
Protobuild.toml Updated containerd1.7; google.golang.org/protobuf (#1706) 2023-07-10 11:25:50 -04:00
README.md updating a link in the readme to its new location (#2214) 2024-07-31 10:09:10 -07:00
SECURITY.md
container.go Lint common error wrapping issues, update README (#1969) 2023-12-11 13:57:32 -05:00
errors.go Lint common error wrapping issues, update README (#1969) 2023-12-11 13:57:32 -05:00
go.mod Bump opa/containerd to latest versions 2024-08-16 09:37:47 -07:00
go.sum Bump opa/containerd to latest versions 2024-08-16 09:37:47 -07:00
hcsshim.go Switch to go-winio/tools/mkwinsyscall (#1409) 2022-09-26 15:56:48 -04:00
hnsaccelnet.go Hcsshim wrapper over HNS API needed for exclusion of management mac addresses for VF reassignment. 2024-06-27 09:32:16 -07:00
hnsendpoint.go
hnsglobals.go
hnsnetwork.go
hnspolicy.go
hnspolicylist.go
hnssupport.go
interface.go
layer.go cimfs: Add a LayerWriter for writing cim layers (#1873) 2023-11-01 11:11:46 -07:00
process.go
zsyscall_windows.go Update go-winio to v0.6.2 & fix lint errors 2024-04-19 14:10:56 -07:00

README.md

hcsshim

Build status

This package contains the Golang interface for using the Windows Host Compute Service (HCS) to launch and manage Windows Containers. It also contains other helpers and functions for managing Windows Containers such as the Golang interface for the Host Network Service (HNS), as well as code for the guest agent (commonly referred to as the GCS or Guest Compute Service in the codebase) used to support running Linux Hyper-V containers.

It is primarily used in the Moby and Containerd projects, but it can be freely used by other projects as well.

Building

While this repository can be used as a library of sorts to call the HCS apis, there are a couple binaries built out of the repository as well. The main ones being the Linux guest agent, and an implementation of the runtime v2 containerd shim api.

Linux Hyper-V Container Guest Agent

To build the Linux guest agent itself all that's needed is to set your GOOS to "Linux" and build out of ./cmd/gcs.

C:\> $env:GOOS="linux"
C:\> go build .\cmd\gcs\

or on a Linux machine

> go build ./cmd/gcs

If you want it to be packaged inside of a rootfs to boot with alongside all of the other tools then you'll need to provide a rootfs that it can be packaged inside of. An easy way is to export the rootfs of a container.

docker pull busybox
docker run --name base_image_container busybox
docker export base_image_container | gzip > base.tar.gz
BASE=./base.tar.gz
make all

If the build is successful, in the ./out folder you should see:

> ls ./out/
delta.tar.gz  initrd.img  rootfs.tar.gz

Containerd Shim

For info on the Runtime V2 API.

Contrary to the typical Linux architecture of shim -> runc, the runhcs shim is used both to launch and manage the lifetime of containers.

C:\> $env:GOOS="windows"
C:\> go build .\cmd\containerd-shim-runhcs-v1

Then place the binary in the same directory that Containerd is located at in your environment. A default Containerd configuration file can be generated by running:

.\containerd.exe config default | Out-File "C:\Program Files\containerd\config.toml" -Encoding ascii

This config file will already have the shim set as the default runtime for cri interactions.

To trial using the shim out with ctr.exe:

C:\> ctr.exe run --runtime io.containerd.runhcs.v1 --rm mcr.microsoft.com/windows/nanoserver:2004 windows-test cmd /c "echo Hello World!"

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit Microsoft CLA.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

We require that contributors sign their commits to certify they either authored the work themselves or otherwise have permission to use it in this project.

We also require that contributors sign their commits using using git commit --signoff to certify they either authored the work themselves or otherwise have permission to use it in this project. A range of commits can be signed off using git rebase --signoff.

Please see the developer certificate for more info, as well as to make sure that you can attest to the rules listed. Our CI uses the DCO Github app to ensure that all commits in a given PR are signed-off.

Linting

Code must pass a linting stage, which uses golangci-lint. Since ./test is a separate Go module, the linter is run from both the root and the test directories. Additionally, the linter is run with GOOS set to both windows and linux.

The linting settings are stored in .golangci.yaml, and can be run automatically with VSCode by adding the following to your workspace or folder settings:

    "go.lintTool": "golangci-lint",
    "go.lintOnSave": "package",

Additional editor integrations options are also available.

Alternatively, golangci-lint can be installed and run locally:

# use . or specify a path to only lint a package
# to show all lint errors, use flags "--max-issues-per-linter=0 --max-same-issues=0"
> golangci-lint run

To run across the entire repo for both GOOS=windows and linux:

> foreach ( $goos in ('windows', 'linux') ) {
    foreach ( $repo in ('.', 'test') ) {
        pwsh -Command "cd $repo && go env -w GOOS=$goos && golangci-lint.exe run --verbose"
    }
}

Go Generate

The pipeline checks that auto-generated code, via go generate, are up to date. Similar to the linting stage, go generate is run in both the root and test Go modules.

This can be done via:

> go generate ./...
> cd test && go generate ./...

Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Dependencies

This project requires Golang 1.18 or newer to build.

For system requirements to run this project, see the Microsoft docs on Windows Container requirements.

Reporting Security Issues

Security issues and bugs should be reported privately, via email, to the Microsoft Security Response Center (MSRC) at secure@microsoft.com. You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Further information, including the MSRC PGP key, can be found in the Security TechCenter.

For additional details, see Report a Computer Security Vulnerability on Technet


Copyright (c) 2018 Microsoft Corp. All rights reserved.