diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 11967af4..25b28de4 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -38,8 +38,10 @@ jobs: go-version: 1.18 # - name: Test cmd pkg # run: cd cmd && go test -v ./... - - name: Install dependencies - run: python3 --version && python3 install_dependencies.py + + - name: Install libgit2 + run: make libgit2 + if: matrix.os != 'windows-latest' - name: Test core pkg env: diff --git a/.github/workflows/build_dev.yaml b/.github/workflows/build_dev.yaml index 78189a28..153bab25 100644 --- a/.github/workflows/build_dev.yaml +++ b/.github/workflows/build_dev.yaml @@ -29,8 +29,10 @@ jobs: # - name: Test cmd pkg # run: cd cmd && go test -v ./... - - name: Install dependencies - run: python3 --version && python3 install_dependencies.py + + - name: Install libgit2 + run: make libgit2 + if: matrix.os != 'windows-latest' - name: Test core pkg env: diff --git a/.github/workflows/pr_checks.yaml b/.github/workflows/pr_checks.yaml index b3ca159d..a49c7833 100644 --- a/.github/workflows/pr_checks.yaml +++ b/.github/workflows/pr_checks.yaml @@ -21,8 +21,9 @@ jobs: with: go-version: 1.18 - - name: Install dependencies - run: python3 --version && python3 install_dependencies.py + - name: Install libgit2 + run: make libgit2 + if: matrix.os != 'windows-latest' # - name: Test cmd pkg # run: cd cmd && go test -v ./... diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..1fd42de0 --- /dev/null +++ b/Makefile @@ -0,0 +1,20 @@ +.PHONY: test all build libgit2 + +# default task invoked while running make +all: libgit2 build + +export CGO_ENABLED=1 + +# build and install libgit2 +libgit2: + git submodule update --init --recursive + cd git2go; make install-static + +# go build tags +TAGS = "static" + +build: + go build -v -tags=$(TAGS) . + +test: + go test -v -tags=$(TAGS) ./... diff --git a/README.md b/README.md index 7d656a41..80bea113 100644 --- a/README.md +++ b/README.md @@ -144,9 +144,6 @@ home-manager: Or to your profile (not preferred): `nix-env --install -A nixpkgs.kubescape` -## Install using Go - -With a sufficient version of `go` you can install and build with `go install github.com/armosec/kubescape/v2@latest` ## Usage & Examples @@ -302,7 +299,6 @@ Now you can submit the results to the Kubescape SaaS version - kubescape submit results path/to/results.json ``` - # Integrations ## VS Code Extension @@ -315,6 +311,57 @@ Scan the YAML files while writing them using the [vs code extension](https://git View Kubescape scan results directly in [Lens IDE](https://k8slens.dev/) using kubescape [Lens extension](https://github.com/armosec/lens-kubescape/blob/master/README.md) + +# Building Kubescape + +## Windows + +Simply run `go build .` OR `make build` + +## Linux / MacOS + +1. Install libgit2 dependency (first time): `make libgit2` +2. Build: `make build` +3. Test: `make test` + +## VS code configuration samples + +You can use the samples files below to setup your VS code environment for building and debugging purposes. + + +```json5 +// .vscode/settings.json +{ + "go.testTags": "static", + "go.buildTags": "static", + "go.toolsEnvVars": { + "CGO_ENABLED": "1" + } +} +``` + +```json5 +// .vscode/launch.json∂ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Launch Package", + "type": "go", + "request": "launch", + "mode": "auto", + "program": "${workspaceFolder}/main.go", + "args": [ + "scan", + "--logger", + "debug" + ], + "buildFlags": "-tags=static" + } + ] +} +``` + # Under the hood ## Technology diff --git a/build/Dockerfile b/build/Dockerfile index dfde7bca..542bc210 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -19,11 +19,9 @@ RUN pip3 install --no-cache --upgrade pip setuptools WORKDIR /work ADD . . -# install git2go +# install libgit2 WORKDIR /work -RUN git submodule update --init --recursive -WORKDIR /work/git2go -RUN make install-static +RUN rm -rf git2go && make libgit2 # build kubescape server WORKDIR /work/httphandler diff --git a/install_dependencies.py b/install_dependencies.py deleted file mode 100644 index 096f6d0d..00000000 --- a/install_dependencies.py +++ /dev/null @@ -1,15 +0,0 @@ -import os -import platform - - -def main(): - current_platform = platform.system() - if current_platform == "Windows": - pass - elif current_platform == "Linux" or current_platform == "Darwin": - os.system(f"git submodule update --init --recursive --init && cd git2go && make install-static") - else: - raise OSError("Platform %s is not supported!" % (current_platform)) - -if __name__ == '__main__': - main()