-
-
Notifications
You must be signed in to change notification settings - Fork 397
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* chore: move CGO_ENABLE arg to makefile * chore: use actual current executable path * chore: fix generated binary on M1 mac * net: fix #344 qemu process missing gvproxy config * chore: update gitignore * chore: refactor, mock filesystem in tests * chore: update nix environment * chore: refactor Makefile (#354) * refactor: extract build logic from build.sh to Makefile * chore: add test rule to Makefile * apply review suggestion Co-authored-by: Abiola Ibrahim <[email protected]> * fix: use defined `OUTPUT_DIR` variable * chore: remove -race flag from test as it needs CGO_ENABLED=1 * chore: generate sha in binaries directory * chore: propagate Go build environment variables Co-authored-by: Abiola Ibrahim <[email protected]> * chore: disable CGO * chore: remove empty file Co-authored-by: tricktron <[email protected]>
- Loading branch information
Showing
17 changed files
with
212 additions
and
34 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 |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
_output/ | ||
_build/ | ||
bin/ | ||
result |
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
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
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,34 @@ | ||
let | ||
pkgs = import <nixpkgs> { }; | ||
in | ||
let | ||
# override Lima to remove wrapper for qemu | ||
# https://github.com/NixOS/nixpkgs/blob/f2537a505d45c31fe5d9c27ea9829b6f4c4e6ac5/pkgs/applications/virtualization/lima/default.nix#L35 | ||
lima = pkgs.lima.overrideAttrs (old: { | ||
installPhase = '' | ||
runHook preInstall | ||
mkdir -p $out | ||
cp -r _output/* $out | ||
runHook postInstall | ||
''; | ||
}); | ||
in | ||
pkgs.buildGo118Module rec { | ||
name = "colima"; | ||
pname = "colima"; | ||
src = ./.; | ||
nativeBuildInputs = with pkgs; [ installShellFiles makeWrapper git coreutils ]; | ||
vendorSha256 = "sha256-jDzDwK7qA9lKP8CfkKzfooPDrHuHI4OpiLXmX9vOpOg="; | ||
preConfigure = '' | ||
ldflags="-X github.com/abiosoft/colima/config.appVersion=$(git describe --tags --always) | ||
-X github.com/abiosoft/colima/config.revision=$(git rev-parse HEAD)" | ||
''; | ||
postInstall = '' | ||
wrapProgram $out/bin/colima \ | ||
--prefix PATH : ${pkgs.lib.makeBinPath [ pkgs.qemu lima ]} | ||
installShellCompletion --cmd colima \ | ||
--bash <($out/bin/colima completion bash) \ | ||
--fish <($out/bin/colima completion fish) \ | ||
--zsh <($out/bin/colima completion zsh) | ||
''; | ||
} |
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
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,50 @@ | ||
package fsutil | ||
|
||
import ( | ||
"io/fs" | ||
"os" | ||
"testing/fstest" | ||
) | ||
|
||
// FS is the host filesystem implementation. | ||
var FS FileSystem = DefaultFS{} | ||
|
||
// MkdirAll calls FS.MakedirAll | ||
func MkdirAll(path string, perm os.FileMode) error { return FS.MkdirAll(path, perm) } | ||
|
||
// Open calls FS.Open | ||
func Open(name string) (fs.File, error) { return FS.Open(name) } | ||
|
||
// FS is abstraction for filesystem. | ||
type FileSystem interface { | ||
MkdirAll(path string, perm os.FileMode) error | ||
fs.FS | ||
} | ||
|
||
var _ FileSystem = DefaultFS{} | ||
var _ FileSystem = fakeFS{} | ||
|
||
// DefaultFS is the default OS implementation of FileSystem. | ||
type DefaultFS struct{} | ||
|
||
// Open implements FS | ||
func (DefaultFS) Open(name string) (fs.File, error) { return os.Open(name) } | ||
|
||
// MkdirAll implements FS | ||
func (DefaultFS) MkdirAll(path string, perm fs.FileMode) error { return os.MkdirAll(path, perm) } | ||
|
||
// FakeFS is a mock FS. The following can be done in a test before usage. | ||
// osutil.FS = osutil.FakeFS | ||
var FakeFS FileSystem = fakeFS{} | ||
|
||
type fakeFS struct{} | ||
|
||
// Open implements FileSystem | ||
func (fakeFS) Open(name string) (fs.File, error) { | ||
return fstest.MapFS{name: &fstest.MapFile{ | ||
Data: []byte("fake file - " + name), | ||
}}.Open(name) | ||
} | ||
|
||
// MkdirAll implements FileSystem | ||
func (fakeFS) MkdirAll(path string, perm fs.FileMode) error { return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package osutil | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
const EnvColimaBinary = "COLIMA_BINARY" | ||
|
||
// Executable returns the path name for the executable that started | ||
// the current process. | ||
func Executable() string { | ||
e, err := func(s string) (string, error) { | ||
// prioritize env var in case this is a nested process | ||
if e := os.Getenv(EnvColimaBinary); e != "" { | ||
return e, nil | ||
} | ||
|
||
if filepath.IsAbs(s) { | ||
return s, nil | ||
} | ||
|
||
e, err := exec.LookPath(s) | ||
if err != nil { | ||
return "", fmt.Errorf("error looking up '%s' in PATH: %w", s, err) | ||
} | ||
|
||
abs, err := filepath.Abs(e) | ||
if err != nil { | ||
return "", fmt.Errorf("error computing absolute path of '%s': %w", e, err) | ||
} | ||
|
||
return abs, nil | ||
}(os.Args[0]) | ||
|
||
if err != nil { | ||
// this should never happen, thereby it is safe to do | ||
logrus.Warnln(fmt.Errorf("cannot detect current running executable: %w", err)) | ||
logrus.Warnln("falling back to first CLI argument") | ||
return os.Args[0] | ||
} | ||
|
||
return e | ||
} |
Oops, something went wrong.