Skip to content

Commit

Permalink
ci: add e2e test step for windows
Browse files Browse the repository at this point in the history
- Adds a workflow step to run e2e tests on the Windows runner.
- Adds script for code gen on Windows
- Increase test timeouts to 120m
- fix some lints
- update go.mod
- install SOCI as systemd unit; on Windows, starting as background
  process in script was still started in foreground, resulting in
termination after script completion
- fix config test to use LOCALAPPDATA

Signed-off-by: Gavin Inglis <[email protected]>
  • Loading branch information
ginglis13 committed Oct 12, 2023
1 parent 235327c commit 6dc25e7
Show file tree
Hide file tree
Showing 14 changed files with 187 additions and 48 deletions.
103 changes: 92 additions & 11 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ name: CI
on:
push:
branches:
- main
# TODO: revert to main on merge of windev branch with main
- windev
paths-ignore:
- '**.md'
- 'contrib/**'
- '.github/CODEOWNERS'
pull_request:
branches:
- main
# TODO: revert to main on merge of windev branch with main
- windev
paths-ignore:
- '**.md'
- 'contrib/**'
Expand All @@ -26,7 +28,10 @@ concurrency:

jobs:
gen-code-no-diff:
runs-on: ubuntu-latest
strategy:
matrix:
os: [macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
- uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
Expand All @@ -36,7 +41,11 @@ jobs:
- run: make gen-code
- run: git diff --exit-code
unit-tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os: [macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
- uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
Expand All @@ -48,25 +57,36 @@ jobs:
- run: make test-unit
# It's recommended to run golangci-lint in a job separate from other jobs (go test, etc) because different jobs run in parallel.
go-linter:
strategy:
matrix:
os: [macos-latest, windows-latest]
name: lint
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
- uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
with:
go-version-file: go.mod
cache: true
- name: golangci-lint
cache: false # caching can result in tar errors that files already exist
- name: set GOOS env to windows
run: |
echo "GOOS=windows" >> $GITHUB_ENV
- name: golangci-lint - windows
uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3.7.0
with:
# Pin the version in case all the builds start to fail at the same time.
# There may not be an automatic way (e.g., dependabot) to update a specific parameter of a GitHub Action,
# so we will just update it manually whenever it makes sense (e.g., a feature that we want is added).
version: v1.53.3
args: --fix=false --timeout=5m
- name: set GOOS env to darwin
run: |
echo "GOOS=darwin" >> $GITHUB_ENV
- name: golangci-lint - darwin
uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3.7.0
with:
# Pin the version in case all the builds start to fail at the same time.
# There may not be an automatic way (e.g., dependabot) to update a specific parameter of a GitHub Action,
# so we will just update it manually whenever it makes sense (e.g., a feature that we want is added).
version: v1.53.3
args: --fix=false --timeout=5m --skip-dirs="(^|/)deps($|/)"
shellcheck:
name: ShellCheck
runs-on: ubuntu-latest
Expand Down Expand Up @@ -115,7 +135,7 @@ jobs:
# We need to get all the git tags to make version injection work. See VERSION in Makefile for more detail.
fetch-depth: 0
persist-credentials: false
submodules: true
submodules: recursive
- name: Set output variables
id: vars
run: |
Expand Down Expand Up @@ -153,6 +173,67 @@ jobs:
git clean -f -d
REGISTRY=${{ steps.vars.outputs.has_creds == true && env.REGISTRY || '' }} make test-e2e
shell: zsh {0}
windows-e2e-tests:
strategy:
fail-fast: false
matrix:
os:
[
[self-hosted, windows, amd64, test],
]
runs-on: ${{ matrix.os }}
timeout-minutes: 180
steps:
- name: Configure git CRLF settings
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- uses: actions/checkout@v4
with:
# We need to get all the git tags to make version injection work. See VERSION in Makefile for more detail.
fetch-depth: 0
persist-credentials: false
submodules: recursive
- name: Set output variables
id: vars
run: |
$has_creds="${{ github.event_name == 'push' || github.repository == github.event.pull_request.head.repo.full_name }}"
echo "has_creds=$has_creds" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
exit 0 # if $has_creds is false, powershell will exit with code 1 and this step will fail
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v4
if: env.has_creds == 'true'
with:
role-to-assume: ${{ secrets.ROLE }}
role-session-name: credhelper-test
aws-region: ${{ secrets.REGION }}
- name: Remove Finch VM
run: |
wsl --list --verbose
wsl --shutdown
wsl --unregister lima-finch
wsl --list --verbose
- name: Clean up previous files
run: |
Remove-Item C:\Users\Administrator\.finch -Recurse -ErrorAction Ignore
Remove-Item C:\Users\Administrator\AppData\Local\.finch -Recurse -ErrorAction Ignore
make clean
cd deps/finch-core && make clean
- name: Build project
run: |
make
- name: Run e2e tests
run: |
# set path to use newer ssh version
$newPath = (";C:\Program Files\Git\bin\;" + "C:\Program Files\Git\usr\bin\;" + "$env:Path")
$env:Path = $newPath
# set networking config option to allow for VM/container -> host communication
echo "[experimental]`nnetworkingMode=mirrored`nhostAddressLoopback=true" > C:\Users\Administrator\.wslconfig
git status
git clean -f -d
make test-e2e
mdlint:
runs-on: ubuntu-latest
steps:
Expand Down
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -336,15 +336,15 @@ test-e2e: test-e2e-vm-serial

.PHONY: test-e2e-vm-serial
test-e2e-vm-serial: test-e2e-container
go test -ldflags $(LDFLAGS) -timeout 45m ./e2e/vm -test.v -ginkgo.v --installed="$(INSTALLED)"
go test -ldflags $(LDFLAGS) -timeout 2h ./e2e/vm -test.v -ginkgo.v -ginkgo.timeout=2h --installed="$(INSTALLED)"

.PHONY: test-e2e-container
test-e2e-container:
go test -ldflags $(LDFLAGS) -timeout 30m ./e2e/container -test.v -ginkgo.v --installed="$(INSTALLED)"
go test -ldflags $(LDFLAGS) -timeout 2h ./e2e/container -test.v -ginkgo.v -ginkgo.timeout=2h --installed="$(INSTALLED)"

.PHONY: test-e2e-vm
test-e2e-vm:
go test -ldflags $(LDFLAGS) -timeout 45m ./e2e/vm -test.v -ginkgo.v --installed="$(INSTALLED)" --registry="$(REGISTRY)"
go test -ldflags $(LDFLAGS) -timeout 2h ./e2e/vm -test.v -ginkgo.v -ginkgo.timeout=2h --installed="$(INSTALLED)" --registry="$(REGISTRY)"

.PHONY: test-benchmark
test-benchmark:
Expand All @@ -367,8 +367,12 @@ gen-code: GOBIN = $(CURDIR)/tools_bin
gen-code:
GOBIN=$(GOBIN) go install github.com/golang/mock/mockgen
GOBIN=$(GOBIN) go install golang.org/x/tools/cmd/stringer
# Make sure that we are using the tool binaries which are just built to generate code.
# Make sure that we are using the tool binaries which are just built to generate code.
ifeq ($(GOOS),windows)
powershell ./scripts/gen-code-windows.ps1
else
PATH=$(GOBIN):$(PATH) go generate ./...
endif

.PHONY: lint
# To run golangci-lint locally: https://golangci-lint.run/usage/install/#local-installation
Expand Down
2 changes: 1 addition & 1 deletion e2e/vm/config_darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/runfinch/finch/pkg/config"
)

var finchConfigFilePath string = os.Getenv("HOME") + "/.finch/finch.yaml"
var finchConfigFilePath = os.Getenv("HOME") + "/.finch/finch.yaml"

var testConfig = func(o *option.Option, installed bool) {
ginkgo.Describe("Config (after init)", ginkgo.Serial, func() {
Expand Down
9 changes: 9 additions & 0 deletions e2e/vm/config_windows_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
//go:build windows

package vm

import "os"

var finchConfigFilePath = os.Getenv("LOCALAPPDATA") + "/.finch/finch.yaml"
20 changes: 13 additions & 7 deletions e2e/vm/soci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"

"github.com/onsi/ginkgo/v2"
Expand All @@ -28,7 +29,7 @@ const (
var testSoci = func(o *option.Option, installed bool) {
ginkgo.Describe("SOCI", func() {
var limactlO *option.Option
var fpath, realFinchPath, limactlPath, limaHomePathEnv, wd string
var fpath, realFinchPath, limactlPath, limaHomePathEnv, wd, vmType string
var err error
var port int

Expand All @@ -52,13 +53,18 @@ var testSoci = func(o *option.Option, installed bool) {
limactlO, err = option.New([]string{limactlPath},
option.Env([]string{limaHomePathEnv}))
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
if runtime.GOOS == "windows" {
vmType = "wsl2"
} else {
vmType = "qemu"
}
})

ginkgo.It("finch pull should have same mounts as nerdctl pull with SOCI", func() {
resetVM(o, installed)
resetDisks(o, installed)
writeFile(finchConfigFilePath, []byte("cpus: 6\nmemory: 4GiB\nsnapshotters:\n "+
"- soci\nvmType: qemu\nrosetta: false"))
writeFile(finchConfigFilePath, []byte(fmt.Sprintf("cpus: 6\nmemory: 4GiB\nsnapshotters:\n "+
"- soci\nvmType: %s\nrosetta: false", vmType)))
command.New(o, virtualMachineRootCmd, "init").WithTimeoutInSeconds(600).Run()
command.New(o, "pull", "--snapshotter=soci", ffmpegSociImage).WithTimeoutInSeconds(30).Run()
finchPullMounts := countMounts(limactlO)
Expand All @@ -73,8 +79,8 @@ var testSoci = func(o *option.Option, installed bool) {
ginkgo.It("finch run should have same mounts as nerdctl run with SOCI", func() {
resetVM(o, installed)
resetDisks(o, installed)
writeFile(finchConfigFilePath, []byte("cpus: 6\nmemory: 4GiB\nsnapshotters:\n "+
"- soci\nvmType: qemu\nrosetta: false"))
writeFile(finchConfigFilePath, []byte(fmt.Sprintf("cpus: 6\nmemory: 4GiB\nsnapshotters:\n "+
"- soci\nvmType: %s\nrosetta: false", vmType)))
command.New(o, virtualMachineRootCmd, "init").WithTimeoutInSeconds(600).Run()
command.New(o, "run", "--snapshotter=soci", ffmpegSociImage).WithTimeoutInSeconds(30).Run()
finchPullMounts := countMounts(limactlO)
Expand All @@ -88,8 +94,8 @@ var testSoci = func(o *option.Option, installed bool) {
ginkgo.It("finch push should work", func() {
resetVM(o, installed)
resetDisks(o, installed)
writeFile(finchConfigFilePath, []byte("cpus: 6\nmemory: 4GiB\nsnapshotters:\n "+
"- soci\nvmType: qemu\nrosetta: false"))
writeFile(finchConfigFilePath, []byte(fmt.Sprintf("cpus: 6\nmemory: 4GiB\nsnapshotters:\n "+
"- soci\nvmType: %s\nrosetta: false", vmType)))
command.New(o, virtualMachineRootCmd, "init").WithTimeoutInSeconds(600).Run()
port = fnet.GetFreePort()
command.New(o, "run", "-dp", fmt.Sprintf("%d:5000", port), "--name", "registry", registryImage).
Expand Down
1 change: 1 addition & 0 deletions e2e/vm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var resetVM = func(o *option.Option, installed bool) string {
command.New(o, virtualMachineRootCmd, "remove").WithTimeoutInSeconds(90).Run()
if runtime.GOOS == "windows" {
// clean up iptables
//nolint:lll // link to explanation
// https://docs.rancherdesktop.io/troubleshooting-tips/#q-how-do-i-fix-fata0005-subnet-1040024-overlaps-with-other-one-on-this-address-space-when-running-a-container-using-nerdctl-run
gomega.Expect(exec.Command("wsl", "--shutdown").Run()).Should(gomega.BeNil())
}
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ require (
github.com/golang/mock v1.6.0
github.com/google/go-licenses v1.6.0
github.com/lima-vm/lima v0.17.2
github.com/onsi/ginkgo/v2 v2.12.1
github.com/onsi/ginkgo/v2 v2.13.0
github.com/onsi/gomega v1.28.0
github.com/pelletier/go-toml v1.9.5
github.com/pkg/sftp v1.13.6
github.com/runfinch/common-tests v0.7.7
github.com/runfinch/common-tests v0.7.8
github.com/shirou/gopsutil/v3 v3.23.8
github.com/sirupsen/logrus v1.9.3
github.com/spf13/afero v1.10.0
Expand Down Expand Up @@ -62,7 +62,7 @@ require (
github.com/emirpasic/gods v1.12.0 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/goccy/go-yaml v1.11.0 // indirect
github.com/goccy/go-yaml v1.11.0
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/licenseclassifier v0.0.0-20210722185704-3043a050f148 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrk
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/onsi/ginkgo/v2 v2.12.1 h1:uHNEO1RP2SpuZApSkel9nEh1/Mu+hmQe7Q+Pepg5OYA=
github.com/onsi/ginkgo/v2 v2.12.1/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o=
github.com/onsi/ginkgo/v2 v2.13.0 h1:0jY9lJquiL8fcf3M4LAXN5aMlS/b2BV86HFFPCPMgE4=
github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o=
github.com/onsi/gomega v1.28.0 h1:i2rg/p9n/UqIDAMFUJ6qIUUMcsqOuUHgbpbu235Vr1c=
github.com/onsi/gomega v1.28.0/go.mod h1:A1H2JE76sI14WIP57LMKj7FVfCHx3g3BcZVjJG8bjX8=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
Expand Down Expand Up @@ -318,8 +318,8 @@ github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/runfinch/common-tests v0.7.7 h1:ZJjRI4fk02C1Qoj3A9Z+Jdkk2pUZiSqH5L/3peIN1Qs=
github.com/runfinch/common-tests v0.7.7/go.mod h1:3BP9a6r5HeILCy/0IiTeC0zwyAgkUI0X2WZWZIctPj4=
github.com/runfinch/common-tests v0.7.8 h1:uXskg7qUSLp+2H+BT3rsAn5RZ90XVTn8LYOOj6ODsUg=
github.com/runfinch/common-tests v0.7.8/go.mod h1:SiFfCOWo+b2SpA/MwEa3z3cFTCyuEJQJXBJ6ItH6G64=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
Expand Down
11 changes: 7 additions & 4 deletions msi-builder/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
# FinchWindowsMSI

Finch Windows MSI Tool to generate MSI installer from Finch build

## Instructions:
## Instructions

[1] Build finch: `make FINCH_ROOTFS_LOCATION_ROOT=/__INSTALLFOLDER__`

- It will inject the placeholder `__INSTALLFOLDER__` into `os\finch.yaml` for the rootfs location

[2] Run the following command to generate the MSI installer:
`.\BuildFinchMSI.ps1 -SourcePath "<SourcePath>" -Version <Version>`

**Parameters:**

- SourcePath: Refers to the finch build _output folder, e.g., C:\Users\<UserName>\Repo\finch\_output\. It's an optional parameter. If not provided, the default path is finch's _output folder. (You need to build finch before running the MSI tool).
- SourcePath: Refers to the finch build `_output` folder, e.g., `C:\Users\<UserName>\Repo\finch\_output\.` It's an optional parameter. If not provided, the default path is finch's _output folder. (You need to build finch before running the MSI tool).

- Version: A required parameter that should match the version format, e.g., 0.10.2.
- Version: A required parameter that should match the version format, e.g., `0.10.2`.

[3] The Finch-<Version>.msi will be generated to the `msi-builder\build` folder
[3] The `Finch-<Version>.msi` will be generated to the `msi-builder\build` folder
Loading

0 comments on commit 6dc25e7

Please sign in to comment.