From c356246f82210c6bea83e59f3395f6ec91eb53a8 Mon Sep 17 00:00:00 2001 From: Amir Malka Date: Sun, 17 Jul 2022 17:48:19 +0300 Subject: [PATCH] update build process with libgit2 --- .github/workflows/build.yaml | 10 +++++++++- .github/workflows/build_dev.yaml | 8 +++++++- .github/workflows/master_pr_checks.yaml | 8 +++++++- .gitmodules | 3 +++ build.py | 2 +- build/Dockerfile | 12 ++++++++++-- git2go | 1 + go.mod | 2 ++ go.sum | 2 -- httphandler/build.py | 2 +- httphandler/go.mod | 3 +++ httphandler/go.sum | 4 ++++ install_dependencies.py | 15 +++++++++++++++ 13 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 .gitmodules create mode 160000 git2go create mode 100644 install_dependencies.py diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 01135a11..df24b9d4 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -29,12 +29,18 @@ jobs: os: [ubuntu-latest, macos-latest, windows-latest] steps: - uses: actions/checkout@v3 + with: + submodules: recursive + - name: Set up Go uses: actions/setup-go@v3 with: 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: Test core pkg env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -51,7 +57,7 @@ jobs: ArmoAuthServer: auth.armo.cloud ArmoERServer: report.armo.cloud ArmoWebsite: portal.armo.cloud - CGO_ENABLED: 0 + CGO_ENABLED: 1 run: python3 --version && python3 build.py - name: Smoke Testing @@ -93,6 +99,8 @@ jobs: steps: - uses: actions/checkout@v2 + with: + submodules: recursive - name: Set image version id: image-version diff --git a/.github/workflows/build_dev.yaml b/.github/workflows/build_dev.yaml index ef50af89..fed4dda5 100644 --- a/.github/workflows/build_dev.yaml +++ b/.github/workflows/build_dev.yaml @@ -12,6 +12,8 @@ jobs: os: [ubuntu-latest, macos-latest, windows-latest] steps: - uses: actions/checkout@v3 + with: + submodules: recursive - name: Set up Go uses: actions/setup-go@v3 with: @@ -27,6 +29,8 @@ jobs: # - name: Test cmd pkg # run: cd cmd && go test -v ./... + - name: Install dependencies + run: python3 --version && python3 install_dependencies.py - name: Test core pkg env: @@ -44,7 +48,7 @@ jobs: ArmoAuthServer: auth.armo.cloud ArmoERServer: report.armo.cloud ArmoWebsite: portal.armo.cloud - CGO_ENABLED: 0 + CGO_ENABLED: 1 run: python3 --version && python3 build.py - name: Smoke Testing @@ -71,6 +75,8 @@ jobs: steps: - uses: actions/checkout@v2 + with: + submodules: recursive - name: Set image version id: image-version diff --git a/.github/workflows/master_pr_checks.yaml b/.github/workflows/master_pr_checks.yaml index ae9a279e..5d58d3be 100644 --- a/.github/workflows/master_pr_checks.yaml +++ b/.github/workflows/master_pr_checks.yaml @@ -13,11 +13,17 @@ jobs: os: [ubuntu-latest, macos-latest, windows-latest] steps: - uses: actions/checkout@v3 + with: + submodules: recursive + - name: Set up Go uses: actions/setup-go@v3 with: go-version: 1.18 + - name: Install dependencies + run: python3 --version && python3 install_dependencies.py + # - name: Test cmd pkg # run: cd cmd && go test -v ./... @@ -37,7 +43,7 @@ jobs: ArmoAuthServer: auth.armo.cloud ArmoERServer: report.armo.cloud ArmoWebsite: portal.armo.cloud - CGO_ENABLED: 0 + CGO_ENABLED: 1 run: python3 --version && python3 build.py - name: Smoke Testing diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..0cda0556 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "git2go"] + path = git2go + url = https://github.com/libgit2/git2go.git diff --git a/build.py b/build.py index 56e2d646..f035cd4a 100644 --- a/build.py +++ b/build.py @@ -73,7 +73,7 @@ def main(): if armo_auth_server: ldflags += " -X {}={}".format(AUTH_SERVER_CONST, armo_auth_server) - build_command = ["go", "build", "-o", ks_file, "-ldflags" ,ldflags] + build_command = ["go", "build", "-tags=static", "-o", ks_file, "-ldflags" ,ldflags] print("Building kubescape and saving here: {}".format(ks_file)) print("Build command: {}".format(" ".join(build_command))) diff --git a/build/Dockerfile b/build/Dockerfile index d67403cc..27724661 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -8,17 +8,25 @@ ENV CLIENT=$client ENV GO111MODULE= -ENV CGO_ENABLED=0 +ENV CGO_ENABLED=1 # Install required python/pip ENV PYTHONUNBUFFERED=1 -RUN apk add --update --no-cache python3 && ln -sf python3 /usr/bin/python +RUN apk add --update --no-cache python3 git openssl-dev musl-dev gcc make cmake pkgconfig && ln -sf python3 /usr/bin/python RUN python3 -m ensurepip RUN pip3 install --no-cache --upgrade pip setuptools WORKDIR /work ADD . . +# install git2go +WORKDIR /work +RUN rm -rf /work/git2go +RUN git submodule update --init +WORKDIR /work/git2go +RUN git submodule update --init +RUN make install-static + # build kubescape server WORKDIR /work/httphandler RUN python build.py diff --git a/git2go b/git2go new file mode 160000 index 00000000..9db5de10 --- /dev/null +++ b/git2go @@ -0,0 +1 @@ +Subproject commit 9db5de109c166aa802b85cfae2dced3c4728a00d diff --git a/go.mod b/go.mod index 7b629b3c..3845820f 100644 --- a/go.mod +++ b/go.mod @@ -163,3 +163,5 @@ require ( sigs.k8s.io/json v0.0.0-20220525155127-227cbc7cc124 // indirect sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect ) + +replace github.com/libgit2/git2go/v33 => ./git2go diff --git a/go.sum b/go.sum index 1ebeec2c..7bc527ea 100644 --- a/go.sum +++ b/go.sum @@ -864,8 +864,6 @@ github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/libgit2/git2go/v33 v33.0.9 h1:4ch2DJed6IhJO28BEohkUoGvxLsRzUjxljoNFJ6/O78= -github.com/libgit2/git2go/v33 v33.0.9/go.mod h1:KdpqkU+6+++4oHna/MIOgx4GCQ92IPCdpVRMRI80J+4= github.com/linuxkit/virtsock v0.0.0-20201010232012-f8cee7dfc7a3/go.mod h1:3r6x7q95whyfWQpmGZTu3gk3v2YkMi05HEzl7Tf7YEo= github.com/lunixbochs/vtclean v1.0.0/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= diff --git a/httphandler/build.py b/httphandler/build.py index 7be5c512..b5f01c16 100644 --- a/httphandler/build.py +++ b/httphandler/build.py @@ -69,7 +69,7 @@ def main(): if ArmoAuthServer: ldflags += " -X {}={}".format(AUTH_SERVER_CONST, ArmoAuthServer) - build_command = ["go", "build", "-o", ks_file, "-ldflags" ,ldflags] + build_command = ["go", "build", "-tags=static", "-o", ks_file, "-ldflags" ,ldflags] print("Building kubescape and saving here: {}".format(ks_file)) print("Build command: {}".format(" ".join(build_command))) diff --git a/httphandler/go.mod b/httphandler/go.mod index 01489569..f30e39b6 100644 --- a/httphandler/go.mod +++ b/httphandler/go.mod @@ -99,6 +99,7 @@ require ( github.com/json-iterator/go v1.1.12 // indirect github.com/jung-kurt/gofpdf v1.16.2 // indirect github.com/kevinburke/ssh_config v1.2.0 // indirect + github.com/libgit2/git2go/v33 v33.0.9 // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/mattn/go-colorable v0.1.12 // indirect github.com/mattn/go-isatty v0.0.14 // indirect @@ -165,3 +166,5 @@ require ( sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect sigs.k8s.io/yaml v1.3.0 // indirect ) + +replace github.com/libgit2/git2go/v33 => ../git2go diff --git a/httphandler/go.sum b/httphandler/go.sum index 0077f8b2..7f67971b 100644 --- a/httphandler/go.sum +++ b/httphandler/go.sum @@ -717,6 +717,8 @@ github.com/google/pprof v0.0.0-20210601050228-01bbb1931b22/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4= +github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -1357,6 +1359,7 @@ golang.org/x/crypto v0.0.0-20200414173820-0848c9571904/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= @@ -1609,6 +1612,7 @@ golang.org/x/sys v0.0.0-20201117170446-d9b008d0a637/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201202213521-69691e467435/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/install_dependencies.py b/install_dependencies.py new file mode 100644 index 00000000..a185aa98 --- /dev/null +++ b/install_dependencies.py @@ -0,0 +1,15 @@ +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 && cd git2go && git submodule update --init&& make install-static") + else: + raise OSError("Platform %s is not supported!" % (current_platform)) + +if __name__ == '__main__': + main()