From 92bf1866aea2dd5128c22171142d44095a04c533 Mon Sep 17 00:00:00 2001 From: Mauro Ezequiel Moltrasio Date: Tue, 2 Apr 2024 13:01:05 +0200 Subject: [PATCH] Add os-uno devcontainer --- Makefile | 6 +++++- collector/Dockerfile | 3 ++- collector/clangd.yaml | 1 + lua/init.lua | 25 +++++++++++++++++++------ lua/os-uni.lua | 24 ++++++++++++++++++++++++ os-uni/Containerfile | 18 ++++++++++++++++++ os-uni/Makefile | 7 +++++++ os-uni/clangd.yaml | 13 +++++++++++++ 8 files changed, 89 insertions(+), 8 deletions(-) create mode 100644 lua/os-uni.lua create mode 100644 os-uni/Containerfile create mode 100644 os-uni/Makefile create mode 100644 os-uni/clangd.yaml diff --git a/Makefile b/Makefile index b244adf..4f86544 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ .PHONY: all -all: collector falco clean +all: collector falco os-uni clean kluars xlate $(CURDIR)/lua | podman play kube - .PHONY: clean @@ -13,3 +13,7 @@ collector: .PHONY: falco falco: make -C falco-libs build + +.PHONY: os-uni +os-uni: + make -C os-uni build diff --git a/collector/Dockerfile b/collector/Dockerfile index c731370..2de339d 100644 --- a/collector/Dockerfile +++ b/collector/Dockerfile @@ -9,7 +9,8 @@ RUN dnf install -y epel-release && \ dnf clean all && \ ln -s $(which ccache) /usr/local/bin/gcc && \ ln -s $(which ccache) /usr/local/bin/g++ && \ - echo "" > /etc/profile.d/ccache.sh + echo "" > /etc/profile.d/ccache.sh && \ + echo 'export MAKEFLAGS="-j$(nproc)"' >> /root/.bashrc ENV CC=/usr/local/bin/gcc ENV CXX=/usr/local/bin/g++ diff --git a/collector/clangd.yaml b/collector/clangd.yaml index c166911..21ce036 100644 --- a/collector/clangd.yaml +++ b/collector/clangd.yaml @@ -10,6 +10,7 @@ Diagnostics: - readability-identifier-length - modernize-use-nodiscard - modernize-use-trailing-return-type + - cppcoreguidelines-avoid-magic-numbers CheckOptions: readability-identifier-naming.NamespaceCase: lower_case readability-identifier-naming.ClassCase: CamelCase diff --git a/lua/init.lua b/lua/init.lua index 13b53ce..3591ff1 100644 --- a/lua/init.lua +++ b/lua/init.lua @@ -1,8 +1,12 @@ local collector_repo = os.getenv('GOPATH') .. '/src/github.com/stackrox/collector' local falco_repo = os.getenv('GOPATH') .. '/src/github.com/falcosecurity/libs' +local os_uni_repo = os.getenv('GOPATH') .. '/src/github.com/molter73/os-uni' +local user_name = os.getenv("USER") +local collector_home_mountpath = '/home/' .. user_name .. '/go/src/github.com/stackrox/collector' local collector = require('collector') local falco = require('falco') +local os_uni = require('os-uni') local collector_claim = collector.volume_claim() local falco_claim = falco.volume_claim() @@ -17,6 +21,7 @@ local volumes = { { name = 'docker-sock', hostPath = { path = '/var/run/docker.sock', } }, { name = 'collector-repo', hostPath = { path = collector_repo, } }, { name = 'falco-repo', hostPath = { path = falco_repo, } }, + { name = 'os-uni-repo', hostPath = { path = os_uni_repo, } }, { name = 'collector-ccache', persistentVolumeClaim = { claimName = collector_claim.metadata.name } }, { name = 'falco-ccache', persistentVolumeClaim = { claimName = falco_claim.metadata.name, } }, } @@ -24,12 +29,13 @@ local volumes = { local collector_opts = { repo_path = collector_repo, volumes = { - { mountPath = '/host/proc', name = 'proc-fs', readOnly = true, }, - { mountPath = '/host/sys', name = 'sys-fs', readOnly = true, }, - { mountPath = '/host/etc', name = 'etc-fs', readOnly = true, }, - { mountPath = '/host/usr/lib', name = 'usr-lib-fs', readOnly = true, }, - { mountPath = '/root/.cache/ccache', name = 'collector-ccache', }, - { mountPath = collector_repo, name = 'collector-repo', }, + { mountPath = '/host/proc', name = 'proc-fs', readOnly = true, }, + { mountPath = '/host/sys', name = 'sys-fs', readOnly = true, }, + { mountPath = '/host/etc', name = 'etc-fs', readOnly = true, }, + { mountPath = '/host/usr/lib', name = 'usr-lib-fs', readOnly = true, }, + { mountPath = '/root/.cache/ccache', name = 'collector-ccache', }, + { mountPath = collector_repo, name = 'collector-repo', }, + { mountPath = collector_home_mountpath, name = 'collector-repo', }, }, } @@ -49,6 +55,12 @@ local falco_opts = { } } +local os_uni_opts = { + repo_path = os_uni_repo, + volumes = { + { mountPath = os_uni_repo, name = 'os-uni-repo', }, + }, +} local metadata = { name = 'devcontainers', @@ -62,6 +74,7 @@ local spec = { containers = { collector.setup(collector_opts), falco.setup(falco_opts), + os_uni.setup(os_uni_opts), }, volumes = volumes, } diff --git a/lua/os-uni.lua b/lua/os-uni.lua new file mode 100644 index 0000000..61dc3e6 --- /dev/null +++ b/lua/os-uni.lua @@ -0,0 +1,24 @@ +local name = 'os-uni-builder' + +local M = {} + +M.setup = function(opts) + local repo_path = opts.repo_path or os.exit(1) + return { + name = name, + image = 'quay.io/mmoltras/devcontainers:os-uni', + workingDir = repo_path, + command = { '/bin/bash', }, + env = { + { name = 'CMAKE_EXPORT_COMPILE_COMMANDS', value = 'ON', }, + }, + securityContext = { + privileged = true, + }, + volumeMounts = opts.volumes or {}, + stdin = true, + tty = true, + } +end + +return M diff --git a/os-uni/Containerfile b/os-uni/Containerfile new file mode 100644 index 0000000..34c97cc --- /dev/null +++ b/os-uni/Containerfile @@ -0,0 +1,18 @@ +FROM fedora:39 + +# hadolint ignore=DL3041 +RUN dnf install -y \ + gcc \ + gdb \ + procps \ + make \ + ncurses \ + python3-pip \ + # vvv clangd vvv + clang-tools-extra \ + bear && \ + dnf clean all + +COPY clangd.yaml /root/.config/clangd/config.yaml + +WORKDIR /workdir diff --git a/os-uni/Makefile b/os-uni/Makefile new file mode 100644 index 0000000..a3d049b --- /dev/null +++ b/os-uni/Makefile @@ -0,0 +1,7 @@ +.PHONY: all +all: build + +.PHONY: build +build: + docker build -t quay.io/mmoltras/devcontainers:os-uni \ + -f $(CURDIR)/Containerfile $(CURDIR) diff --git a/os-uni/clangd.yaml b/os-uni/clangd.yaml new file mode 100644 index 0000000..243c2bc --- /dev/null +++ b/os-uni/clangd.yaml @@ -0,0 +1,13 @@ +Diagnostics: + ClangTidy: + Add: + - bugprone* + - cppcoreguidelines* + - modernize* + - performance* + - readability* + Remove: + - readability-identifier-length + - modernize-use-nodiscard + - modernize-use-trailing-return-type + - cppcoreguidelines-avoid-magic-numbers