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

feat: add Linux support #1023

Merged
merged 39 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
1819ee1
feat(wip): allow finch to build on Linux without Lima
pendo324 Jun 26, 2024
4ad889d
fix Makefile
pendo324 Jul 9, 2024
3bdf5c8
refactor lima_cmd_creator => nerdctl_cmd_creator
pendo324 Jul 9, 2024
01b5b73
fix some refactoring/renaming misses
pendo324 Jul 10, 2024
26c56dc
fix unit tests
pendo324 Jul 23, 2024
bf18a4d
Merge branch 'main' into linux
pendo324 Jul 23, 2024
7c52c4d
fix linting
pendo324 Jul 23, 2024
efc06d5
remove unnecessary mockgen call
pendo324 Jul 23, 2024
44b2fd5
remove unused code
pendo324 Jul 23, 2024
e4c14ed
fix windows unit tests
pendo324 Jul 23, 2024
e65052c
fix linux linting errors
pendo324 Jul 23, 2024
b6a070b
refactor to use standard Linux config path
pendo324 Jul 25, 2024
6e4ab1b
update docs
pendo324 Jul 25, 2024
0712bcd
fix shared settings not being inlined
pendo324 Jul 25, 2024
eec59bf
refactor support bundles to only export files that would be relevant …
pendo324 Jul 25, 2024
8b454e7
update build guards
pendo324 Jul 25, 2024
6fbb0ec
fix FinchRootDir
pendo324 Jul 25, 2024
5f0d7cf
refactor cmd/nerdctl for Linux
pendo324 Jul 25, 2024
03e23ef
refactor nerdctl to use custom paths for buildkit socket and nerdctl.…
pendo324 Jul 26, 2024
350d07f
fix linting
pendo324 Jul 26, 2024
d2e45f9
automatically set the NATIVE_BUILD parameter if using Linux since tha…
pendo324 Jul 29, 2024
11fadda
allow GITCOMMIT to be overwritten to make RPM builds easier
pendo324 Jul 29, 2024
cba2d82
finch-general => finch-all
pendo324 Jul 29, 2024
4dc7985
main_local.go => main_native.go
pendo324 Jul 29, 2024
dc6688b
remove ensureCredentials check in native mode
pendo324 Jul 29, 2024
72f0ce9
virtual_machine_local.go => virtual_machine_native.go
pendo324 Jul 29, 2024
2a3c9f5
ensure all remote only tests have _remote suffix
pendo324 Jul 29, 2024
564aa7d
prepend path to vended buildkit binaries for Fedora-based systems
pendo324 Jul 29, 2024
d84a7f5
fix Makefile not handling default case for NATIVE_BUILD not on Linux
pendo324 Jul 29, 2024
5b15065
simplify makefile
pendo324 Jul 30, 2024
e8743ab
rename variable
pendo324 Jul 30, 2024
ad62d42
add native build tag
pendo324 Jul 30, 2024
a1d03ee
update NerdctlCmdCreator comment
pendo324 Jul 30, 2024
b84b424
fix Makefile for non-native builds
pendo324 Jul 30, 2024
e3555cd
remove native build tag and simplify platform separation
pendo324 Aug 5, 2024
c83c38b
remove unnecessary remote in names
pendo324 Aug 5, 2024
3e3f4c3
fix unit tests
pendo324 Aug 6, 2024
601e040
fix BuildkitSocketPath
pendo324 Aug 21, 2024
b6fe134
Merge branch 'main' into linux
pendo324 Sep 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 31 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ LIMA_EXTENSION := .tar.gz
LIMA_VDE_SUDOERS_FILE := /etc/sudoers.d/finch-lima
# Final installation prefix for vde created by CLI after installation, only used in uninstall step
VDE_INSTALL ?= /opt/finch
UNAME := $(shell uname -m)
ARCH ?= $(UNAME)
ARCH ?= $(shell uname -m)
SUPPORTED_ARCH = false
LICENSEDIR := $(OUTDIR)/license-files
VERSION ?= $(shell git describe --match 'v[0-9]*' --dirty='.modified' --always --tags)
GITCOMMIT := $(shell git rev-parse HEAD)$(shell test -z "$(git status --porcelain)" || echo .m)
GITCOMMIT ?= $(shell git rev-parse HEAD)$(shell test -z "$(git status --porcelain)" || echo .m)
LDFLAGS = "-w -X $(PACKAGE)/pkg/version.Version=$(VERSION) -X $(PACKAGE)/pkg/version.GitCommit=$(GITCOMMIT)"
MIN_MACOS_VERSION ?= 11.0

