open-policy-agent / kube-mgmt

Sidecar for managing OPA instances in Kubernetes.
Apache License 2.0
234 stars 105 forks source link

help to build kube-mgmt locally. #255

Closed porwalameet closed 2 months ago

porwalameet commented 2 months ago

I have all the pre-req installed on the WSL ubuntu.

Environment: WSL ubuntu Required binary installed: just, skaffold, go, k3d and helm.

I am trying to build kube-mgmt locally for testing.

~/code/kube-mgmt-pipeline/kube-mgmt$ go version
go version go1.22.2 linux/amd64
~/code/kube-mgmt-pipeline/kube-mgmt$ just --version
just 1.27.0
~/code/kube-mgmt-pipeline/kube-mgmt$ helm version
version.BuildInfo{Version:"v3.9.4", GitCommit:"dbc6d8e20fe1d58d50e6ed30f09a04a77e4c68db", GitTreeState:"clean", GoVersion:"go1.17.13"}
~/code/kube-mgmt-pipeline/kube-mgmt$ k3d version
k3d version v5.6.3
k3s version v1.28.8-k3s1 (default)
~/code/kube-mgmt-pipeline/kube-mgmt$ skaffold version
v2.12.0

From the command, i have cloned kube-mgmt and trying to build image locally before making any changes. I get the following error:

~/code/kube-mgmt-pipeline/kube-mgmt$ just build
set value default-repo to localhost:5000 for context kind-c1
skaffold build --file-output=tags.json --platform=linux/amd64
Generating tags...
 - openpolicyagent/kube-mgmt -> localhost:5000/openpolicyagent_kube-mgmt:8.5.7-1-g6ce4ced1-dirty
Checking cache...
 - openpolicyagent/kube-mgmt: Not found. Building
Starting build...
Found [kind-c1] context, using local docker daemon.
Building [openpolicyagent/kube-mgmt]...
Target platforms: [linux/amd64]
Using base alpine:3.19.1@sha256:c5b1261d6d3e43071626931fc004f70149baeba2c8ec672bd4f27761f8e1ad6b for github.com/open-policy-agent/kube-mgmt/cmd/kube-mgmt
Using build config openpolicyagent/kube-mgmt for github.com/open-policy-agent/kube-mgmt/cmd/kube-mgmt
Building github.com/open-policy-agent/kube-mgmt/cmd/kube-mgmt for linux/amd64
Publishing localhost:5000/openpolicyagent_kube-mgmt:8.5.7-1-g6ce4ced1-dirty
could not build and publish ko image "openpolicyagent/kube-mgmt": failed to publish ko image: error publishing ko://github.com/open-policy-agent/kube-mgmt/cmd/kube-mgmt: Get "https://localhost:5000/v2/": dial tcp 127.0.0.1:5000: connect: connection refused; Get "http://localhost:5000/v2/": dial tcp 127.0.0.1:5000: connect: connection refused
error: Recipe `build` failed on line 65 with exit code 1

I want to build the image and tag separately and pushed registry as manual commands. Can someone please point, any discrepancy from expected set of commands. Thanks.

