Skip to content

Commit 82f698b

Browse files
authored
feat: add Linux support (runfinch#1023)
* feat(wip): allow finch to build on Linux without Lima Signed-off-by: Justin Alvarez <[email protected]> * fix Makefile Signed-off-by: Justin Alvarez <[email protected]> * refactor lima_cmd_creator => nerdctl_cmd_creator Signed-off-by: Justin Alvarez <[email protected]> * fix some refactoring/renaming misses Signed-off-by: Justin Alvarez <[email protected]> * fix unit tests Signed-off-by: Justin Alvarez <[email protected]> * fix linting Signed-off-by: Justin Alvarez <[email protected]> * remove unnecessary mockgen call Signed-off-by: Justin Alvarez <[email protected]> * remove unused code Signed-off-by: Justin Alvarez <[email protected]> * fix windows unit tests Signed-off-by: Justin Alvarez <[email protected]> * fix linux linting errors Signed-off-by: Justin Alvarez <[email protected]> * refactor to use standard Linux config path Signed-off-by: Justin Alvarez <[email protected]> * update docs Signed-off-by: Justin Alvarez <[email protected]> * fix shared settings not being inlined Signed-off-by: Justin Alvarez <[email protected]> * refactor support bundles to only export files that would be relevant on Linux Signed-off-by: Justin Alvarez <[email protected]> * update build guards Signed-off-by: Justin Alvarez <[email protected]> * fix FinchRootDir Signed-off-by: Justin Alvarez <[email protected]> * refactor cmd/nerdctl for Linux Signed-off-by: Justin Alvarez <[email protected]> * refactor nerdctl to use custom paths for buildkit socket and nerdctl.toml Signed-off-by: Justin Alvarez <[email protected]> * fix linting Signed-off-by: Justin Alvarez <[email protected]> * automatically set the NATIVE_BUILD parameter if using Linux since that's the only supported config Signed-off-by: Justin Alvarez <[email protected]> * allow GITCOMMIT to be overwritten to make RPM builds easier Signed-off-by: Justin Alvarez <[email protected]> * finch-general => finch-all Signed-off-by: Justin Alvarez <[email protected]> * main_local.go => main_native.go Signed-off-by: Justin Alvarez <[email protected]> * remove ensureCredentials check in native mode Signed-off-by: Justin Alvarez <[email protected]> * virtual_machine_local.go => virtual_machine_native.go Signed-off-by: Justin Alvarez <[email protected]> * ensure all remote only tests have _remote suffix Signed-off-by: Justin Alvarez <[email protected]> * prepend path to vended buildkit binaries for Fedora-based systems Signed-off-by: Justin Alvarez <[email protected]> * fix Makefile not handling default case for NATIVE_BUILD not on Linux Signed-off-by: Justin Alvarez <[email protected]> * simplify makefile Signed-off-by: Justin Alvarez <[email protected]> * rename variable Signed-off-by: Justin Alvarez <[email protected]> * add native build tag Signed-off-by: Justin Alvarez <[email protected]> * update NerdctlCmdCreator comment Signed-off-by: Justin Alvarez <[email protected]> * fix Makefile for non-native builds Signed-off-by: Justin Alvarez <[email protected]> * remove native build tag and simplify platform separation Signed-off-by: Justin Alvarez <[email protected]> * remove unnecessary remote in names Signed-off-by: Justin Alvarez <[email protected]> * fix unit tests Signed-off-by: Justin Alvarez <[email protected]> * fix BuildkitSocketPath Signed-off-by: Justin Alvarez <[email protected]> --------- Signed-off-by: Justin Alvarez <[email protected]>
1 parent 35bc4dc commit 82f698b

File tree

103 files changed

+2625
-2328
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+2625
-2328
lines changed

Makefile

+28-11
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@ LIMA_EXTENSION := .tar.gz
2222
LIMA_VDE_SUDOERS_FILE := /etc/sudoers.d/finch-lima
2323
# Final installation prefix for vde created by CLI after installation, only used in uninstall step
2424
VDE_INSTALL ?= /opt/finch
25-
UNAME := $(shell uname -m)
26-
ARCH ?= $(UNAME)
25+
ARCH ?= $(shell uname -m)
2726
SUPPORTED_ARCH = false
2827
LICENSEDIR := $(OUTDIR)/license-files
2928
VERSION ?= $(shell git describe --match 'v[0-9]*' --dirty='.modified' --always --tags)
30-
GITCOMMIT := $(shell git rev-parse HEAD)$(shell test -z "$(git status --porcelain)" || echo .m)
29+
GITCOMMIT ?= $(shell git rev-parse HEAD)$(shell test -z "$(git status --porcelain)" || echo .m)
3130
LDFLAGS = "-w -X $(PACKAGE)/pkg/version.Version=$(VERSION) -X $(PACKAGE)/pkg/version.GitCommit=$(GITCOMMIT)"
3231
MIN_MACOS_VERSION ?= 11.0
3332

@@ -52,16 +51,29 @@ endif
5251
arch-test:
5352
@if [ $(SUPPORTED_ARCH) != "true" ]; then echo "Unsupported architecture: $(ARCH)"; exit "1"; fi
5453

54+
# OS will be set on Windows (to Windows_NT), and undefined otherwise unless
55+
# it is explicity specified on the commandline.
56+
# On Unix (or, not-Windows), query OS and set it using uname -s
5557
BUILD_OS ?= $(OS)
58+
ifeq ($(BUILD_OS),)
59+
BUILD_OS = $(shell uname -s)
60+
endif
61+
5662
FINCH_CORE_DIR := $(CURDIR)/deps/finch-core
63+
64+
remote-all: arch-test finch install.finch-core-dependencies finch.yaml networks.yaml config.yaml
65+
5766
ifeq ($(BUILD_OS), Windows_NT)
5867
include Makefile.windows
59-
else
68+
all: remote-all
69+
else ifeq ($(BUILD_OS), Darwin)
6070
include Makefile.darwin
71+
all: remote-all
72+
else ifeq ($(BUILD_OS), Linux)
73+
# on Linux, we only need to build "finch"
74+
all: finch
6175
endif
6276

63-
all: arch-test finch install.finch-core-dependencies finch.yaml networks.yaml config.yaml
64-
6577
.PHONY: install.finch-core-dependencies
6678
install.finch-core-dependencies:
6779
OUTDIR=$(OUTDIR) ARCH=$(ARCH) "$(MAKE)" -C $(FINCH_CORE_DIR) install.dependencies
@@ -106,11 +118,13 @@ uninstall: uninstall.finch
106118

107119
.PHONY: finch
108120
ifeq ($(GOOS),windows)
109-
finch: finch-windows finch-general
121+
finch: finch-windows finch-all
110122
else ifeq ($(GOOS),darwin)
111123
finch: finch-macos
124+
else ifeq ($(NATIVE_BUILD),true)
125+
finch: finch-native
112126
else
113-
finch: finch-unix
127+
finch: finch-all
114128
endif
115129

116130
finch-windows:
@@ -121,10 +135,13 @@ finch-macos: export CGO_CFLAGS := -mmacosx-version-min=$(MIN_MACOS_VERSION)
121135
finch-macos: export CGO_LDFLAGS := -mmacosx-version-min=$(MIN_MACOS_VERSION)
122136
finch-macos: finch-unix
123137

124-
finch-unix: finch-general
138+
finch-unix: finch-all
139+
140+
finch-native: GO_BUILD_TAGS += native
141+
finch-native: finch-all
125142

126-
finch-general:
127-
$(GO) build -ldflags $(LDFLAGS) -o $(OUTDIR)/bin/$(BINARYNAME) $(PACKAGE)/cmd/finch
143+
finch-all:
144+
$(GO) build -ldflags $(LDFLAGS) -tags "$(GO_BUILD_TAGS)" -o $(OUTDIR)/bin/$(BINARYNAME) $(PACKAGE)/cmd/finch
128145

129146
.PHONY: release
130147
release: check-licenses all download-licenses

cmd/finch/lima_args_windows.go

-20
This file was deleted.

cmd/finch/main.go

+2-68
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@ import (
1717
"github.com/runfinch/finch/pkg/config"
1818
"github.com/runfinch/finch/pkg/flog"
1919
"github.com/runfinch/finch/pkg/fmemory"
20-
"github.com/runfinch/finch/pkg/lima/wrapper"
2120
"github.com/runfinch/finch/pkg/path"
22-
"github.com/runfinch/finch/pkg/support"
2321
"github.com/runfinch/finch/pkg/system"
24-
"github.com/runfinch/finch/pkg/version"
2522
)
2623

2724
const finchRootCmd = "finch"
@@ -83,77 +80,14 @@ func xmain(logger flog.Logger,
8380
).Execute()
8481
}
8582