Expand All @@ -52,15 +51,33 @@ endif
arch-test:
@if [ $(SUPPORTED_ARCH) != "true" ]; then echo "Unsupported architecture: $(ARCH)"; exit "1"; fi

# OS will be set on Windows (to Windows_NT), and undefined otherwise unless
# it is explicity specified on the commandline.
# On Unix (or, not-Windows), query OS and set it using uname -s
BUILD_OS ?= $(OS)
ifeq ($(BUILD_OS),)
BUILD_OS = $(shell uname -s)
endif

FINCH_CORE_DIR := $(CURDIR)/deps/finch-core

ifeq ($(BUILD_OS), Windows_NT)
include Makefile.windows
else
else ifeq ($(BUILD_OS), Darwin)
include Makefile.darwin
else ifeq ($(BUILD_OS), Linux)
# on Linux, set NATIVE_BUILD unless it was otherwise
# set by the environment
NATIVE_BUILD ?= true
endif
# if not set at this point, default it to false
NATIVE_BUILD ?= false

ifeq ($(NATIVE_BUILD),true)
all: finch
else ifeq ($(NATIVE_BUILD),false)
all: arch-test finch install.finch-core-dependencies finch.yaml networks.yaml config.yaml
endif

.PHONY: install.finch-core-dependencies
install.finch-core-dependencies:
Expand Down Expand Up @@ -106,11 +123,13 @@ uninstall: uninstall.finch

.PHONY: finch
ifeq ($(GOOS),windows)
finch: finch-windows finch-general
finch: finch-windows finch-all
else ifeq ($(GOOS),darwin)
finch: finch-macos
else ifeq ($(NATIVE_BUILD),true)
finch: finch-native
else
finch: finch-unix
finch: finch-all
endif

finch-windows:
Expand All @@ -121,10 +140,13 @@ finch-macos: export CGO_CFLAGS := -mmacosx-version-min=$(MIN_MACOS_VERSION)
finch-macos: export CGO_LDFLAGS := -mmacosx-version-min=$(MIN_MACOS_VERSION)
finch-macos: finch-unix

finch-unix: finch-general
finch-unix: finch-all

finch-native: GO_BUILD_TAGS += native
finch-native: finch-all

finch-general:
$(GO) build -ldflags $(LDFLAGS) -o $(OUTDIR)/bin/$(BINARYNAME) $(PACKAGE)/cmd/finch
finch-all:
$(GO) build -ldflags $(LDFLAGS) -tags "$(GO_BUILD_TAGS)" -o $(OUTDIR)/bin/$(BINARYNAME) $(PACKAGE)/cmd/finch

.PHONY: release
release: check-licenses all download-licenses
Expand Down
20 changes: 0 additions & 20 deletions cmd/finch/lima_args_windows.go

This file was deleted.

26 changes: 12 additions & 14 deletions cmd/finch/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,47 +111,45 @@ var newApp = func(
return nil
}

lcc := command.NewLimaCmdCreator(ecc,
logger,
fp.LimaHomePath(),
fp.LimactlPath(),
fp.QEMUBinDir(),
system.NewStdLib(),
)
ncc := nerdctlCmdCreator(ecc, logger, fp, finchRootPath)
lima := wrapper.NewLimaWrapper()
supportBundleBuilder := support.NewBundleBuilder(
logger,
fs,
support.NewBundleConfig(fp, finchRootPath),
fp,
ecc,
lcc,
ncc,
lima,
)