To add, I followed the workflow file of github action: Steps:

  1. install staticcheck module using command: go install honnef.co/go/tools/cmd/staticcheck@2022.1.3
  2. run just test , and returns following error:
    ~/code/kube-mgmt-pipeline/kube-mgmt$ just test
    go vet ./...
    staticcheck ./...
    -: cannot import "internal/cpu" (unknown bexport format version -1 ("u\x01\x00\x00\x00\x00\x00\x00\x00L\x00\x00\x00N\x00\x00\x00P\x00\x00\x00R\x00\x00\x00_\x00\x00\x00m\x00\x00\x00z\x00\x00\x00\x87\x00\x00\x00\x94\x00\x00\x00\x94\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x0f\x00\x00\x00.\x00\x00\x00/\x00\x00\x006\x00\x00\x00:\x00\x00\x00F\x00\x00\x00N\x00\x00\x00V\x00\x00\x00b\x00\x00\x00e\x00\x00\x00k\x00\x00\x00s\x00\x00\x00z\x00\x00\x00\x81\x00\x00\x00\x8a\x00\x00\x00\x92\x00\x00\x00\x9c\x00\x00\x00\xa4\x00\x00\x00\xae\x00\x00\x00\xb3\x00\x00\x00\xd6\x00\x00\x00\xe6\x00\x00\x00\xf3\x00\x00\x00\xff\x00\x00\x00\x02\x01\x00\x00\f\x01\x00\x00\x10\x01\x00\x00\x16\x01\x00\x00\x1d\x01\x00\x00!\x01\x00\x00(\x01\x00\x00.\x01\x00\x006\x01\x00\x00>\x01\x00\x00G\x01\x00\x00L\x01\x00\x00T\x01\x00\x00\\\x01\x00\x00d\x01\x00\x00k\x01\x00\x00q\x01\x00\x00z\x01\x00\x00\x83\x01\x00\x00\x8c\x01\x00\x00\x95\x01\x00\x00\x9d\x01\x00\x00\xa6\x01\x00\x00\xad\x01\x00\x00\xb2\x01\x00\x00\xb8\x01\x00\x00\xbf\x01\x00\x00\xc7\x01\x00\x00\xcf\x01\x00\x00\xd4\x01\x00\x00\xda\x01\x00\x00\xe0\x01\x00\x00\xe7\x01\x00\x00\xf1\x01\x00\x00\xfc\x01\x00\x00\a\x02\x00\x00\x0e\x02\x00\x00\x15\x02\x00\x00\x1c\x02\x00\x00\"\x02\x00\x00,\x02\x00\x008\x02\x00\x00A\x02\x00\x00J\x02\x00\x00P\x02\x00\x00W\x02\x00\x00_\x02\x00\x00g\x02\x00\x00o\x02\x00\x00r\x02\x00\x00\xb9\x02\x00\x00\xbc\x02\x00\x00\xc1\x02\x00\x00\xc6\x02\x00\x00\xd0\x02\x00\x00\xd6\x02\x00\x00\xde\x02\x00\x00\xe6\x02\x00\x00\xee\x02\x00\x00\xf6\x02\x00\x00\xfe\x02\x00\x00\x06\x03\x00\x00\x0e\x03\x00\x00\x16\x03\x00\x00\x1e\x03\x00\x00&\x03\x00\x00.\x03\x00\x006\x03\x00\x00>\x03\x00\x00\x85\x03\x00\x00\x8c\x03\x00\x00\xa3\x03\x00\x00\xaa\x03\x00\x00\xb1\x03\x00\x00\xb4\x03\x00\x00C\x04\x00\x00F\x04\x00\x00I\x04\x00\x00L\x04\x00\x00{\x04\x00\x00\xda\x04\x00\x00\xf9\x05\x00\x00\f\a\x00\x00\x17\a\x00\x00#\a\x00\x00$\a\x00\x00/\a\x00\x00>\a\x00\x00I\a\x00\x00T\a\x00\x00s\a\x00\x00~\a\x00\x00\x9d\a\x00\x00\xa8\a\x00\x00\xb3\a\x00\x00\xbe\a\x00\x00\xc0\a\x00\x00\xc4\a\x00\x00\xc5\a\x00\x00\xc7\a\x00\x00\xc8\a\x00\x00\xca\a\x00\x00\xcc\a\x00\x00\xd5\a\x00\x00\xd7\a\x00\x00\xdd\a\x00\x00\xdf\a\x00\x00\xe1\a\x00\x00\xe3\a\x00\x00\xeb\a\x00\x00\xf3\a\x00\x00\xfb\a\x00\x00\x03\b\x00\x00\v\b\x00\x00\x13\b\x00\x00\x1b\b\x00\x00#\b\x00\x00+\b\x00\x003\b\x00\x00;\b\x00\x00C\b\x00\x00K\b\x00\x00cpuinternal/cpu$GOROOT/src/internal/cpu/cpu.go_builtinbyteCacheLinePadHasVFPv4HasIDIVAHasV7AtomicsARMHasAESHasPMULLHasSHA1HasSHA2HasSHA512HasCRC32HasATOMICSHasCPUIDIsNeoverseARM64$GOROOT/src/internal/cpu/cpu_x86.goCacheLinePadSizeCacheLineSizeDebugOptionsenvInitializeesc:HasMSAMIPS64XNameHasDARNHasSCVIsPOWER8IsPOWER9IsPOWER10PPC64HasZARCHHasSTFLEHasLDISPHasEIMMHasDFPHasETF3EHHasAESCBCHasAESCTRHasAESGCMHasGHASHHasSHA256HasSHA3HasVXHasVXEHasKDSAHasECDSAHasEDDSAS390XHasADXHasAVXHasAVX2HasAVX512FHasAVX512BWHasAVX512VLHasBMI1HasBMI2HasERMSHasFMAHasOSXSAVEHasPCLMULQDQHasPOPCNTHasRDTSCPHasSHAHasSSE3HasSSSE3HasSSE41HasSSE42X86\x0e\x03\x00\x06\x00\x06\x01\x06\x02\x06\x03\x06\x04\x06\x05\x06\x06\x06\a\x06\b\x06\t\x06")), possibly version skew - reinstall package (compile)
    -: cannot import "internal/goarch" (unknown bexport format version -1 ("u\x01\x00\x00\x00\x00\x00\x00\x003\x00\x00\x005\x00\x00\x007\x00\x00\x008\x00\x00\x00e\x00\x00\x00j\x00\x00\x00\x97\x00\x00\x00\xc4\x00\x00\x00\xf1\x00\x00\x00\xf1\x00\x00\x00\x00\x00\x00\x00\x06\x00\x00\x00\x15\x00\x00\x00:\x00\x00\x00H\x00\x00\x00M\x00\x00\x00P\x00\x00\x00U\x00\x00\x00_\x00\x00\x00h\x00\x00\x00{\x00\x00\x00\xa7\x00\x00\x00\xac\x00\x00\x00\xb2\x00\x00\x00\xb6\x00\x00\x00\xc0\x00\x00\x00\xc5\x00\x00\x00\xcc\x00\x00\x00\xd6\x00\x00\x00\xdb\x00\x00\x00\xe2\x00\x00\x00\xeb\x00\x00\x00\xf2\x00\x00\x00\xfb\x00\x00\x00\x01\x01\x00\x00\t\x01\x00\x00\x13\x01\x00\x00\x1e\x01\x00\x00+\x01\x00\x003\x01\x00\x008\x01\x00\x00?\x01\x00\x00H\x01\x00\x00O\x01\x00\x00X\x01\x00\x00^\x01\x00\x00e\x01\x00\x00l\x01\x00\x00u\x01\x00\x00{\x01\x00\x00\x82\x01\x00\x00\x86\x01\x00\x00\x8c\x01\x00\x00\x98\x01\x00\x00\xa1\x01\x00\x00\xa6\x01\x00\x00\xad\x01\x00\x00\xb4\x01\x00\x00\xb9\x01\x00\x00\xc3\x01\x00\x00\xc7\x01\x00\x00\xae\x02\x00\x00\xb1\x02\x00\x00\xb6\x02\x00\x00\xbb\x02\x00\x00\xc5\x02\x00\x00\xcd\x02\x00\x00\xd5\x02\x00\x00\xdd\x02\x00\x00\xe5\x02\x00\x00\xed\x02\x00\x00\xf5\x02\x00\x00\xfd\x02\x00\x00\x05\x03\x00\x00\r\x03\x00\x00\x15\x03\x00\x00\x1d\x03\x00\x00%\x03\x00\x00-\x03\x00\x005\x03\x00\x00=\x03\x00\x00E\x03\x00\x00M\x03\x00\x00U\x03\x00\x00]\x03\x00\x00e\x03\x00\x00m\x03\x00\x00u\x03\x00\x00}\x03\x00\x00\x85\x03\x00\x00\x8d\x03\x00\x00\x95\x03\x00\x00\x9d\x03\x00\x00\xa5\x03\x00\x00\xad\x03\x00\x00\xb5\x03\x00\x00\xbd\x03\x00\x00\xc5\x03\x00\x00\xcd\x03\x00\x00\xd5\x03\x00\x00\xdd\x03\x00\x00\xe5\x03\x00\x00\xed\x03\x00\x00\xf5\x03\x00\x00\xfd\x03\x00\x00\x05\x04\x00\x00\r\x04\x00\x00\x15\x04\x00\x00\x1d\x04\x00\x00%\x04\x00\x00-\x04\x00\x004\x04\x00\x007\x04\x00\x00:\x04\x00\x00=\x04\x00\x00@\x04\x00\x00N\x04\x00\x00Z\x04\x00\x00h\x04\x00\x00v\x04\x00\x00\x84\x04\x00\x00\x92\x04\x00\x00\xa1\x04\x00\x00\xb1\x04\x00\x00\xbf\x04\x00\x00\xcd\x04\x00\x00\xdb\x04\x00\x00\xe9\x04\x00\x00\xf7\x04\x00\x00\x05\x05\x00\x00\x13\x05\x00\x00!\x05\x00\x00/\x05\x00\x00=\x05\x00\x00K\x05\x00\x00Y\x05\x00\x00g\x05\x00\x00u\x05\x00\x00\x83\x05\x00\x00\x91\x05\x00\x00\x9f\x05\x00\x00\xad\x05\x00\x00\xbb\x05\x00\x00\xc9\x05\x00\x00\xd7\x05\x00\x00\xe5\x05\x00\x00\xf3\x05\x00\x00\x01\x06\x00\x00\x0f\x06\x00\x00\x1d\x06\x00\x00+\x06\x00\x009\x06\x00\x00G\x06\x00\x00U\x06\x00\x00c\x06\x00\x00q\x06\x00\x00\x7f\x06\x00\x00\x8d\x06\x00\x00\x9b\x06\x00\x00\xa9\x06\x00\x00\xb7\x06\x00\x00\xb8\x06\x00\x00\xbc\x06\x00\x00\xbd\x06\x00\x00\xbe\x06\x00\x00\xbf\x06\x00\x00\xc0\x06\x00\x00\xc1\x06\x00\x00\xc2\x06\x00\x00\xc3\x06\x00\x00\xc4\x06\x00\x00\xc5\x06\x00\x00\xc6\x06\x00\x00\xc7\x06\x00\x00\xc8\x06\x00\x00\xc9\x06\x00\x00\xca\x06\x00\x00\xcb\x06\x00\x00\xcc\x06\x00\x00\xcd\x06\x00\x00\xce\x06\x00\x00\xcf\x06\x00\x00\xd0\x06\x00\x00\xd1\x06\x00\x00\xd2\x06\x00\x00\xd3\x06\x00\x00\xd4\x06\x00\x00\xd5\x06\x00\x00\xd6\x06\x00\x00\xd7\x06\x00\x00\xd8\x06\x00\x00\xd9\x06\x00\x00\xda\x06\x00\x00\xdb\x06\x00\x00\xdc\x06\x00\x00\xdd\x06\x00\x00\xde\x06\x00\x00\xdf\x06\x00\x00\xe0\x06\x00\x00\xe1\x06\x00\x00\xe2\x06\x00\x00\xe3\x06\x00\x00\xe4\x06\x00\x00\xe5\x06\x00\x00\xe6\x06\x00\x00\xe7\x06\x00\x00\xef\x06\x00\x00\xf7\x06\x00\x00\xff\x06\x00\x00\a\a\x00\x00\x0f\a\x00\x00\x17\a\x00\x00\x1f\a\x00\x00'\a\x00\x00/\a\x00\x007\a\x00\x00?\a\x00\x00G\a\x00\x00O\a\x00\x00W\a\x00\x00_\a\x00\x00g\a\x00\x00o\a\x00\x00w\a\x00\x00\x7f\a\x00\x00\x87\a\x00\x00\x8f\a\x00\x00\x97\a\x00\x00\x9f\a\x00\x00\xa7\a\x00\x00\xaf\a\x00\x00\xb7\a\x00\x00\xbf\a\x00\x00\xc7\a\x00\x00\xcf\a\x00\x00\xd7\a\x00\x00\xdf\a\x00\x00\xe7\a\x00\x00\xef\a\x00\x00\xf7\a\x00\x00\xff\a\x00\x00\a\b\x00\x00\x0f\b\x00\x00\x17\b\x00\x00\x1f\b\x00\x00'\b\x00\x00/\b\x00\x007\b\x00\x00?\b\x00\x00G\b\x00\x00O\b\x00\x00goarchinternal/goarch$GOROOT/src/internal/goarch/goarch.goArchFamilyTypeAMD64ARMARM64ArchFamilyBigEndianDefaultPhysPageSize$GOROOT/src/internal/goarch/zgoarch_amd64.goamd64GOARCHI386Int64AlignIs386IsAmd64IsAmd64p32IsArmIsArm64IsArm64beIsArmbeIsLoong64IsMipsIsMips64IsMips64leIsMips64p32IsMips64p32leIsMipsleIsPpcIsPpc64IsPpc64leIsRiscvIsRiscv64IsS390IsS390xIsSparcIsSparc64IsWasmLOONG64MIPSMIPS64MinFrameSizePCQuantumPPC64PtrSizeRISCV64S390XStackAlignWASM.\x03\x00\x06\x00\x06\x01\x06\x02\x06\x03\x06\x04\x06\x05\x06\x06\x06\a\x06\b\x06\t\x06")), possibly version skew - reinstall package (compile)
    -: cannot import "math/bits" (unknown bexport format version -1 ("u\x01\x00\x00\x00\x00\x00\x00\x00^\x00\x00\x00`\x00\x00\x00b\x00\x00\x00e\x00\x00\x00\x9d\x00\x00\x00\xbb\x00\x00\x00\xf3\x00\x00\x00+\x01\x00\x00c\x01\x00\x00\x92\x01\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00")), possibly version skew - reinstall package (compile)
    error: Recipe `lint-go` failed on line 35 with exit code 1

    @eshepelyuk

eshepelyuk commented 2 months ago
  1. use just k3d to setup a cluster with registry.
  2. then use just build
porwalameet commented 2 months ago

thanks @eshepelyuk. Is there a way we can just build docker image without spinning up k3d or pushing to local registry which is running at port 5000. The reason for ask is, we have a pipeline where we are trying to clone kube-mgmt, build the code, create docker image, tag and push to private container registry. There will be no local changes.

eshepelyuk commented 2 months ago

Then why do you care about building docker image at all ? Just pull it from dockerhub, tag it however you want and push to your private registry.

porwalameet commented 2 months ago

Agree with your point. Howver, the pipeline does static code analysis and even patch base OS vulnerabilities if any, similar to COPA(https://github.com/project-copacetic/copacetic). So it tries to build from source.

porwalameet commented 2 months ago

@eshepelyuk , if this is the only to build image for kube-mgmt, then we can close the ticket. Thanks.