86-
var newApp = func(
87-
logger flog.Logger,
88-
fp path.Finch,
89-
fs afero.Fs,
90-
fc *config.Finch,
91-
stdOut io.Writer,
92-
home,
93-
finchRootPath string,
94-
ecc command.Creator,
95-
) *cobra.Command {
96-
usage := fmt.Sprintf("%v <command>", finchRootCmd)
97-
rootCmd := &cobra.Command{
98-
Use: usage,
99-
Short: "Finch: open-source container development tool",
100-
SilenceUsage: true,
101-
SilenceErrors: true,
102-
Version: version.Version,
103-
}
104-
// TODO: Decide when to forward --debug to the dependencies
105-
// (e.g. nerdctl for container commands and limactl for VM commands).
106-
rootCmd.PersistentFlags().Bool("debug", false, "running under debug mode")
107-
rootCmd.PersistentPreRunE = func(cmd *cobra.Command, _ []string) error {
108-
// running commands under debug mode will print out debug logs
109-
debugMode, _ := cmd.Flags().GetBool("debug")
110-
if debugMode {
111-
logger.SetLevel(flog.Debug)
112-
}
113-
return nil
114-
}
115-
116-
lcc := command.NewLimaCmdCreator(ecc,
117-
logger,
118-
fp.LimaHomePath(),
119-
fp.LimactlPath(),
120-
fp.QEMUBinDir(),
121-
system.NewStdLib(),
122-
)
123-
lima := wrapper.NewLimaWrapper()
124-
supportBundleBuilder := support.NewBundleBuilder(
125-
logger,
126-
fs,
127-
support.NewBundleConfig(fp, finchRootPath),
128-
fp,
129-
ecc,
130-
lcc,
131-
lima,
132-
)
133-
134-
// append nerdctl commands
135-
allCommands := initializeNerdctlCommands(lcc, ecc, logger, fs, fc)
136-
// append finch specific commands
137-
allCommands = append(allCommands,
138-
newVersionCommand(lcc, logger, stdOut),
139-
virtualMachineCommands(logger, fp, lcc, ecc, fs, fc, home, finchRootPath),
140-
newSupportBundleCommand(logger, supportBundleBuilder, lcc),
141-
newGenDocsCommand(rootCmd, logger, fs, system.NewStdLib()),
142-
)
143-
144-
rootCmd.AddCommand(allCommands...)
145-
146-
return rootCmd
147-
}
148-
14983
func initializeNerdctlCommands(
150-
lcc command.LimaCmdCreator,
84+
ncc command.NerdctlCmdCreator,
15185
ecc command.Creator,
15286
logger flog.Logger,
15387
fs afero.Fs,
15488
fc *config.Finch,
15589
) []*cobra.Command {
156-
nerdctlCommandCreator := newNerdctlCommandCreator(lcc, ecc, system.NewStdLib(), logger, fs, fc)
90+
nerdctlCommandCreator := newNerdctlCommandCreator(ncc, ecc, system.NewStdLib(), logger, fs, fc)
15791
var allNerdctlCommands []*cobra.Command
15892
for cmdName, cmdDescription := range nerdctlCmds {
15993
allNerdctlCommands = append(allNerdctlCommands, nerdctlCommandCreator.create(cmdName, cmdDescription))

cmd/finch/main_darwin.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func dependencies(
2323
fc *config.Finch,
2424
fp path.Finch,
2525
fs afero.Fs,
26-
lcc command.LimaCmdCreator,
26+
ncc command.NerdctlCmdCreator,
2727
logger flog.Logger,
2828
finchRootPath string,
2929
) []*dependency.Group {
@@ -37,6 +37,6 @@ func dependencies(
3737
finchRootPath,
3838
system.NewStdLib().Arch(),
3939
),
40-
vmnet.NewDependencyGroup(ecc, lcc, fs, fp, logger),
40+
vmnet.NewDependencyGroup(ecc, ncc, fs, fp, logger),
4141
}
4242
}

cmd/finch/main_native.go

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
//go:build linux
5+
6+
package main
7+
8+
import (
9+
"fmt"
10+
"io"
11+
12+
"github.com/spf13/afero"
13+
"github.com/spf13/cobra"
14+
15+
"github.com/runfinch/finch/pkg/command"
16+
"github.com/runfinch/finch/pkg/config"
17+
"github.com/runfinch/finch/pkg/flog"
18+
"github.com/runfinch/finch/pkg/lima/wrapper"
19+
"github.com/runfinch/finch/pkg/path"
20+
"github.com/runfinch/finch/pkg/support"
21+
"github.com/runfinch/finch/pkg/system"
22+
"github.com/runfinch/finch/pkg/version"
23+
)
24+
25+
var newApp = func(
26+
logger flog.Logger,
27+
fp path.Finch,
28+
fs afero.Fs,
29+
fc *config.Finch,
30+
stdOut io.Writer,
31+
_,
32+
finchRootPath string,
33+
ecc command.Creator,
34+
) *cobra.Command {
35+
usage := fmt.Sprintf("%v <command>", finchRootCmd)
36+
rootCmd := &cobra.Command{
37+
Use: usage,
38+
Short: "Finch: open-source container development tool",
39+
SilenceUsage: true,
40+
SilenceErrors: true,
41+
Version: version.Version,
42+
}
43+
// TODO: Decide when to forward --debug to the dependencies
44+
// (e.g. nerdctl for container commands and limactl for VM commands).
45+
rootCmd.PersistentFlags().Bool("debug", false, "running under debug mode")
46+
rootCmd.PersistentPreRunE = func(cmd *cobra.Command, _ []string) error {
47+
// running commands under debug mode will print out debug logs
48+
debugMode, _ := cmd.Flags().GetBool("debug")
49+
if debugMode {
50+
logger.SetLevel(flog.Debug)
51+
}
52+
return nil
53+
}
54+
55+
ncc := command.NewNerdctlCmdCreator(ecc,
56+
logger,
57+
fp.NerdctlConfigFilePath(finchRootPath),
58+
fp.BuildkitSocketPath(),
59+
fp.FinchDependencyBinDir(),
60+
system.NewStdLib(),
61+
)
62+
lima := wrapper.NewLimaWrapper()
63+
supportBundleBuilder := support.NewBundleBuilder(
64+
logger,
65+
fs,
66+
support.NewBundleConfig(fp, finchRootPath),
67+
fp,
68+
ecc,
69+
ncc,
70+
lima,
71+
)
72+
73+
// append nerdctl commands
74+
allCommands := initializeNerdctlCommands(ncc, ecc, logger, fs, fc)
75+
// append finch specific commands
76+
allCommands = append(allCommands,
77+
newVersionCommand(ncc, logger, stdOut),
78+
newSupportBundleCommand(logger, supportBundleBuilder, ncc),
79+
newGenDocsCommand(rootCmd, logger, fs, system.NewStdLib()),
80+
)
81+
82+
rootCmd.AddCommand(allCommands...)
83+
84+
return rootCmd
85+
}

cmd/finch/main_remote.go

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
//go:build darwin || windows
5+
6+
package main
7+
8+
import (
9+
"fmt"
10+
"io"
11+
12+
"github.com/spf13/afero"
13+
"github.com/spf13/cobra"
14+
15+
"github.com/runfinch/finch/pkg/command"
16+
"github.com/runfinch/finch/pkg/config"
17+
"github.com/runfinch/finch/pkg/flog"
18+
"github.com/runfinch/finch/pkg/lima/wrapper"
19+
"github.com/runfinch/finch/pkg/path"
20+
"github.com/runfinch/finch/pkg/support"
21+
"github.com/runfinch/finch/pkg/system"
22+
"github.com/runfinch/finch/pkg/version"
23+
)
24+
25+
var newApp = func(
26+
logger flog.Logger,
27+
fp path.Finch,
28+
fs afero.Fs,
29+
fc *config.Finch,
30+
stdOut io.Writer,
31+
home,
32+
finchRootPath string,
33+
ecc command.Creator,
34+
) *cobra.Command {
35+
usage := fmt.Sprintf("%v <command>", finchRootCmd)
36+
rootCmd := &cobra.Command{
37+
Use: usage,
38+
Short: "Finch: open-source container development tool",
39+
SilenceUsage: true,
40+
SilenceErrors: true,
41+
Version: version.Version,
42+
}
43+
// TODO: Decide when to forward --debug to the dependencies
44+
// (e.g. nerdctl for container commands and limactl for VM commands).
45+
rootCmd.PersistentFlags().Bool("debug", false, "running under debug mode")
46+
rootCmd.PersistentPreRunE = func(cmd *cobra.Command, _ []string) error {
47+
// running commands under debug mode will print out debug logs
48+
debugMode, _ := cmd.Flags().GetBool("debug")
49+
if debugMode {
50+
logger.SetLevel(flog.Debug)
51+
}
52+
return nil
53+
}
54+
55+
ncc := command.NewNerdctlCmdCreator(ecc,
56+
logger,
57+
fp.LimaHomePath(),
58+
fp.LimactlPath(),
59+
fp.QEMUBinDir(),
60+
system.NewStdLib(),
61+
)
62+
lima := wrapper.NewLimaWrapper()
63+
supportBundleBuilder := support.NewBundleBuilder(
64+
logger,
65+
fs,
66+
support.NewBundleConfig(fp, finchRootPath),
67+
fp,
68+
ecc,
69+
ncc,
70+
lima,
71+
)
72+
73+
// append nerdctl commands
74+
allCommands := initializeNerdctlCommands(ncc, ecc, logger, fs, fc)
75+
// append finch specific commands
76+
allCommands = append(allCommands,
77+
newVersionCommand(ncc, logger, stdOut),
78+
virtualMachineCommands(logger, fp, ncc, ecc, fs, fc, home, finchRootPath),
79+
newSupportBundleCommand(logger, supportBundleBuilder, ncc),
80+
newGenDocsCommand(rootCmd, logger, fs, system.NewStdLib()),
81+
)
82+
83+
rootCmd.AddCommand(allCommands...)
84+
85+
return rootCmd
86+
}

cmd/finch/main_windows.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func dependencies(
2424
fc *config.Finch,
2525
fp path.Finch,
2626
fs afero.Fs,
27-
_ command.LimaCmdCreator,
27+
_ command.NerdctlCmdCreator,
2828
logger flog.Logger,
2929
finchDir string,
3030
) []*dependency.Group {

0 commit comments

Comments
 (0)