// append nerdctl commands
allCommands := initializeNerdctlCommands(lcc, ecc, logger, fs, fc)
allCommands := initializeNerdctlCommands(ncc, ecc, logger, fs, fc)
// append finch specific commands
allCommands = append(allCommands,
newVersionCommand(lcc, logger, stdOut),
virtualMachineCommands(logger, fp, lcc, ecc, fs, fc, home, finchRootPath),
newSupportBundleCommand(logger, supportBundleBuilder, lcc),
newVersionCommand(ncc, logger, stdOut),
virtualMachineCommands(logger, fp, ncc, ecc, fs, fc, home, finchRootPath),
newSupportBundleCommand(logger, supportBundleBuilder, ncc),
newGenDocsCommand(rootCmd, logger, fs, system.NewStdLib()),
)

rootCmd.AddCommand(allCommands...)

if err := configureNerdctl(fs); err != nil {
logger.Fatal(err)
}

return rootCmd
}

func initializeNerdctlCommands(
lcc command.LimaCmdCreator,
ncc command.NerdctlCmdCreator,
ecc command.Creator,
logger flog.Logger,
fs afero.Fs,
fc *config.Finch,
) []*cobra.Command {
nerdctlCommandCreator := newNerdctlCommandCreator(lcc, ecc, system.NewStdLib(), logger, fs, fc)
nerdctlCommandCreator := newNerdctlCommandCreator(ncc, ecc, system.NewStdLib(), logger, fs, fc)
var allNerdctlCommands []*cobra.Command
for cmdName, cmdDescription := range nerdctlCmds {
allNerdctlCommands = append(allNerdctlCommands, nerdctlCommandCreator.create(cmdName, cmdDescription))
Expand Down
6 changes: 3 additions & 3 deletions cmd/finch/main_darwin.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

//go:build darwin
//go:build darwin && !native

package main

Expand All @@ -23,7 +23,7 @@ func dependencies(
fc *config.Finch,
fp path.Finch,
fs afero.Fs,
lcc command.LimaCmdCreator,
ncc command.NerdctlCmdCreator,
logger flog.Logger,
finchRootPath string,
) []*dependency.Group {
Expand All @@ -37,6 +37,6 @@ func dependencies(
finchRootPath,
system.NewStdLib().Arch(),
),
vmnet.NewDependencyGroup(ecc, lcc, fs, fp, logger),
vmnet.NewDependencyGroup(ecc, ncc, fs, fp, logger),
}
}
38 changes: 38 additions & 0 deletions cmd/finch/main_native.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

//go:build linux || native

package main

import (
"github.com/spf13/afero"

"github.com/runfinch/finch/pkg/command"
"github.com/runfinch/finch/pkg/config"
"github.com/runfinch/finch/pkg/flog"
"github.com/runfinch/finch/pkg/path"
"github.com/runfinch/finch/pkg/system"
)

func nerdctlCmdCreator(ecc command.Creator, logger flog.Logger, fp path.Finch, finchRootPath string) command.NerdctlCmdCreator {
return command.NewNerdctlCmdCreator(ecc,
logger,
fp.NerdctlConfigFilePath(finchRootPath),
fp.BuildkitSocketPath(finchRootPath),
fp.FinchDependencyBinDir(),
system.NewStdLib(),
)
}

func configureNerdctl(fs afero.Fs) error {
return config.NewNerdctlApplier(
nil,
fs,
"",
"",
"",
"",
nil,
).Apply("")
}
29 changes: 29 additions & 0 deletions cmd/finch/main_remote.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

//go:build (darwin || windows) && !native

package main

import (
"github.com/spf13/afero"

"github.com/runfinch/finch/pkg/command"
"github.com/runfinch/finch/pkg/flog"
"github.com/runfinch/finch/pkg/path"
"github.com/runfinch/finch/pkg/system"
)

func nerdctlCmdCreator(ecc command.Creator, logger flog.Logger, fp path.Finch, _ string) command.NerdctlCmdCreator {
return command.NewNerdctlCmdCreator(ecc,
logger,
fp.LimaHomePath(),
fp.LimactlPath(),
fp.QEMUBinDir(),
system.NewStdLib(),
)
}

func configureNerdctl(_ afero.Fs) error {
return nil
}
2 changes: 1 addition & 1 deletion cmd/finch/main_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func dependencies(
fc *config.Finch,
fp path.Finch,
fs afero.Fs,
_ command.LimaCmdCreator,
_ command.NerdctlCmdCreator,
logger flog.Logger,
finchDir string,
) []*dependency.Group {
Expand Down
Loading
Loading