diff --git a/.gitignore b/.gitignore index 66fd13c903cac02eb9657cd53fb227823484401d..a1eb1811f11befd7a1f1f93a9388049a5044fe45 100644 --- a/.gitignore +++ b/.gitignore @@ -1,15 +1,2 @@ -# Binaries for programs and plugins -*.exe -*.exe~ -*.dll -*.so -*.dylib - -# Test binary, built with `go test -c` -*.test - -# Output of the go coverage tool, specifically when used with LiteIDE *.out - -# Dependency directories (remove the comment below to include it) -# vendor/ +bin/ diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000000000000000000000000000000000000..dd337cd2051195cb5bf9e85eb7e44a82cb057f5c --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,34 @@ +linters: + enable: + - deadcode + - errcheck + - errorlint + - cyclop + - errname + - exhaustive + - exportloopref + - gocritic + - goimports + - gosimple + - govet + - ineffassign + - revive + - staticcheck + - structcheck + - stylecheck + - typecheck + - unused + - varcheck +linters-settings: + stylecheck: + go: "1.17" + gocritic: + enabled-checks: + - hugeParam + - rangeExprCopy + - rangeValCopy + - indexAlloc + - deprecatedComment + cyclop: + max-complexity: 20 + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..ee3cc4d894b8ef24eded3a59435352b923bd78a1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,30 @@ +# Build the manager binary +FROM registry.access.redhat.com/ubi8/go-toolset:1.16.7-5 as builder +ARG VERSION="unknown" + +WORKDIR /opt/app-root + +# TEMPORARY STEPS UNTIL ubi8 releases a go1.17 image +RUN wget -q https://go.dev/dl/go1.17.8.linux-amd64.tar.gz && tar -xzf go1.17.8.linux-amd64.tar.gz +ENV GOROOT /opt/app-root/go +ENV PATH $GOROOT/bin:$PATH +# END OF LINES TO REMOVE + +# Copy the go manifests and source +COPY go.mod go.mod +COPY go.sum go.sum +COPY vendor/ vendor/ +COPY main.go main.go +COPY cmd/ cmd/ +COPY pkg/ pkg/ + +# Build +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -ldflags "-X main.version=$OPVERSION" -mod vendor -a -o manager main.go + +# Create final image from minimal + built binary +FROM registry.access.redhat.com/ubi8/ubi-minimal:8.5-204 +WORKDIR / +COPY --from=builder /opt/app-root/netobserv-agent . +USER 65532:65532 + +ENTRYPOINT ["/netobserv-agent"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..39a000b1202e75969bc8b9f390d75bdeb4624fed --- /dev/null +++ b/Makefile @@ -0,0 +1,68 @@ +# VERSION defines the project version for the bundle. +# Update this value when you upgrade the version of your project. +# To re-generate a bundle for another specific version without changing the standard setup, you can: +# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2) +# - use environment variables to overwrite this value (e.g export VERSION=0.0.2) +VERSION ?= main + +# IMAGE_TAG_BASE defines the namespace and part of the image name for remote images. +# This variable is used to construct full image tags for bundle and catalog images. +IMAGE_TAG_BASE ?= quay.io/netobserv/netobserv-agent + +# Image URL to use all building/pushing image targets +IMG ?= $(IMAGE_TAG_BASE):$(VERSION) + +GOLANGCI_LINT_VERSION = v1.42.1 + +# Image building tool (docker / podman) +ifeq (,$(shell which podman 2>/dev/null)) +OCI_BIN=docker +else +OCI_BIN=podman +endif + +.PHONY: vendors +vendors: + @echo "### Checking vendors" + go mod tidy && go mod vendor + +.PHONY: prereqs +prereqs: + @echo "### Check if prerequisites are met, and installing missing dependencies" + test -f $(go env GOPATH)/bin/golangci-lint || GOFLAGS="" go install github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCI_LINT_VERSION} + +.PHONY: fmt +fmt: ## Run go fmt against code. + @echo "### Formatting code" + go fmt ./... + +.PHONY: lint +lint: prereqs + @echo "### Linting code" + golangci-lint run ./... + +.PHONY: build +build: fmt vendors lint + @echo "### Building project" + go build -ldflags "-X main.version=${VERSION}" -mod vendor -o bin/netobserv-agent cmd/netobserv-agent.go + +.PHONY: test +test: + @echo "### Testing code" + go test ./... -coverpkg=./... -coverprofile cover.out + +.PHONY: coverage-report +coverage-report: + @echo "### Generating coverage report" + go tool cover --func=./cover.out + +.PHONY: coverage-report-html +coverage-report-html: + @echo "### Generating HTML coverage report" + go tool cover --html=./cover.out + +image-build: test ## Build OCI image with the manager. + $(OCI_BIN) build --build-arg VERSION="$(VERSION)" -t ${IMG} . + +image-push: ## Push OCI image with the manager. + $(OCI_BIN) push ${IMG} \ No newline at end of file diff --git a/README.md b/README.md index f4e98d1f06e6403ad47029b631deb8ae86f4d526..1b9d663b73ea76db58e35cc5924e51696df5a9c1 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ -# netobserv-agent +# Network Observability Agent + Network Observability Agent diff --git a/cmd/netobserv-agent.go b/cmd/netobserv-agent.go new file mode 100644 index 0000000000000000000000000000000000000000..8a8c31d34bcb9f2568afc92d6671c97e1377f04d --- /dev/null +++ b/cmd/netobserv-agent.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Printf("hello") +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000000000000000000000000000000000000..d83e2b17e9a38d325b908c58ee58fabec9ee3dd7 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/netobserv/netobserv-agent + +go 1.17